Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
usMacroCreateModule.cmake
Go to the documentation of this file.
1 # For internal use only
2 
3 macro(usMacroCreateModule _project_name)
4 
5 project(${_project_name})
6 
7 cmake_parse_arguments(${PROJECT_NAME}
8  "SKIP_EXAMPLES;SKIP_INIT"
9  "VERSION;TARGET"
10  "DEPENDS;INTERNAL_INCLUDE_DIRS;LINK_LIBRARIES;SOURCES;PRIVATE_HEADERS;PUBLIC_HEADERS;RESOURCES;BINARY_RESOURCES"
11  ${ARGN}
12 )
13 
14 if(NOT ${PROJECT_NAME}_VERSION MATCHES "^[0-9]+\\.[0-9]+\\.[0-9]+$")
15  message(SEND_ERROR "VERSION argument invalid: ${${PROJECT_NAME}_VERSION}")
16 endif()
17 
18 string(REPLACE "." ";" _version_numbers ${${PROJECT_NAME}_VERSION})
19 list(GET _version_numbers 0 ${PROJECT_NAME}_MAJOR_VERSION)
20 list(GET _version_numbers 1 ${PROJECT_NAME}_MINOR_VERSION)
21 list(GET _version_numbers 2 ${PROJECT_NAME}_PATCH_VERSION)
22 
23 if(NOT ${PROJECT_NAME}_TARGET)
24  set(${PROJECT_NAME}_TARGET us${PROJECT_NAME})
25 endif()
26 set(PROJECT_TARGET ${${PROJECT_NAME}_TARGET})
27 
28 if(${PROJECT_NAME}_DEPENDS)
29  find_package(CppMicroServices REQUIRED ${${PROJECT_NAME}_DEPENDS} QUIET
30  HINTS ${CppMicroServices_BINARY_DIR}
31  NO_DEFAULT_PATH
32  )
33 endif()
34 
35 #-----------------------------------------------------------------------------
36 # Include dirs and libraries
37 #-----------------------------------------------------------------------------
38 
39 set(${PROJECT_NAME}_INCLUDE_DIRS
40  ${CMAKE_CURRENT_SOURCE_DIR}/include
41  ${CMAKE_CURRENT_BINARY_DIR}/include
42 )
43 
44 configure_file(${CppMicroServices_SOURCE_DIR}/cmake/usExport.h.in
45  ${CMAKE_CURRENT_BINARY_DIR}/include/us${PROJECT_NAME}Export.h)
46 list(APPEND ${PROJECT_NAME}_PUBLIC_HEADERS
47  ${CMAKE_CURRENT_BINARY_DIR}/include/us${PROJECT_NAME}Export.h)
48 
49 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/include/us${PROJECT_NAME}Config.h.in)
50  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/us${PROJECT_NAME}Config.h.in
51  ${CMAKE_CURRENT_BINARY_DIR}/include/us${PROJECT_NAME}Config.h)
52  list(APPEND ${PROJECT_NAME}_PUBLIC_HEADERS
53  ${CMAKE_CURRENT_BINARY_DIR}/include/us${PROJECT_NAME}Config.h)
54 endif()
55 
56 set(_internal_include_dirs ${${PROJECT_NAME}_INTERNAL_INCLUDE_DIRS})
57 set(${PROJECT_NAME}_INTERNAL_INCLUDE_DIRS )
58 
59 if(_internal_include_dirs)
60  foreach(_internal_include_dir ${_internal_include_dirs})
61  if(IS_ABSOLUTE "${_internal_include_dir}")
62  list(APPEND ${PROJECT_NAME}_INTERNAL_INCLUDE_DIRS ${_internal_include_dir})
63  else()
64  list(APPEND ${PROJECT_NAME}_INTERNAL_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/${_internal_include_dir})
65  endif()
66  endforeach()
67 endif()
68 
69 
70 if(CMAKE_VERSION VERSION_LESS 2.8.12)
71  include_directories(
72  ${US_INCLUDE_DIRS}
73  ${${PROJECT_NAME}_INCLUDE_DIRS}
74  ${${PROJECT_NAME}_INTERNAL_INCLUDE_DIRS}
75  )
76 endif()
77 
78 #-----------------------------------------------------------------------------
79 # Create library
80 #-----------------------------------------------------------------------------
81 
82 # Generate the module init file
83 if(NOT ${PROJECT_NAME}_SKIP_INIT)
84  usFunctionGenerateModuleInit(${PROJECT_NAME}_SOURCES)
85 endif()
86 
87 if(${PROJECT_NAME}_RESOURCES OR ${PROJECT_NAME}_BINARY_RESOURCES)
88  usFunctionGetResourceSource(TARGET ${${PROJECT_NAME}_TARGET} OUT ${PROJECT_NAME}_SOURCES)
89 endif()
90 
91 # Create the module library
92 add_library(${${PROJECT_NAME}_TARGET} ${${PROJECT_NAME}_SOURCES}
93  ${${PROJECT_NAME}_PRIVATE_HEADERS} ${${PROJECT_NAME}_PUBLIC_HEADERS})
94 
95 # Compile definitions
96 set_property(TARGET ${${PROJECT_NAME}_TARGET} APPEND PROPERTY COMPILE_DEFINITIONS US_MODULE_NAME=${${PROJECT_NAME}_TARGET})
97 set_property(TARGET ${${PROJECT_NAME}_TARGET} PROPERTY US_MODULE_NAME ${${PROJECT_NAME}_TARGET})
98 if(NOT US_BUILD_SHARED_LIBS)
99  set_property(TARGET ${${PROJECT_NAME}_TARGET} APPEND PROPERTY COMPILE_DEFINITIONS US_STATIC_MODULE)
100 endif()
101 
102 # Link flags
103 if(${PROJECT_NAME}_LINK_FLAGS OR US_LINK_FLAGS)
104  set_target_properties(${${PROJECT_NAME}_TARGET} PROPERTIES
105  LINK_FLAGS "${US_LINK_FLAGS} ${${PROJECT_NAME}_LINK_FLAGS}"
106  )
107 endif()
108 
109 if(CMAKE_VERSION VERSION_GREATER 2.8.11.99)
110  # Currently, public headers include private header files,
111  # so the internal include dirs need to be in the public
112  # include dir section. This needs to be fixed.
113  target_include_directories(${${PROJECT_NAME}_TARGET}
114  PUBLIC ${US_INCLUDE_DIRS} ${${PROJECT_NAME}_INCLUDE_DIRS}
115  PUBLIC ${${PROJECT_NAME}_INTERNAL_INCLUDE_DIRS}
116  )
117 endif()
118 
119 
120 set_target_properties(${${PROJECT_NAME}_TARGET} PROPERTIES
121  SOVERSION ${${PROJECT_NAME}_VERSION}
122  PUBLIC_HEADER "${${PROJECT_NAME}_PUBLIC_HEADERS}"
123  PRIVATE_HEADER "${${PROJECT_NAME}_PRIVATE_HEADERS}"
124 )
125 
126 # Link additional libraries
127 if(${PROJECT_NAME}_LINK_LIBRARIES OR US_LIBRARIES)
128  target_link_libraries(${${PROJECT_NAME}_TARGET} ${US_LIBRARIES} ${${PROJECT_NAME}_LINK_LIBRARIES})
129 endif()
130 
131 # Embed module resources
132 
133 if(${PROJECT_NAME}_RESOURCES OR US_LIBRARIES)
134  usFunctionAddResources(TARGET ${${PROJECT_NAME}_TARGET}
135  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/resources
136  FILES ${${PROJECT_NAME}_RESOURCES}
137  ZIP_ARCHIVES ${US_LIBRARIES}
138  )
139 endif()
140 if(${PROJECT_NAME}_BINARY_RESOURCES)
141  usFunctionAddResources(TARGET ${${PROJECT_NAME}_TARGET}
142  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/resources
143  FILES ${${PROJECT_NAME}_BINARY_RESOURCES}
144  )
145 endif()
146 usFunctionEmbedResources(TARGET ${${PROJECT_NAME}_TARGET})
147 
148 #-----------------------------------------------------------------------------
149 # Install support
150 #-----------------------------------------------------------------------------
151 
152 if(NOT US_NO_INSTALL)
153  install(TARGETS ${${PROJECT_NAME}_TARGET}
154  EXPORT us${PROJECT_NAME}Targets
155  RUNTIME DESTINATION ${RUNTIME_INSTALL_DIR} ${US_SDK_INSTALL_COMPONENT}
156  LIBRARY DESTINATION ${LIBRARY_INSTALL_DIR} ${US_SDK_INSTALL_COMPONENT}
157  ARCHIVE DESTINATION ${ARCHIVE_INSTALL_DIR} ${US_SDK_INSTALL_COMPONENT}
158  PUBLIC_HEADER DESTINATION ${HEADER_INSTALL_DIR} ${US_SDK_INSTALL_COMPONENT}
159  PRIVATE_HEADER DESTINATION ${HEADER_INSTALL_DIR} ${US_SDK_INSTALL_COMPONENT})
160 endif()
161 
162 #-----------------------------------------------------------------------------
163 # US testing
164 #-----------------------------------------------------------------------------
165 
166 if(US_BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")
167  add_subdirectory(test)
168 endif()
169 
170 #-----------------------------------------------------------------------------
171 # Documentation
172 #-----------------------------------------------------------------------------
173 
174 if(US_BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/doc/snippets/CMakeLists.txt")
175  # Compile source code snippets
176  add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/doc/snippets)
177 endif()
178 
179 #-----------------------------------------------------------------------------
180 # Last configuration and install steps
181 #-----------------------------------------------------------------------------
182 
183 # Version information
184 configure_file(
185  ${US_CMAKE_DIR}/usModuleConfigVersion.cmake.in
186  ${CppMicroServices_BINARY_DIR}/us${PROJECT_NAME}ConfigVersion.cmake
187  @ONLY
188  )
189 
190 export(TARGETS ${${PROJECT_NAME}_TARGET} ${US_LIBRARIES}
191  FILE ${CppMicroServices_BINARY_DIR}/us${PROJECT_NAME}Targets.cmake)
192 if(NOT US_NO_INSTALL)
193  install(EXPORT us${PROJECT_NAME}Targets
194  FILE us${PROJECT_NAME}Targets.cmake
195  DESTINATION ${AUXILIARY_CMAKE_INSTALL_DIR})
196 endif()
197 
198 # Configure config file for the build tree
199 
200 set(PACKAGE_CONFIG_INCLUDE_DIR
201  ${${PROJECT_NAME}_INCLUDE_DIRS}
202  ${${PROJECT_NAME}_INTERNAL_INCLUDE_DIRS})
203 set(PACKAGE_CONFIG_RUNTIME_LIBRARY_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
204 
205 configure_file(
206  ${US_CMAKE_DIR}/usModuleConfig.cmake.in
207  ${CppMicroServices_BINARY_DIR}/us${PROJECT_NAME}Config.cmake
208  @ONLY
209  )
210 
211 # Configure config file for the install tree
212 
213 if(NOT US_NO_INSTALL)
214  set(CONFIG_INCLUDE_DIR ${HEADER_INSTALL_DIR})
215  set(CONFIG_RUNTIME_LIBRARY_DIR ${RUNTIME_INSTALL_DIR})
216 
217  configure_package_config_file(
218  ${US_CMAKE_DIR}/usModuleConfig.cmake.in
219  ${CppMicroServices_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/us${PROJECT_NAME}Config.cmake
220  INSTALL_DESTINATION ${AUXILIARY_CMAKE_INSTALL_DIR}
221  PATH_VARS CONFIG_INCLUDE_DIR CONFIG_RUNTIME_LIBRARY_DIR
222  NO_SET_AND_CHECK_MACRO
223  NO_CHECK_REQUIRED_COMPONENTS_MACRO
224  )
225 
226  install(FILES ${CppMicroServices_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/us${PROJECT_NAME}Config.cmake
227  ${CppMicroServices_BINARY_DIR}/us${PROJECT_NAME}ConfigVersion.cmake
228  DESTINATION ${AUXILIARY_CMAKE_INSTALL_DIR}
229  ${US_SDK_INSTALL_COMPONENT})
230 endif()
231 
232 #-----------------------------------------------------------------------------
233 # Build the examples
234 #-----------------------------------------------------------------------------
235 
236 if(US_BUILD_EXAMPLES AND NOT ${PROJECT_NAME}_SKIP_EXAMPLES AND
237  EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/examples/CMakeLists.txt)
238  set(CppMicroServices_DIR ${CppMicroServices_BINARY_DIR})
239  add_subdirectory(examples)
240 endif()
241 
242 endmacro()
Follow Up Storage - Class to facilitate loading/accessing structured follow-up data.
Definition: testcase.h:32
usFunctionAddResources()
Add resources to a library or executable.
usFunctionEmbedResources()
Embed resources in a library or executable.
usMacroCreateModule(_project_name)
usFunctionGetResourceSource()
Get a source file name for handling resource dependencies.
usFunctionGenerateModuleInit(src_var)
Generate a source file which handles proper initialization of a module.
const std::string TARGET