3 #
get all files called
"main.cpp"
4 file(GLOB_RECURSE main_cpp_list
"${snippet_path}/main.cpp")
6 foreach(main_cpp_file ${main_cpp_list})
7 #
get the directory containing the
main.cpp file
8 get_filename_component(main_cpp_dir
"${main_cpp_file}" PATH)
10 set(snippet_src_files )
12 # If there exists a "files.cmake" file in the snippet directory,
13 # include it and assume it sets the variable "snippet_src_files"
14 # to a list of source files for the snippet.
15 if(EXISTS
"${main_cpp_dir}/files.cmake")
16 include(
"${main_cpp_dir}/files.cmake")
17 set(_tmp_src_files ${snippet_src_files})
18 set(snippet_src_files )
19 foreach(_src_file ${_tmp_src_files})
20 if(IS_ABSOLUTE ${_src_file})
21 list(APPEND snippet_src_files ${_src_file})
23 list(APPEND snippet_src_files ${main_cpp_dir}/${_src_file})
27 # glob all files in the directory and add them to the snippet src list
28 file(GLOB_RECURSE snippet_src_files
"${main_cpp_dir}/*")
31 # Uset the top-level directory name as the executable name
32 string(REPLACE
"/" ";" main_cpp_dir_tokens
"${main_cpp_dir}")
33 list(GET main_cpp_dir_tokens -1 snippet_exec_name)
34 set(snippet_target_name "Snippet-${snippet_exec_name}
")
36 add_executable(${snippet_target_name} ${snippet_src_files})
37 target_link_libraries(${snippet_target_name} ${PROJECT_TARGET} ${snippet_link_libraries})
38 set_property(TARGET ${snippet_target_name} APPEND PROPERTY COMPILE_DEFINITIONS US_MODULE_NAME=main)
39 set_property(TARGET ${snippet_target_name} PROPERTY US_MODULE_NAME main)
40 set_target_properties(${snippet_target_name} PROPERTIES
42 RUNTIME_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/snippets
"
43 ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/snippets
"
44 LIBRARY_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/snippets
"
45 OUTPUT_NAME ${snippet_exec_name}
int main(int argc, char **argv)
usFunctionCompileSnippets(snippet_path)