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 #----------------------------------------------------------------------------
17 #----------------------------------------------------------------------------
18 # VARS CONFIGURED IN bbPackage.h
19 SET(BBTK_PACKAGE_AUTHOR "\"${${BBTK_PACKAGE_NAME}_AUTHOR}\"")
20 SET(BBTK_PACKAGE_DESCRIPTION "\"${${BBTK_PACKAGE_NAME}_DESCRIPTION}\"")
21 SET(BBTK_PACKAGE_MAJOR_VERSION ${${BBTK_PACKAGE_NAME}_MAJOR_VERSION})
22 SET(BBTK_PACKAGE_MINOR_VERSION ${${BBTK_PACKAGE_NAME}_MINOR_VERSION})
23 SET(BBTK_PACKAGE_BUILD_VERSION ${${BBTK_PACKAGE_NAME}_BUILD_VERSION})
24 SET(BBTK_PACKAGE_VERSION
25 "\"${${BBTK_PACKAGE_NAME}_MAJOR_VERSION}.${${BBTK_PACKAGE_NAME}_MINOR_VERSION}.${${BBTK_PACKAGE_NAME}_BUILD_VERSION}\"")
26 #----------------------------------------------------------------------------
28 #----------------------------------------------------------------------------
30 #----------------------------------------------------------------------------
31 # CREATES bb${BBTK_PACKAGE_NAME}Package.h
33 ${BBTK_CMAKE_DIR}/bbPackage.h.in
34 ${CMAKE_CURRENT_BINARY_DIR}/bb${BBTK_PACKAGE_NAME}Package.h
38 FILES ${CMAKE_CURRENT_BINARY_DIR}/bb${BBTK_PACKAGE_NAME}Package.h
39 DESTINATION include/bb${BBTK_PACKAGE_NAME}
41 #----------------------------------------------------------------------------
43 #----------------------------------------------------------------------------
44 # CREATES bb${BBTK_PACKAGE_NAME}Package.cxx
46 ${BBTK_CMAKE_DIR}/bbPackage.cxx.in
47 ${CMAKE_CURRENT_BINARY_DIR}/bb${BBTK_PACKAGE_NAME}Package.cxx
50 #----------------------------------------------------------------------------
52 #----------------------------------------------------------------------------
53 SET_SOURCE_FILES_PROPERTIES(
54 ${CMAKE_CURRENT_BINARY_DIR}/bb${BBTK_PACKAGE_NAME}Package.cxx
55 PROPERTIES GENERATED ON)
56 #----------------------------------------------------------------------------
59 #----------------------------------------------------------------------------
60 IF(${BBTK_PACKAGE_NAME}_COMPILE_ALL_CXX)
61 FILE(GLOB ${BBTK_PACKAGE_NAME}_CXX_SOURCES "." "*.cxx")
62 FILE(GLOB ${BBTK_PACKAGE_NAME}_H_SOURCES "." "*.h")
63 ENDIF(${BBTK_PACKAGE_NAME}_COMPILE_ALL_CXX)
66 SET(${BBTK_PACKAGE_NAME}_CXX_SOURCES
67 ${${BBTK_PACKAGE_NAME}_CXX_SOURCES}
68 #${CMAKE_CURRENT_BINARY_DIR_NAME}/
69 bb${BBTK_PACKAGE_NAME}Package
71 #----------------------------------------------------------------------------
74 #----------------------------------------------------------------------------
75 #----------------------------------------------------------------------------
77 #----------------------------------------------------------------------------
79 #----------------------------------------------------------------------------
80 IF(${BBTK_PACKAGE_NAME}_COMPILE_ALL_XML)
81 FILE(GLOB ${BBTK_PACKAGE_NAME}_XML_SOURCES "." "*.xml")
82 ENDIF(${BBTK_PACKAGE_NAME}_COMPILE_ALL_XML)
83 #----------------------------------------------------------------------------
84 FOREACH(xmlfile ${${BBTK_PACKAGE_NAME}_XML_SOURCES})
86 GET_FILENAME_COMPONENT(filename "${xmlfile}" NAME_WE)
89 SET(BBFY_CXX_OUT ${CMAKE_CURRENT_BINARY_DIR}/${filename}.cxx)
92 OUTPUT ${BBFY_CXX_OUT}
94 ${BBTK_BBFY} ${xmlfile} ${CMAKE_CURRENT_BINARY_DIR}/ -q
96 ${BBTK_BBFY_DEPENDENCY}
99 SET_SOURCE_FILES_PROPERTIES(
101 PROPERTIES GENERATED ON)
104 IF(NOT ${BBTK_PACKAGE_NAME}_CXX_SOURCES MATCHES "${filename}")
105 SET(${BBTK_PACKAGE_NAME}_CXX_SOURCES
106 ${${BBTK_PACKAGE_NAME}_CXX_SOURCES}
109 ENDIF(NOT ${BBTK_PACKAGE_NAME}_CXX_SOURCES MATCHES "${filename}")
112 FILES ${CMAKE_CURRENT_BINARY_DIR}/${filename}.h
113 DESTINATION include/bb${BBTK_PACKAGE_NAME})
116 #----------------------------------------------------------------------------
120 #----------------------------------------------------------------------------
122 ADD_LIBRARY(bb${BBTK_PACKAGE_NAME} SHARED
123 ${${BBTK_PACKAGE_NAME}_CXX_SOURCES} ${${BBTK_PACKAGE_NAME}_H_SOURCES}
125 TARGET_LINK_LIBRARIES(bb${BBTK_PACKAGE_NAME}
127 ${${BBTK_PACKAGE_NAME}_LIBS}
129 #----------------------------------------------------------------------------
132 #----------------------------------------------------------------------------
134 FILE(GLOB ${BBTK_PACKAGE_NAME}_HEADERS "*.h")
136 FILES ${${BBTK_PACKAGE_NAME}_HEADERS}
137 DESTINATION include/bb${BBTK_PACKAGE_NAME}
140 TARGETS bb${BBTK_PACKAGE_NAME}
144 SET( LIBRARY_NAME bb${BBTK_PACKAGE_NAME} )
145 # SET THE LIB VERSION
146 SET(${LIBRARY_NAME}_MAJOR_VERSION ${${BBTK_PACKAGE_NAME}_MAJOR_VERSION})
147 SET(${LIBRARY_NAME}_MINOR_VERSION ${${BBTK_PACKAGE_NAME}_MINOR_VERSION})
148 SET(${LIBRARY_NAME}_BUILD_VERSION ${${BBTK_PACKAGE_NAME}_BUILD_VERSION})
150 SET(${LIBRARY_NAME}_INSTALL_FOLDER bb${BBTK_PACKAGE_NAME})
151 SET(${LIBRARY_NAME}_LIBRARIES bb${BBTK_PACKAGE_NAME})
154 ${LIBRARY_NAME}_BUILD_TREE_RELATIVE_INCLUDE_PATHS
155 ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
159 SET(${LIBRARY_NAME}_BUILD_TREE_RELATIVE_LIBRARY_PATHS
160 ${EXECUTABLE_OUTPUT_REL_PATH})
162 SET(${LIBRARY_NAME}_BUILD_TREE_RELATIVE_LIBRARY_PATHS
163 ${EXECUTABLE_OUTPUT_REL_PATH}/Debug
164 ${EXECUTABLE_OUTPUT_REL_PATH}/Release)
166 SET(${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_INCLUDE_PATHS
167 include/bb${BBTK_PACKAGE_NAME})
168 SET(${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_LIBRARY_PATHS lib)
170 # REQUIRED BUILD FLAGS
171 #SET(${LIBRARY_NAME}_REQUIRED_C_FLAGS "")
172 #SET(${LIBRARY_NAME}_REQUIRED_CXX_FLAGS "")
173 #SET(${LIBRARY_NAME}_REQUIRED_LINK_FLAGS "")
175 # Additional config/use
176 # Prepare for configure
177 SET(BBTK_PACKAGE_USE_VTK ${${BBTK_PACKAGE_NAME}_USE_VTK})
178 SET(BBTK_PACKAGE_USE_ITK ${${BBTK_PACKAGE_NAME}_USE_ITK})
179 SET(BBTK_PACKAGE_USE_GDCM ${${BBTK_PACKAGE_NAME}_USE_GDCM})
180 SET(BBTK_PACKAGE_USE_GSMIS ${${BBTK_PACKAGE_NAME}_USE_GSMIS})
181 SET(BBTK_PACKAGE_USE_WXWIDGETS ${${BBTK_PACKAGE_NAME}_USE_WXWIDGETS})
182 SET(BBTK_PACKAGE_USE_PACKAGES ${${BBTK_PACKAGE_NAME}_USE_PACKAGES})
183 SET(BBTK_PACKAGE_INCLUDE_DIRS ${${BBTK_PACKAGE_NAME}_INCLUDE_DIRS})
184 SET(BBTK_PACKAGE_LIBS ${${BBTK_PACKAGE_NAME}_LIBS})
186 SET(${LIBRARY_NAME}_HAS_ADDITIONAL_CONFIG_FILE TRUE)
187 SET(${LIBRARY_NAME}_ADDITIONAL_CONFIG_FILE
188 ${${BBTK_PACKAGE_NAME}_SOURCE_DIR}/PackageConfig.cmake.in)
189 SET(${LIBRARY_NAME}_ADDITIONAL_USE_FILE
190 ${${BBTK_PACKAGE_NAME}_SOURCE_DIR}/UsePackage.cmake.in)
191 #-----------------------------------------------------------------------------
193 #-----------------------------------------------------------------------------
194 # Includes CMakeCreateFindPackage
195 INCLUDE(${CMakeCreateFindPackage_DIR}/CMakeCreateFindPackage.cmake)
196 CMAKE_CREATE_FIND_PACKAGE(${LIBRARY_NAME})
197 #-----------------------------------------------------------------------------
199 #----------------------------------------------------------------------------
204 #---------------------------------------------------------------------------
206 # On recent linux running SELinux :
207 # Have to change the context of the library created
208 # to be able to load it dynamically and avoid the error :
209 # "cannot restore segment prot after reloc: Permission denied"
211 # http://www.ittvis.com/services/techtip.asp?ttid=3092
213 FIND_PROGRAM(CHCON_EXECUTABLE
219 MARK_AS_ADVANCED(CHCON_EXECUTABLE)
222 # custom post_build command to change the context of the .so generated
224 TARGET bb${BBTK_PACKAGE_NAME}
226 COMMAND chcon -t texrel_shlib_t ${LIBRARY_OUTPUT_PATH}/libbb${BBTK_PACKAGE_NAME}.so
228 # custom post-install command to change the context of the .so installed
229 INSTALL(CODE "EXEC_PROGRAM(chcon ARGS -t texrel_shlib_t ${CMAKE_INSTALL_PREFIX}/lib/libbb${BBTK_PACKAGE_NAME}.so)")
230 ENDIF(CHCON_EXECUTABLE)
231 ENDIF(CHCON_LIBRARIES)
232 #----------------------------------------------------------------------------