@@ -8,8 +8,24 @@ project(CPP-NETLIB)
8
8
9
9
option ( CPP-NETLIB_BUILD_SHARED_LIBS "Build cpp-netlib as shared libraries." OFF )
10
10
11
+ include (GNUInstallDirs)
12
+
13
+ # determine install path for CMake config files
14
+ if (WIN32 AND NOT CYGWIN )
15
+ set (DEF_INSTALL_CMAKE_DIR CMake)
16
+ else ()
17
+ set (DEF_INSTALL_CMAKE_DIR lib/CMake/cppnetlib)
18
+ endif ()
19
+ set (INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files" )
20
+
21
+ # Make relative cmake install path absolute (needed later on)
22
+ if (NOT IS_ABSOLUTE "${INSTALL_CMAKE_DIR} " )
23
+ set (INSTALL_CMAKE_DIR "${CMAKE_INSTALL_PREFIX} /${INSTALL_CMAKE_DIR} " )
24
+ endif ()
25
+
26
+
11
27
if (CPP-NETLIB_BUILD_SHARED_LIBS OR BUILD_SHARED_LIBS )
12
- message ("Linking boost testing libs dynamically..." )
28
+ message (STATUS "Linking boost testing libs dynamically..." )
13
29
set (Boost_USE_STATIC_LIBS OFF )
14
30
set (CPP-NETLIB_BUILD_SHARED_LIBS ON )
15
31
set (BUILD_SHARED_LIBS ON )
@@ -68,5 +84,40 @@ endif()
68
84
69
85
enable_testing ()
70
86
71
- include (GNUInstallDirs)
72
87
install (DIRECTORY boost DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
88
+
89
+ ###
90
+ ## Export Targets
91
+ # (so cpp-netlib can be easily used by other CMake projects)
92
+ # [see http://www.cmake.org/Wiki/CMake/Tutorials/How_to_create_a_ProjectConfig.cmake_file]
93
+
94
+ # Add all targets to the build-tree export set
95
+ export (TARGETS cppnetlib-client-connections cppnetlib-server-parsers cppnetlib-uri
96
+ FILE "${PROJECT_BINARY_DIR} /cppnetlibTargets.cmake" )
97
+ # Export the package for use from the build-tree
98
+ # (this registers the build-tree with a global CMake-registry)
99
+ export (PACKAGE cppnetlib)
100
+ # Create the cppnetlibConfig.cmake and cppnetlibConfigVersion files
101
+ file (RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR} "
102
+ "${CMAKE_INSTALL_FULL_INCLUDEDIR} " )
103
+ # ... for the build tree
104
+ set (CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR} " )
105
+ configure_file (cppnetlibConfig.cmake.in
106
+ "${PROJECT_BINARY_DIR} /cppnetlibConfig.cmake" @ONLY)
107
+ # ... for the install tree
108
+ set (CONF_INCLUDE_DIRS "\$ {CPPNETLIB_CMAKE_DIR}/${REL_INCLUDE_DIR} " )
109
+ configure_file (cppnetlibConfig.cmake.in
110
+ "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY} /cppnetlibConfig.cmake" @ONLY)
111
+ # ... for both
112
+ configure_file (cppnetlibConfigVersion.cmake.in
113
+ "${PROJECT_BINARY_DIR} /cppnetlibConfigVersion.cmake" @ONLY)
114
+ # Install the cppnetlibConfig.cmake and cppnetlibConfigVersion.cmake
115
+ install (FILES
116
+ "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY} /cppnetlibConfig.cmake"
117
+ "${PROJECT_BINARY_DIR} /cppnetlibConfigVersion.cmake"
118
+ DESTINATION "${INSTALL_CMAKE_DIR} "
119
+ COMPONENT dev)
120
+ # Install the export set for use with the install-tree
121
+ install (EXPORT cppnetlibTargets
122
+ DESTINATION "${INSTALL_CMAKE_DIR} "
123
+ COMPONENT dev)
0 commit comments