forked from seznam/elasticlient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
85 lines (71 loc) · 3.2 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
cmake_minimum_required(VERSION 2.8.7)
project(Elasticlient LANGUAGES CXX)
message(STATUS "Checking compiler C++11 support.")
if(CMAKE_VERSION VERSION_LESS "3.1")
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-std=c++11" COMPILER_SUPPORTS_CXX11)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support.")
endif()
else()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pipe -Wall -Wextra -Wfatal-errors -Wformat-security -Wuninitialized -Wfloat-equal -fPIC -g")
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
macro(get_variable VAR_NAME VAR_TEXT DEFAULT_VALUE IS_OPTION)
if(${IS_OPTION})
option(${VAR_NAME} ${VAR_TEXT} ${DEFAULT_VALUE})
elseif(NOT DEFINED ${VAR_NAME})
set(${VAR_NAME} ${DEFAULT_VALUE})
endif()
# Also check if defined in environment
if(DEFINED ENV{${VAR_NAME}})
set(${VAR_NAME} $ENV{${VAR_NAME}})
endif()
message(STATUS " ${VAR_NAME}: ${${VAR_NAME}}")
endmacro()
get_variable(ELASTICLIENT_VERSION_MAJOR "Set elasticlient major version." 2 NO)
get_variable(ELASTICLIENT_VERSION_MINOR "Set elasticlient minor version." 1 NO)
get_variable(ELASTICLIENT_VERSION_PATCH "Set elasticlient patch version." 0 NO)
get_variable(BUILD_ELASTICLIENT_TESTS "Build tests for elasticlient library." YES YES)
get_variable(BUILD_ELASTICLIENT_EXAMPLE "Build exmaple program which using elasticlient library." YES YES)
get_variable(USE_ALL_SYSTEM_LIBS "Will found all libraries in system." NO YES)
if(USE_ALL_SYSTEM_LIBS)
set(USE_SYSTEM_JSONCPP YES)
set(USE_SYSTEM_CPR YES)
set(USE_SYSTEM_HTTPMOCKSERVER YES)
set(USE_SYSTEM_GTEST YES)
else()
get_variable(USE_SYSTEM_JSONCPP "Will found JsonCpp library in system." NO YES)
get_variable(USE_SYSTEM_CPR "Will found CPR library in system." NO YES)
get_variable(USE_SYSTEM_HTTPMOCKSERVER "Will found HTTPMockServer library in system." NO YES)
get_variable(USE_SYSTEM_GTEST "Will found GTest library in system." NO YES)
endif()
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
link_directories(${LIBRARY_OUTPUT_PATH})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
message(STATUS "CMAKE_MODULE_PATH: ${CMAKE_MODULE_PATH}")
# Dependencies are solved in external subdirectory
add_subdirectory(external)
set(ELASTICLIENT_LIBRARY elasticlient CACHE INTERNAL "")
set(ELASTICLIENT_LIBRARIES ${ELASTICLIENT_LIBRARY} ${CPR_LIBRARIES} ${JSONCPP_LIBRARIES} CACHE INTERNAL "")
set(ELASTICLIENT_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include CACHE INTERNAL "")
set(ELASTICLIENT_INCLUDE_DIRS ${ELASTICLIENT_INCLUDE_DIR} ${CPR_INCLUDE_DIRS} ${JSONCPP_INCLUDE_DIRS} CACHE INTERNAL "")
add_subdirectory(src)
if(BUILD_ELASTICLIENT_TESTS)
enable_testing()
add_subdirectory(test)
endif()
if(BUILD_ELASTICLIENT_EXAMPLE)
add_subdirectory(example)
endif()
install(DIRECTORY ${ELASTICLIENT_INCLUDE_DIR}/elasticlient
DESTINATION include
FILES_MATCHING PATTERN "*.h")