-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCMakeLists.txt
174 lines (148 loc) · 6.27 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
# Top-Level CMakeLists.txt
cmake_minimum_required(VERSION 3.9.0)
# Project information
project( SparrowCompiler )
# Get compiler version
set(SparrowCompiler_BUILD_VERSION 0)
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
find_package(Git)
if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --long --tags --dirty --always
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
OUTPUT_VARIABLE "SparrowCompiler_BUILD_VERSION"
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
endif()
string(REGEX REPLACE
"v([0-9]+)\\.([0-9]+).*"
"\\1"
SparrowCompiler_MAJOR_VERSION ${SparrowCompiler_BUILD_VERSION})
string(REGEX REPLACE
"v([0-9]+)\\.([0-9]+).*"
"\\2"
SparrowCompiler_MINOR_VERSION ${SparrowCompiler_BUILD_VERSION})
string(TIMESTAMP SparrowCompiler_BUILD_DATE "%Y-%m-%d")
string(TIMESTAMP SparrowCompiler_BUILD_YEAR "%Y")
# Print configuration
message(STATUS "System : ${CMAKE_SYSTEM}")
message(STATUS "System name : ${CMAKE_SYSTEM_NAME}")
message(STATUS "System ver : ${CMAKE_SYSTEM_VERSION}")
message(STATUS "Compiler ver : ${SparrowCompiler_BUILD_VERSION}")
message(STATUS " major ver : ${SparrowCompiler_MAJOR_VERSION}")
message(STATUS " minor ver : ${SparrowCompiler_MINOR_VERSION}")
message(STATUS "Build date : ${SparrowCompiler_BUILD_DATE}")
message(STATUS "Build year : ${SparrowCompiler_BUILD_YEAR}")
message(STATUS)
# Configure required files
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/SparrowImplicitLib/std/compilerInfo.spr.in ${CMAKE_CURRENT_SOURCE_DIR}/SparrowImplicitLib/std/compilerInfo.spr)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/src/SparrowCompiler/VersionInfo.h.in ${CMAKE_CURRENT_SOURCE_DIR}/src/SparrowCompiler/VersionInfo.h)
# User passed compilation options
option(BOOTSTRAP_SPARROW "Use system-wide SparrowCompiler to compile Sparrow files needed for the compiler" OFF)
message(STATUS "BOOTSTRAP_SPARROW: ${BOOTSTRAP_SPARROW}")
option(SPARROW_PROFILING "Enable Tracy integration into Sparrow compiler" OFF)
message(STATUS "SPARROW_PROFILING: ${SPARROW_PROFILING}")
option(ENABLE_TIDY "Enable clang-tidy checks when building" OFF)
message(STATUS "ENABLE_TIDY: ${ENABLE_TIDY}")
# Where to output the results of the compilation
set(OutDir ${CMAKE_CURRENT_SOURCE_DIR}/build/bin)
set(EXECUTABLE_OUTPUT_PATH ${OutDir})
set(LIBRARY_OUTPUT_PATH ${OutDir})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OutDir})
set(RUNTIME_OUTPUT_DIRECTORY ${OutDir})
message(STATUS "OutDir: ${OutDir}")
message(STATUS "exe output path: ${EXECUTABLE_OUTPUT_PATH}")
message(STATUS "lib output path: ${LIBRARY_OUTPUT_PATH}")
# Find the boost library
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
set(BOOST_LIBRARYDIR "" CACHE PATH "Path to Boost libraries")
find_package( Boost 1.54.0 COMPONENTS filesystem system program_options timer REQUIRED )
message(STATUS "Boost include dir: ${Boost_INCLUDE_DIRS}")
message(STATUS "Boost lib dir: ${Boost_LIBRARY_DIRS}")
include_directories( "${Boost_INCLUDE_DIRS}" )
link_directories(${Boost_LIBRARY_DIRS})
# Find the LLVM library
find_package( LLVM REQUIRED )
include_directories( "${LLVM_INCLUDE_DIRS}" )
link_directories(${LLVM_LIBRARY_DIRS})
message(STATUS "LLVM version: ${LLVM_VERSION}")
message(STATUS "LLVM bin dir: ${LLVM_TOOLS_BINARY_DIR}")
message(STATUS "LLVM include dir: ${LLVM_INCLUDE_DIRS}")
# Project options
if( NOT CMAKE_BUILD_TYPE ) # set default cmake build type to Release (None Debug Release RelWithDebInfo MinSizeRel)
set( CMAKE_BUILD_TYPE "Release" )
endif()
# Compilation flags
if(MSVC)
add_definitions( "-W4" ) # Warning level 4
add_definitions( -DWIN32 )
add_definitions( -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE )
else()
add_definitions( -D__STDC_LIMIT_MACROS=1 )
# set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address" )
add_definitions( -Wall ) # All warnings...
add_definitions( -Wno-deprecated ) # ... and except deprecated functions
endif()
if(SPARROW_PROFILING)
add_definitions( -DSPARROW_PROFILING=1 )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17" )
else()
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
endif()
# Add our macros
include(Macros.cmake)
# Add target for clang-format
find_program(CLANG_FORMAT "clang-format" HINTS ${LLVM_TOOLS_BINARY_DIR})
if(CLANG_FORMAT)
add_custom_target(
clang-format
COMMAND
find ../src/ -name '*.c' -o -name '*.cpp' -o -name '*.h' -o -name '*.hpp'
| xargs ${CLANG_FORMAT} -i
)
endif()
# Add target for clang-tidy
set(TIDY_CHECKS
-*, # Disable for non-debug builds
modernize-*,
bugprone-*,
cppcoreguidelines-*,
-cppcoreguidelines-owning-memory, # not met, requires gsl
-cppcoreguidelines-pro-bounds-array-to-pointer-decay, # not met, requires gsl
-cppcoreguidelines-pro-bounds-constant-array-index, # not met, requires gsl
-cppcoreguidelines-pro-bounds-pointer-arithmetic, # not met, requires gsl
-cppcoreguidelines-pro-type-union-access, # not met (we use some unions)
-cppcoreguidelines-pro-type-vararg, # not met (we are using printf)
)
string (REPLACE ";" " " TIDY_CHECKS "${TIDY_CHECKS}")
if(ENABLE_TIDY)
# Search for clang-tidy and clang-apply-replacements
find_program(CLANG_TIDY "clang-tidy" HINTS ${LLVM_TOOLS_BINARY_DIR})
message(STATUS "Tidy checks: ${TIDY_CHECKS}")
set(TIDY_HEADER_FILTER ${CMAKE_SOURCE_DIR}/*)
# Set extra arguments
set(TIDY_FIX 1)
set(TIDY_EXTRA_ARGS -quiet;-format-style=file)
if (TIDY_FIX)
set(TIDY_EXTRA_ARGS ${TIDY_EXTRA_ARGS};-fix)
endif()
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY};-checks=\"${TIDY_CHECKS}\";-header-filter='${TIDY_HEADER_FILTER}';${TIDY_EXTRA_ARGS}"
CACHE STRING "" FORCE)
else()
set(CMAKE_CXX_CLANG_TIDY "")
endif()
# Ensure generation of compile_commands.json; needed for clang-tidy
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Externals
option(RC_ENABLE_CATCH "Use Catch framework for testing" ON)
add_subdirectory( externals/rapidcheck )
# Dive into subdirectories
add_subdirectory( src/Nest )
add_subdirectory( src/Feather )
add_subdirectory( src/LLVMBackend )
add_subdirectory( src/SparrowFrontend )
add_subdirectory( src/SparrowCompiler )
add_subdirectory( unittests )