-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
166 lines (157 loc) · 6.11 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# ----------------------------------------------------------------------------------------
# fiber (header only)
# Copyright (C) 2022-23 Fix8 Market Technologies Pty Ltd
# by David L. Dight
# see https://github.com/fix8mt/fiber
#
# Lightweight header-only stackful per-thread fiber
# with built-in roundrobin scheduler x86_64 / linux only
#
# Distributed under the Boost Software License, Version 1.0 August 17th, 2003
#
# Permission is hereby granted, free of charge, to any person or organization
# obtaining a copy of the software and accompanying documentation covered by
# this license (the "Software") to use, reproduce, display, distribute,
# execute, and transmit the Software, and to prepare derivative works of the
# Software, and to permit third-parties to whom the Software is furnished to
# do so, all subject to the following:
#
# The copyright notices in the Software and this entire statement, including
# the above license grant, this restriction and the following disclaimer,
# must be included in all copies of the Software, in whole or in part, and
# all derivative works of the Software, unless such copies or derivative
# works are solely in the form of machine-executable object code generated by
# a source language processor.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
# SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
# FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
# ----------------------------------------------------------------------------------------
# cmake config
# clang
# CXX="clang++" CC="clang" cmake ..
# gcc
# CXX="g++" CC="gcc" cmake ..
#
# min cmake version 3.20 (Mar 24, 2021)
# ----------------------------------------------------------------------------------------
cmake_minimum_required (VERSION 3.20)
project (fiber
LANGUAGES CXX
HOMEPAGE_URL https://github.com/fix8mt/fiber
DESCRIPTION "Lightweight header-only stackful per-thread C++20 fiber"
VERSION 2.3
)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
link_libraries(Threads::Threads)
include_directories(${CMAKE_SOURCE_DIR}/include)
if(CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE "RELEASE")
endif()
if (CMAKE_BUILD_TYPE STREQUAL "DEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -D_DEBUG -ggdb")
set(CMAKE_C_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
else(CMAKE_BUILD_TYPE STREQUAL "RELEASE")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -ggdb")
set(CMAKE_C_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
endif()
message("-- cxx flags ${CMAKE_BUILD_TYPE}: \"${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}}\"")
set(exdir ${CMAKE_SOURCE_DIR}/examples)
file(GLOB esrc CONFIGURE_DEPENDS "${exdir}/fiber*.cpp")
foreach(x ${esrc})
cmake_path(GET x STEM LAST_ONLY target)
add_executable(${target} ${x})
set_target_properties(${target} PROPERTIES CXX_STANDARD 20 CXX_STANDARD_REQUIRED true)
get_target_property(v1 ${target} CXX_STANDARD)
cmake_path(GET x FILENAME fname)
message("-- adding ${fname} cxx std: c++${v1}")
endforeach()
# to disable building monitor tests:
# cmake -DBUILD_MONITOR=false ..
option(BUILD_MONITOR "enable building monitor tests" true)
message("-- Build monitor tests: ${BUILD_MONITOR}")
if(BUILD_MONITOR)
message(STATUS "Populating termbox2...")
include(ExternalProject)
ExternalProject_Add(termbox2
GIT_REPOSITORY https://github.com/termbox/termbox2.git
GIT_PROGRESS true
GIT_SHALLOW ON
GIT_TAG master
UPDATE_DISCONNECTED true
CONFIGURE_COMMAND ""
BUILD_IN_SOURCE true
BUILD_COMMAND sh -c "make -j4"
INSTALL_COMMAND ""
)
set(termbox2 ${CMAKE_CURRENT_BINARY_DIR}/termbox2-prefix/src/termbox2)
message(STATUS "Populating GMP...")
ExternalProject_Add(gmp
GIT_REPOSITORY https://github.com/alisw/GMP.git
GIT_PROGRESS true
GIT_SHALLOW ON
GIT_TAG master
UPDATE_DISCONNECTED true
CONFIGURE_COMMAND sh -c "./configure --enable-cxx -enable-alloca=alloca"
BUILD_IN_SOURCE true
BUILD_COMMAND sh -c "make -j4"
INSTALL_COMMAND ""
TEST_COMMAND sh -c "make -j4 check"
)
set(gmp ${CMAKE_CURRENT_BINARY_DIR}/gmp-prefix/src/gmp)
file(GLOB msrc CONFIGURE_DEPENDS "${exdir}/montest*.cpp")
foreach(x ${msrc})
cmake_path(GET x STEM LAST_ONLY target)
add_executable(${target} ${x})
set_target_properties(${target} PROPERTIES CXX_STANDARD 20 CXX_STANDARD_REQUIRED true CXX_EXTENSIONS off)
add_dependencies(${target} termbox2 gmp)
target_include_directories(${target} PRIVATE ${termbox2} ${gmp})
target_link_directories(${target} PRIVATE ${termbox2} ${gmp}/.libs)
target_link_libraries(${target} PRIVATE termbox2.a gmpxx.a gmp.a)
get_target_property(v1 ${target} CXX_STANDARD)
cmake_path(GET x FILENAME fname)
message("-- adding ${fname} cxx std: c++${v1}")
endforeach()
endif()
# to disable building unit tests:
# cmake -DBUILD_TESTS=false ..
option(BUILD_TESTS "enable building unit tests" true)
message("-- Build unit tests: ${BUILD_TESTS}")
if(BUILD_TESTS)
message(STATUS "Populating Catch2...")
include(FetchContent)
enable_testing()
FetchContent_Declare(Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_SHALLOW ON
GIT_TAG devel
)
FetchContent_MakeAvailable(Catch2)
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
include(Catch)
set(testdir ${CMAKE_SOURCE_DIR}/test)
add_executable(utest01 ${testdir}/utest01.cpp)
target_link_libraries(utest01 PRIVATE Catch2::Catch2WithMain)
catch_discover_tests(utest01)
add_executable(utest02 ${testdir}/utest02.cpp)
set_target_properties(utest01 utest02 PROPERTIES CXX_STANDARD 20 CXX_STANDARD_REQUIRED true)
target_link_libraries(utest02 PRIVATE Catch2::Catch2)
catch_discover_tests(utest02)
endif()
# to dump all non-empty cmake variables
# cmake -DCMAKE_DUMP_VARS=true ..
option(CMAKE_DUMP_VARS "dump all cmake vars" false)
if(CMAKE_DUMP_VARS)
get_cmake_property(varname VARIABLES)
foreach (var ${varname})
if(NOT ${var} STREQUAL "")
message(STATUS "${var}=${${var}}")
endif()
endforeach()
endif()