I am porting project from Makefile to cmake. There is a CFLAG/CXXFLAG in Makefile -include "SystemTest.h"
. I tried to add this to my toolchain file directly to CMAKE_C_FLAGS
and CMAKE_CXX_FLAGS
but then test compilation fails because it cannot find SystemTest.h
.
I searched and found answers like these: Can I force cmake to include my header file in specific targets? and cmake include header into every source file which looked promising but didn't work for me.
Here are the lines where I use add_executable. Commented code is what I already tried:
add_executable(my_target ${SRC})
if (WIN32)
target_link_libraries(my_target PRIVATE module_a module_b module_c module_d module_e module_f)
elseif(UNIX)
target_link_libraries(my_target PRIVATE module_a module_b module_c module_d module_e module_f ${CURSES_LIBRARIES})
else(WIN32)
message(FATAL_ERROR "Not supported OS.")
endif(WIN32)
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -include SystemTest.h")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include SystemTest.h")
# add_definitions(-include SystemTest.h)
# target_compile_definitions(cherrySim_runner
# PRIVATE $<$<COMPILE_LANGUAGE:C>:-include SystemTest.h>
# $<$<COMPILE_LANGUAGE:CXX>:-include SystemTest.h>
# )
# target_compile_definitions(cherrySim_runner "-include SystemTest.h")
CMake/gcc fails when compiling files from module_b
complaining about stuff that should come from SystemTest.h
.