Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkFunctionCompileSnippets.cmake
Go to the documentation of this file.
1 function(mitkFunctionCompileSnippets 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  add_executable(${snippet_target_name} ${snippet_src_files})
36  if(ARGN)
37  target_link_libraries(${snippet_target_name} ${ARGN})
38  endif()
39  set_target_properties(${snippet_target_name} PROPERTIES
40  LABELS Documentation
41  RUNTIME_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/snippets"
42  ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/snippets"
43  LIBRARY_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/snippets"
44  OUTPUT_NAME ${snippet_exec_name}
45  )
46 
47  endforeach()
48 
49 endfunction()
int main(int argc, char **argv)
Definition: MitkCoreApp.cpp:22
mitkFunctionCompileSnippets(snippet_path)