How do I write a CMakeLists.txt file so that cmake generates a Makefile with functionality equivalent to
all: proj
debug: CXXFLAGS += -DDEBUG -g -Og
debug: proj
proj:
$(CXX) $(CXXFLAGS) main.cpp -o proj
In other words, I want to be able to build the same executable in the same folder with make [build_target]
, but depending on the build target, with different flags.
Currently I have
cmake_minimum_required(VERSION 3.12)
set(PROJ_NAME "proj")
project(${PROJ_NAME} CXX)
add_executable(${PROJ_NAME} main.cpp)
add_custom_target(debug)
target_compile_definitions(debug PUBLIC -DDEBUG -g -Og)
But when I m calling cmake, I get an error saying target_compile_definitions called with non-compilable target type
, and I don t know how to make it "compilable".