Skip to content

Instantly share code, notes, and snippets.

@kopp
Created November 12, 2024 13:17
Show Gist options
  • Select an option

  • Save kopp/a98a803ff2eff5738815f6cfa8e88f91 to your computer and use it in GitHub Desktop.

Select an option

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)
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}")
mkdir source
mv CMakeLists.txt source/
mkdir build
cmake -S source -B build
ls build/Makefile build/build.ninja
@J-Siu
Copy link

J-Siu commented Nov 12, 2024

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.

@kopp
Copy link
Author

kopp commented Nov 12, 2024

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