Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
usFunctionCompileSnippets.cmake
Go to the documentation of this file.
1 function(usFunctionCompileSnippets snippet_path)
2 
3  # get all files called "main.cpp"
4  file(GLOB_RECURSE main_cpp_list "${snippet_path}/main.cpp")
5 
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)
9 
10  set(snippet_src_files )
11 
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})
22  else()
23  list(APPEND snippet_src_files ${main_cpp_dir}/${_src_file})
24  endif()
25  endforeach()
26  else()
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}/*")
29  endif()
30 
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}")
35 
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
41  LABELS Documentation
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}
46  )
47 
48  endforeach()
49 
50 endfunction()
int main(int argc, char **argv)
Definition: MitkCoreApp.cpp:22
usFunctionCompileSnippets(snippet_path)