]> Creatis software - bbtk.git/blob - kernel/cmake/BBTKConfigurePackage_src.cmake
Initial revision
[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_DIR}/bbPackage.h.in
15   ${CMAKE_CURRENT_BINARY_DIR}/bb${BBTK_PACKAGE_NAME}Package.h
16   @ONLY IMMEDIATE
17   ) 
18 INSTALL_FILES(/include/bb${BBTK_PACKAGE_NAME} FILES bb${BBTK_PACKAGE_NAME}Package.h)  
19 #----------------------------------------------------------------------------
20   
21 #----------------------------------------------------------------------------
22 # CREATES bb${BBTK_PACKAGE_NAME}Package.cxx
23 CONFIGURE_FILE(
24   ${BBTK_DIR}/bbPackage.cxx.in
25   ${CMAKE_CURRENT_BINARY_DIR}/bb${BBTK_PACKAGE_NAME}Package.cxx
26   @ONLY IMMEDIATE
27   )
28 #----------------------------------------------------------------------------
29
30 #----------------------------------------------------------------------------
31 SET_SOURCE_FILES_PROPERTIES(
32   ${CMAKE_CURRENT_BINARY_DIR}/bb${BBTK_PACKAGE_NAME}Package.cxx
33   PROPERTIES GENERATED ON)
34 #----------------------------------------------------------------------------
35
36
37 #----------------------------------------------------------------------------
38 IF(BBTK_PACKAGE_COMPILE_ALL_CXX) 
39   FILE(GLOB BBTK_PACKAGE_CXX_SOURCES "." "*.cxx")
40   FILE(GLOB BBTK_PACKAGE_H_SOURCES "." "*.h")
41 ENDIF(BBTK_PACKAGE_COMPILE_ALL_CXX) 
42
43
44 SET(BBTK_PACKAGE_CXX_SOURCES
45   ${BBTK_PACKAGE_CXX_SOURCES}
46   #${CMAKE_CURRENT_BINARY_DIR_NAME}/
47   bb${BBTK_PACKAGE_NAME}Package
48   )
49 #----------------------------------------------------------------------------
50
51
52 #----------------------------------------------------------------------------
53 #----------------------------------------------------------------------------
54 # bbfy
55 #----------------------------------------------------------------------------
56
57 #----------------------------------------------------------------------------
58 IF(BBTK_PACKAGE_COMPILE_ALL_XML) 
59   FILE(GLOB BBTK_PACKAGE_XML_SOURCES "." "*.xml")
60 ENDIF(BBTK_PACKAGE_COMPILE_ALL_XML) 
61 #----------------------------------------------------------------------------
62 FOREACH(xmlfile ${BBTK_PACKAGE_XML_SOURCES})
63   
64   GET_FILENAME_COMPONENT(filename "${xmlfile}" NAME_WE) 
65   
66   IF(WIN32)
67     SET(bbfy_EXECUTABLE $(TargetDir)/bbfy.exe)
68   ELSE(WIN32)
69     SET(bbfy_EXECUTABLE ${EXECUTABLE_OUTPUT_PATH}/bbfy)
70   ENDIF(WIN32)      
71   
72   IF(BBFY_DEPENDENCY)
73     SET(BBFY_DEPENDENCY_STR ${bbfy_EXECUTABLE})
74   ENDIF(BBFY_DEPENDENCY)
75   
76   SET(BBFY_CXX_OUT ${CMAKE_CURRENT_BINARY_DIR}/${filename}.cxx)
77   
78   ADD_CUSTOM_COMMAND(
79     OUTPUT ${BBFY_CXX_OUT}
80     COMMAND 
81     ${bbfy_EXECUTABLE} ${xmlfile} ${CMAKE_CURRENT_BINARY_DIR}/ -q
82     DEPENDS ${xmlfile}
83     # LG : REMOVE AUTOMATIC DEPEDENCY ON bbfy BECAUSE CAUSED ALWAYS REBUILD xml BOXES WHEN bbtk CHANGED HENCE bbfy CHANGED
84     ${BBFY_DEPENDENCY_STR} 
85     #${bbfy_EXECUTABLE} 
86     )
87   
88   SET_SOURCE_FILES_PROPERTIES(
89     ${BBFY_CXX_OUT}
90     PROPERTIES GENERATED ON)
91   
92   
93   IF(NOT BBTK_PACKAGE_CXX_SOURCES MATCHES "${filename}")
94     SET(BBTK_PACKAGE_CXX_SOURCES
95       ${BBTK_PACKAGE_CXX_SOURCES}
96       ${filename}
97       )
98   ENDIF(NOT BBTK_PACKAGE_CXX_SOURCES MATCHES "${filename}") 
99   
100   INSTALL_FILES(/include/bb${BBTK_PACKAGE_NAME} FILES ${filename}.h)  
101 ENDFOREACH(xmlfile)
102 #----------------------------------------------------------------------------
103
104
105
106 #----------------------------------------------------------------------------
107 # CREATES LIBRARY
108 ADD_LIBRARY(bb${BBTK_PACKAGE_NAME} SHARED 
109   ${BBTK_PACKAGE_CXX_SOURCES} ${BBTK_PACKAGE_H_SOURCES}
110   )
111 TARGET_LINK_LIBRARIES(bb${BBTK_PACKAGE_NAME} 
112   bbtk
113   #  ${BBP_LINK_LIBRARIES} 
114   ${BBTK_PACKAGE_LIBS}
115   )
116 #----------------------------------------------------------------------------
117
118
119 #----------------------------------------------------------------------------
120 # INSTALLS LIBRARY
121 # NOW USES THE InstallLibrary.cmake 
122 SET( LIBRARY_NAME bb${BBTK_PACKAGE_NAME} )
123 # SET THE LIB VERSION
124 SET(${LIBRARY_NAME}_MAJOR_VERSION ${BBTK_PACKAGE_MAJOR_VERSION})
125 SET(${LIBRARY_NAME}_MINOR_VERSION ${BBTK_PACKAGE_MINOR_VERSION})
126 SET(${LIBRARY_NAME}_BUILD_VERSION ${BBTK_PACKAGE_BUILD_VERSION})
127
128 #SET(INSTALL_LIBRARY_PATH ../cmake)
129 # Include the file 'InstallLibrary.cmake' which does the clean install job
130 #INCLUDE(${INSTALL_LIBRARY_PATH}/InstallLibrary.cmake)
131
132 # OLD VERSION :
133 # DEPRECATED SYNTAX BUT WHICH WORKS !!
134 INSTALL_FILES(/include/bb${BBTK_PACKAGE_NAME} "\\.h$")  
135 #INSTALL(FILES "$.h" DESTINATION include/${BBTK_PACKAGE_NAME})  
136 INSTALL(TARGETS bb${BBTK_PACKAGE_NAME} DESTINATION lib)
137 #  INSTALL_TARGETS(/lib bb${BBTK_PACKAGE_NAME})
138 #----------------------------------------------------------------------------
139
140
141
142
143 #---------------------------------------------------------------------------
144 IF(CHCON_LIBRARIES)
145   # On recent linux running SELinux : 
146   # Have to change the context of the library created 
147   # to be able to load it dynamically and avoid the error : 
148   # "cannot restore segment prot after reloc: Permission denied"
149   # see e.g. 
150   # http://www.ittvis.com/services/techtip.asp?ttid=3092
151   # Try to find chcon
152   FIND_PROGRAM(CHCON_EXECUTABLE
153     NAMES chcon
154     PATHS
155     /usr/bin
156     /usr/local/bin
157     )
158   MARK_AS_ADVANCED(CHCON_EXECUTABLE)
159   IF(CHCON_EXECUTABLE)
160     # chcon found 
161     # custom post_build command to change the context of the .so generated
162     ADD_CUSTOM_COMMAND(
163       TARGET bb${BBTK_PACKAGE_NAME}
164       POST_BUILD
165       COMMAND chcon -t texrel_shlib_t ${LIBRARY_OUTPUT_PATH}/libbb${BBTK_PACKAGE_NAME}.so
166       ) 
167     # custom post-install command to change the context of the .so installed
168     INSTALL(CODE "EXEC_PROGRAM(chcon ARGS -t texrel_shlib_t ${CMAKE_INSTALL_PREFIX}/lib/libbb${BBTK_PACKAGE_NAME}.so)")
169   ENDIF(CHCON_EXECUTABLE)
170 ENDIF(CHCON_LIBRARIES)
171 #----------------------------------------------------------------------------
172