1 # ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
27 #-----------------------------------------------------------------------------
28 # Macro CREA_ADVANCED_INSTALL_LIBRARY_FOR_CMAKE
29 # Creates and install the cmake files which allow
30 # to find the library by the cmake command FIND_PACKAGE.
34 # LIBRARY_NAME : name of the library to find
36 # The following variables **MUST** have been set previously :
38 # * ${LIBRARY_NAME}_BUILD_TREE_RELATIVE_INCLUDE_PATHS
39 # The list of include paths
40 # when someone uses a *BUILD TREE* version of ${LIBRARY_NAME}.
42 # THE PATHS *MUST BE RELATIVE* TO THE ROOT DIR OF THE PROJECT **SOURCES** !
43 # Assume your project architecture is :
44 # install/ : directory in which the macro is invoked
45 # src/part1/include/ : first include dir
46 # src/part2/include/ : second include dir
47 # Then you should set the var with :
48 # SET(${LIBRARY_NAME}_BUILD_TREE_RELATIVE_INCLUDE_PATHS
51 # Which will result in actual include paths :
52 # ${PROJECT_SOURCE_DIR}/src/part1/include;
53 # ${PROJECT_SOURCE_DIR}/src/part2/include
54 # * ${LIBRARY_NAME}_BUILD_TREE_RELATIVE_LIBRARY_PATHS
55 # Like the previous var but for the library paths.
57 # THE PATHS *MUST BE RELATIVE* TO THE ROOT DIR OF THE **BUILD TREE**
58 # THAT IS POINT TO THE FOLDERS WHERE THE LIBS WILL BE BUILD
59 # Assume that your project architecture is :
60 # src/part1/src/ : first source dir, in which the lib 'part1' is built
61 # src/part2/src/ : first source dir, in which the lib 'part2' is built
62 # Then you should set the var with
63 # SET(${LIBRARY_NAME}_BUILD_TREE_RELATIVE_LIBRARY_PATHS
67 # Which will result in actual library paths :
68 # ${PROJECT_BINARY_DIR}/src/part1/src
69 # ${PROJECT_BINARY_DIR}/src/part2/src
70 # * ${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_INCLUDE_PATHS
71 # The list of include paths
72 # when someone uses an *INSTALLED* version of ${LIBRARY_NAME}
73 # The paths *MUST BE RELATIVE* to CMAKE_INSTALL_PREFIX
74 # # A typical example is "include/${LIBRARY_NAME}"
75 # * ${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_LIBRARY_PATHS
76 # Like the previous var but for library paths.
77 # A typical example is "lib"
78 # * ${LIBRARY_NAME}_LIBRARIES
79 # The list of libraries to link against when using ${LIBRARY_NAME}
81 # The following variables can be set optionally :
83 # * ${LIBRARY_NAME}_REQUIRED_C_FLAGS
84 # * ${LIBRARY_NAME}_REQUIRED_CXX_FLAGS
85 # * ${LIBRARY_NAME}_REQUIRED_LINK_FLAGS
86 # * ${LIBRARY_NAME}_MAJOR_VERSION
87 # * ${LIBRARY_NAME}_MINOR_VERSION
88 # * ${LIBRARY_NAME}_BUILD_VERSION
89 # * ${LIBRARY_NAME}_INSTALL_FOLDER : if set then install the generated files
90 # in CMAKE_INSTALL_PREFIX/lib/${LIBRARY_NAME}_INSTALL_FOLDER
91 # instead of CMAKE_INSTALL_PREFIX/lib/${LIBRARY_NAME}
94 # To provide a user defined
95 # couple of Config/Use file (in addition to the standard one) use :
96 # SET( ${LIBRARY_NAME}_HAS_ADDITIONAL_CONFIG_FILE TRUE )
97 # and store the *ABSOLUTE* paths to the additional files in the vars :
98 # ${LIBRARY_NAME}_ADDITIONAL_CONFIG_FILE
99 # ${LIBRARY_NAME}_ADDITIONAL_USE_FILE
100 # (e.g. ${CMAKE_CURRENT_SOURCE_DIR}/MyConfig.cmake)
104 # At cmake run-time, the macro creates the following files
105 # in the current dir of the build tree (where the macro is invoked) :
106 # Use${LIBRARY_NAME}.cmake
107 # ${LIBRARY_NAME}Config.cmake
108 # ${LIBRARY_NAME}BuildSettings.cmake
109 # And if the vars ${LIBRARY_NAME}_ADDITIONAL_CONFIG_FILE and
110 # ${LIBRARY_NAME}_ADDITIONAL_USE_FILE are set, it also creates :
111 # Additional${LIBRARY_NAME}Config.cmake
112 # AdditionalUse${LIBRARY_NAME}.cmake
114 # At install-time, the same files are installed
115 # in CMAKE_INSTALL_PREFIX/lib/${LIBRARY_NAME}_INSTALL_FOLDER
117 # Find${LIBRARY_NAME}.cmake
118 # is installed in ${CMAKE_ROOT}/Modules/
121 #-----------------------------------------------------------------------------
123 MACRO(CREA_ADVANCED_INSTALL_LIBRARY_FOR_CMAKE LIBRARY_NAME)
125 #---------------------------------------------------------------------------
126 # Sets the common values to build tree and install tree configs
127 SET(CILC_LIB_REQUIRED_C_FLAGS ${${LIBRARY_NAME}_REQUIRED_C_FLAGS})
128 SET(CILC_LIB_REQUIRED_CXX_FLAGS ${${LIBRARY_NAME}_REQUIRED_CXX_FLAGS})
129 SET(CILC_LIB_REQUIRED_LINK_FLAGS ${${LIBRARY_NAME}_REQUIRED_LINK_FLAGS})
130 SET(CILC_LIB_MAJOR_VERSION ${${LIBRARY_NAME}_MAJOR_VERSION})
131 SET(CILC_LIB_MINOR_VERSION ${${LIBRARY_NAME}_MINOR_VERSION})
132 SET(CILC_LIB_BUILD_VERSION ${${LIBRARY_NAME}_BUILD_VERSION})
134 ${CILC_LIB_MAJOR_VERSION}.${CILC_LIB_MINOR_VERSION}.${CILC_LIB_BUILD_VERSION})
135 SET(CILC_LIB_LIBRARIES ${${LIBRARY_NAME}_LIBRARIES})
136 IF (${LIBRARY_NAME}_HAS_ADDITIONAL_CONFIG_FILE)
137 SET(CILC_LIB_HAS_ADDITIONAL_CONFIG_FILE TRUE)
138 ELSE (${LIBRARY_NAME}_HAS_ADDITIONAL_CONFIG_FILE)
139 SET(CILC_LIB_HAS_ADDITIONAL_CONFIG_FILE FALSE)
140 ENDIF (${LIBRARY_NAME}_HAS_ADDITIONAL_CONFIG_FILE)
141 #---------------------------------------------------------------------------
144 #---------------------------------------------------------------------------
145 #-- BUILD TREE configuration
146 SET(CILC_BUILD_TREE_CONFIGURATION TRUE)
147 # UseLIBRARY_NAME.cmake
149 ${CREA_CMAKE_DIR}/InstallLibraryForCMake_UseLibrary.cmake.in
150 ${PROJECT_BINARY_DIR}/Use${LIBRARY_NAME}.cmake
153 # LIBRARY_NAMEConfig.cmake
154 SET(CILC_LIB_RELATIVE_INCLUDE_PATHS
155 ${${LIBRARY_NAME}_BUILD_TREE_RELATIVE_INCLUDE_PATHS})
156 SET(CILC_LIB_RELATIVE_LIBRARY_PATHS
157 ${${LIBRARY_NAME}_BUILD_TREE_RELATIVE_LIBRARY_PATHS})
159 ${CREA_CMAKE_DIR}/InstallLibraryForCMake_LibraryConfig.cmake.in
160 ${PROJECT_BINARY_DIR}/${LIBRARY_NAME}Config.cmake
163 # LIBRARY_NAMEBuildSettings.cmake :
164 # Save the compiler settings so another project can import them.
165 # FCY : DEPREDCATED FUNCTION FOR CMAKE 2.8
166 IF( "${CMAKE_MINIMUM_REQUIRED_VERSION}" VERSION_LESS 2.7)
167 INCLUDE(${CMAKE_ROOT}/Modules/CMakeExportBuildSettings.cmake)
168 CMAKE_EXPORT_BUILD_SETTINGS(${PROJECT_BINARY_DIR}/${LIBRARY_NAME}BuildSettings.cmake)
170 # Additional Config and Use files
171 IF(CILC_LIB_HAS_ADDITIONAL_CONFIG_FILE)
173 ${${LIBRARY_NAME}_ADDITIONAL_CONFIG_FILE}
174 ${PROJECT_BINARY_DIR}/Additional${LIBRARY_NAME}Config.cmake
178 ${${LIBRARY_NAME}_ADDITIONAL_USE_FILE}
179 ${PROJECT_BINARY_DIR}/AdditionalUse${LIBRARY_NAME}.cmake
182 ENDIF(CILC_LIB_HAS_ADDITIONAL_CONFIG_FILE)
183 #---------------------------------------------------------------------------
186 #---------------------------------------------------------------------------
187 #-- INSTALL TREE configuration
190 SET(CILC_BUILD_TREE_CONFIGURATION FALSE)
191 # Create work directory to put the configured files because
192 # if the user invoked the macro at the root of the build tree the files
193 # would overwrite those configured for the build tree
194 SET(CILC_WORK_DIR ${CMAKE_CURRENT_BINARY_DIR}/InstallLibraryForCMake_tmp)
195 IF(NOT IS_DIRECTORY ${CILC_WORK_DIR})
196 FILE(MAKE_DIRECTORY ${CILC_WORK_DIR})
197 ENDIF(NOT IS_DIRECTORY ${CILC_WORK_DIR})
199 #----------------------------------------------------------------------------
204 IF(${LIBRARY_NAME}_INSTALL_FOLDER)
205 ##EED SET(INSTALL_PATH lib/${${LIBRARY_NAME}_INSTALL_FOLDER})
206 SET(INSTALL_PATH ${${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_LIBRARY_PATHS}/${${LIBRARY_NAME}_INSTALL_FOLDER})
207 ELSE(${LIBRARY_NAME}_INSTALL_FOLDER)
208 ##EED SET(INSTALL_PATH lib/${LIBRARY_NAME})
209 SET(INSTALL_PATH ${${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_LIBRARY_PATHS}/${LIBRARY_NAME})
210 ENDIF(${LIBRARY_NAME}_INSTALL_FOLDER)
213 message(STATUS "Library Install Path ${INSTALL_PATH}")
215 # UseLIBRARY_NAME.cmake
217 ${CREA_CMAKE_DIR}/InstallLibraryForCMake_UseLibrary.cmake.in
218 ${CILC_WORK_DIR}/Use${LIBRARY_NAME}.cmake
223 ${CILC_WORK_DIR}/Use${LIBRARY_NAME}.cmake
224 DESTINATION ${INSTALL_PATH}
226 # LIBRARY_NAMEConfig.cmake
227 SET(CILC_LIB_RELATIVE_INCLUDE_PATHS
228 ${${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_INCLUDE_PATHS})
229 SET(CILC_LIB_RELATIVE_LIBRARY_PATHS
230 ${${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_LIBRARY_PATHS})
232 ${CREA_CMAKE_DIR}/InstallLibraryForCMake_LibraryConfig.cmake.in
233 ${CILC_WORK_DIR}/${LIBRARY_NAME}Config.cmake
238 ${CILC_WORK_DIR}/${LIBRARY_NAME}Config.cmake
239 DESTINATION ${INSTALL_PATH}
241 # LIBRARY_NAMEBuildSettings.cmake :
242 # FCY : DEPREDCATED FUNCTION FOR CMAKE 2.8
243 IF( "${CMAKE_MINIMUM_REQUIRED_VERSION}" VERSION_LESS 2.7)
244 CMAKE_EXPORT_BUILD_SETTINGS(${CILC_WORK_DIR}/${LIBRARY_NAME}BuildSettings.cmake)
248 ${CILC_WORK_DIR}/${LIBRARY_NAME}BuildSettings.cmake
249 DESTINATION ${INSTALL_PATH}
251 # Additional Config and Use files
252 IF(CILC_LIB_HAS_ADDITIONAL_CONFIG_FILE)
254 ${${LIBRARY_NAME}_ADDITIONAL_CONFIG_FILE}
255 ${CILC_WORK_DIR}/Additional${LIBRARY_NAME}Config.cmake
260 ${CILC_WORK_DIR}/Additional${LIBRARY_NAME}Config.cmake
261 DESTINATION ${INSTALL_PATH}
264 ${${LIBRARY_NAME}_ADDITIONAL_USE_FILE}
265 ${CILC_WORK_DIR}/AdditionalUse${LIBRARY_NAME}.cmake
270 ${CILC_WORK_DIR}/AdditionalUse${LIBRARY_NAME}.cmake
271 DESTINATION ${INSTALL_PATH}
273 ENDIF(CILC_LIB_HAS_ADDITIONAL_CONFIG_FILE)
274 # Specific to install tree
275 # FindLIBRARY_NAME.cmake in CMake/Modules dir
277 ${CREA_CMAKE_DIR}/InstallLibraryForCMake_FindLibrary.cmake.in
278 ${CILC_WORK_DIR}/Find${LIBRARY_NAME}.cmake
283 # FILES ${CILC_WORK_DIR}/Find${LIBRARY_NAME}.cmake
284 # DESTINATION ${CMAKE_ROOT}/Modules
289 FILES ${CILC_WORK_DIR}/Find${LIBRARY_NAME}.cmake
290 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/cmake/Modules
294 #---------------------------------------------------------------------------
299 ENDMACRO(CREA_ADVANCED_INSTALL_LIBRARY_FOR_CMAKE)
300 #-----------------------------------------------------------------------------
305 #-----------------------------------------------------------------------------
306 MACRO(CREA_INSTALL_LIBRARY_FOR_CMAKE LIBRARY_NAME1)
308 # Sets the settings to default values
309 IF(NOT ${LIBRARY_NAME1}_INSTALL_FOLDER)
310 SET(${LIBRARY_NAME1}_INSTALL_FOLDER ${LIBRARY_NAME1})
311 ENDIF(NOT ${LIBRARY_NAME1}_INSTALL_FOLDER)
313 SET(${LIBRARY_NAME1}_LIBRARIES ${LIBRARY_NAME1})
316 ${LIBRARY_NAME1}_BUILD_TREE_RELATIVE_INCLUDE_PATHS
317 ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
319 IF ( ${PROJECT_BINARY_DIR} STREQUAL ${EXECUTABLE_OUTPUT_PATH} )
320 SET(CILFC_EXECUTABLE_OUTPUT_REL_PATH ".")
321 ELSE ( ${PROJECT_BINARY_DIR} STREQUAL ${EXECUTABLE_OUTPUT_PATH} )
324 CILFC_EXECUTABLE_OUTPUT_REL_PATH
325 ${PROJECT_BINARY_DIR} ${EXECUTABLE_OUTPUT_PATH})
326 ENDIF ( ${PROJECT_BINARY_DIR} STREQUAL ${EXECUTABLE_OUTPUT_PATH} )
330 SET(${LIBRARY_NAME1}_BUILD_TREE_RELATIVE_LIBRARY_PATHS
331 ${CILFC_EXECUTABLE_OUTPUT_REL_PATH})
332 SET(${LIBRARY_NAME1}_INSTALL_TREE_RELATIVE_LIBRARY_PATHS ${CMAKE_CREA_LIB_PATH} )
334 SET(${LIBRARY_NAME1}_BUILD_TREE_RELATIVE_LIBRARY_PATHS
335 ${CILFC_EXECUTABLE_OUTPUT_REL_PATH} )
337 # ${CILFC_EXECUTABLE_OUTPUT_REL_PATH}/Debug
338 # ${CILFC_EXECUTABLE_OUTPUT_REL_PATH}/Release)
339 SET(${LIBRARY_NAME1}_INSTALL_TREE_RELATIVE_LIBRARY_PATHS bin)
342 IF(NOT ${LIBRARY_NAME1}_INSTALL_TREE_RELATIVE_INCLUDE_PATHS)
343 SET(${LIBRARY_NAME1}_INSTALL_TREE_RELATIVE_INCLUDE_PATHS include/${LIBRARY_NAME1})
344 ENDIF(NOT ${LIBRARY_NAME1}_INSTALL_TREE_RELATIVE_INCLUDE_PATHS)
346 # Invoke the advanced macro
347 CREA_ADVANCED_INSTALL_LIBRARY_FOR_CMAKE(${LIBRARY_NAME1})
350 ENDMACRO(CREA_INSTALL_LIBRARY_FOR_CMAKE)
351 #-----------------------------------------------------------------------------