-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
119 lines (100 loc) · 3.64 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
cmake_minimum_required(VERSION 2.8.11)
project(httpverbs)
enable_testing()
include(CTest)
include(CheckIncludeFileCXX)
include(CheckCXXSourceCompiles)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY build)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY build)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY tests)
option(PER_THREAD_CACHE "Enable per-thread connection pool" ON)
option(USE_BOOST_CHRONO "Use Boost.Chrono instead of C++11 <chrono>" OFF)
option(USE_BOOST_TSS "Use Boost TSS instead of C++11 thread_local" OFF)
configure_file(src/config.h.in ${CMAKE_SOURCE_DIR}/src/config.h)
if(BUILD_TESTING)
find_package(PythonInterp REQUIRED)
file(TO_NATIVE_PATH ${PYTHON_EXECUTABLE} PYTHON_CMD)
configure_file(tests/run_test_server.in
tests/run_test_server @ONLY)
configure_file(tests/run_test_server.bat.in
tests/run_test_server.bat)
if(NOT WIN32)
get_filename_component(START_SCRIPT_PATH
tests/run_test_server ABSOLUTE)
get_filename_component(STOP_SCRIPT_PATH
tests/stop_test_server ABSOLUTE)
else()
get_filename_component(START_SCRIPT_PATH
tests/run_test_server.bat ABSOLUTE)
get_filename_component(STOP_SCRIPT_PATH
tests/stop_test_server.bat ABSOLUTE)
endif()
configure_file(CTestCustom.cmake.in CTestCustom.cmake @ONLY)
endif()
if(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Wall")
else()
foreach(flagvar CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
string(REGEX REPLACE "/MD" "/MT" ${flagvar} "${${flagvar}}")
string(REGEX REPLACE "/MDd" "/MTd" ${flagvar} "${${flagvar}}")
endforeach()
endif()
if(USE_BOOST_CHRONO)
set(boost_in_use system)
else()
CHECK_INCLUDE_FILE_CXX(chrono HAVE_CHRONO)
if(NOT HAVE_CHRONO)
message(FATAL_ERROR "C++11 <chrono> not found.
Change option to use Boost.Chrono")
endif()
endif()
if(PER_THREAD_CACHE AND USE_BOOST_TSS)
set(boost_in_use system thread)
elseif(PER_THREAD_CACHE)
CHECK_CXX_SOURCE_COMPILES("
#include <string>
int main() { thread_local std::string x; }"
CXX11_THREAD_LOCAL)
if(NOT CXX11_THREAD_LOCAL)
message(FATAL_ERROR "C++11 thread_local unsupported.
Change option to use Boost TSS")
endif()
endif()
find_package(CURL 7.28.0 REQUIRED)
find_package(Boost 1.48.0 COMPONENTS ${boost_in_use} REQUIRED)
if(WIN32)
# fix libcurl linking on Windows
foreach(libvar CURL_LIBRARIES)
if(${libvar} MATCHES "curl.*\\.lib$")
add_definitions(-DCURL_STATICLIB)
break()
endif()
endforeach()
list(INSERT CURL_LIBRARIES 0 ws2_32 wldap32 crypt32)
endif()
include_directories(${CURL_INCLUDE_DIRS})
include_directories(include)
file(GLOB httpverbs_srcs src/*.cc)
file(GLOB tests_srcs tests/*.cc)
add_library(httpverbs STATIC ${httpverbs_srcs})
target_include_directories(httpverbs PUBLIC ${Boost_INCLUDE_DIRS})
target_link_libraries(httpverbs ${CURL_LIBRARIES})
target_link_libraries(httpverbs ${Boost_LIBRARIES})
if(BUILD_TESTING)
foreach(test_src ${tests_srcs})
get_filename_component(test_suite ${test_src} NAME_WE)
add_executable(${test_suite} ${test_src})
target_link_libraries(${test_suite} httpverbs)
add_test(${test_suite} tests/${test_suite})
endforeach()
endif()
file(GLOB httpverbs_hdrs include/httpverbs/*.h)
get_target_property(_link_libs httpverbs LINK_LIBRARIES)
get_target_property(_inc_dir httpverbs INTERFACE_INCLUDE_DIRECTORIES)
configure_file(httpverbs-config.cmake.in httpverbs-config.cmake)
export(PACKAGE httpverbs)
install(FILES ${httpverbs_hdrs} DESTINATION include/httpverbs)
install(TARGETS httpverbs EXPORT httpverbs-targets ARCHIVE DESTINATION lib)
install(EXPORT httpverbs-targets DESTINATION lib/cmake/httpverbs)
install(FILES httpverbs-config.cmake DESTINATION lib/cmake/httpverbs)