Created
November 12, 2024 13:17
-
-
Save kopp/a98a803ff2eff5738815f6cfa8e88f91 to your computer and use it in GitHub Desktop.
cmake: Selecting a generator within CMakeLists.txt (SO https://stackoverflow.com/q/11269833)
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
cmake_minimum_required(VERSION 3.31.0) | |
project(build_with_ninja CXX) | |
set(CMAKE_GENERATOR "Ninja" CACHE INTERNAL "" FORCE) | |
message("generator is set to ${CMAKE_GENERATOR}") | |
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
mkdir source | |
mv CMakeLists.txt source/ | |
mkdir build | |
cmake -S source -B build | |
ls build/Makefile build/build.ninja |
Interestingly I still get a Makefile
in this case @J-Siu ...
So to confirm, if you do not set the generator, you get a Makefile (system default) and when you run the code above you get a ninja file?
I'm running on Arch Linux with cmake
cmake version 3.31.0
CMake suite maintained and supported by Kitware (kitware.com/cmake).
I am on MacOS. I ran into this as VSCode seems to work better with ninja(as I don't know how to configure vscode task yet). I used the above to force a switch from makefile to ninja.
ok, interesting. So I cannot confirm, but glad that it works for you :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Following is what I did:
Command line: