Computer Assited Medical Intervention Tool Kit  version 4.1
CamiTKInstallAllHeaders.h
Go to the documentation of this file.
43 
44  set(options "")
45  set(oneValueArgs COMPONENT GROUP)
46  set(multiValueArgs "")
47  cmake_parse_arguments(CAMITK_INSTALL_ALL_HEADERS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
48 
49  # The base include directories
50  set(CAMITK_INSTALL_ALL_HEADERS_BUILD_BASE_DIR ${CMAKE_BINARY_DIR}/include/${CAMITK_SHORT_VERSION_STRING})
51  set(CAMITK_INSTALL_ALL_HEADERS_INSTALL_RELATIVE_DIR include/${CAMITK_SHORT_VERSION_STRING})
52 
53  # Get action, component or library name without its prefix
54  set(CAMITK_INSTALL_ALL_HEADERS_TARGET_NAME ${CAMITK_INSTALL_ALL_HEADERS_COMPONENT})
55  string(REGEX REPLACE "^component-|^component_|^action-|^action_|^library_|^library-" "" CAMITK_INSTALL_ALL_HEADERS_COMPONENT "${CAMITK_INSTALL_ALL_HEADERS_COMPONENT}")
56 
57  # Check group directory
58  if(CAMITK_INSTALL_ALL_HEADERS_GROUP)
59  # Create group directory if not already existing
60  if (NOT EXISTS "${CAMITK_INSTALL_ALL_HEADERS_BUILD_BASE_DIR}/${CAMITK_INSTALL_ALL_HEADERS_GROUP}" AND NOT CAMITK_INSTALL_ALL_HEADERS_DIRECTORY)
61  add_custom_command( TARGET ${CAMITK_INSTALL_ALL_HEADERS_TARGET_NAME}
62  POST_BUILD
63  COMMAND ${CMAKE_COMMAND} -E make_directory ${CAMITK_INSTALL_ALL_HEADERS_BUILD_BASE_DIR}/${CAMITK_INSTALL_ALL_HEADERS_GROUP}
64  COMMENT "Creating build-time group include dir ${CAMITK_INSTALL_ALL_HEADERS_BUILD_BASE_DIR}/${CAMITK_INSTALL_ALL_HEADERS_GROUP}"
65  VERBATIM
66  )
67  endif()
68  # Update base dirs
69  set(CAMITK_INSTALL_ALL_HEADERS_BUILD_BASE_DIR ${CAMITK_INSTALL_ALL_HEADERS_BUILD_BASE_DIR}/${CAMITK_INSTALL_ALL_HEADERS_GROUP})
70  set(CAMITK_INSTALL_ALL_HEADERS_INSTALL_RELATIVE_DIR ${CAMITK_INSTALL_ALL_HEADERS_INSTALL_RELATIVE_DIR}/${CAMITK_INSTALL_ALL_HEADERS_GROUP})
71  endif()
72 
73  # Create component directory if not already existing
74  if (NOT EXISTS "${CAMITK_INSTALL_ALL_HEADERS_BUILD_BASE_DIR}/${CAMITK_INSTALL_ALL_HEADERS_COMPONENT}" AND NOT CAMITK_INSTALL_ALL_HEADERS_DIRECTORY)
75  add_custom_command( TARGET ${CAMITK_INSTALL_ALL_HEADERS_TARGET_NAME}
76  POST_BUILD
77  COMMAND ${CMAKE_COMMAND} -E make_directory ${CAMITK_INSTALL_ALL_HEADERS_BUILD_BASE_DIR}/${CAMITK_INSTALL_ALL_HEADERS_COMPONENT}
78  COMMENT "Creating build-time include dir ${CAMITK_INSTALL_ALL_HEADERS_BUILD_BASE_DIR}/${CAMITK_INSTALL_ALL_HEADERS_COMPONENT}"
79  VERBATIM
80  )
81  endif()
82  # Update base dirs
83  set(CAMITK_INSTALL_ALL_HEADERS_BUILD_BASE_DIR ${CAMITK_INSTALL_ALL_HEADERS_BUILD_BASE_DIR}/${CAMITK_INSTALL_ALL_HEADERS_COMPONENT})
84  set(CAMITK_INSTALL_ALL_HEADERS_INSTALL_RELATIVE_DIR ${CAMITK_INSTALL_ALL_HEADERS_INSTALL_RELATIVE_DIR}/${CAMITK_INSTALL_ALL_HEADERS_COMPONENT})
85 
86  # Build time installation
87  file(GLOB_RECURSE HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/ *.h)
88  foreach(HEADER ${HEADERS})
89  # Get the subdirectory name of the header
90  string(REGEX MATCH ".*/" SUBDIR ${HEADER})
91 
92  # Create subdirectory if not already existing
93  if(NOT EXISTS "${CAMITK_INSTALL_ALL_HEADERS_BUILD_BASE_DIR}/${SUBDIR}" AND NOT CAMITK_INSTALL_ALL_HEADERS_${SUBDIR})
94  # Create directory at build time
95  add_custom_command( TARGET ${CAMITK_INSTALL_ALL_HEADERS_TARGET_NAME}
96  POST_BUILD
97  COMMAND ${CMAKE_COMMAND} -E make_directory ${CAMITK_INSTALL_ALL_HEADERS_BUILD_BASE_DIR}/${SUBDIR}
98  COMMENT "Creating build-time include dir ${CAMITK_INSTALL_ALL_HEADERS_COMPONENT}/${SUBDIR}"
99  VERBATIM
100  )
101  set(CAMITK_INSTALL_ALL_HEADERS_${SUBDIR} "CREATED") # To avoid creating the directory another time
102  endif()
103 
104  # Install header at build time
105  add_custom_command( TARGET ${CAMITK_INSTALL_ALL_HEADERS_TARGET_NAME}
106  POST_BUILD
107  COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/${HEADER} ${CAMITK_INSTALL_ALL_HEADERS_BUILD_BASE_DIR}/${SUBDIR}
108  COMMENT "Installing build-time header ${CAMITK_INSTALL_ALL_HEADERS_COMPONENT}/${HEADER}"
109  VERBATIM
110  )
111  endforeach()
112 
113  # Install time, copy all the .h directories structure
114  install( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
115  COMPONENT ${CAMITK_INSTALL_ALL_HEADERS_TARGET_NAME}
116  DESTINATION ${CAMITK_INSTALL_ALL_HEADERS_INSTALL_RELATIVE_DIR}
117  FILES_MATCHING
118  PATTERN "*.h"
119  )
120 
121 end(){)
122 
cmake modules macros camitk test endif() add_custom_target(camitk-ce-iwyu COMMAND $
Definition: CamiTKIncludeWhatYouUse.h:37
camitk_install_all_headers()
camitk_install_all_headers is a macro that install all header files of a project at build and install...
Definition: CamiTKInstallAllHeaders.h:42
static void include(QRect &r, const QRect &rect)
Definition: canvas_typed/qtcanvas.cpp:98