]> Creatis software - bbtk.git/blob - kernel/cmake/BBTKConfigurePackage_src.cmake
no 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 # CREATES bb${BBTK_PACKAGE_NAME}_EXPORT.h
13 CREA_DYNAMIC_LIBRARY_EXPORT(bb${BBTK_PACKAGE_NAME})
14 INSTALL(
15   FILES ${CMAKE_CURRENT_BINARY_DIR}/bb${BBTK_PACKAGE_NAME}_EXPORT.h
16   DESTINATION include/bb${BBTK_PACKAGE_NAME} 
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}_CPP_SOURCES "." "*.cpp")
53   SET(${BBTK_PACKAGE_NAME}_CXX_SOURCES ${${BBTK_PACKAGE_NAME}_CXX_SOURCES} ${${BBTK_PACKAGE_NAME}_CPP_SOURCES})
54   FILE(GLOB ${BBTK_PACKAGE_NAME}_H_SOURCES "." "*.h")
55 ENDIF(${BBTK_PACKAGE_NAME}_COMPILE_ALL_CXX) 
56
57 IF(NOT PROJECT_BINARY_DIR STREQUAL ${PROJECT_SOURCE_DIR})
58   SET(${BBTK_PACKAGE_NAME}_CXX_SOURCES
59     ${${BBTK_PACKAGE_NAME}_CXX_SOURCES}
60     bb${BBTK_PACKAGE_NAME}Package
61     )
62 ENDIF(NOT PROJECT_BINARY_DIR STREQUAL ${PROJECT_SOURCE_DIR})
63 #----------------------------------------------------------------------------
64
65
66 #----------------------------------------------------------------------------
67 #----------------------------------------------------------------------------
68 # bbfy
69 #----------------------------------------------------------------------------
70
71 #----------------------------------------------------------------------------
72 IF(${BBTK_PACKAGE_NAME}_COMPILE_ALL_XML) 
73   FILE(GLOB ${BBTK_PACKAGE_NAME}_XML_SOURCES "." "*.xml")
74 ENDIF(${BBTK_PACKAGE_NAME}_COMPILE_ALL_XML) 
75 #----------------------------------------------------------------------------
76 FOREACH(xmlfile ${${BBTK_PACKAGE_NAME}_XML_SOURCES})
77   GET_FILENAME_COMPONENT(filename "${xmlfile}" NAME_WE) 
78   
79   SET(BBFY_CXX_OUT ${CMAKE_CURRENT_BINARY_DIR}/${filename}.cxx)
80   
81   IF (WIN32)
82     MAKE_DLL_PATH()
83  #   SET(command00 Path=c:/creatis/dlls__RR__%WXWIN%/lib/vc_dll/__RR__%VTK_DIR%__RR__%ITK_DIR%/../../bin/__RR__%PATH%)
84  #   STRING(REPLACE "__RR__" "\;" SETPATH ${command00} )
85  #   SET(SETPATH set ${command0} &&)
86  ADD_CUSTOM_COMMAND(
87     OUTPUT ${BBFY_CXX_OUT}
88     COMMAND
89     set Path=${DLL_PATH} && ${BBTK_BBFY} ${xmlfile} ${BBTK_PACKAGE_NAME} ${CMAKE_CURRENT_BINARY_DIR}/ -q
90     DEPENDS ${xmlfile}
91     ${BBTK_BBFY_DEPENDENCY} 
92     )
93   ELSE(WIN32)
94     SET(LD_LIBRARY_PATH "$ENV{LD_LIBRARY_PATH}:${LIBRARY_OUTPUT_PATH}")
95     ADD_CUSTOM_COMMAND(
96       OUTPUT ${BBFY_CXX_OUT}
97       COMMAND
98       export LD_LIBRARY_PATH=${LD_LIBRARY_PATH} && ${BBTK_BBFY} ${xmlfile} ${BBTK_PACKAGE_NAME} ${CMAKE_CURRENT_BINARY_DIR}/ -q
99       DEPENDS ${xmlfile}
100       ${BBTK_BBFY_DEPENDENCY} 
101       )
102     
103   ENDIF(WIN32)
104   
105   
106   SET_SOURCE_FILES_PROPERTIES(
107     ${BBFY_CXX_OUT}
108     PROPERTIES GENERATED ON)
109   
110   
111  IF(NOT ${BBTK_PACKAGE_NAME}_CXX_SOURCES MATCHES "${filename}.cxx")
112  # message ("EED Alert BBTKConfigurePackage_src  "  "IF NOT MATCHES" )
113   SET(${BBTK_PACKAGE_NAME}_CXX_SOURCES
114       ${${BBTK_PACKAGE_NAME}_CXX_SOURCES}
115       ${filename}.cxx
116       )
117  ENDIF(NOT ${BBTK_PACKAGE_NAME}_CXX_SOURCES MATCHES "${filename}.cxx") 
118   
119   INSTALL(
120     FILES       ${CMAKE_CURRENT_BINARY_DIR}/${filename}.h 
121     DESTINATION include/bb${BBTK_PACKAGE_NAME})  
122 ENDFOREACH(xmlfile)
123 #----------------------------------------------------------------------------
124
125
126
127 #----------------------------------------------------------------------------
128 # CREATES LIBRARY
129 #----------------------------------------------------------------------------
130 # TCL WRAPPING FOR KWWIDGETS
131 IF(BBTK_USE_KWWIDGETS)
132 #MESSAGE(STATUS "****TCL=${${BBTK_PACKAGE_NAME}_CXX_SOURCES_WRAP_TCL}")
133 IF(${BBTK_PACKAGE_NAME}_CXX_SOURCES_WRAP_TCL )
134 #MESSAGE(STATUS "****TCL OK")
135 include("${KWWidgets_CMAKE_DIR}/KWWidgetsWrappingMacros.cmake")
136 kwwidgets_wrap_tcl(bb${BBTK_PACKAGE_NAME} LIB_TCL_SRCS ${${BBTK_PACKAGE_NAME}_CXX_SOURCES_WRAP_TCL} "")
137 SET(${BBTK_PACKAGE_NAME}_CXX_SOURCES 
138   ${${BBTK_PACKAGE_NAME}_CXX_SOURCES} 
139   ${LIB_TCL_SRCS})
140 ENDIF(${BBTK_PACKAGE_NAME}_CXX_SOURCES_WRAP_TCL)
141 ENDIF(BBTK_USE_KWWIDGETS)
142 #----------------------------------------------------------------------------
143 #MESSAGE(STATUS ${${BBTK_PACKAGE_NAME}_CXX_SOURCES})
144
145 ADD_LIBRARY(bb${BBTK_PACKAGE_NAME} SHARED 
146   ${${BBTK_PACKAGE_NAME}_CXX_SOURCES} ${${BBTK_PACKAGE_NAME}_H_SOURCES}
147   )
148
149
150 TARGET_LINK_LIBRARIES(bb${BBTK_PACKAGE_NAME} 
151   bbtk
152   ${${BBTK_PACKAGE_NAME}_LIBS}
153   )
154 IF(UNIX)
155 SET_TARGET_PROPERTIES(bb${BBTK_PACKAGE_NAME} PROPERTIES COMPILE_FLAGS -Wall)
156 ENDIF(UNIX)
157 #----------------------------------------------------------------------------
158
159
160 #----------------------------------------------------------------------------
161 # INSTALLS LIBRARY
162 FILE(GLOB ${BBTK_PACKAGE_NAME}_HEADERS "*.h")
163 INSTALL(
164   FILES ${${BBTK_PACKAGE_NAME}_HEADERS}
165   DESTINATION include/bb${BBTK_PACKAGE_NAME}
166   )  
167 INSTALL(
168   TARGETS bb${BBTK_PACKAGE_NAME} 
169   DESTINATION ${BBTK_PACKAGE_LIB_PATH}
170   )
171
172
173 # Preparing macro invocation : CREA_ADVANCED_INSTALL_LIBRARY_FOR_CMAKE
174 SET( LIBRARY_NAME bb${BBTK_PACKAGE_NAME} )
175 # SET THE LIB VERSION
176 SET(${LIBRARY_NAME}_MAJOR_VERSION ${${BBTK_PACKAGE_NAME}_MAJOR_VERSION})
177 SET(${LIBRARY_NAME}_MINOR_VERSION ${${BBTK_PACKAGE_NAME}_MINOR_VERSION})
178 SET(${LIBRARY_NAME}_BUILD_VERSION ${${BBTK_PACKAGE_NAME}_BUILD_VERSION})
179
180 SET(${LIBRARY_NAME}_INSTALL_FOLDER bb${BBTK_PACKAGE_NAME})
181 SET(${LIBRARY_NAME}_LIBRARIES bb${BBTK_PACKAGE_NAME})
182
183 FILE(RELATIVE_PATH 
184   ${LIBRARY_NAME}_BUILD_TREE_RELATIVE_INCLUDE_PATHS 
185   ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
186   )
187
188 IF ( ${PROJECT_BINARY_DIR} STREQUAL ${EXECUTABLE_OUTPUT_PATH} )
189   SET(CILFC_EXECUTABLE_OUTPUT_REL_PATH ".")
190 ELSE ( ${PROJECT_BINARY_DIR} STREQUAL ${EXECUTABLE_OUTPUT_PATH} )
191   FILE(RELATIVE_PATH 
192     CILFC_EXECUTABLE_OUTPUT_REL_PATH
193     ${PROJECT_BINARY_DIR} ${EXECUTABLE_OUTPUT_PATH})
194 ENDIF ( ${PROJECT_BINARY_DIR} STREQUAL ${EXECUTABLE_OUTPUT_PATH} )
195
196 IF(UNIX)
197   SET(${LIBRARY_NAME}_BUILD_TREE_RELATIVE_LIBRARY_PATHS
198     ${CILFC_EXECUTABLE_OUTPUT_REL_PATH})
199 ELSE(UNIX)
200   SET(${LIBRARY_NAME}_BUILD_TREE_RELATIVE_LIBRARY_PATHS
201     ${CILFC_EXECUTABLE_OUTPUT_REL_PATH})
202 ENDIF(UNIX)
203
204 SET(${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_INCLUDE_PATHS 
205   include/bb${BBTK_PACKAGE_NAME})
206 SET(${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_LIBRARY_PATHS ${BBTK_PACKAGE_LIB_PATH})
207
208 # REQUIRED BUILD FLAGS
209 #SET(${LIBRARY_NAME}_REQUIRED_C_FLAGS "")
210 #SET(${LIBRARY_NAME}_REQUIRED_CXX_FLAGS "")
211 #SET(${LIBRARY_NAME}_REQUIRED_LINK_FLAGS "")
212
213 # Additional config/use
214 # Prepare for configure
215 SET(BBTK_PACKAGE_USE_VTK       ${${BBTK_PACKAGE_NAME}_USE_VTK})
216 SET(BBTK_PACKAGE_USE_ITK       ${${BBTK_PACKAGE_NAME}_USE_ITK})
217 SET(BBTK_PACKAGE_USE_QT        ${${BBTK_PACKAGE_NAME}_USE_QT})
218 SET(BBTK_PACKAGE_USE_GDCM      ${${BBTK_PACKAGE_NAME}_USE_GDCM})
219 SET(BBTK_PACKAGE_USE_GDCM2     ${${BBTK_PACKAGE_NAME}_USE_GDCM2})
220 SET(BBTK_PACKAGE_USE_GSMIS     ${${BBTK_PACKAGE_NAME}_USE_GSMIS})
221 SET(BBTK_PACKAGE_USE_WXWIDGETS ${${BBTK_PACKAGE_NAME}_USE_WXWIDGETS})
222 SET(BBTK_PACKAGE_USE_PACKAGES  ${${BBTK_PACKAGE_NAME}_USE_PACKAGES})
223 SET(BBTK_PACKAGE_INCLUDE_DIRS  ${${BBTK_PACKAGE_NAME}_INCLUDE_DIRS})
224 SET(BBTK_PACKAGE_LIBS          ${${BBTK_PACKAGE_NAME}_LIBS})
225
226 SET(${LIBRARY_NAME}_HAS_ADDITIONAL_CONFIG_FILE TRUE)
227 SET(${LIBRARY_NAME}_ADDITIONAL_CONFIG_FILE 
228   ${${BBTK_PACKAGE_NAME}_SOURCE_DIR}/PackageConfig.cmake.in)
229 SET(${LIBRARY_NAME}_ADDITIONAL_USE_FILE 
230   ${${BBTK_PACKAGE_NAME}_SOURCE_DIR}/UsePackage.cmake.in)
231 #-----------------------------------------------------------------------------
232
233 #-----------------------------------------------------------------------------
234 CREA_ADVANCED_INSTALL_LIBRARY_FOR_CMAKE(${LIBRARY_NAME})
235 #-----------------------------------------------------------------------------
236
237 #----------------------------------------------------------------------------
238
239
240
241
242 #---------------------------------------------------------------------------
243 IF(CHCON_LIBRARIES)
244   # On recent linux running SELinux : 
245   # Have to change the context of the library created 
246   # to be able to load it dynamically and avoid the error : 
247   # "cannot restore segment prot after reloc: Permission denied"
248   # see e.g. 
249   # http://www.ittvis.com/services/techtip.asp?ttid=3092
250   # Try to find chcon
251   FIND_PROGRAM(CHCON_EXECUTABLE
252     NAMES chcon
253     PATHS
254     /usr/bin
255     /usr/local/bin
256     )
257   MARK_AS_ADVANCED(CHCON_EXECUTABLE)
258   IF(CHCON_EXECUTABLE)
259     # chcon found 
260     # custom post_build command to change the context of the .so generated
261     ADD_CUSTOM_COMMAND(
262       TARGET bb${BBTK_PACKAGE_NAME}
263       POST_BUILD
264       COMMAND chcon -t texrel_shlib_t ${LIBRARY_OUTPUT_PATH}/libbb${BBTK_PACKAGE_NAME}.so
265       ) 
266     # custom post-install command to change the context of the .so installed
267     INSTALL(CODE "EXEC_PROGRAM(chcon ARGS -t texrel_shlib_t ${CMAKE_INSTALL_PREFIX}/lib/libbb${BBTK_PACKAGE_NAME}.so)")
268   ENDIF(CHCON_EXECUTABLE)
269 ENDIF(CHCON_LIBRARIES)
270 #----------------------------------------------------------------------------
271