1 #-----------------------------------------------------------------------------
2 # Macro CREA_ADVANCED_INSTALL_LIBRARY
3 # Creates and install the cmake files which allow
4 # to find a 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 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 ".."
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 stuff
64 # in INSTALL_PREFIX/lib/${LIBRARY_NAME}_INSTALL_FOLDER
65 # instead of 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 INSTALL_PREFIX/lib/${LIBRARY_NAME}
91 # Find${LIBRARY_NAME}.cmake
92 # is installed in ${CMAKE_ROOT}/Modules/
95 #-----------------------------------------------------------------------------
97 MACRO(CREA_ADVANCED_INSTALL_LIBRARY 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 INCLUDE(${CMAKE_ROOT}/Modules/CMakeExportBuildSettings.cmake)
140 CMAKE_EXPORT_BUILD_SETTINGS(${PROJECT_BINARY_DIR}/${LIBRARY_NAME}BuildSettings.cmake)
141 # Additional Config and Use files
142 IF(CILC_LIB_HAS_ADDITIONAL_CONFIG_FILE)
144 ${${LIBRARY_NAME}_ADDITIONAL_CONFIG_FILE}
145 ${PROJECT_BINARY_DIR}/Additional${LIBRARY_NAME}Config.cmake
149 ${${LIBRARY_NAME}_ADDITIONAL_USE_FILE}
150 ${PROJECT_BINARY_DIR}/AdditionalUse${LIBRARY_NAME}.cmake
153 ENDIF(CILC_LIB_HAS_ADDITIONAL_CONFIG_FILE)
154 #---------------------------------------------------------------------------
157 #---------------------------------------------------------------------------
158 #-- INSTALL TREE configuration
159 SET(CILC_BUILD_TREE_CONFIGURATION FALSE)
160 # CREAte work directory to put the configured files because
161 # if the user invoked the macro at the root of the build tree the files
162 # would overwrite those configured for the build tree
163 SET(CILC_WORK_DIR ${CMAKE_CURRENT_BINARY_DIR}/InstallLibraryForCMake_tmp)
164 IF(NOT IS_DIRECTORY ${CILC_WORK_DIR})
165 FILE(MAKE_DIRECTORY ${CILC_WORK_DIR})
166 ENDIF(NOT IS_DIRECTORY ${CILC_WORK_DIR})
168 #----------------------------------------------------------------------------
173 IF(${LIBRARY_NAME}_INSTALL_FOLDER)
174 SET(INSTALL_PATH lib/${${LIBRARY_NAME}_INSTALL_FOLDER})
175 ELSE(${LIBRARY_NAME}_INSTALL_FOLDER)
176 SET(INSTALL_PATH lib/${LIBRARY_NAME})
177 ENDIF(${LIBRARY_NAME}_INSTALL_FOLDER)
181 # UseLIBRARY_NAME.cmake
183 ${CREA_CMAKE_DIR}/InstallLibraryForCMake_UseLibrary.cmake.in
184 ${CILC_WORK_DIR}/Use${LIBRARY_NAME}.cmake
189 ${CILC_WORK_DIR}/Use${LIBRARY_NAME}.cmake
190 DESTINATION ${INSTALL_PATH}
192 # LIBRARY_NAMEConfig.cmake
193 SET(CILC_LIB_RELATIVE_INCLUDE_PATHS
194 ${${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_INCLUDE_PATHS})
195 SET(CILC_LIB_RELATIVE_LIBRARY_PATHS
196 ${${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_LIBRARY_PATHS})
198 ${CREA_CMAKE_DIR}/InstallLibraryForCMake_LibraryConfig.cmake.in
199 ${CILC_WORK_DIR}/${LIBRARY_NAME}Config.cmake
204 ${CILC_WORK_DIR}/${LIBRARY_NAME}Config.cmake
205 DESTINATION ${INSTALL_PATH}
207 # LIBRARY_NAMEBuildSettings.cmake :
208 CMAKE_EXPORT_BUILD_SETTINGS(${CILC_WORK_DIR}/${LIBRARY_NAME}BuildSettings.cmake)
211 ${CILC_WORK_DIR}/${LIBRARY_NAME}BuildSettings.cmake
212 DESTINATION ${INSTALL_PATH}
214 # Additional Config and Use files
215 IF(CILC_LIB_HAS_ADDITIONAL_CONFIG_FILE)
217 ${${LIBRARY_NAME}_ADDITIONAL_CONFIG_FILE}
218 ${CILC_WORK_DIR}/Additional${LIBRARY_NAME}Config.cmake
223 ${CILC_WORK_DIR}/Additional${LIBRARY_NAME}Config.cmake
224 DESTINATION ${INSTALL_PATH}
227 ${${LIBRARY_NAME}_ADDITIONAL_USE_FILE}
228 ${CILC_WORK_DIR}/AdditionalUse${LIBRARY_NAME}.cmake
233 ${CILC_WORK_DIR}/AdditionalUse${LIBRARY_NAME}.cmake
234 DESTINATION ${INSTALL_PATH}
236 ENDIF(CILC_LIB_HAS_ADDITIONAL_CONFIG_FILE)
237 # Specific to install tree
238 # FindLIBRARY_NAME.cmake in CMake/Modules dir
240 ${CREA_CMAKE_DIR}/InstallLibraryForCMake_FindLibrary.cmake.in
241 ${CILC_WORK_DIR}/Find${LIBRARY_NAME}.cmake
245 FILES ${CILC_WORK_DIR}/Find${LIBRARY_NAME}.cmake
246 DESTINATION ${CMAKE_ROOT}/Modules
248 #---------------------------------------------------------------------------
253 ENDMACRO(CREA_ADVANCED_INSTALL_LIBRARY)
254 #-----------------------------------------------------------------------------
259 #-----------------------------------------------------------------------------
260 MACRO(CREA_INSTALL_LIBRARY LIBRARY_NAME)
262 # Sets the settings to default values
263 SET(${LIBRARY_NAME}_INSTALL_FOLDER ${LIBRARY_NAME})
264 SET(${LIBRARY_NAME}_LIBRARIES ${LIBRARY_NAME})
267 ${LIBRARY_NAME}_BUILD_TREE_RELATIVE_INCLUDE_PATHS
268 ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
272 SET(${LIBRARY_NAME}_BUILD_TREE_RELATIVE_LIBRARY_PATHS
273 ${EXECUTABLE_OUTPUT_REL_PATH})
275 SET(${LIBRARY_NAME}_BUILD_TREE_RELATIVE_LIBRARY_PATHS
276 ${EXECUTABLE_OUTPUT_REL_PATH}/Debug
277 ${EXECUTABLE_OUTPUT_REL_PATH}/Release)
279 SET(${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_INCLUDE_PATHS include/${LIBRARY_NAME})
280 SET(${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_LIBRARY_PATHS lib)
282 # Invoke the advanced macro
283 CREA_ADVANCED_INSTALL_LIBRARY(${LIBRARY_NAME})
286 ENDMACRO(CREA_INSTALL_LIBRARY)
287 #-----------------------------------------------------------------------------