-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
134 lines (116 loc) · 4.19 KB
/
Copy pathCMakeLists.txt
File metadata and controls
134 lines (116 loc) · 4.19 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
cmake_minimum_required(VERSION 3.16)
project(SwarmRT C ASM)
set(CMAKE_C_STANDARD 11)
# Platform detection
if(WIN32)
add_definitions(-D_WIN32)
set(PLATFORM_LIBS ws2_32)
elseif(APPLE)
add_definitions(-D_DARWIN_C_SOURCE)
set(PLATFORM_LIBS "")
else()
add_definitions(-D_GNU_SOURCE)
set(PLATFORM_LIBS ssl crypto)
endif()
# SQLite — the db_* builtins (in swarmrt_io / studio builtins) link against
# libsqlite3. Mirrors the Makefile: on macOS the system header is old, so
# prefer Homebrew's sqlite3 if it's installed.
if(APPLE)
execute_process(COMMAND brew --prefix sqlite3
OUTPUT_VARIABLE BREW_SQLITE
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET)
if(BREW_SQLITE)
include_directories(${BREW_SQLITE}/include)
link_directories(${BREW_SQLITE}/lib)
endif()
endif()
# Common flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-function -O2")
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-macro-redefined")
endif()
# Source directory
set(SRC_DIR ${CMAKE_SOURCE_DIR}/src)
# Core runtime objects
set(CORE_SOURCES
${SRC_DIR}/swarmrt_native.c
${SRC_DIR}/swarmrt_asm.S
${SRC_DIR}/swarmrt_otp.c
${SRC_DIR}/swarmrt_task.c
${SRC_DIR}/swarmrt_ets.c
${SRC_DIR}/swarmrt_phase4.c
${SRC_DIR}/swarmrt_phase5.c
${SRC_DIR}/swarmrt_hotload.c
${SRC_DIR}/swarmrt_io.c
${SRC_DIR}/swarmrt_gc.c
${SRC_DIR}/swarmrt_node.c
${SRC_DIR}/swarmrt_lang.c
${SRC_DIR}/swarmrt_http.c
${SRC_DIR}/swarmrt_pdf.c
)
# swarmrt_native.c needs -fno-stack-protector (processes migrate between
# scheduler threads via context_swap, invalidating the per-thread canary)
set_source_files_properties(${SRC_DIR}/swarmrt_native.c
PROPERTIES COMPILE_FLAGS "-fno-stack-protector")
# Enable .S assembly files
enable_language(ASM)
# Static library
add_library(swarmrt_lib STATIC ${CORE_SOURCES})
target_include_directories(swarmrt_lib PUBLIC ${SRC_DIR})
target_link_libraries(swarmrt_lib pthread z sqlite3 m ${PLATFORM_LIBS})
# SwarmRT Compiler (swc)
# swarmrt_lsp.c defines sw_lsp_main (the `swc lsp` subcommand). It was
# missing here, so `cmake --build --target swc` failed to link.
add_executable(swc
${SRC_DIR}/swc.c
${SRC_DIR}/swarmrt_codegen.c
${SRC_DIR}/swarmrt_obfusc.c
${SRC_DIR}/swarmrt_repl.c
${SRC_DIR}/swarmrt_test.c
${SRC_DIR}/swarmrt_lsp.c
)
target_link_libraries(swc swarmrt_lib)
# Search module
add_library(swarmrt_search STATIC ${SRC_DIR}/swarmrt_search.c)
target_include_directories(swarmrt_search PUBLIC ${SRC_DIR})
if(NOT WIN32)
target_compile_options(swarmrt_search PRIVATE -march=native)
endif()
# Filesystem search CLI (sws)
add_executable(sws ${SRC_DIR}/swarmrt_fsindex.c)
target_link_libraries(sws swarmrt_search pthread z m ${PLATFORM_LIBS})
if(NOT WIN32)
target_compile_options(sws PRIVATE -march=native)
endif()
# Native benchmark
add_executable(swarmrt-native ${SRC_DIR}/benchmark_native.c)
target_link_libraries(swarmrt-native swarmrt_lib)
# Output to bin/
set_target_properties(swc sws swarmrt-native swarmrt_lib swarmrt_search
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin
)
# Test targets
if(EXISTS ${SRC_DIR}/test_otp.c)
add_executable(test-otp ${SRC_DIR}/test_otp.c)
target_link_libraries(test-otp swarmrt_lib)
set_target_properties(test-otp PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
endif()
if(EXISTS ${SRC_DIR}/test_phase2.c)
add_executable(test-phase2 ${SRC_DIR}/test_phase2.c)
target_link_libraries(test-phase2 swarmrt_lib)
set_target_properties(test-phase2 PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
endif()
if(EXISTS ${SRC_DIR}/test_search.c)
add_executable(test-search ${SRC_DIR}/test_search.c)
target_link_libraries(test-search swarmrt_search pthread z m ${PLATFORM_LIBS})
if(NOT WIN32)
target_compile_options(test-search PRIVATE -march=native)
endif()
set_target_properties(test-search PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
endif()
# MinGW-w64 cross-compilation toolchain
# Usage: cmake -DCMAKE_TOOLCHAIN_FILE=mingw-w64.cmake ..