]> Creatis software - bbtk.git/blob - kernel/cmake/BBTKConfigurePackage_src.cmake
* Created vtk package
[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   
79   SET(BBFY_CXX_OUT ${CMAKE_CURRENT_BINARY_DIR}/${filename}.cxx)
80   
81   ADD_CUSTOM_COMMAND(
82     OUTPUT ${BBFY_CXX_OUT}
83     COMMAND 
84     ${BBTK_BBFY} ${xmlfile} ${BBTK_PACKAGE_NAME} ${CMAKE_CURRENT_BINARY_DIR}/ -q
85     DEPENDS ${xmlfile}
86     ${BBTK_BBFY_DEPENDENCY} 
87     )
88   
89   SET_SOURCE_FILES_PROPERTIES(
90     ${BBFY_CXX_OUT}
91     PROPERTIES GENERATED ON)
92   
93   
94   IF(NOT ${BBTK_PACKAGE_NAME}_CXX_SOURCES MATCHES "${filename}")
95     SET(${BBTK_PACKAGE_NAME}_CXX_SOURCES
96       ${${BBTK_PACKAGE_NAME}_CXX_SOURCES}
97       ${filename}
98       )
99   ENDIF(NOT ${BBTK_PACKAGE_NAME}_CXX_SOURCES MATCHES "${filename}") 
100   
101   INSTALL(
102     FILES       ${CMAKE_CURRENT_BINARY_DIR}/${filename}.h 
103     DESTINATION include/bb${BBTK_PACKAGE_NAME})  
104
105 ENDFOREACH(xmlfile)
106 #----------------------------------------------------------------------------
107
108
109
110 #----------------------------------------------------------------------------
111 # CREATES LIBRARY
112 ADD_LIBRARY(bb${BBTK_PACKAGE_NAME} SHARED 
113   ${${BBTK_PACKAGE_NAME}_CXX_SOURCES} ${${BBTK_PACKAGE_NAME}_H_SOURCES}
114   )
115 TARGET_LINK_LIBRARIES(bb${BBTK_PACKAGE_NAME} 
116   bbtk
117   ${${BBTK_PACKAGE_NAME}_LIBS}
118   )
119 #----------------------------------------------------------------------------
120
121
122 #----------------------------------------------------------------------------
123 # INSTALLS LIBRARY
124 FILE(GLOB ${BBTK_PACKAGE_NAME}_HEADERS "*.h")
125 INSTALL(
126   FILES ${${BBTK_PACKAGE_NAME}_HEADERS}
127   DESTINATION include/bb${BBTK_PACKAGE_NAME}
128   )  
129 INSTALL(
130   TARGETS bb${BBTK_PACKAGE_NAME} 
131   DESTINATION lib)
132
133 # CreateFindPackage
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})
139
140 SET(${LIBRARY_NAME}_INSTALL_FOLDER bb${BBTK_PACKAGE_NAME})
141 SET(${LIBRARY_NAME}_LIBRARIES bb${BBTK_PACKAGE_NAME})
142
143 FILE(RELATIVE_PATH 
144   ${LIBRARY_NAME}_BUILD_TREE_RELATIVE_INCLUDE_PATHS 
145   ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
146   )
147
148 IF(UNIX)
149   SET(${LIBRARY_NAME}_BUILD_TREE_RELATIVE_LIBRARY_PATHS 
150     ${EXECUTABLE_OUTPUT_REL_PATH})
151 ELSE(UNIX)
152   SET(${LIBRARY_NAME}_BUILD_TREE_RELATIVE_LIBRARY_PATHS 
153     ${EXECUTABLE_OUTPUT_REL_PATH}/Debug
154     ${EXECUTABLE_OUTPUT_REL_PATH}/Release)
155 ENDIF(UNIX)
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)
159
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 "")
164
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})
175
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 #-----------------------------------------------------------------------------
182
183 #-----------------------------------------------------------------------------
184 # Includes CMakeCreateFindPackage
185 INCLUDE(${CMakeCreateFindPackage_DIR}/CMakeCreateFindPackage.cmake)
186 CMAKE_CREATE_FIND_PACKAGE(${LIBRARY_NAME})
187 #-----------------------------------------------------------------------------
188
189 #----------------------------------------------------------------------------
190
191
192
193
194 #---------------------------------------------------------------------------
195 IF(CHCON_LIBRARIES)
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"
200   # see e.g. 
201   # http://www.ittvis.com/services/techtip.asp?ttid=3092
202   # Try to find chcon
203   FIND_PROGRAM(CHCON_EXECUTABLE
204     NAMES chcon
205     PATHS
206     /usr/bin
207     /usr/local/bin
208     )
209   MARK_AS_ADVANCED(CHCON_EXECUTABLE)
210   IF(CHCON_EXECUTABLE)
211     # chcon found 
212     # custom post_build command to change the context of the .so generated
213     ADD_CUSTOM_COMMAND(
214       TARGET bb${BBTK_PACKAGE_NAME}
215       POST_BUILD
216       COMMAND chcon -t texrel_shlib_t ${LIBRARY_OUTPUT_PATH}/libbb${BBTK_PACKAGE_NAME}.so
217       ) 
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 #----------------------------------------------------------------------------
223