Ninja and updated CMAKE

On macOS Big Sur with Homebrew, I update swipl-devel from git source usually with a shell script (1), which works without problem except when CMAKE via the homebrew is updated, and (1) fails to update. In such case, I need (2) instead of (1). Although it is a small problem, but I would like to know a way to unify (1) and (2) so that it works no matter whether CMAKE via homebrew is updated or not.

Thanks.

(1)

% more ~/bin/update-swipl
#! /bin/sh
echo " updating swipl ..."
pushd ~/src/swipl-devel/build
git pull

echo "Continue ? (Y/n)"
stty raw -echo
char=`dd bs=1 count=1 2>/dev/null`
stty -raw echo

if  [ $char == y ]
then
         echo "Compiling SWI-Prolog."
     continue
else
         echo "No updates."
     exit 0
fi
# only once
# cmake -DCMAKE_INSTALL_PREFIX=$HOME -G Ninja ..
ninja
ninja install

echo "\nDone: swipl built.\n"
popd;
exit 0

(2)

% more ~/bin/ninja-for-updated-cmake
#! /bin/sh
SWIBUILD=$HOME/src/swipl-devel/build
pushd $SWIBUILD

echo "git -C .. submodule update --init"
git -C .. submodule update --init

cmake -DCMAKE_OSX_SYSROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -DCMAKE_INSTALL_PREFIX=$HOME -G Ninja .. && ninja && ninja install

popd
echo "Done: Ninja for updated Cmake.\n"

It is not clear to me why this is needed. Normally, simply running ninja after git has updated the sources should suffice. Ninja will run cmake and that is it.

It is often necessary to restart from the beginning after an OS update, major Homebrew/Macport update and maybe after CMake updates. If there are issues after an update of one of these components I typically remove CMakeCache.txt and run cmake with all the necessary flags.

This all still works fine on my Mac running Big Sur and using Macports for the dependencies. CMake (from Macports) is at version 3.18.4.

I’m typically also too lazy to install and once run ../scripts/swipl-activate. This creates links from $HOME/bin to the binaries in the current build directory.

I have checked that in CMakeCache.txt, there are lines which refers to exact version suffix of the cmake binary. I am afraid that when updating cmake, this cache can’t find the new cmake binary because Homebrew seems not keep that old cmake binary. I don’t care about what is cmake about, but I will check this guess when I have next brew cmake chance.

Thanks ../scripts/swipl-activate etc. .

CMAKE_COMMAND:INTERNAL=/usr/local/Cellar/cmake/3.19.1/bin/cmake                     
//Path to cpack program executable.                                                 
CMAKE_CPACK_COMMAND:INTERNAL=/usr/local/Cellar/cmake/3.19.1/bin/cpack               
//Path to ctest program executable.                                                 
CMAKE_CTEST_COMMAND:INTERNAL=/usr/local/Cellar/cmake/3.19.1/bin/ctest               
//ADVANCED property for variable: CMAKE_CXX_COMPILER       

EDIT.

I noticed that brew info cmake says cmake not installed. I am confused. So, after uninstalling cmake, I have installed it, this time, by

brew install --cask cmake

I will see what happens at next cmake update.

This all suggests you should remove CMakeCache.txt and re-run cmake with the proper install prefix and whatever options you need. CMake uses as much as possible absolute paths to binaries, headers and libraries. I guess they do so to make re-running independent from environment variables. The downside is that if tools and libraries get updated you typically have to re-run from scratch.

Sounds reasonable. I will insert a few of lines in the shell script adding option to remove CMakeCache.txt before calling ninja. Thanks.