1 # ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # This software is governed by the CeCILL-B license under French law and
8 # abiding by the rules of distribution of free software. You can use,
9 # modify and/ or redistribute the software under the terms of the CeCILL-B
10 # license as circulated by CEA, CNRS and INRIA at the following URL
11 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
12 # or in the file LICENSE.txt.
14 # As a counterpart to the access to the source code and rights to copy,
15 # modify and redistribute granted by the license, users are provided only
16 # with a limited warranty and the software's author, the holder of the
17 # economic rights, and the successive licensors have only limited
20 # The fact that you are presently reading this means that you have had
21 # knowledge of the CeCILL-B license and that you accept its terms.
22 # ------------------------------------------------------------------------ */
25 #-----------------------------------------------------------------------------
26 # Macro CREA_ADVANCED_INSTALL_LIBRARY_FOR_CMAKE
27 # Creates and install the cmake files which allow
28 # to find the library by the cmake command FIND_PACKAGE.
32 # LIBRARY_NAME : name of the library to find
34 # The following variables **MUST** have been set previously :
36 # * ${LIBRARY_NAME}_BUILD_TREE_RELATIVE_INCLUDE_PATHS
37 # The list of include paths
38 # when someone uses a *BUILD TREE* version of ${LIBRARY_NAME}.
40 # THE PATHS *MUST BE RELATIVE* TO THE ROOT DIR OF THE PROJECT **SOURCES** !
41 # Assume your project architecture is :
42 # install/ : directory in which the macro is invoked
43 # src/part1/include/ : first include dir
44 # src/part2/include/ : second include dir
45 # Then you should set the var with :
46 # SET(${LIBRARY_NAME}_BUILD_TREE_RELATIVE_INCLUDE_PATHS
49 # Which will result in actual include paths :
50 # ${PROJECT_SOURCE_DIR}/src/part1/include;
51 # ${PROJECT_SOURCE_DIR}/src/part2/include
52 # * ${LIBRARY_NAME}_BUILD_TREE_RELATIVE_LIBRARY_PATHS
53 # Like the previous var but for the library paths.
55 # THE PATHS *MUST BE RELATIVE* TO THE ROOT DIR OF THE **BUILD TREE**
56 # THAT IS POINT TO THE FOLDERS WHERE THE LIBS WILL BE BUILD
57 # Assume that your project architecture is :
58 # src/part1/src/ : first source dir, in which the lib 'part1' is built
59 # src/part2/src/ : first source dir, in which the lib 'part2' is built
60 # Then you should set the var with
61 # SET(${LIBRARY_NAME}_BUILD_TREE_RELATIVE_LIBRARY_PATHS
65 # Which will result in actual library paths :
66 # ${PROJECT_BINARY_DIR}/src/part1/src
67 # ${PROJECT_BINARY_DIR}/src/part2/src
68 # * ${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_INCLUDE_PATHS
69 # The list of include paths
70 # when someone uses an *INSTALLED* version of ${LIBRARY_NAME}
71 # The paths *MUST BE RELATIVE* to CMAKE_INSTALL_PREFIX
72 # # A typical example is "include/${LIBRARY_NAME}"
73 # * ${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_LIBRARY_PATHS
74 # Like the previous var but for library paths.
75 # A typical example is "lib"
76 # * ${LIBRARY_NAME}_LIBRARIES
77 # The list of libraries to link against when using ${LIBRARY_NAME}
79 # The following variables can be set optionally :
81 # * ${LIBRARY_NAME}_REQUIRED_C_FLAGS
82 # * ${LIBRARY_NAME}_REQUIRED_CXX_FLAGS
83 # * ${LIBRARY_NAME}_REQUIRED_LINK_FLAGS
84 # * ${LIBRARY_NAME}_MAJOR_VERSION
85 # * ${LIBRARY_NAME}_MINOR_VERSION
86 # * ${LIBRARY_NAME}_BUILD_VERSION
87 # * ${LIBRARY_NAME}_INSTALL_FOLDER : if set then install the generated files
88 # in CMAKE_INSTALL_PREFIX/lib/${LIBRARY_NAME}_INSTALL_FOLDER
89 # instead of CMAKE_INSTALL_PREFIX/lib/${LIBRARY_NAME}
92 # To provide a user defined
93 # couple of Config/Use file (in addition to the standard one) use :
94 # SET( ${LIBRARY_NAME}_HAS_ADDITIONAL_CONFIG_FILE TRUE )
95 # and store the *ABSOLUTE* paths to the additional files in the vars :
96 # ${LIBRARY_NAME}_ADDITIONAL_CONFIG_FILE
97 # ${LIBRARY_NAME}_ADDITIONAL_USE_FILE
98 # (e.g. ${CMAKE_CURRENT_SOURCE_DIR}/MyConfig.cmake)
102 # At cmake run-time, the macro creates the following files
103 # in the current dir of the build tree (where the macro is invoked) :
104 # Use${LIBRARY_NAME}.cmake
105 # ${LIBRARY_NAME}Config.cmake
106 # ${LIBRARY_NAME}BuildSettings.cmake
107 # And if the vars ${LIBRARY_NAME}_ADDITIONAL_CONFIG_FILE and
108 # ${LIBRARY_NAME}_ADDITIONAL_USE_FILE are set, it also creates :
109 # Additional${LIBRARY_NAME}Config.cmake
110 # AdditionalUse${LIBRARY_NAME}.cmake
112 # At install-time, the same files are installed
113 # in CMAKE_INSTALL_PREFIX/lib/${LIBRARY_NAME}_INSTALL_FOLDER
115 # Find${LIBRARY_NAME}.cmake
116 # is installed in ${CMAKE_ROOT}/Modules/
119 #-----------------------------------------------------------------------------
121 MACRO(CREA_ADVANCED_INSTALL_LIBRARY_FOR_CMAKE LIBRARY_NAME)
123 #---------------------------------------------------------------------------
124 # Sets the common values to build tree and install tree configs
125 SET(CILC_LIB_REQUIRED_C_FLAGS ${${LIBRARY_NAME}_REQUIRED_C_FLAGS})
126 SET(CILC_LIB_REQUIRED_CXX_FLAGS ${${LIBRARY_NAME}_REQUIRED_CXX_FLAGS})
127 SET(CILC_LIB_REQUIRED_LINK_FLAGS ${${LIBRARY_NAME}_REQUIRED_LINK_FLAGS})
128 SET(CILC_LIB_MAJOR_VERSION ${${LIBRARY_NAME}_MAJOR_VERSION})
129 SET(CILC_LIB_MINOR_VERSION ${${LIBRARY_NAME}_MINOR_VERSION})
130 SET(CILC_LIB_BUILD_VERSION ${${LIBRARY_NAME}_BUILD_VERSION})
132 ${CILC_LIB_MAJOR_VERSION}.${CILC_LIB_MINOR_VERSION}.${CILC_LIB_BUILD_VERSION})
133 SET(CILC_LIB_LIBRARIES ${${LIBRARY_NAME}_LIBRARIES})
134 IF (${LIBRARY_NAME}_HAS_ADDITIONAL_CONFIG_FILE)
135 SET(CILC_LIB_HAS_ADDITIONAL_CONFIG_FILE TRUE)
136 ELSE (${LIBRARY_NAME}_HAS_ADDITIONAL_CONFIG_FILE)
137 SET(CILC_LIB_HAS_ADDITIONAL_CONFIG_FILE FALSE)
138 ENDIF (${LIBRARY_NAME}_HAS_ADDITIONAL_CONFIG_FILE)
139 #---------------------------------------------------------------------------
142 #---------------------------------------------------------------------------
143 #-- BUILD TREE configuration
144 SET(CILC_BUILD_TREE_CONFIGURATION TRUE)
145 # UseLIBRARY_NAME.cmake
147 ${CREA_CMAKE_DIR}/InstallLibraryForCMake_UseLibrary.cmake.in
148 ${PROJECT_BINARY_DIR}/Use${LIBRARY_NAME}.cmake
151 # LIBRARY_NAMEConfig.cmake
152 SET(CILC_LIB_RELATIVE_INCLUDE_PATHS
153 ${${LIBRARY_NAME}_BUILD_TREE_RELATIVE_INCLUDE_PATHS})
154 SET(CILC_LIB_RELATIVE_LIBRARY_PATHS
155 ${${LIBRARY_NAME}_BUILD_TREE_RELATIVE_LIBRARY_PATHS})
157 ${CREA_CMAKE_DIR}/InstallLibraryForCMake_LibraryConfig.cmake.in
158 ${PROJECT_BINARY_DIR}/${LIBRARY_NAME}Config.cmake
161 # LIBRARY_NAMEBuildSettings.cmake :
162 # Save the compiler settings so another project can import them.
163 # FCY : DEPREDCATED FUNCTION FOR CMAKE 2.8
164 IF( "${CMAKE_MINIMUM_REQUIRED_VERSION}" VERSION_LESS 2.7)
165 INCLUDE(${CMAKE_ROOT}/Modules/CMakeExportBuildSettings.cmake)
166 CMAKE_EXPORT_BUILD_SETTINGS(${PROJECT_BINARY_DIR}/${LIBRARY_NAME}BuildSettings.cmake)
168 # Additional Config and Use files
169 IF(CILC_LIB_HAS_ADDITIONAL_CONFIG_FILE)
171 ${${LIBRARY_NAME}_ADDITIONAL_CONFIG_FILE}
172 ${PROJECT_BINARY_DIR}/Additional${LIBRARY_NAME}Config.cmake
176 ${${LIBRARY_NAME}_ADDITIONAL_USE_FILE}
177 ${PROJECT_BINARY_DIR}/AdditionalUse${LIBRARY_NAME}.cmake
180 ENDIF(CILC_LIB_HAS_ADDITIONAL_CONFIG_FILE)
181 #---------------------------------------------------------------------------
184 #---------------------------------------------------------------------------
185 #-- INSTALL TREE configuration
188 SET(CILC_BUILD_TREE_CONFIGURATION FALSE)
189 # Create work directory to put the configured files because
190 # if the user invoked the macro at the root of the build tree the files
191 # would overwrite those configured for the build tree
192 SET(CILC_WORK_DIR ${CMAKE_CURRENT_BINARY_DIR}/InstallLibraryForCMake_tmp)
193 IF(NOT IS_DIRECTORY ${CILC_WORK_DIR})
194 FILE(MAKE_DIRECTORY ${CILC_WORK_DIR})
195 ENDIF(NOT IS_DIRECTORY ${CILC_WORK_DIR})
197 #----------------------------------------------------------------------------
202 IF(${LIBRARY_NAME}_INSTALL_FOLDER)
203 ##EED SET(INSTALL_PATH lib/${${LIBRARY_NAME}_INSTALL_FOLDER})
204 SET(INSTALL_PATH ${${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_LIBRARY_PATHS}/${${LIBRARY_NAME}_INSTALL_FOLDER})
205 ELSE(${LIBRARY_NAME}_INSTALL_FOLDER)
206 ##EED SET(INSTALL_PATH lib/${LIBRARY_NAME})
207 SET(INSTALL_PATH ${${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_LIBRARY_PATHS}/${LIBRARY_NAME})
208 ENDIF(${LIBRARY_NAME}_INSTALL_FOLDER)
211 message(STATUS "Library Install Path ${INSTALL_PATH}")
213 # UseLIBRARY_NAME.cmake
215 ${CREA_CMAKE_DIR}/InstallLibraryForCMake_UseLibrary.cmake.in
216 ${CILC_WORK_DIR}/Use${LIBRARY_NAME}.cmake
221 ${CILC_WORK_DIR}/Use${LIBRARY_NAME}.cmake
222 DESTINATION ${INSTALL_PATH}
224 # LIBRARY_NAMEConfig.cmake
225 SET(CILC_LIB_RELATIVE_INCLUDE_PATHS
226 ${${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_INCLUDE_PATHS})
227 SET(CILC_LIB_RELATIVE_LIBRARY_PATHS
228 ${${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_LIBRARY_PATHS})
230 ${CREA_CMAKE_DIR}/InstallLibraryForCMake_LibraryConfig.cmake.in
231 ${CILC_WORK_DIR}/${LIBRARY_NAME}Config.cmake
236 ${CILC_WORK_DIR}/${LIBRARY_NAME}Config.cmake
237 DESTINATION ${INSTALL_PATH}
239 # LIBRARY_NAMEBuildSettings.cmake :
240 # FCY : DEPREDCATED FUNCTION FOR CMAKE 2.8
241 IF( "${CMAKE_MINIMUM_REQUIRED_VERSION}" VERSION_LESS 2.7)
242 CMAKE_EXPORT_BUILD_SETTINGS(${CILC_WORK_DIR}/${LIBRARY_NAME}BuildSettings.cmake)
246 ${CILC_WORK_DIR}/${LIBRARY_NAME}BuildSettings.cmake
247 DESTINATION ${INSTALL_PATH}
249 # Additional Config and Use files
250 IF(CILC_LIB_HAS_ADDITIONAL_CONFIG_FILE)
252 ${${LIBRARY_NAME}_ADDITIONAL_CONFIG_FILE}
253 ${CILC_WORK_DIR}/Additional${LIBRARY_NAME}Config.cmake
258 ${CILC_WORK_DIR}/Additional${LIBRARY_NAME}Config.cmake
259 DESTINATION ${INSTALL_PATH}
262 ${${LIBRARY_NAME}_ADDITIONAL_USE_FILE}
263 ${CILC_WORK_DIR}/AdditionalUse${LIBRARY_NAME}.cmake
268 ${CILC_WORK_DIR}/AdditionalUse${LIBRARY_NAME}.cmake
269 DESTINATION ${INSTALL_PATH}
271 ENDIF(CILC_LIB_HAS_ADDITIONAL_CONFIG_FILE)
272 # Specific to install tree
273 # FindLIBRARY_NAME.cmake in CMake/Modules dir
275 ${CREA_CMAKE_DIR}/InstallLibraryForCMake_FindLibrary.cmake.in
276 ${CILC_WORK_DIR}/Find${LIBRARY_NAME}.cmake
281 # FILES ${CILC_WORK_DIR}/Find${LIBRARY_NAME}.cmake
282 # DESTINATION ${CMAKE_ROOT}/Modules
287 FILES ${CILC_WORK_DIR}/Find${LIBRARY_NAME}.cmake
288 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/cmake/Modules
292 #---------------------------------------------------------------------------
297 ENDMACRO(CREA_ADVANCED_INSTALL_LIBRARY_FOR_CMAKE)
298 #-----------------------------------------------------------------------------
303 #-----------------------------------------------------------------------------
304 MACRO(CREA_INSTALL_LIBRARY_FOR_CMAKE LIBRARY_NAME1)
306 # Sets the settings to default values
307 IF(NOT ${LIBRARY_NAME1}_INSTALL_FOLDER)
308 SET(${LIBRARY_NAME1}_INSTALL_FOLDER ${LIBRARY_NAME1})
309 ENDIF(NOT ${LIBRARY_NAME1}_INSTALL_FOLDER)
311 SET(${LIBRARY_NAME1}_LIBRARIES ${LIBRARY_NAME1})
314 ${LIBRARY_NAME1}_BUILD_TREE_RELATIVE_INCLUDE_PATHS
315 ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
317 IF ( ${PROJECT_BINARY_DIR} STREQUAL ${EXECUTABLE_OUTPUT_PATH} )
318 SET(CILFC_EXECUTABLE_OUTPUT_REL_PATH ".")
319 ELSE ( ${PROJECT_BINARY_DIR} STREQUAL ${EXECUTABLE_OUTPUT_PATH} )
322 CILFC_EXECUTABLE_OUTPUT_REL_PATH
323 ${PROJECT_BINARY_DIR} ${EXECUTABLE_OUTPUT_PATH})
324 ENDIF ( ${PROJECT_BINARY_DIR} STREQUAL ${EXECUTABLE_OUTPUT_PATH} )
328 SET(${LIBRARY_NAME1}_BUILD_TREE_RELATIVE_LIBRARY_PATHS
329 ${CILFC_EXECUTABLE_OUTPUT_REL_PATH})
330 SET(${LIBRARY_NAME1}_INSTALL_TREE_RELATIVE_LIBRARY_PATHS ${CMAKE_CREA_LIB_PATH} )
332 SET(${LIBRARY_NAME1}_BUILD_TREE_RELATIVE_LIBRARY_PATHS
333 ${CILFC_EXECUTABLE_OUTPUT_REL_PATH} )
335 # ${CILFC_EXECUTABLE_OUTPUT_REL_PATH}/Debug
336 # ${CILFC_EXECUTABLE_OUTPUT_REL_PATH}/Release)
337 SET(${LIBRARY_NAME1}_INSTALL_TREE_RELATIVE_LIBRARY_PATHS bin)
340 IF(NOT ${LIBRARY_NAME1}_INSTALL_TREE_RELATIVE_INCLUDE_PATHS)
341 SET(${LIBRARY_NAME1}_INSTALL_TREE_RELATIVE_INCLUDE_PATHS include/${LIBRARY_NAME1})
342 ENDIF(NOT ${LIBRARY_NAME1}_INSTALL_TREE_RELATIVE_INCLUDE_PATHS)
344 # Invoke the advanced macro
345 CREA_ADVANCED_INSTALL_LIBRARY_FOR_CMAKE(${LIBRARY_NAME1})
348 ENDMACRO(CREA_INSTALL_LIBRARY_FOR_CMAKE)
349 #-----------------------------------------------------------------------------