The way I build CMake projects cross platform is the following:
/project-root> mkdir build
/project-root> cd build
/project-root/build> cmake -G "<generator>" -DCMAKE_INSTALL_PREFIX=stage ..
/project-root/build> cmake --build . --target=install --config=Release
./project-root/build/stage
- the path is always considered relative to the current directory if it is not absolute).
with the buildsystem configured in the line before. It will execute the install
target which also builds all necessary dependent targets if they need to be built and then copies the files into the CMAKE_INSTALL_PREFIX
(which in this case is ./project-root/build/stage
. For multi-configuration builds, like in Visual Studio, you can also specify the configuration with the optional --config <config>
flag.cmake --build
command is that it works for all generators (i.e. makefiles and Visual Studio) without needing different commands.Afterwards I use the installed files to create packages or include them in other projects...