]> 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 # CREATES bb${BBTK_PACKAGE_NAME}Package.h
13 CONFIGURE_FILE(
14   ${BBTK_CMAKE_DIR}/bbPackage.h.in
15   ${CMAKE_CURRENT_BINARY_DIR}/bb${BBTK_PACKAGE_NAME}Package.h
16   @ONLY IMMEDIATE
17   ) 
18 INSTALL(
19   FILES ${CMAKE_CURRENT_BINARY_DIR}/bb${BBTK_PACKAGE_NAME}Package.h
20   DESTINATION include/bb${BBTK_PACKAGE_NAME} 
21   )
22 #----------------------------------------------------------------------------
23   
24 #----------------------------------------------------------------------------
25 # CREATES bb${BBTK_PACKAGE_NAME}Package.cxx
26 CONFIGURE_FILE(
27   ${BBTK_CMAKE_DIR}/bbPackage.cxx.in
28   ${CMAKE_CURRENT_BINARY_DIR}/bb${BBTK_PACKAGE_NAME}Package.cxx
29   @ONLY IMMEDIATE
30   )
31 #----------------------------------------------------------------------------
32
33 #----------------------------------------------------------------------------
34 SET_SOURCE_FILES_PROPERTIES(
35   ${CMAKE_CURRENT_BINARY_DIR}/bb${BBTK_PACKAGE_NAME}Package.cxx
36   PROPERTIES GENERATED ON)
37 #----------------------------------------------------------------------------
38
39
40 #----------------------------------------------------------------------------
41 IF(BBTK_PACKAGE_COMPILE_ALL_CXX) 
42   FILE(GLOB BBTK_PACKAGE_CXX_SOURCES "." "*.cxx")
43   FILE(GLOB BBTK_PACKAGE_H_SOURCES "." "*.h")
44 ENDIF(BBTK_PACKAGE_COMPILE_ALL_CXX) 
45
46
47 SET(BBTK_PACKAGE_CXX_SOURCES
48   ${BBTK_PACKAGE_CXX_SOURCES}
49   #${CMAKE_CURRENT_BINARY_DIR_NAME}/
50   bb${BBTK_PACKAGE_NAME}Package
51   )
52 #----------------------------------------------------------------------------
53
54
55 #----------------------------------------------------------------------------
56 #----------------------------------------------------------------------------
57 # bbfy
58 #----------------------------------------------------------------------------
59
60 #----------------------------------------------------------------------------
61 IF(BBTK_PACKAGE_COMPILE_ALL_XML) 
62   FILE(GLOB BBTK_PACKAGE_XML_SOURCES "." "*.xml")
63 ENDIF(BBTK_PACKAGE_COMPILE_ALL_XML) 
64 #----------------------------------------------------------------------------
65 FOREACH(xmlfile ${BBTK_PACKAGE_XML_SOURCES})
66   
67   GET_FILENAME_COMPONENT(filename "${xmlfile}" NAME_WE) 
68   
69   
70   SET(BBFY_CXX_OUT ${CMAKE_CURRENT_BINARY_DIR}/${filename}.cxx)
71   
72   ADD_CUSTOM_COMMAND(
73     OUTPUT ${BBFY_CXX_OUT}
74     COMMAND 
75     ${BBTK_BBFY} ${xmlfile} ${CMAKE_CURRENT_BINARY_DIR}/ -q
76     DEPENDS ${xmlfile}
77     ${BBTK_BBFY_DEPENDENCY} 
78     )
79   
80   SET_SOURCE_FILES_PROPERTIES(
81     ${BBFY_CXX_OUT}
82     PROPERTIES GENERATED ON)
83   
84   
85   IF(NOT BBTK_PACKAGE_CXX_SOURCES MATCHES "${filename}")
86     SET(BBTK_PACKAGE_CXX_SOURCES
87       ${BBTK_PACKAGE_CXX_SOURCES}
88       ${filename}
89       )
90   ENDIF(NOT BBTK_PACKAGE_CXX_SOURCES MATCHES "${filename}") 
91   
92   INSTALL(
93     FILES       ${CMAKE_CURRENT_BINARY_DIR}/${filename}.h 
94     DESTINATION include/bb${BBTK_PACKAGE_NAME})  
95
96 ENDFOREACH(xmlfile)
97 #----------------------------------------------------------------------------
98
99
100
101 #----------------------------------------------------------------------------
102 # CREATES LIBRARY
103 ADD_LIBRARY(bb${BBTK_PACKAGE_NAME} SHARED 
104   ${BBTK_PACKAGE_CXX_SOURCES} ${BBTK_PACKAGE_H_SOURCES}
105   )
106 TARGET_LINK_LIBRARIES(bb${BBTK_PACKAGE_NAME} 
107   bbtk
108   ${BBTK_PACKAGE_LIBS}
109   )
110 #----------------------------------------------------------------------------
111
112
113 #----------------------------------------------------------------------------
114 # INSTALLS LIBRARY
115 FILE(GLOB ${BBTK_PACKAGE_NAME}_HEADERS "*.h")
116 INSTALL(
117   FILES ${${BBTK_PACKAGE_NAME}_HEADERS}
118   DESTINATION include/bb${BBTK_PACKAGE_NAME}
119   )  
120 INSTALL(
121   TARGETS bb${BBTK_PACKAGE_NAME} 
122   DESTINATION lib)
123
124 # CreateFindPackage
125 SET( LIBRARY_NAME bb${BBTK_PACKAGE_NAME} )
126 # SET THE LIB VERSION
127 SET(${LIBRARY_NAME}_MAJOR_VERSION ${BBTK_PACKAGE_MAJOR_VERSION})
128 SET(${LIBRARY_NAME}_MINOR_VERSION ${BBTK_PACKAGE_MINOR_VERSION})
129 SET(${LIBRARY_NAME}_BUILD_VERSION ${BBTK_PACKAGE_BUILD_VERSION})
130
131 SET(${LIBRARY_NAME}_INSTALL_FOLDER bb${BBTK_PACKAGE_NAME})
132 SET(${LIBRARY_NAME}_LIBRARIES bb${BBTK_PACKAGE_NAME})
133
134 FILE(RELATIVE_PATH 
135   ${LIBRARY_NAME}_BUILD_TREE_RELATIVE_INCLUDE_PATHS 
136   ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
137   )
138
139 IF(UNIX)
140   SET(${LIBRARY_NAME}_BUILD_TREE_RELATIVE_LIBRARY_PATHS 
141     ${EXECUTABLE_OUTPUT_REL_PATH})
142 ELSE(UNIX)
143   SET(${LIBRARY_NAME}_BUILD_TREE_RELATIVE_LIBRARY_PATHS 
144     ${EXECUTABLE_OUTPUT_REL_PATH}/Debug
145     ${EXECUTABLE_OUTPUT_REL_PATH}/Release)
146 ENDIF(UNIX)
147 SET(${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_INCLUDE_PATHS 
148   include/bb${BBTK_PACKAGE_NAME})
149 SET(${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_LIBRARY_PATHS lib)
150
151 # OPTIONAL 
152 # - Set the version of your library
153 # SET YOUR LIB VERSION
154 #SET(${LIBRARY_NAME}_MAJOR_VERSION 1)
155 #SET(${LIBRARY_NAME}_MINOR_VERSION 0)
156 #SET(${LIBRARY_NAME}_BUILD_VERSION 0)
157 # REQUIRED BUILD FLAGS
158 #SET(${LIBRARY_NAME}_REQUIRED_C_FLAGS "")
159 #SET(${LIBRARY_NAME}_REQUIRED_CXX_FLAGS "")
160 #SET(${LIBRARY_NAME}_REQUIRED_LINK_FLAGS "")
161 # ADDITIONAL CONFIG FILE
162 # HERE WE USE ONE TO EXPORT testLib_EXPORTED_VALUE
163
164 SET(${LIBRARY_NAME}_HAS_ADDITIONAL_CONFIG_FILE TRUE)
165 SET(${LIBRARY_NAME}_ADDITIONAL_CONFIG_FILE 
166   ${PROJECT_SOURCE_DIR}/PackageConfig.cmake.in)
167 SET(${LIBRARY_NAME}_ADDITIONAL_USE_FILE 
168   ${PROJECT_SOURCE_DIR}/UsePackage.cmake.in)
169 #-----------------------------------------------------------------------------
170
171 #-----------------------------------------------------------------------------
172 # Includes CMakeCreateFindPackage
173 INCLUDE(${CMakeCreateFindPackage_DIR}/CMakeCreateFindPackage.cmake)
174 CMAKE_CREATE_FIND_PACKAGE(${LIBRARY_NAME})
175 #-----------------------------------------------------------------------------
176
177 #----------------------------------------------------------------------------
178
179
180
181
182 #---------------------------------------------------------------------------
183 IF(CHCON_LIBRARIES)
184   # On recent linux running SELinux : 
185   # Have to change the context of the library created 
186   # to be able to load it dynamically and avoid the error : 
187   # "cannot restore segment prot after reloc: Permission denied"
188   # see e.g. 
189   # http://www.ittvis.com/services/techtip.asp?ttid=3092
190   # Try to find chcon
191   FIND_PROGRAM(CHCON_EXECUTABLE
192     NAMES chcon
193     PATHS
194     /usr/bin
195     /usr/local/bin
196     )
197   MARK_AS_ADVANCED(CHCON_EXECUTABLE)
198   IF(CHCON_EXECUTABLE)
199     # chcon found 
200     # custom post_build command to change the context of the .so generated
201     ADD_CUSTOM_COMMAND(
202       TARGET bb${BBTK_PACKAGE_NAME}
203       POST_BUILD
204       COMMAND chcon -t texrel_shlib_t ${LIBRARY_OUTPUT_PATH}/libbb${BBTK_PACKAGE_NAME}.so
205       ) 
206     # custom post-install command to change the context of the .so installed
207     INSTALL(CODE "EXEC_PROGRAM(chcon ARGS -t texrel_shlib_t ${CMAKE_INSTALL_PREFIX}/lib/libbb${BBTK_PACKAGE_NAME}.so)")
208   ENDIF(CHCON_EXECUTABLE)
209 ENDIF(CHCON_LIBRARIES)
210 #----------------------------------------------------------------------------
211