forked from Countly/countly-sdk-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
109 lines (92 loc) · 4.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
cmake_minimum_required(VERSION 3.0)
cmake_policy(SET CMP0091 NEW)
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/include/countly.hpp COUNTLY_HPP_CONTENTS)
string(REGEX MATCH "#define COUNTLY_SDK_VERSION \"[^\"]+\"" COUNTLY_SDK_VERSION ${COUNTLY_HPP_CONTENTS})
string(REGEX REPLACE "#define COUNTLY_SDK_VERSION \"([^\"]+)\"" "\\1" COUNTLY_SDK_VERSION ${COUNTLY_SDK_VERSION})
project(countly VERSION ${COUNTLY_SDK_VERSION} LANGUAGES CXX C)
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(COUNTLY_USE_CUSTOM_HTTP "Use a custom HTTP library" OFF)
option(COUNTLY_USE_SQLITE "Use SQLite" ON)
option(COUNTLY_BUILD_TESTS "Build test programs" OFF)
option(COUNTLY_BUILD_SAMPLE "Build Sample programs" OFF)
if (NOT WIN32 AND NOT BUILD_SHARED_LIBS AND NOT COUNTLY_USE_CUSTOM_HTTP)
message(FATAL_ERROR "You must provide a custom HTTP function when compiling statically.")
endif()
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS off)
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
add_compile_options("$<$<NOT:$<CONFIG:Debug>>:/Zi>")
add_link_options("$<$<NOT:$<CONFIG:Debug>>:/DEBUG>")
add_link_options("$<$<NOT:$<CONFIG:Debug>>:/OPT:REF>")
add_link_options("$<$<NOT:$<CONFIG:Debug>>:/OPT:ICF>")
endif()
add_library(countly
${CMAKE_CURRENT_SOURCE_DIR}/src/countly.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/event.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/countly_c.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/countly_c.def
${CMAKE_CURRENT_SOURCE_DIR}/vendor/sqlite/sqlite3.c)
set_property(TARGET countly PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
target_include_directories(countly
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
set_target_properties(countly PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO)
find_package(Threads)
target_link_libraries(countly Threads::Threads version)
target_include_directories(countly PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/vendor/json/include)
if (APPLE)
set(OPENSSL_ROOT_DIR "/usr/local/opt/openssl")
endif()
#find_package(OpenSSL REQUIRED)
#target_include_directories(countly PRIVATE ${OPENSSL_INCLUDE_DIR})
#target_link_libraries(countly ${OPENSSL_LIBRARIES})
if(COUNTLY_USE_CUSTOM_HTTP)
target_compile_definitions(countly PRIVATE COUNTLY_USE_CUSTOM_HTTP)
elseif(NOT WIN32)
find_package(CURL REQUIRED)
target_include_directories(countly PRIVATE ${CURL_INCLUDE_DIRS})
target_link_libraries(countly ${CURL_LIBRARIES})
endif()
if(COUNTLY_USE_SQLITE)
target_compile_definitions(countly PRIVATE COUNTLY_USE_SQLITE)
#set(Sqlite3_DIR ${CMAKE_CURRENT_SOURCE_DIR}/vendor/sqlite/build)
#find_package(Sqlite3)
target_include_directories(countly PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/vendor/sqlite)
#target_link_libraries(countly sqlite3)
endif()
if(COUNTLY_BUILD_TESTS)
add_executable(countly-tests
${CMAKE_CURRENT_SOURCE_DIR}/tests/main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tests/event.cpp)
if(COUNTLY_USE_SQLITE)
target_compile_definitions(countly-tests PRIVATE COUNTLY_USE_SQLITE)
target_include_directories(countly-tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/vendor/sqlite)
endif()
target_include_directories(countly-tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/vendor/doctest/doctest)
target_include_directories(countly-tests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/vendor/json/include)
target_link_libraries(countly-tests countly)
set_target_properties(countly-tests PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO)
endif()
if(COUNTLY_BUILD_SAMPLE)
add_executable(countly-sample
${CMAKE_CURRENT_SOURCE_DIR}/examples/example_integration.cpp)
if(COUNTLY_USE_SQLITE)
if(COUNTLY_BUILD_TESTS)
target_compile_definitions(countly-tests PRIVATE COUNTLY_USE_SQLITE)
target_include_directories(countly-tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/vendor/sqlite)
endif()
endif()
target_include_directories(countly-sample PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/vendor/doctest/doctest)
target_include_directories(countly-sample PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/vendor/json/include)
target_link_libraries(countly-sample countly)
set_target_properties(countly-sample PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO)
endif()