Propagating CXX flags to out of source projects?

Like I said this works for me in CMake 3.16. I’ve tested both add_compile_definitions() and add_compile_options(). Both of these propagate correctly when using add_subdirectory(../src2 src2). The command I use when running CMake is cmake -S src1 -B test_build. Where src1 and src2 are at the same directory level.

$ cat src1/CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(ProjectName)

#add_compile_definitions(testflag1)
add_compile_options(-Dtestflag1)
add_subdirectory(../src2 src2)
add_executable(exe_test file1.c)
target_link_libraries(exe_test lib2)
1 Like