2 #----------------------------------------------------------------------------
3 # BINARY DIR MUST BE IN INCLUDE DIRS
4 # TO FIND .h OF AUTOMATICALLY GENERATED FILES (e.g. FROM XML)
5 INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} )
6 # SOURCES DIR MUST ALSO BE IN INCLUDE DIRS FOR FILES COMPILED IN BINARY DIR
7 # WHICH NEED TO INCLUDE OTHER FILES OF THE PACKAGE
8 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} )
9 #----------------------------------------------------------------------------
11 #----------------------------------------------------------------------------
12 # USER DEFINED ADDITIONAL INCLUDE DIRS
13 # NB : PATHS PROVIDED BY THE USER ARE RELATIVE TO THE PARENT DIR
14 INCLUDE_DIRECTORIES(../${${BBTK_PACKAGE_NAME}_INCLUDE_DIRS})
15 #----------------------------------------------------------------------------
18 #----------------------------------------------------------------------------
20 #----------------------------------------------------------------------------
21 # CREATES bb${BBTK_PACKAGE_NAME}Package.h
23 ${BBTK_CMAKE_DIR}/bbPackage.h.in
24 ${CMAKE_CURRENT_BINARY_DIR}/bb${BBTK_PACKAGE_NAME}Package.h
28 FILES ${CMAKE_CURRENT_BINARY_DIR}/bb${BBTK_PACKAGE_NAME}Package.h
29 DESTINATION include/bb${BBTK_PACKAGE_NAME}
31 #----------------------------------------------------------------------------
33 #----------------------------------------------------------------------------
34 # CREATES bb${BBTK_PACKAGE_NAME}Package.cxx
36 ${BBTK_CMAKE_DIR}/bbPackage.cxx.in
37 ${CMAKE_CURRENT_BINARY_DIR}/bb${BBTK_PACKAGE_NAME}Package.cxx
40 #----------------------------------------------------------------------------
42 #----------------------------------------------------------------------------
43 SET_SOURCE_FILES_PROPERTIES(
44 ${CMAKE_CURRENT_BINARY_DIR}/bb${BBTK_PACKAGE_NAME}Package.cxx
45 PROPERTIES GENERATED ON)
46 #----------------------------------------------------------------------------
49 #----------------------------------------------------------------------------
50 IF(${BBTK_PACKAGE_NAME}_COMPILE_ALL_CXX)
51 FILE(GLOB ${BBTK_PACKAGE_NAME}_CXX_SOURCES "." "*.cxx")
52 FILE(GLOB ${BBTK_PACKAGE_NAME}_H_SOURCES "." "*.h")
53 ENDIF(${BBTK_PACKAGE_NAME}_COMPILE_ALL_CXX)
56 SET(${BBTK_PACKAGE_NAME}_CXX_SOURCES
57 ${${BBTK_PACKAGE_NAME}_CXX_SOURCES}
58 #${CMAKE_CURRENT_BINARY_DIR_NAME}/
59 bb${BBTK_PACKAGE_NAME}Package
61 #----------------------------------------------------------------------------
64 #----------------------------------------------------------------------------
65 #----------------------------------------------------------------------------
67 #----------------------------------------------------------------------------
69 #----------------------------------------------------------------------------
70 IF(${BBTK_PACKAGE_NAME}_COMPILE_ALL_XML)
71 FILE(GLOB ${BBTK_PACKAGE_NAME}_XML_SOURCES "." "*.xml")
72 ENDIF(${BBTK_PACKAGE_NAME}_COMPILE_ALL_XML)
73 #----------------------------------------------------------------------------
74 FOREACH(xmlfile ${${BBTK_PACKAGE_NAME}_XML_SOURCES})
76 GET_FILENAME_COMPONENT(filename "${xmlfile}" NAME_WE)
79 SET(BBFY_CXX_OUT ${CMAKE_CURRENT_BINARY_DIR}/${filename}.cxx)
82 OUTPUT ${BBFY_CXX_OUT}
84 ${BBTK_BBFY} ${xmlfile} ${BBTK_PACKAGE_NAME} ${CMAKE_CURRENT_BINARY_DIR}/ -q
86 ${BBTK_BBFY_DEPENDENCY}
89 SET_SOURCE_FILES_PROPERTIES(
91 PROPERTIES GENERATED ON)
94 IF(NOT ${BBTK_PACKAGE_NAME}_CXX_SOURCES MATCHES "${filename}")
95 SET(${BBTK_PACKAGE_NAME}_CXX_SOURCES
96 ${${BBTK_PACKAGE_NAME}_CXX_SOURCES}
99 ENDIF(NOT ${BBTK_PACKAGE_NAME}_CXX_SOURCES MATCHES "${filename}")
102 FILES ${CMAKE_CURRENT_BINARY_DIR}/${filename}.h
103 DESTINATION include/bb${BBTK_PACKAGE_NAME})
106 #----------------------------------------------------------------------------
110 #----------------------------------------------------------------------------
112 ADD_LIBRARY(bb${BBTK_PACKAGE_NAME} SHARED
113 ${${BBTK_PACKAGE_NAME}_CXX_SOURCES} ${${BBTK_PACKAGE_NAME}_H_SOURCES}
115 TARGET_LINK_LIBRARIES(bb${BBTK_PACKAGE_NAME}
117 ${${BBTK_PACKAGE_NAME}_LIBS}
119 #----------------------------------------------------------------------------
122 #----------------------------------------------------------------------------
124 FILE(GLOB ${BBTK_PACKAGE_NAME}_HEADERS "*.h")
126 FILES ${${BBTK_PACKAGE_NAME}_HEADERS}
127 DESTINATION include/bb${BBTK_PACKAGE_NAME}
130 TARGETS bb${BBTK_PACKAGE_NAME}
134 SET( LIBRARY_NAME bb${BBTK_PACKAGE_NAME} )
135 # SET THE LIB VERSION
136 SET(${LIBRARY_NAME}_MAJOR_VERSION ${${BBTK_PACKAGE_NAME}_MAJOR_VERSION})
137 SET(${LIBRARY_NAME}_MINOR_VERSION ${${BBTK_PACKAGE_NAME}_MINOR_VERSION})
138 SET(${LIBRARY_NAME}_BUILD_VERSION ${${BBTK_PACKAGE_NAME}_BUILD_VERSION})
140 SET(${LIBRARY_NAME}_INSTALL_FOLDER bb${BBTK_PACKAGE_NAME})
141 SET(${LIBRARY_NAME}_LIBRARIES bb${BBTK_PACKAGE_NAME})
144 ${LIBRARY_NAME}_BUILD_TREE_RELATIVE_INCLUDE_PATHS
145 ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
149 SET(${LIBRARY_NAME}_BUILD_TREE_RELATIVE_LIBRARY_PATHS
150 ${EXECUTABLE_OUTPUT_REL_PATH})
152 SET(${LIBRARY_NAME}_BUILD_TREE_RELATIVE_LIBRARY_PATHS
153 ${EXECUTABLE_OUTPUT_REL_PATH}/Debug
154 ${EXECUTABLE_OUTPUT_REL_PATH}/Release)
156 SET(${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_INCLUDE_PATHS
157 include/bb${BBTK_PACKAGE_NAME})
158 SET(${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_LIBRARY_PATHS lib)
160 # REQUIRED BUILD FLAGS
161 #SET(${LIBRARY_NAME}_REQUIRED_C_FLAGS "")
162 #SET(${LIBRARY_NAME}_REQUIRED_CXX_FLAGS "")
163 #SET(${LIBRARY_NAME}_REQUIRED_LINK_FLAGS "")
165 # Additional config/use
166 # Prepare for configure
167 SET(BBTK_PACKAGE_USE_VTK ${${BBTK_PACKAGE_NAME}_USE_VTK})
168 SET(BBTK_PACKAGE_USE_ITK ${${BBTK_PACKAGE_NAME}_USE_ITK})
169 SET(BBTK_PACKAGE_USE_GDCM ${${BBTK_PACKAGE_NAME}_USE_GDCM})
170 SET(BBTK_PACKAGE_USE_GSMIS ${${BBTK_PACKAGE_NAME}_USE_GSMIS})
171 SET(BBTK_PACKAGE_USE_WXWIDGETS ${${BBTK_PACKAGE_NAME}_USE_WXWIDGETS})
172 SET(BBTK_PACKAGE_USE_PACKAGES ${${BBTK_PACKAGE_NAME}_USE_PACKAGES})
173 SET(BBTK_PACKAGE_INCLUDE_DIRS ${${BBTK_PACKAGE_NAME}_INCLUDE_DIRS})
174 SET(BBTK_PACKAGE_LIBS ${${BBTK_PACKAGE_NAME}_LIBS})
176 SET(${LIBRARY_NAME}_HAS_ADDITIONAL_CONFIG_FILE TRUE)
177 SET(${LIBRARY_NAME}_ADDITIONAL_CONFIG_FILE
178 ${${BBTK_PACKAGE_NAME}_SOURCE_DIR}/PackageConfig.cmake.in)
179 SET(${LIBRARY_NAME}_ADDITIONAL_USE_FILE
180 ${${BBTK_PACKAGE_NAME}_SOURCE_DIR}/UsePackage.cmake.in)
181 #-----------------------------------------------------------------------------
183 #-----------------------------------------------------------------------------
184 # Includes CMakeCreateFindPackage
185 INCLUDE(${CMakeCreateFindPackage_DIR}/CMakeCreateFindPackage.cmake)
186 CMAKE_CREATE_FIND_PACKAGE(${LIBRARY_NAME})
187 #-----------------------------------------------------------------------------
189 #----------------------------------------------------------------------------
194 #---------------------------------------------------------------------------
196 # On recent linux running SELinux :
197 # Have to change the context of the library created
198 # to be able to load it dynamically and avoid the error :
199 # "cannot restore segment prot after reloc: Permission denied"
201 # http://www.ittvis.com/services/techtip.asp?ttid=3092
203 FIND_PROGRAM(CHCON_EXECUTABLE
209 MARK_AS_ADVANCED(CHCON_EXECUTABLE)
212 # custom post_build command to change the context of the .so generated
214 TARGET bb${BBTK_PACKAGE_NAME}
216 COMMAND chcon -t texrel_shlib_t ${LIBRARY_OUTPUT_PATH}/libbb${BBTK_PACKAGE_NAME}.so
218 # custom post-install command to change the context of the .so installed
219 INSTALL(CODE "EXEC_PROGRAM(chcon ARGS -t texrel_shlib_t ${CMAKE_INSTALL_PREFIX}/lib/libbb${BBTK_PACKAGE_NAME}.so)")
220 ENDIF(CHCON_EXECUTABLE)
221 ENDIF(CHCON_LIBRARIES)
222 #----------------------------------------------------------------------------