-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
206 lines (172 loc) · 9.02 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
project (Henson)
cmake_minimum_required (VERSION 3.9)
option (use_boost "Use Boost.Context" OFF)
option (python "Build Python bindings" ON)
option (mpi-wrappers "Include MPI wrappers" ON)
option (regenerate-wrapper "Regenerate MPI wrapper" ON)
option (henson_backward "Use cpp-backward" ON)
# Default to Release
if (NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
set_property (CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif (NOT CMAKE_BUILD_TYPE)
set (CMAKE_POSITION_INDEPENDENT_CODE ON)
# Boost
if (use_boost)
find_package (Boost COMPONENTS context)
include_directories (SYSTEM ${Boost_INCLUDE_DIR})
endif()
# backward
#
if (henson_backward)
add_subdirectory(ext/backward-cpp)
set(HENSON_BACKWARD_ENABLE ${BACKWARD_ENABLE})
else()
set(HENSON_BACKWARD_ENABLE "")
endif()
# MPI
find_package (MPI REQUIRED)
set (mpi_libraries MPI::MPI_C MPI::MPI_CXX)
# DL
set (libraries ${libraries} ${CMAKE_DL_LIBS})
# Threads
find_package (Threads)
set (libraries ${libraries} ${CMAKE_THREAD_LIBS_INIT})
include_directories (${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/ext/spdlog/include
${CMAKE_CURRENT_SOURCE_DIR}/include
SYSTEM ${MPI_C_INCLUDE_PATH})
if (NOT use_boost)
set (CORO_TYPE "-DCORO_SJLJ")
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set (CORO_TYPE "-DCORO_ASM")
endif()
# Libcoro
add_library (coro src/coro.c)
set_target_properties (coro PROPERTIES COMPILE_FLAGS ${CORO_TYPE})
set (HENSON_LIB_SOURCES src/coro.c)
endif()
if (python)
add_subdirectory (ext/pybind11)
add_definitions (-DHENSON_PYTHON)
endif()
set (CMAKE_CXX_STANDARD 14)
# Format
add_subdirectory (ext/fmt)
include_directories (ext/fmt/include)
set (HENSON_LIB_SOURCES src/context.cpp src/data.cpp ${HENSON_LIB_SOURCES})
add_library (henson_lib ${HENSON_LIB_SOURCES})
set_target_properties (henson_lib PROPERTIES OUTPUT_NAME henson)
if (use_boost)
set_target_properties (henson_lib PROPERTIES COMPILE_FLAGS "-DUSE_BOOST")
else()
set_target_properties (henson_lib PROPERTIES COMPILE_FLAGS ${CORO_TYPE})
endif()
# MPI wrapper
if (mpi-wrappers)
if (regenerate-wrapper)
set (WRAP ${PROJECT_SOURCE_DIR}/src/wrap.py)
include (${PROJECT_SOURCE_DIR}/src/WrapConfig.cmake)
add_wrapped_file (restrict-world.c src/restrict-world.w)
else()
add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/restrict-world.c
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/src/restrict-world.c ${CMAKE_CURRENT_BINARY_DIR}/restrict-world.c
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/src/restrict-world.c)
endif()
add_library (henson-pmpi SHARED restrict-world.c)
target_link_libraries (henson-pmpi henson_lib ${mpi_libraries})
set (libraries ${libraries} henson-pmpi)
add_library (henson-pmpi-static STATIC restrict-world.c)
else()
set (libraries henson_lib ${libraries} ${mpi_libraries})
endif()
# git version
include (git_watcher.cmake)
add_executable (henson-hwl henson-hwl.cpp)
add_executable (henson-chai henson-chai.cpp
${CMAKE_CURRENT_BINARY_DIR}/src/version.cpp
src/chai/puppet.cpp
src/chai/data.cpp
src/chai/procs.cpp
src/chai/scheduler.cpp
src/chai/util.cpp
src/chai/stdlib.cpp
${HENSON_BACKWARD_ENABLE})
if (henson_backward)
add_backward(henson-chai)
endif()
add_executable (henson-exec henson-exec.cpp
${CMAKE_CURRENT_BINARY_DIR}/src/version.cpp)
target_link_libraries (henson-hwl PRIVATE fmt ${libraries})
target_link_libraries (henson-chai PRIVATE fmt ${libraries})
target_link_libraries (henson-exec PRIVATE fmt ${libraries})
if (python)
target_link_libraries(henson-chai PRIVATE pybind11::embed)
endif()
if (use_boost)
target_link_libraries (henson-hwl PRIVATE ${Boost_CONTEXT_LIBRARY})
target_link_libraries (henson_lib PRIVATE ${Boost_CONTEXT_LIBRARY})
target_link_libraries (henson-chai PRIVATE ${Boost_CONTEXT_LIBRARY})
target_link_libraries (henson-exec PRIVATE ${Boost_CONTEXT_LIBRARY})
set_target_properties (henson-hwl PROPERTIES COMPILE_FLAGS "-DUSE_BOOST")
set_target_properties (henson-chai PROPERTIES COMPILE_FLAGS "-DUSE_BOOST")
set_target_properties (henson-exec PROPERTIES COMPILE_FLAGS "-DUSE_BOOST")
else()
target_link_libraries (henson-hwl PRIVATE coro)
set_target_properties (henson-hwl PROPERTIES COMPILE_FLAGS "${CORO_TYPE}")
target_link_libraries (henson-chai PRIVATE coro)
set_target_properties (henson-chai PROPERTIES COMPILE_FLAGS "${CORO_TYPE}")
target_link_libraries (henson-exec PRIVATE coro)
set_target_properties (henson-exec PROPERTIES COMPILE_FLAGS "${CORO_TYPE}")
endif()
add_dependencies (henson-chai AlwaysCheckGit)
add_dependencies (henson-exec AlwaysCheckGit)
add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/examples/run_test.sh
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/examples/run_test.sh ${CMAKE_CURRENT_BINARY_DIR}/examples/run_test.sh
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/examples/run_test.sh)
add_custom_target (run_test.sh ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/examples/run_test.sh)
# Helper to compile Henson executables
function (add_henson_executable name sources)
if (APPLE)
add_executable (${name} ${sources})
else ()
#add_executable (${name} ${sources})
add_library (${name} SHARED ${sources})
set_target_properties (${name} PROPERTIES PREFIX "")
set_target_properties (${name} PROPERTIES SUFFIX "")
#set (linker_flags "-pie -Wl,--export-dynamic")
set (linker_flags "-Wl,--export-dynamic")
set (linker_flags "${linker_flags} -Wl,-u,henson_set_contexts,-u,henson_set_namemap")
set_target_properties (${name} PROPERTIES LINK_FLAGS ${linker_flags})
endif ()
endfunction()
add_subdirectory (examples/simple)
add_subdirectory (examples/intercomm)
add_subdirectory (examples/async)
add_subdirectory (examples/fair)
add_subdirectory (examples/storage)
add_subdirectory (examples/queue)
add_subdirectory (examples/embed-python)
add_subdirectory (tools)
if (python)
add_subdirectory (bindings/python)
endif (python)
# henson-chai + henson_lib
install (TARGETS henson-chai henson_lib henson-exec
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
if (mpi-wrappers)
# libraries
install (TARGETS henson-pmpi henson-pmpi-static
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
endif (mpi-wrappers)
# headers
foreach (h data.h data.hpp context.h context.hpp coro.h
procs.hpp coroutine.hpp puppet.hpp python-puppet.hpp
time.hpp variant.hpp serialization.hpp)
install (FILES ${CMAKE_SOURCE_DIR}/include/henson/${h}
DESTINATION include/henson)
endforeach ()