1 #-----------------------------------------------------------------------------
2 # Macro CREATE_FIND_PACKAGE
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 CREATE_FIND_PACKAGE 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(CMAKE_CREATE_FIND_PACKAGE LIBRARY_NAME)
99 #---------------------------------------------------------------------------
100 # Sets the common values to build tree and install tree configs
101 SET(CFP_LIB_REQUIRED_C_FLAGS ${${LIBRARY_NAME}_REQUIRED_C_FLAGS})
102 SET(CFP_LIB_REQUIRED_CXX_FLAGS ${${LIBRARY_NAME}_REQUIRED_CXX_FLAGS})
103 SET(CFP_LIB_REQUIRED_LINK_FLAGS ${${LIBRARY_NAME}_REQUIRED_LINK_FLAGS})
104 SET(CFP_LIB_MAJOR_VERSION ${${LIBRARY_NAME}_MAJOR_VERSION})
105 SET(CFP_LIB_MINOR_VERSION ${${LIBRARY_NAME}_MINOR_VERSION})
106 SET(CFP_LIB_BUILD_VERSION ${${LIBRARY_NAME}_BUILD_VERSION})
108 ${CFP_LIB_MAJOR_VERSION}.${CFP_LIB_MINOR_VERSION}.${CFP_LIB_BUILD_VERSION})
109 SET(CFP_LIB_LIBRARIES ${${LIBRARY_NAME}_LIBRARIES})
110 IF (${LIBRARY_NAME}_HAS_ADDITIONAL_CONFIG_FILE)
111 SET(CFP_LIB_HAS_ADDITIONAL_CONFIG_FILE TRUE)
112 ELSE (${LIBRARY_NAME}_HAS_ADDITIONAL_CONFIG_FILE)
113 SET(CFP_LIB_HAS_ADDITIONAL_CONFIG_FILE FALSE)
114 ENDIF (${LIBRARY_NAME}_HAS_ADDITIONAL_CONFIG_FILE)
115 #---------------------------------------------------------------------------
118 #---------------------------------------------------------------------------
119 #-- BUILD TREE configuration
120 SET(CFP_BUILD_TREE_CONFIGURATION TRUE)
121 # UseLIBRARY_NAME.cmake
123 ${CMakeCreateFindPackage_DIR}/CMakeCreateFindPackage_UseLibrary.cmake.in
124 ${PROJECT_BINARY_DIR}/Use${LIBRARY_NAME}.cmake
127 # LIBRARY_NAMEConfig.cmake
128 SET(CFP_LIB_RELATIVE_INCLUDE_PATHS
129 ${${LIBRARY_NAME}_BUILD_TREE_RELATIVE_INCLUDE_PATHS})
130 SET(CFP_LIB_RELATIVE_LIBRARY_PATHS
131 ${${LIBRARY_NAME}_BUILD_TREE_RELATIVE_LIBRARY_PATHS})
133 ${CMakeCreateFindPackage_DIR}/CMakeCreateFindPackage_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(CFP_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(CFP_LIB_HAS_ADDITIONAL_CONFIG_FILE)
154 #---------------------------------------------------------------------------
157 #---------------------------------------------------------------------------
158 #-- INSTALL TREE configuration
159 SET(CFP_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(CFP_WORK_DIR ${CMAKE_CURRENT_BINARY_DIR}/CMakeCreateFindPackage_stuff)
164 IF(NOT IS_DIRECTORY ${CFP_WORK_DIR})
165 FILE(MAKE_DIRECTORY ${CFP_WORK_DIR})
166 ENDIF(NOT IS_DIRECTORY ${CFP_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 ${CMakeCreateFindPackage_DIR}/CMakeCreateFindPackage_UseLibrary.cmake.in
184 ${CFP_WORK_DIR}/Use${LIBRARY_NAME}.cmake
189 ${CFP_WORK_DIR}/Use${LIBRARY_NAME}.cmake
190 DESTINATION ${INSTALL_PATH}
192 # LIBRARY_NAMEConfig.cmake
193 SET(CFP_LIB_RELATIVE_INCLUDE_PATHS
194 ${${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_INCLUDE_PATHS})
195 SET(CFP_LIB_RELATIVE_LIBRARY_PATHS
196 ${${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_LIBRARY_PATHS})
198 ${CMakeCreateFindPackage_DIR}/CMakeCreateFindPackage_LibraryConfig.cmake.in
199 ${CFP_WORK_DIR}/${LIBRARY_NAME}Config.cmake
204 ${CFP_WORK_DIR}/${LIBRARY_NAME}Config.cmake
205 DESTINATION ${INSTALL_PATH}
207 # LIBRARY_NAMEBuildSettings.cmake :
208 CMAKE_EXPORT_BUILD_SETTINGS(${CFP_WORK_DIR}/${LIBRARY_NAME}BuildSettings.cmake)
211 ${CFP_WORK_DIR}/${LIBRARY_NAME}BuildSettings.cmake
212 DESTINATION ${INSTALL_PATH}
214 # Additional Config and Use files
215 IF(CFP_LIB_HAS_ADDITIONAL_CONFIG_FILE)
217 ${${LIBRARY_NAME}_ADDITIONAL_CONFIG_FILE}
218 ${CFP_WORK_DIR}/Additional${LIBRARY_NAME}Config.cmake
223 ${CFP_WORK_DIR}/Additional${LIBRARY_NAME}Config.cmake
224 DESTINATION ${INSTALL_PATH}
227 ${${LIBRARY_NAME}_ADDITIONAL_USE_FILE}
228 ${CFP_WORK_DIR}/AdditionalUse${LIBRARY_NAME}.cmake
233 ${CFP_WORK_DIR}/AdditionalUse${LIBRARY_NAME}.cmake
234 DESTINATION ${INSTALL_PATH}
236 ENDIF(CFP_LIB_HAS_ADDITIONAL_CONFIG_FILE)
237 # Specific to install tree
238 # FindLIBRARY_NAME.cmake in CMake/Modules dir
240 ${CMakeCreateFindPackage_DIR}/CMakeCreateFindPackage_FindLibrary.cmake.in
241 ${CFP_WORK_DIR}/Find${LIBRARY_NAME}.cmake
245 FILES ${CFP_WORK_DIR}/Find${LIBRARY_NAME}.cmake
246 DESTINATION ${CMAKE_ROOT}/Modules
248 #---------------------------------------------------------------------------
253 ENDMACRO(CMAKE_CREATE_FIND_PACKAGE)
254 #-----------------------------------------------------------------------------