I have
dir
CMakeLists.txt
main.c
subdir
CMakeLists.txt
file1.c
file2.c
I am trying to build a target like so
dir CMakeLists.txt has
add_subdirectory(subdir)
add_executable(main main.c ${EXTRA_SOURCES})
subdir CMakeLists.txt has
set(EXTRA_SOURCES file1.c file2.c)
I get a linking error for file1.c and file2.c. They are not being compiled into main binary. I have tried switching
adding_executable(main main.c ${EXTRA_SOURCES})
add_subdirectory(subdir)
I still get linking errors. The compiler will give undefined reference to ...
because file1.c and file2.c were not added to main.c objects.
How do I properly set cmake to compile files in the sub directory to the main executable in the main directory?