-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
136 lines (114 loc) · 4.74 KB
/
Copy pathCMakeLists.txt
File metadata and controls
136 lines (114 loc) · 4.74 KB
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
cmake_minimum_required(VERSION 3.15)
project(tinycoro
VERSION 1.2
LANGUAGES CXX
DESCRIPTION "a high performance C++20 coroutine library combined with io_uring"
)
# check build dir
get_filename_component(BUILD_DIR_NAME ${CMAKE_BINARY_DIR} NAME)
string(TOLOWER "${BUILD_DIR_NAME}" BUILD_DIR_NAME_LOWER)
if(NOT BUILD_DIR_NAME_LOWER MATCHES "build")
message(FATAL_ERROR
"The build directory must be named include 'build'.\n"
"Current build directory: ${CMAKE_BINARY_DIR}\n"
"Please create a build directory with the correct name and run CMake again."
)
endif()
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# TODO: Complete api visiblity
# set(CMAKE_CXX_VISIBILITY_PRESET hidden)
# set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
include(GNUInstallDirs)
include(GenerateExportHeader)
include(CMakeDependentOption)
include(cmake/env.cmake)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
set(SRC_INCLUDE_DIR
"${PROJECT_SOURCE_DIR}/include"
"${PROJECT_BINARY_DIR}/include"
"${PROJECT_SOURCE_DIR}/config")
set(THIRD_PARTY_INCLUDE_DIR
"${PROJECT_SOURCE_DIR}/third_party/spdlog/include"
"${PROJECT_SOURCE_DIR}/third_party/googletest/googletest/include"
"${PROJECT_SOURCE_DIR}/third_party/atomic_queue/include"
"${PROJECT_SOURCE_DIR}/third_party/benchmark/include")
option(ENABLE_UNIT_TESTS "Enable unit tests" ON)
option(ENABLE_DEBUG_MODE "Enable debug mode" OFF)
option(ENABLE_BUILD_SHARED_LIBS "Enable build shared libs" OFF)
cmake_dependent_option(ENABLE_COMPILE_OPTIMIZE "Enable compile options -O3" ON "NOT ENABLE_DEBUG_MODE" OFF)
set(BUILD_SHARED_LIBS ${ENABLE_BUILD_SHARED_LIBS} CACHE INTERNAL "")
if(NOT CMAKE_BUILD_TYPE)
if(ENABLE_DEBUG_MODE)
set(CMAKE_BUILD_TYPE Debug)
else()
set(CMAKE_BUILD_TYPE Release)
endif()
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(ENABLE_DEBUG_MODE ON)
set(ENABLE_COMPILE_OPTIMIZE OFF)
endif()
# TODO: add more options
message(STATUS "${PROJECT_NAME} version: ${PROJECT_VERSION}")
message(STATUS "Complier path: ${CMAKE_CXX_COMPILER}")
message(STATUS "Enable testing: ${ENABLE_UNIT_TESTS}")
message(STATUS "Enable debug mode: ${ENABLE_DEBUG_MODE}")
message(STATUS "Enable build shared libs: ${ENABLE_BUILD_SHARED_LIBS}")
message(STATUS "Enable compile options -O3: ${ENABLE_COMPILE_OPTIMIZE}")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
message(WARNING "The debug mode use -O0(-Og), which cause gcc won't optimize coroutine tail recursion, "
"loop co_await too many times(such as 10w) will cause stack overflow!")
endif()
# check python version
check_python_command()
if(PYTHON_COMMAND_AVAILABLE)
message(STATUS "python command: ${python_command}")
else()
message(FATAL_ERROR "Can't exec python or python3 or version is lower than 3.7. Please install Python 3.7 or higher.")
endif()
find_library(URING_PATH
NAMES uring
PATHS /usr/lib
)
if (URING_PATH)
message(STATUS "Found liburing at ${URING_PATH}")
else()
message(FATAL_ERROR "Could not find liburing")
endif()
add_subdirectory(third_party)
add_subdirectory(src)
configure_file(${PROJECT_SOURCE_DIR}/config/config.h.in ${PROJECT_SOURCE_DIR}/config/config.h @ONLY)
add_library(${PROJECT_NAME} ${TINYCORO_SOURCE_FILES})
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX PREFIX "" VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR})
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_options(${PROJECT_NAME} PRIVATE "-g")
endif()
if(ENABLE_COMPILE_OPTIMIZE)
target_compile_options(${PROJECT_NAME} PUBLIC -O3)
endif()
target_compile_definitions(${PROJECT_NAME} PRIVATE "$<$<CONFIG:DEBUG>:DEBUG>")
target_compile_definitions(${PROJECT_NAME} PRIVATE "$<$<CONFIG:RELEASE>:RELEASE>")
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20)
target_include_directories(${PROJECT_NAME} PUBLIC ${SRC_INCLUDE_DIR} ${THIRD_PARTY_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} PRIVATE ${URING_PATH} pthread)
generate_export_header(${PROJECT_NAME} BASE_NAME CORO EXPORT_FILE_NAME include/coro/export.hpp)
if(ENABLE_UNIT_TESTS)
enable_testing()
endif()
add_subdirectory(tests)
add_subdirectory(benchtests)
add_subdirectory(examples)
add_subdirectory(benchmark)
configure_file(tinycoro.pc.in tinycoro.pc @ONLY)
# TODO: add install command
# install(TARGETS tinycoro)
# install(DIRECTORY include/coro TYPE INCLUDE)
# install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/coro TYPE INCLUDE)
# install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tinycoro.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)