Skip to content

Instantly share code, notes, and snippets.

@nadiaholmquist
Created October 26, 2022 14:18
Show Gist options
  • Save nadiaholmquist/7416df540c273bc0e5f57a3ef38d46e7 to your computer and use it in GitHub Desktop.
Save nadiaholmquist/7416df540c273bc0e5f57a3ef38d46e7 to your computer and use it in GitHub Desktop.
Small hacky script to update the CMake version pointed to in build directories created by Homebrew's CMake
#!/usr/bin/env ruby
if ARGV.size < 1 then
puts "Usage: #{$0} <build-dir>"
exit
end
build_dir=ARGV[0]
cmake_prefix=File.realpath(`brew --prefix cmake`.strip)
cellar_cmake_path=File.dirname(cmake_prefix)
cache_file="#{build_dir}/CMakeCache.txt"
unless File.exist? cache_file then
puts "#{build_dir} doesn't look like a CMake build directory"
exit
end
new_file = File.open("#{cache_file}.new", "w")
File.readlines(cache_file).each do |line|
if line.match? /.*?=#{cellar_cmake_path}/ then
line = line.sub(/#{cellar_cmake_path}\/.+?\//, "#{cmake_prefix}/")
end
new_file.write(line)
end
new_file.close
File.rename(cache_file, "#{cache_file}.old")
File.rename("#{cache_file}.new", cache_file)
exec("cmake", "-B", build_dir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment