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