I've run into an issue, I want to compile all my source file but each of them have an main method. My idea was to take cmake and run an for each statement and create the executable for them.
file(GLOB_RECURSE my_c_list RELATIVE ${CMAKE_SOURCE_DIR} "src/*")
foreach(file_path ${my_c_list})
message(${file_path})
string( REPLACE ".c" "" name ${file_path} )
add_executable( ${name} ${my_c_list} )
endforeach()
The folder structure is the followning:
|-- CMakeLists.txt
+-- src
| +-- Chapter 1
| +-- 1.0.1
| someCode.c
| +-- 1.0.2
| ohAFunction.c
| +-- Chapter 2
| +-- 2.0.1
| lookCode.c
These snippets come from here
Unfortunately it doesn't work could you help me ?
BTW I run CLion and the CLI both doesn't work.
EDIT: Working CMakeLists.txt
file(GLOB_RECURSE my_c_list RELATIVE ${CMAKE_SOURCE_DIR} "src/*")
foreach(file_path ${my_c_list})
string( REPLACE ".c" "" new_name ${file_path} )
get_filename_component(filename ${new_name} NAME)
add_executable( ${filename} ${file_path} )
endforeach()
file(GLOB_RECURSE)call found none files. Note, that RELATIVE options doesn't affect on a way howfile(GLOB_RECURSE)searches the files; it affects only on output for each file which has been found. Where yourCMakeLists.txtis located? (Show the place ofCMakeLists.txtin the file structure you already have in the question post).