-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
79 lines (64 loc) · 2.18 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
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
# Package hunter
include("cmake-modules/HunterGate.cmake")
HunterGate(
URL "https://github.com/ruslo/hunter/archive/v0.23.214.tar.gz"
SHA1 "e14bc153a7f16d6a5eeec845fb0283c8fad8c358"
)
project(ucrono)
# Import cmake modules
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules")
# Get git tags and set lib version
include(SetSharedLibVersion)
# Use GNUInstallDirs to install libraries into correct
# locations on multiple platforms
include(GNUInstallDirs)
# Debug build
if (CMAKE_BUILD_TYPE MATCHES Debug)
message(STATUS "Debug build")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${CMAKE_C_FLAGS} -g -O0 -DDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -O0 -DDEBUG")
if (COVERAGE MATCHES ON)
message(STATUS "Coverage enabled")
find_package(PythonInterp)
set(CMAKE_COVERAGE_FLAGS "-fprofile-arcs -ftest-coverage --coverage")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${CMAKE_COVERAGE_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${CMAKE_COVERAGE_FLAGS}")
endif()
else()
message(STATUS "Release build")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2")
endif()
# Define source files for library
set(UCRONO_SRC src/ucrono.c)
set(UCRONO_INC src)
set(LIBRARY_SRC
${UCRONO_SRC}
)
add_library(ucrono STATIC ${LIBRARY_SRC})
# Define header files for library
target_include_directories(ucrono PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE ${UCRONO_INC} libs/uthash/include
)
# Link libraries
target_link_libraries(ucrono ${LIBRARY_LINKS})
set_target_properties(ucrono
PROPERTIES
VERSION ${GENERIC_LIB_VERSION}
SOVERSION ${GENERIC_LIB_SOVERSION}
)
# Install library to GNU locations
install(TARGETS ucrono EXPORT ucrono-config
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# Add examples
set(callback_src
examples/callback.c
)
add_executable(callback ${callback_src})
target_link_libraries(callback ucrono)