Created
October 26, 2022 14:18
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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