forked from Chia-Network/chiapos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
180 lines (153 loc) · 5.16 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
CMAKE_MINIMUM_REQUIRED(VERSION 3.14 FATAL_ERROR)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE "RELEASE")
ENDIF()
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
endif()
project(chiapos C CXX ASM)
# CMake 3.14+
include(FetchContent)
FetchContent_Declare(
pybind11-src
GIT_REPOSITORY https://github.com/pybind/pybind11.git
GIT_TAG v2.6.2
)
FetchContent_MakeAvailable(pybind11-src)
FetchContent_Declare(
cxxopts
GIT_REPOSITORY https://github.com/jarro2783/cxxopts.git
GIT_TAG v2.2.1
)
FetchContent_MakeAvailable(cxxopts)
FetchContent_Declare(
gulrak
GIT_REPOSITORY https://github.com/gulrak/filesystem.git
GIT_TAG v1.5.4
)
FetchContent_MakeAvailable(gulrak)
set(FSE_LIB ${CMAKE_CURRENT_SOURCE_DIR}/lib/FiniteStateEntropy/lib)
set(FSE_FILES
${FSE_LIB}/fse_compress.c
${FSE_LIB}/fse_decompress.c
${FSE_LIB}/entropy_common.c
${FSE_LIB}/hist.c
)
include_directories(
${INCLUDE_DIRECTORIES}
${CMAKE_CURRENT_SOURCE_DIR}/../lib/include
${cxxopts_SOURCE_DIR}/include
${gulrak_SOURCE_DIR}/include/ghc
${CMAKE_CURRENT_SOURCE_DIR}/../lib/FiniteStateEntropy/lib
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/test
)
add_library(fse ${FSE_FILES})
IF (MSVC)
IF (CMAKE_BUILD_TYPE STREQUAL "RELEASE")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /Oy")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /O2 /Oy")
ELSE()
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Ob1")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Ob1")
ENDIF()
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zi")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Zi")
ELSE()
IF (CMAKE_BUILD_TYPE STREQUAL "RELEASE")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
ELSE()
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0")
ENDIF()
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -g")
ENDIF()
IF (CMAKE_BUILD_TYPE STREQUAL "ASAN")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fsanitize=address -fsanitize=undefined")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer -fsanitize=address -fsanitize=undefined")
set (CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=address -fsanitize=undefined")
ENDIF()
IF (CMAKE_BUILD_TYPE STREQUAL "TSAN")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fsanitize=thread")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer -fsanitize=thread")
set (CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=thread")
ENDIF()
IF (APPLE)
# on macOS "uname -m" returns the architecture (x86_64 or arm64)
execute_process(
COMMAND uname -m
RESULT_VARIABLE result
OUTPUT_VARIABLE OSX_NATIVE_ARCHITECTURE
OUTPUT_STRIP_TRAILING_WHITESPACE)
ENDIF()
IF (WIN32)
set(BLAKE3_SRC
src/b3/blake3.c
src/b3/blake3_portable.c
src/b3/blake3_dispatch.c
src/b3/blake3_avx2.c
src/b3/blake3_avx512.c
src/b3/blake3_sse41.c
)
ELSEIF(OSX_NATIVE_ARCHITECTURE STREQUAL "arm64")
set(BLAKE3_SRC
src/b3/blake3.c
src/b3/blake3_portable.c
src/b3/blake3_dispatch.c
)
ELSE()
set(BLAKE3_SRC
src/b3/blake3.c
src/b3/blake3_portable.c
src/b3/blake3_dispatch.c
src/b3/blake3_avx2_x86-64_unix.S
src/b3/blake3_avx512_x86-64_unix.S
src/b3/blake3_sse41_x86-64_unix.S
)
ENDIF()
pybind11_add_module(chiapos ${CMAKE_CURRENT_SOURCE_DIR}/python-bindings/chiapos.cpp src/chacha8.c ${BLAKE3_SRC})
add_executable(ProofOfSpace
src/cli.cpp
src/chacha8.c
${BLAKE3_SRC}
)
add_executable(RunTests
tests/test-main.cpp
tests/test.cpp
src/chacha8.c
${BLAKE3_SRC}
)
find_package(Threads REQUIRED)
add_library(uint128 STATIC uint128_t/uint128_t.cpp)
target_include_directories(uint128 PUBLIC uint128_t)
target_compile_features(fse PUBLIC cxx_std_17)
target_compile_features(chiapos PUBLIC cxx_std_17)
target_compile_features(RunTests PUBLIC cxx_std_17)
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
target_link_libraries(chiapos PRIVATE fse Threads::Threads)
target_link_libraries(ProofOfSpace fse Threads::Threads)
target_link_libraries(RunTests fse Threads::Threads)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD")
target_link_libraries(chiapos PRIVATE fse Threads::Threads)
target_link_libraries(ProofOfSpace fse Threads::Threads)
target_link_libraries(RunTests fse Threads::Threads)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
target_link_libraries(chiapos PRIVATE fse Threads::Threads)
target_link_libraries(ProofOfSpace fse Threads::Threads)
target_link_libraries(RunTests fse Threads::Threads)
elseif (MSVC)
target_link_libraries(chiapos PRIVATE fse Threads::Threads uint128)
target_link_libraries(ProofOfSpace fse Threads::Threads uint128)
target_link_libraries(RunTests fse Threads::Threads uint128)
else()
target_link_libraries(chiapos PRIVATE fse stdc++fs Threads::Threads)
target_link_libraries(ProofOfSpace fse stdc++fs Threads::Threads)
target_link_libraries(RunTests fse stdc++fs Threads::Threads)
endif()
enable_testing()
add_test(NAME RunTests COMMAND RunTests)