44# (See accompanying file LICENSE_1_0.txt or copy at
55# http://www.boost.org/LICENSE_1_0.txt)
66
7- cmake_minimum_required (VERSION 2.8 )
8- project (CPP-NETLIB)
7+ cmake_minimum_required (VERSION 3.5 FATAL_ERROR )
8+ project (CPP-NETLIB CXX )
99
1010option ( CPP-NETLIB_BUILD_SHARED_LIBS "Build cpp-netlib as shared libraries." OFF )
1111option ( CPP-NETLIB_BUILD_TESTS "Build the cpp-netlib project tests." ON )
@@ -42,22 +42,25 @@ endif()
4242# Use Boost's static libraries
4343if (CPP-NETLIB_STATIC_BOOST)
4444 set (Boost_USE_STATIC_LIBS ON )
45+ else ()
46+ # We need this for all tests to use the dynamic version.
47+ set_property (DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS BOOST_ALL_DYN_LINK )
4548endif ()
4649
47- # We need this for all tests to use the dynamic version.
48- add_definitions ( -DBOOST_TEST_DYN_LINK )
50+ # The interface target for public usage requirements
51+ add_library ( cppnetlib INTERFACE )
4952
5053# Always use multi-threaded Boost libraries.
51- set (Boost_USE_MULTI_THREADED ON )
54+ set (Boost_USE_MULTITHREADED ON )
5255
53- find_package (Boost 1.58.0 REQUIRED COMPONENTS system thread )
56+ find_package (Boost 1.58.0 REQUIRED COMPONENTS system thread regex )
5457
5558if (CPP-NETLIB_ENABLE_HTTPS)
5659 if (APPLE )
5760 # If we're on OS X check for Homebrew's copy of OpenSSL instead of Apple's
5861 if (NOT OpenSSL_DIR)
5962 find_program (HOMEBREW brew )
60- if (HOMEBREW STREQUAL " HOMEBREW-NOTFOUND" )
63+ if (NOT HOMEBREW)
6164 message (WARNING "Homebrew not found: not using Homebrew's OpenSSL" )
6265 if (NOT OPENSSL_ROOT_DIR)
6366 message (WARNING "Use -DOPENSSL_ROOT_DIR for non-Apple OpenSSL" )
@@ -69,109 +72,134 @@ if (CPP-NETLIB_ENABLE_HTTPS)
6972 endif ()
7073 endif ()
7174 endif ()
75+
76+ if (CPP-NETLIB_STATIC_OPENSSL)
77+ set (OPENSSL_USE_STATIC_LIBS TRUE )
78+ endif ()
79+
80+ find_package (OpenSSL REQUIRED )
81+ target_compile_definitions (cppnetlib INTERFACE BOOST_NETWORK_ENABLE_HTTPS )
7282 if (CPP-NETLIB_STATIC_OPENSSL)
73- set ( CMAKE_FIND_LIBRARY_SUFFIXES .a )
83+ target_link_libraries ( cppnetlib INTERFACE ${CMAKE_DL_LIBS} )
7484 endif ()
75- find_package (OpenSSL )
7685endif ()
7786
78- find_package ( Threads )
87+
7988set (CMAKE_VERBOSE_MAKEFILE true )
8089
8190set (CPPNETLIB_VERSION_MAJOR 0) # MUST bump this whenever we make ABI-incompatible changes
8291set (CPPNETLIB_VERSION_MINOR 13)
8392set (CPPNETLIB_VERSION_PATCH 0)
8493set (CPPNETLIB_VERSION_STRING ${CPPNETLIB_VERSION_MAJOR} .${CPPNETLIB_VERSION_MINOR} .${CPPNETLIB_VERSION_PATCH} )
8594
86- if (CMAKE_BUILD_TYPE MATCHES Debug)
87- add_definitions (-DBOOST_NETWORK_DEBUG )
88- endif ()
95+ set_property (DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG :Debug >:BOOST_NETWORK_DEBUG >)
8996
90- if (OPENSSL_FOUND)
91- add_definitions (-DBOOST_NETWORK_ENABLE_HTTPS )
92- include_directories (${OPENSSL_INCLUDE_DIR} )
97+ # Use C++11
98+ if (CMAKE_VERSION VERSION_LESS 3.8)
99+ set (CMAKE_CXX_STANDARD 11)
100+ set (CMAKE_CXX_STANDARD_REQUIRED ON )
101+ else ()
102+ target_compile_features (cppnetlib INTERFACE cxx_std_11 )
93103endif ()
94104
95- if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
96- # Use C++11 when using GNU compilers.
97- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11" )
98- elseif (${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
99- # We want to link in C++11 mode in Clang too, but also set a high enough
100- # template depth for the template metaprogramming.
101- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -ftemplate-depth=256 -std=c++11" )
102- if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" )
105+ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" )
106+ add_compile_options (-Wall )
107+ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
108+ # A high enough template depth for the template metaprogramming.
109+ add_compile_options (-Wall -ftemplate-depth=256 )
110+ if (CMAKE_SYSTEM_NAME MATCHES "Darwin" )
103111 # Use libc++ only in OS X.
104- set ( CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -stdlib=libc++" )
105- set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lc++" )
112+ add_compile_options ( -stdlib=libc++ )
113+ set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lc++" )
106114 endif ()
107115endif ()
108116
109117
110- if (MSVC )
111- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj" )
112- set (gtest_force_shared_crt true )
118+ if (WIN32 )
119+ target_compile_definitions (cppnetlib INTERFACE _WIN32_WINNT=0x0501 )
120+
121+ if (MSVC )
122+ target_compile_options (cppnetlib INTERFACE /bigobj )
123+ target_compile_definitions (cppnetlib INTERFACE _SCL_SECURE_NO_WARNINGS )
124+ endif ()
125+
126+ if (MINGW)
127+ target_link_libraries (cppnetlib INTERFACE ws2_32 wsock32 )
128+ endif ()
113129endif ()
114130
115- if (Boost_FOUND)
116- if (MSVC )
117- add_definitions (-D_SCL_SECURE_NO_WARNINGS )
118- endif (MSVC )
119- if (WIN32 )
120- add_definitions (-D_WIN32_WINNT=0x0501 )
121- endif (WIN32 )
122- include_directories (${Boost_INCLUDE_DIRS} )
123- link_directories (${Boost_LIBRARY_DIRS} )
124-
125- enable_testing ()
126- add_subdirectory (libs/network/src )
127- if (CPP-NETLIB_BUILD_TESTS)
128- add_subdirectory (deps/googletest )
129- add_subdirectory (libs/network/test )
130- endif (CPP-NETLIB_BUILD_TESTS )
131- if (CPP-NETLIB_BUILD_EXAMPLES)
132- add_subdirectory (libs/network/example )
133- endif (CPP-NETLIB_BUILD_EXAMPLES )
134- endif (Boost_FOUND )
135-
136- enable_testing ()
137-
138- set (CPP-NETLIB_LIBRARIES ${Boost_LIBRARIES} CACHE INTERNAL "Dependent libraries for header-only use" )
139-
140- install (DIRECTORY boost DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
141-
142- ###
143- ## Export Targets
144- # (so cpp-netlib can be easily used by other CMake projects)
145- # [see http://www.cmake.org/Wiki/CMake/Tutorials/How_to_create_a_ProjectConfig.cmake_file]
146-
147- # Add all targets to the build-tree export set
148- export (TARGETS cppnetlib-client-connections cppnetlib-server-parsers cppnetlib-uri
149- FILE "${PROJECT_BINARY_DIR} /cppnetlibTargets.cmake" )
150- # Export the package for use from the build-tree
151- # (this registers the build-tree with a global CMake-registry)
152- export (PACKAGE cppnetlib )
153- # Create the cppnetlibConfig.cmake and cppnetlibConfigVersion files
154- file (RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR} "
155- "${CMAKE_INSTALL_FULL_INCLUDEDIR} " )
156- # ... for the build tree
157- set (CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR} " ${Boost_INCLUDE_DIRS} )
158- configure_file (cppnetlibConfig.cmake.in
159- "${PROJECT_BINARY_DIR} /cppnetlibConfig.cmake" @ONLY )
160- # ... for the install tree
161- set (CONF_INCLUDE_DIRS "\$ {CPPNETLIB_CMAKE_DIR}/${REL_INCLUDE_DIR} " )
162- set (CONF_INCLUDE_DIRS ${CONF_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} )
131+ target_include_directories (cppnetlib INTERFACE
132+ $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} >
133+ $<INSTALL_INTERFACE :${CMAKE_INSTALL_INCLUDEDIR} >)
134+
135+ find_package (Threads REQUIRED )
136+ target_link_libraries (cppnetlib INTERFACE Boost::thread Threads::Threads )
137+
138+ install (TARGETS cppnetlib EXPORT cppnetlibTargets)
139+
140+ add_subdirectory (libs/network/src )
141+
142+ add_library (cppnetlib::cppnetlib ALIAS cppnetlib )
143+ add_library (cppnetlib::uri ALIAS uri )
144+ add_library (cppnetlib::server-parsers ALIAS server-parsers )
145+ add_library (cppnetlib::client-connections ALIAS client-connections )
146+
147+ if (CPP-NETLIB_BUILD_TESTS)
148+ enable_testing ()
149+
150+ if (MSVC )
151+ set (gtest_force_shared_crt ON CACHE BOOL "Use shared (DLL) run-time lib even when Google Test is built as static lib." )
152+ endif ()
153+
154+ add_subdirectory (deps/googletest )
155+
156+ if (MSVC )
157+ target_compile_definitions (gtest PUBLIC _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING )
158+ target_compile_definitions (gtest_main PUBLIC _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING )
159+ target_compile_definitions (gmock PUBLIC _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING )
160+ target_compile_definitions (gmock_main PUBLIC _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING )
161+ endif ()
162+
163+ add_subdirectory (libs/network/test )
164+ endif ()
165+
166+ if (CPP-NETLIB_BUILD_EXAMPLES)
167+ add_library (cxxopts INTERFACE )
168+ target_include_directories (cxxopts INTERFACE deps/cxxopts/src )
169+
170+ add_subdirectory (libs/network/example )
171+ endif ()
172+
173+ install (DIRECTORY boost DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT dev)
174+
175+ ###
176+ ## Export Targets
177+ # (so cpp-netlib can be easily used by other CMake projects)
178+ # [see http://www.cmake.org/Wiki/CMake/Tutorials/How_to_create_a_ProjectConfig.cmake_file]
179+
180+ # Add all targets to the build-tree export set
181+ export (EXPORT cppnetlibTargets
182+ FILE "${CMAKE_CURRENT_BINARY_DIR} /cppnetlibTargets.cmake"
183+ NAMESPACE cppnetlib:: )
163184configure_file (cppnetlibConfig.cmake.in
164- "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY} /cppnetlibConfig.cmake" @ONLY )
165- # ... for both
166- configure_file (cppnetlibConfigVersion.cmake.in
167- "${PROJECT_BINARY_DIR} /cppnetlibConfigVersion.cmake" @ONLY )
168- # Install the cppnetlibConfig.cmake and cppnetlibConfigVersion.cmake
185+ "${CMAKE_CURRENT_BINARY_DIR} /cppnetlibConfig.cmake" @ONLY )
186+
187+ # Export the package for use from the build-tree
188+ # (this registers the build-tree with a global CMake-registry)
189+ export (PACKAGE cppnetlib )
190+
191+ include (CMakePackageConfigHelpers )
192+ write_basic_package_version_file (cppnetlibConfigVersion.cmake VERSION ${CPPNETLIB_VERSION_STRING} COMPATIBILITY AnyNewerVersion )
193+
194+ # Install the cppnetlibConfig.cmake and cppnetlibConfigVersion.cmake
169195install (FILES
170- "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY} /cppnetlibConfig.cmake"
171- "${PROJECT_BINARY_DIR} /cppnetlibConfigVersion.cmake"
196+ "${PROJECT_BINARY_DIR} /cppnetlibConfig.cmake"
197+ "${PROJECT_BINARY_DIR} /cppnetlibConfigVersion.cmake"
172198 DESTINATION "${INSTALL_CMAKE_DIR} "
173- COMPONENT dev)
174- # Install the export set for use with the install-tree
175- install (EXPORT cppnetlibTargets
176- DESTINATION "${INSTALL_CMAKE_DIR} "
177- COMPONENT dev)
199+ COMPONENT dev)
200+
201+ # Install the export set for use with the install-tree
202+ install (EXPORT cppnetlibTargets
203+ FILE cppnetlibTargets.cmake
204+ NAMESPACE cppnetlib::
205+ DESTINATION "${INSTALL_CMAKE_DIR} " )
0 commit comments