-
Notifications
You must be signed in to change notification settings - Fork 7
/
CMakeLists.txt
138 lines (120 loc) · 5.75 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#----------------------------------------------------------------------------------------
# Preload options
# These have to be set before project()
#----------------------------------------------------------------------------------------
# Options to enable locally-compiled boost
set( USE_LOCAL_BOOST OFF CACHE BOOL "Use locally build boost (see build_minimal_boost.sh)")
set( LOCAL_BOOST_PREFIX "/usr/local" CACHE PATH "Location of boost for the local build")
set( LOCAL_BOOST_LIB_PREFIX "${LOCAL_BOOST_PREFIX}/lib" CACHE PATH "Location of boost libraries")
set( LOCAL_BOOST_INCLUDE_PREFIX "${LOCAL_BOOST_PREFIX}/include" CACHE PATH "Location of boost headers")
set( BUILD_SHARED_LIBS ON CACHE BOOL "Build shared or static libraries" )
set( BUILD_TESTS ON CACHE BOOL "Build internal unit tests")
set( CMAKE_BUILD_TYPE "RELEASE" CACHE STRING "Default build type" )
set( CMAKE_EXPORT_COMPILE_COMMANDS "ON" CACHE BOOL "Exports a database for clang-tidy")
set( HBTHREADS_USES_CLANG_TIDY OFF CACHE BOOL "Add clang-tidy during compilation" )
if ( HBTHREADS_USES_CLANG_TIDY )
set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-p=${CMAKE_BINARY_DIR};--warnings-as-errors=*" CACHE STRING "Clang-tidy command line " )
endif()
# Turn this on only after careful consideration of your application usage
# Note that if you enable this, you will need to add -DUSE_SMALL_SIZE and/or
# -DUSE_SMALL_COUNTER in your project as well.
set( USE_SMALL_SIZE OFF CACHE BOOL "Use small size type for memory management" )
set( USE_SMALL_COUNTER OFF CACHE BOOL "Use small counter for intrusive pointers" )
# This will allow VSCode to pick up on dependencies
set( CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE BOOL "Export dependency list")
#----------------------------------------------------------------------------------------
# Global project settings
#----------------------------------------------------------------------------------------
cmake_minimum_required( VERSION 3.10 )
project( hbthreads LANGUAGES C CXX VERSION 1.0.1 )
set(CMAKE_CXX_STANDARD 14)
if ( USE_SMALL_SIZE )
add_compile_options( -DUSE_SMALL_SIZE )
endif()
if ( USE_SMALL_COUNTER )
add_compile_options( -DUSE_SMALL_COUNTER )
endif()
include_directories( ${CMAKE_CURRENT_SOURCE_DIR} )
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/hbthreads )
#----------------------------------------------------------------------------------------
# Dependencies
#----------------------------------------------------------------------------------------
# Let's include Google Tests as a downloadable content so we don't have
# to force the user to install it in their system
if ( BUILD_TESTS )
include(FetchContent)
FetchContent_Declare( googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG main )
FetchContent_MakeAvailable(googletest)
endif()
#----------------------------------------------------------------------------------------
# BOOST complex dependencies
#----------------------------------------------------------------------------------------
if ( USE_LOCAL_BOOST )
# The intent is to use this together with the script ./build_minimal_boost.sh included
# with this repo.
macro( add_boost_library libname )
string( TOUPPER ${libname} libname_upcase )
add_library( boost_${libname}_s STATIC IMPORTED GLOBAL )
set_target_properties( boost_${libname}_s PROPERTIES
IMPORTED_LOCATION "${LOCAL_BOOST_LIB_PREFIX}/libboost_${libname}.a"
INTERFACE_COMPILE_DEFINITIONS "HAVE_BOOST_${libname_upcase}"
)
list( APPEND BOOST_LIBS_STATIC "boost_${libname}_s")
endmacro()
add_boost_library( context )
add_boost_library( container )
add_library( boost INTERFACE IMPORTED )
set_target_properties( boost PROPERTIES
INTERFACE_LINK_LIBRARIES "pthread;${BOOST_LIBS_STATIC}"
INTERFACE_INCLUDE_DIRECTORIES "${LOCAL_BOOST_INCLUDE_PREFIX}"
INTERFACE_COMPILE_DEFINITIONS "HAVE_LOCAL_BOOST"
INTERFACE_LINK_OPTIONS "-Wl,--no-as-needed"
)
else()
# This is the "normal" cmake boost-supported
# On Ubuntu install with `apt install libboost-all-dev`
find_package(Boost COMPONENTS context container REQUIRED)
add_library( boost INTERFACE IMPORTED )
set_target_properties( boost PROPERTIES
INTERFACE_LINK_LIBRARIES "pthread;Boost::context;Boost::container"
)
target_link_options( boost PUBLIC "-Wl,--no-as-needed" )
endif()
#----------------------------------------------------------------------------------------
# Documentation
#----------------------------------------------------------------------------------------
option(BUILD_DOCS "Build documentation" ON)
if ( BUILD_DOCS )
find_package(Doxygen)
if (DOXYGEN_FOUND)
set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
add_custom_target( doc_doxygen ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM )
endif (DOXYGEN_FOUND)
endif()
#----------------------------------------------------------------------------------------
# The library itself and usage examples
#----------------------------------------------------------------------------------------
if ( BUILD_TESTS )
enable_testing()
include(CTest)
include(GoogleTest)
endif()
# hbthreads contains unit tests so it needs to be inside
add_subdirectory(hbthreads)
if ( BUILD_TESTS )
add_subdirectory(tests)
install (TARGETS ${ALL_TESTS}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
PUBLIC_HEADER DESTINATION include/hbthreads
)
endif()