]> Creatis software - bbtk.git/blob - kernel/cmake/BBTKConfigurePackage_src.cmake
*** empty log message ***
[bbtk.git] / kernel / cmake / BBTKConfigurePackage_src.cmake
1
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 #----------------------------------------------------------------------------
10
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 #----------------------------------------------------------------------------
16
17
18 #----------------------------------------------------------------------------
19
20 #----------------------------------------------------------------------------
21 # CREATES bb${BBTK_PACKAGE_NAME}Package.h
22 CONFIGURE_FILE(
23   ${BBTK_CMAKE_DIR}/bbPackage.h.in
24   ${CMAKE_CURRENT_BINARY_DIR}/bb${BBTK_PACKAGE_NAME}Package.h
25   @ONLY IMMEDIATE
26   ) 
27 INSTALL(
28   FILES ${CMAKE_CURRENT_BINARY_DIR}/bb${BBTK_PACKAGE_NAME}Package.h
29   DESTINATION include/bb${BBTK_PACKAGE_NAME} 
30   )
31 #----------------------------------------------------------------------------
32   
33 #----------------------------------------------------------------------------
34 # CREATES bb${BBTK_PACKAGE_NAME}Package.cxx
35 CONFIGURE_FILE(
36   ${BBTK_CMAKE_DIR}/bbPackage.cxx.in
37   ${CMAKE_CURRENT_BINARY_DIR}/bb${BBTK_PACKAGE_NAME}Package.cxx
38   @ONLY IMMEDIATE
39   )
40 #----------------------------------------------------------------------------
41
42 #----------------------------------------------------------------------------
43 SET_SOURCE_FILES_PROPERTIES(
44   ${CMAKE_CURRENT_BINARY_DIR}/bb${BBTK_PACKAGE_NAME}Package.cxx
45   PROPERTIES GENERATED ON)
46 #----------------------------------------------------------------------------
47
48
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) 
54
55
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
60   )
61 #----------------------------------------------------------------------------
62
63
64 #----------------------------------------------------------------------------
65 #----------------------------------------------------------------------------
66 # bbfy
67 #----------------------------------------------------------------------------
68
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})
75   
76   GET_FILENAME_COMPONENT(filename "${xmlfile}" NAME_WE) 
77   
78   SET(BBFY_CXX_OUT ${CMAKE_CURRENT_BINARY_DIR}/${filename}.cxx)
79   
80   IF (WIN32)
81     SET(command00 Path=%WXWIN%/lib/vc_dll/__RR__%VTK_DIR%__RR__%ITK_DIR%/../../bin/__RR__%PATH%)
82     STRING(REPLACE "__RR__" "\;" SETPATH ${command00} )
83         #    SET(SETPATH set ${command0} &&)
84  ADD_CUSTOM_COMMAND(
85     OUTPUT ${BBFY_CXX_OUT}
86     COMMAND
87     set ${SETPATH} && ${BBTK_BBFY} ${xmlfile} ${BBTK_PACKAGE_NAME} ${CMAKE_CURRENT_BINARY_DIR}/ -q
88     DEPENDS ${xmlfile}
89     ${BBTK_BBFY_DEPENDENCY} 
90     )
91   ELSE(WIN32)
92  ADD_CUSTOM_COMMAND(
93     OUTPUT ${BBFY_CXX_OUT}
94     COMMAND
95     ${BBTK_BBFY} ${xmlfile} ${BBTK_PACKAGE_NAME} ${CMAKE_CURRENT_BINARY_DIR}/ -q
96     DEPENDS ${xmlfile}
97     ${BBTK_BBFY_DEPENDENCY} 
98     )
99
100         ENDIF(WIN32)
101   
102    
103   SET_SOURCE_FILES_PROPERTIES(
104     ${BBFY_CXX_OUT}
105     PROPERTIES GENERATED ON)
106   
107   
108  IF(NOT ${BBTK_PACKAGE_NAME}_CXX_SOURCES MATCHES "${filename}.cxx")
109  # message ("EED Alert BBTKConfigurePackage_src  "  "IF NOT MATCHES" )
110   SET(${BBTK_PACKAGE_NAME}_CXX_SOURCES
111       ${${BBTK_PACKAGE_NAME}_CXX_SOURCES}
112       ${filename}.cxx
113       )
114  ENDIF(NOT ${BBTK_PACKAGE_NAME}_CXX_SOURCES MATCHES "${filename}.cxx") 
115   
116   INSTALL(
117     FILES       ${CMAKE_CURRENT_BINARY_DIR}/${filename}.h 
118     DESTINATION include/bb${BBTK_PACKAGE_NAME})  
119 ENDFOREACH(xmlfile)
120 #----------------------------------------------------------------------------
121
122
123
124 #----------------------------------------------------------------------------
125 # CREATES LIBRARY
126 ADD_LIBRARY(bb${BBTK_PACKAGE_NAME} SHARED 
127   ${${BBTK_PACKAGE_NAME}_CXX_SOURCES} ${${BBTK_PACKAGE_NAME}_H_SOURCES}
128   )
129 TARGET_LINK_LIBRARIES(bb${BBTK_PACKAGE_NAME} 
130   bbtk
131   ${${BBTK_PACKAGE_NAME}_LIBS}
132   )
133 #----------------------------------------------------------------------------
134
135
136 #----------------------------------------------------------------------------
137 # INSTALLS LIBRARY
138 FILE(GLOB ${BBTK_PACKAGE_NAME}_HEADERS "*.h")
139 INSTALL(
140   FILES ${${BBTK_PACKAGE_NAME}_HEADERS}
141   DESTINATION include/bb${BBTK_PACKAGE_NAME}
142   )  
143 INSTALL(
144   TARGETS bb${BBTK_PACKAGE_NAME} 
145   DESTINATION lib)
146
147 # CreateFindPackage
148 SET( LIBRARY_NAME bb${BBTK_PACKAGE_NAME} )
149 # SET THE LIB VERSION
150 SET(${LIBRARY_NAME}_MAJOR_VERSION ${${BBTK_PACKAGE_NAME}_MAJOR_VERSION})
151 SET(${LIBRARY_NAME}_MINOR_VERSION ${${BBTK_PACKAGE_NAME}_MINOR_VERSION})
152 SET(${LIBRARY_NAME}_BUILD_VERSION ${${BBTK_PACKAGE_NAME}_BUILD_VERSION})
153
154 SET(${LIBRARY_NAME}_INSTALL_FOLDER bb${BBTK_PACKAGE_NAME})
155 SET(${LIBRARY_NAME}_LIBRARIES bb${BBTK_PACKAGE_NAME})
156
157 FILE(RELATIVE_PATH 
158   ${LIBRARY_NAME}_BUILD_TREE_RELATIVE_INCLUDE_PATHS 
159   ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
160   )
161
162 IF(UNIX)
163   SET(${LIBRARY_NAME}_BUILD_TREE_RELATIVE_LIBRARY_PATHS 
164     ${EXECUTABLE_OUTPUT_REL_PATH})
165 ELSE(UNIX)
166   SET(${LIBRARY_NAME}_BUILD_TREE_RELATIVE_LIBRARY_PATHS 
167     ${EXECUTABLE_OUTPUT_REL_PATH}/Debug
168     ${EXECUTABLE_OUTPUT_REL_PATH}/Release)
169 ENDIF(UNIX)
170 SET(${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_INCLUDE_PATHS 
171   include/bb${BBTK_PACKAGE_NAME})
172 SET(${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_LIBRARY_PATHS lib)
173
174 # REQUIRED BUILD FLAGS
175 #SET(${LIBRARY_NAME}_REQUIRED_C_FLAGS "")
176 #SET(${LIBRARY_NAME}_REQUIRED_CXX_FLAGS "")
177 #SET(${LIBRARY_NAME}_REQUIRED_LINK_FLAGS "")
178
179 # Additional config/use
180 # Prepare for configure
181 SET(BBTK_PACKAGE_USE_VTK ${${BBTK_PACKAGE_NAME}_USE_VTK})
182 SET(BBTK_PACKAGE_USE_ITK ${${BBTK_PACKAGE_NAME}_USE_ITK})
183 SET(BBTK_PACKAGE_USE_GDCM ${${BBTK_PACKAGE_NAME}_USE_GDCM})
184 SET(BBTK_PACKAGE_USE_GSMIS ${${BBTK_PACKAGE_NAME}_USE_GSMIS})
185 SET(BBTK_PACKAGE_USE_WXWIDGETS ${${BBTK_PACKAGE_NAME}_USE_WXWIDGETS})
186 SET(BBTK_PACKAGE_USE_PACKAGES  ${${BBTK_PACKAGE_NAME}_USE_PACKAGES})
187 SET(BBTK_PACKAGE_INCLUDE_DIRS  ${${BBTK_PACKAGE_NAME}_INCLUDE_DIRS})
188 SET(BBTK_PACKAGE_LIBS          ${${BBTK_PACKAGE_NAME}_LIBS})
189
190 SET(${LIBRARY_NAME}_HAS_ADDITIONAL_CONFIG_FILE TRUE)
191 SET(${LIBRARY_NAME}_ADDITIONAL_CONFIG_FILE 
192   ${${BBTK_PACKAGE_NAME}_SOURCE_DIR}/PackageConfig.cmake.in)
193 SET(${LIBRARY_NAME}_ADDITIONAL_USE_FILE 
194   ${${BBTK_PACKAGE_NAME}_SOURCE_DIR}/UsePackage.cmake.in)
195 #-----------------------------------------------------------------------------
196
197 #-----------------------------------------------------------------------------
198 # Includes CMakeCreateFindPackage
199 INCLUDE(${CMakeCreateFindPackage_DIR}/CMakeCreateFindPackage.cmake)
200 CMAKE_CREATE_FIND_PACKAGE(${LIBRARY_NAME})
201 #-----------------------------------------------------------------------------
202
203 #----------------------------------------------------------------------------
204
205
206
207
208 #---------------------------------------------------------------------------
209 IF(CHCON_LIBRARIES)
210   # On recent linux running SELinux : 
211   # Have to change the context of the library created 
212   # to be able to load it dynamically and avoid the error : 
213   # "cannot restore segment prot after reloc: Permission denied"
214   # see e.g. 
215   # http://www.ittvis.com/services/techtip.asp?ttid=3092
216   # Try to find chcon
217   FIND_PROGRAM(CHCON_EXECUTABLE
218     NAMES chcon
219     PATHS
220     /usr/bin
221     /usr/local/bin
222     )
223   MARK_AS_ADVANCED(CHCON_EXECUTABLE)
224   IF(CHCON_EXECUTABLE)
225     # chcon found 
226     # custom post_build command to change the context of the .so generated
227     ADD_CUSTOM_COMMAND(
228       TARGET bb${BBTK_PACKAGE_NAME}
229       POST_BUILD
230       COMMAND chcon -t texrel_shlib_t ${LIBRARY_OUTPUT_PATH}/libbb${BBTK_PACKAGE_NAME}.so
231       ) 
232     # custom post-install command to change the context of the .so installed
233     INSTALL(CODE "EXEC_PROGRAM(chcon ARGS -t texrel_shlib_t ${CMAKE_INSTALL_PREFIX}/lib/libbb${BBTK_PACKAGE_NAME}.so)")
234   ENDIF(CHCON_EXECUTABLE)
235 ENDIF(CHCON_LIBRARIES)
236 #----------------------------------------------------------------------------
237