1 #-----------------------------------------------------------------------------
2 # Macro CREA_ADVANCED_INSTALL_LIBRARY_FOR_CMAKE
3 # Creates and install the cmake files which allow
4 # to find the library by the cmake command FIND_PACKAGE.
8 # LIBRARY_NAME : name of the library to find
10 # The following variables **MUST** have been set previously :
12 # * ${LIBRARY_NAME}_BUILD_TREE_RELATIVE_INCLUDE_PATHS
13 # The list of include paths
14 # when someone uses a *BUILD TREE* version of ${LIBRARY_NAME}.
16 # THE PATHS *MUST BE RELATIVE* TO THE ROOT DIR OF THE PROJECT **SOURCES** !
17 # Assume your project architecture is :
18 # install/ : directory in which the macro is invoked
19 # src/part1/include/ : first include dir
20 # src/part2/include/ : second include dir
21 # Then you should set the var with :
22 # SET(${LIBRARY_NAME}_BUILD_TREE_RELATIVE_INCLUDE_PATHS
25 # Which will result in actual include paths :
26 # ${PROJECT_SOURCE_DIR}/src/part1/include;
27 # ${PROJECT_SOURCE_DIR}/src/part2/include
28 # * ${LIBRARY_NAME}_BUILD_TREE_RELATIVE_LIBRARY_PATHS
29 # Like the previous var but for the library paths.
31 # THE PATHS *MUST BE RELATIVE* TO THE ROOT DIR OF THE **BUILD TREE**
32 # THAT IS POINT TO THE FOLDERS WHERE THE LIBS WILL BE BUILD
33 # Assume that your project architecture is :
34 # src/part1/src/ : first source dir, in which the lib 'part1' is built
35 # src/part2/src/ : first source dir, in which the lib 'part2' is built
36 # Then you should set the var with
37 # SET(${LIBRARY_NAME}_BUILD_TREE_RELATIVE_LIBRARY_PATHS
41 # Which will result in actual library paths :
42 # ${PROJECT_BINARY_DIR}/src/part1/src
43 # ${PROJECT_BINARY_DIR}/src/part2/src
44 # * ${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_INCLUDE_PATHS
45 # The list of include paths
46 # when someone uses an *INSTALLED* version of ${LIBRARY_NAME}
47 # The paths *MUST BE RELATIVE* to CMAKE_INSTALL_PREFIX
48 # # A typical example is "include/${LIBRARY_NAME}"
49 # * ${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_LIBRARY_PATHS
50 # Like the previous var but for library paths.
51 # A typical example is "lib"
52 # * ${LIBRARY_NAME}_LIBRARIES
53 # The list of libraries to link against when using ${LIBRARY_NAME}
55 # The following variables can be set optionally :
57 # * ${LIBRARY_NAME}_REQUIRED_C_FLAGS
58 # * ${LIBRARY_NAME}_REQUIRED_CXX_FLAGS
59 # * ${LIBRARY_NAME}_REQUIRED_LINK_FLAGS
60 # * ${LIBRARY_NAME}_MAJOR_VERSION
61 # * ${LIBRARY_NAME}_MINOR_VERSION
62 # * ${LIBRARY_NAME}_BUILD_VERSION
63 # * ${LIBRARY_NAME}_INSTALL_FOLDER : if set then install the generated files
64 # in CMAKE_INSTALL_PREFIX/lib/${LIBRARY_NAME}_INSTALL_FOLDER
65 # instead of CMAKE_INSTALL_PREFIX/lib/${LIBRARY_NAME}
68 # To provide a user defined
69 # couple of Config/Use file (in addition to the standard one) use :
70 # SET( ${LIBRARY_NAME}_HAS_ADDITIONAL_CONFIG_FILE TRUE )
71 # and store the *ABSOLUTE* paths to the additional files in the vars :
72 # ${LIBRARY_NAME}_ADDITIONAL_CONFIG_FILE
73 # ${LIBRARY_NAME}_ADDITIONAL_USE_FILE
74 # (e.g. ${CMAKE_CURRENT_SOURCE_DIR}/MyConfig.cmake)
78 # At cmake run-time, the macro creates the following files
79 # in the current dir of the build tree (where the macro is invoked) :
80 # Use${LIBRARY_NAME}.cmake
81 # ${LIBRARY_NAME}Config.cmake
82 # ${LIBRARY_NAME}BuildSettings.cmake
83 # And if the vars ${LIBRARY_NAME}_ADDITIONAL_CONFIG_FILE and
84 # ${LIBRARY_NAME}_ADDITIONAL_USE_FILE are set, it also creates :
85 # Additional${LIBRARY_NAME}Config.cmake
86 # AdditionalUse${LIBRARY_NAME}.cmake
88 # At install-time, the same files are installed
89 # in CMAKE_INSTALL_PREFIX/lib/${LIBRARY_NAME}_INSTALL_FOLDER
91 # Find${LIBRARY_NAME}.cmake
92 # is installed in ${CMAKE_ROOT}/Modules/
95 #-----------------------------------------------------------------------------
97 MACRO(CREA_ADVANCED_INSTALL_LIBRARY_FOR_CMAKE LIBRARY_NAME)
99 #---------------------------------------------------------------------------
100 # Sets the common values to build tree and install tree configs
101 SET(CILC_LIB_REQUIRED_C_FLAGS ${${LIBRARY_NAME}_REQUIRED_C_FLAGS})
102 SET(CILC_LIB_REQUIRED_CXX_FLAGS ${${LIBRARY_NAME}_REQUIRED_CXX_FLAGS})
103 SET(CILC_LIB_REQUIRED_LINK_FLAGS ${${LIBRARY_NAME}_REQUIRED_LINK_FLAGS})
104 SET(CILC_LIB_MAJOR_VERSION ${${LIBRARY_NAME}_MAJOR_VERSION})
105 SET(CILC_LIB_MINOR_VERSION ${${LIBRARY_NAME}_MINOR_VERSION})
106 SET(CILC_LIB_BUILD_VERSION ${${LIBRARY_NAME}_BUILD_VERSION})
108 ${CILC_LIB_MAJOR_VERSION}.${CILC_LIB_MINOR_VERSION}.${CILC_LIB_BUILD_VERSION})
109 SET(CILC_LIB_LIBRARIES ${${LIBRARY_NAME}_LIBRARIES})
110 IF (${LIBRARY_NAME}_HAS_ADDITIONAL_CONFIG_FILE)
111 SET(CILC_LIB_HAS_ADDITIONAL_CONFIG_FILE TRUE)
112 ELSE (${LIBRARY_NAME}_HAS_ADDITIONAL_CONFIG_FILE)
113 SET(CILC_LIB_HAS_ADDITIONAL_CONFIG_FILE FALSE)
114 ENDIF (${LIBRARY_NAME}_HAS_ADDITIONAL_CONFIG_FILE)
115 #---------------------------------------------------------------------------
118 #---------------------------------------------------------------------------
119 #-- BUILD TREE configuration
120 SET(CILC_BUILD_TREE_CONFIGURATION TRUE)
121 # UseLIBRARY_NAME.cmake
123 ${CREA_CMAKE_DIR}/InstallLibraryForCMake_UseLibrary.cmake.in
124 ${PROJECT_BINARY_DIR}/Use${LIBRARY_NAME}.cmake
127 # LIBRARY_NAMEConfig.cmake
128 SET(CILC_LIB_RELATIVE_INCLUDE_PATHS
129 ${${LIBRARY_NAME}_BUILD_TREE_RELATIVE_INCLUDE_PATHS})
130 SET(CILC_LIB_RELATIVE_LIBRARY_PATHS
131 ${${LIBRARY_NAME}_BUILD_TREE_RELATIVE_LIBRARY_PATHS})
133 ${CREA_CMAKE_DIR}/InstallLibraryForCMake_LibraryConfig.cmake.in
134 ${PROJECT_BINARY_DIR}/${LIBRARY_NAME}Config.cmake
137 # LIBRARY_NAMEBuildSettings.cmake :
138 # Save the compiler settings so another project can import them.
139 # FCY : DEPREDCATED FUNCTION FOR CMAKE 2.8
140 IF( "${CMAKE_MINIMUM_REQUIRED_VERSION}" VERSION_LESS 2.7)
141 INCLUDE(${CMAKE_ROOT}/Modules/CMakeExportBuildSettings.cmake)
142 CMAKE_EXPORT_BUILD_SETTINGS(${PROJECT_BINARY_DIR}/${LIBRARY_NAME}BuildSettings.cmake)
144 # Additional Config and Use files
145 IF(CILC_LIB_HAS_ADDITIONAL_CONFIG_FILE)
147 ${${LIBRARY_NAME}_ADDITIONAL_CONFIG_FILE}
148 ${PROJECT_BINARY_DIR}/Additional${LIBRARY_NAME}Config.cmake
152 ${${LIBRARY_NAME}_ADDITIONAL_USE_FILE}
153 ${PROJECT_BINARY_DIR}/AdditionalUse${LIBRARY_NAME}.cmake
156 ENDIF(CILC_LIB_HAS_ADDITIONAL_CONFIG_FILE)
157 #---------------------------------------------------------------------------
160 #---------------------------------------------------------------------------
161 #-- INSTALL TREE configuration
164 SET(CILC_BUILD_TREE_CONFIGURATION FALSE)
165 # Create work directory to put the configured files because
166 # if the user invoked the macro at the root of the build tree the files
167 # would overwrite those configured for the build tree
168 SET(CILC_WORK_DIR ${CMAKE_CURRENT_BINARY_DIR}/InstallLibraryForCMake_tmp)
169 IF(NOT IS_DIRECTORY ${CILC_WORK_DIR})
170 FILE(MAKE_DIRECTORY ${CILC_WORK_DIR})
171 ENDIF(NOT IS_DIRECTORY ${CILC_WORK_DIR})
173 #----------------------------------------------------------------------------
178 IF(${LIBRARY_NAME}_INSTALL_FOLDER)
179 ##EED SET(INSTALL_PATH lib/${${LIBRARY_NAME}_INSTALL_FOLDER})
180 SET(INSTALL_PATH ${${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_LIBRARY_PATHS}/${${LIBRARY_NAME}_INSTALL_FOLDER})
181 ELSE(${LIBRARY_NAME}_INSTALL_FOLDER)
182 ##EED SET(INSTALL_PATH lib/${LIBRARY_NAME})
183 SET(INSTALL_PATH ${${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_LIBRARY_PATHS}/${LIBRARY_NAME})
184 ENDIF(${LIBRARY_NAME}_INSTALL_FOLDER)
187 message(STATUS "Library Install Path ${INSTALL_PATH}")
189 # UseLIBRARY_NAME.cmake
191 ${CREA_CMAKE_DIR}/InstallLibraryForCMake_UseLibrary.cmake.in
192 ${CILC_WORK_DIR}/Use${LIBRARY_NAME}.cmake
197 ${CILC_WORK_DIR}/Use${LIBRARY_NAME}.cmake
198 DESTINATION ${INSTALL_PATH}
200 # LIBRARY_NAMEConfig.cmake
201 SET(CILC_LIB_RELATIVE_INCLUDE_PATHS
202 ${${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_INCLUDE_PATHS})
203 SET(CILC_LIB_RELATIVE_LIBRARY_PATHS
204 ${${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_LIBRARY_PATHS})
206 ${CREA_CMAKE_DIR}/InstallLibraryForCMake_LibraryConfig.cmake.in
207 ${CILC_WORK_DIR}/${LIBRARY_NAME}Config.cmake
212 ${CILC_WORK_DIR}/${LIBRARY_NAME}Config.cmake
213 DESTINATION ${INSTALL_PATH}
215 # LIBRARY_NAMEBuildSettings.cmake :
216 # FCY : DEPREDCATED FUNCTION FOR CMAKE 2.8
217 IF( "${CMAKE_MINIMUM_REQUIRED_VERSION}" VERSION_LESS 2.7)
218 CMAKE_EXPORT_BUILD_SETTINGS(${CILC_WORK_DIR}/${LIBRARY_NAME}BuildSettings.cmake)
222 ${CILC_WORK_DIR}/${LIBRARY_NAME}BuildSettings.cmake
223 DESTINATION ${INSTALL_PATH}
225 # Additional Config and Use files
226 IF(CILC_LIB_HAS_ADDITIONAL_CONFIG_FILE)
228 ${${LIBRARY_NAME}_ADDITIONAL_CONFIG_FILE}
229 ${CILC_WORK_DIR}/Additional${LIBRARY_NAME}Config.cmake
234 ${CILC_WORK_DIR}/Additional${LIBRARY_NAME}Config.cmake
235 DESTINATION ${INSTALL_PATH}
238 ${${LIBRARY_NAME}_ADDITIONAL_USE_FILE}
239 ${CILC_WORK_DIR}/AdditionalUse${LIBRARY_NAME}.cmake
244 ${CILC_WORK_DIR}/AdditionalUse${LIBRARY_NAME}.cmake
245 DESTINATION ${INSTALL_PATH}
247 ENDIF(CILC_LIB_HAS_ADDITIONAL_CONFIG_FILE)
248 # Specific to install tree
249 # FindLIBRARY_NAME.cmake in CMake/Modules dir
251 ${CREA_CMAKE_DIR}/InstallLibraryForCMake_FindLibrary.cmake.in
252 ${CILC_WORK_DIR}/Find${LIBRARY_NAME}.cmake
257 # FILES ${CILC_WORK_DIR}/Find${LIBRARY_NAME}.cmake
258 # DESTINATION ${CMAKE_ROOT}/Modules
263 FILES ${CILC_WORK_DIR}/Find${LIBRARY_NAME}.cmake
264 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/cmake/Modules
268 #---------------------------------------------------------------------------
273 ENDMACRO(CREA_ADVANCED_INSTALL_LIBRARY_FOR_CMAKE)
274 #-----------------------------------------------------------------------------
279 #-----------------------------------------------------------------------------
280 MACRO(CREA_INSTALL_LIBRARY_FOR_CMAKE LIBRARY_NAME1)
282 # Sets the settings to default values
283 IF(NOT ${LIBRARY_NAME1}_INSTALL_FOLDER)
284 SET(${LIBRARY_NAME1}_INSTALL_FOLDER ${LIBRARY_NAME1})
285 ENDIF(NOT ${LIBRARY_NAME1}_INSTALL_FOLDER)
287 SET(${LIBRARY_NAME1}_LIBRARIES ${LIBRARY_NAME1})
290 ${LIBRARY_NAME1}_BUILD_TREE_RELATIVE_INCLUDE_PATHS
291 ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
293 IF ( ${PROJECT_BINARY_DIR} STREQUAL ${EXECUTABLE_OUTPUT_PATH} )
294 SET(CILFC_EXECUTABLE_OUTPUT_REL_PATH ".")
295 ELSE ( ${PROJECT_BINARY_DIR} STREQUAL ${EXECUTABLE_OUTPUT_PATH} )
298 CILFC_EXECUTABLE_OUTPUT_REL_PATH
299 ${PROJECT_BINARY_DIR} ${EXECUTABLE_OUTPUT_PATH})
300 ENDIF ( ${PROJECT_BINARY_DIR} STREQUAL ${EXECUTABLE_OUTPUT_PATH} )
304 SET(${LIBRARY_NAME1}_BUILD_TREE_RELATIVE_LIBRARY_PATHS
305 ${CILFC_EXECUTABLE_OUTPUT_REL_PATH})
306 SET(${LIBRARY_NAME1}_INSTALL_TREE_RELATIVE_LIBRARY_PATHS ${CMAKE_CREA_LIB_PATH} )
308 SET(${LIBRARY_NAME1}_BUILD_TREE_RELATIVE_LIBRARY_PATHS
309 ${CILFC_EXECUTABLE_OUTPUT_REL_PATH} )
311 # ${CILFC_EXECUTABLE_OUTPUT_REL_PATH}/Debug
312 # ${CILFC_EXECUTABLE_OUTPUT_REL_PATH}/Release)
313 SET(${LIBRARY_NAME1}_INSTALL_TREE_RELATIVE_LIBRARY_PATHS bin)
316 IF(NOT ${LIBRARY_NAME1}_INSTALL_TREE_RELATIVE_INCLUDE_PATHS)
317 SET(${LIBRARY_NAME1}_INSTALL_TREE_RELATIVE_INCLUDE_PATHS include/${LIBRARY_NAME1})
318 ENDIF(NOT ${LIBRARY_NAME1}_INSTALL_TREE_RELATIVE_INCLUDE_PATHS)
320 # Invoke the advanced macro
321 CREA_ADVANCED_INSTALL_LIBRARY_FOR_CMAKE(${LIBRARY_NAME1})
324 ENDMACRO(CREA_INSTALL_LIBRARY_FOR_CMAKE)
325 #-----------------------------------------------------------------------------