-
Notifications
You must be signed in to change notification settings - Fork 29
/
CMakeLists.txt
164 lines (133 loc) · 4.91 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
cmake_minimum_required(VERSION 3.10.2)
project(sea-dsa)
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR )
message (FATAL_ERROR
"In-source builds are not allowed. Please clean your source tree and try again.")
endif()
# determine if this is top-level or embedded project
if (PROJECT_NAME STREQUAL CMAKE_PROJECT_NAME)
set (TOP_LEVEL TRUE)
else()
set (TOP_LEVEL FALSE)
endif()
if(TOP_LEVEL)
if(CMAKE_VERSION VERSION_GREATER "3.13.0")
cmake_policy(SET CMP0074 NEW)
cmake_policy(SET CMP0077 NEW)
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif()
endif()
option (BUILD_SEA_DSA_LIBS_SHARED "Build all sea-dsa libraries shared." OFF)
option (ENABLE_SANITY_CHECKS "Enable sea-dsa sanity checks." OFF)
if (ENABLE_SANITY_CHECKS)
message (STATUS "Compiling sea-dsa with sanity checks")
set (SANITY_CHECKS TRUE)
else ()
message (STATUS "Compiling sea-dsa without sanity checks")
endif()
# Add path for custom modules
list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# put static libraries first
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" ${CMAKE_FIND_LIBRARY_SUFFIXES})
option(SEA_ENABLE_LLD "Use lld as C and C++ linker." OFF)
if(SEA_ENABLE_LLD)
set(CMAKE_EXE_LINKER_FLAGS "-fuse-ld=lld")
endif()
option (SEA_DSA_STATIC_EXE "Static executable." OFF)
## llvm
if (TOP_LEVEL)
find_package (LLVM 14.0 CONFIG)
if (NOT LLVM_FOUND)
ExternalProject_Get_Property (llvm INSTALL_DIR)
set (LLVM_ROOT ${INSTALL_DIR})
set (LLVM_DIR ${LLVM_ROOT}/lib/cmake/llvm CACHE PATH
"Forced location of LLVM cmake config" FORCE)
message (WARNING "No llvm found. Install LLVM 14.")
return()
endif()
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
# We incorporate the CMake features provided by LLVM:
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
include(AddLLVM)
include(HandleLLVMOptions)
set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LLVM_CXXFLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LLVM_LDFLAGS}")
include_directories(${LLVM_INCLUDE_DIRS})
link_directories(${LLVM_LIBRARY_DIRS})
add_definitions(${LLVM_DEFINITIONS})
if (NOT LLVM_BUILD_TYPE STREQUAL CMAKE_BUILD_TYPE)
message(WARNING
"LLVM_BUILD_TYPE and CMAKE_BUILD_TYPE differ:\n"
"\tLLMV_BUILD_TYPE=${LLVM_BUILD_TYPE}\n"
"\tCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}\n"
"Runtime errors might occur.")
if (LLVM_BUILD_TYPE MATCHES "Release|RelWithDebInfo" AND
CMAKE_BUILD_TYPE MATCHES "Release|RelWithDebInfo")
message(STATUS "Assuming that mixing Release and RelWithDebInfo is allowed.")
else()
message(FATAL_ERROR "Incompatible mix of LLVM_BUILD_TYPE and CMAKE_BUILD_TYPE")
endif()
endif()
endif ()
## Boost
if (TOP_LEVEL)
set (CUSTOM_BOOST_ROOT "" CACHE PATH "Path to custom boost installation.")
if (CUSTOM_BOOST_ROOT)
set (BOOST_ROOT ${CUSTOM_BOOST_ROOT})
set (Boost_NO_SYSTEM_PATHS "ON")
endif()
find_package (Boost 1.65 REQUIRED)
if (Boost_FOUND)
include_directories (${Boost_INCLUDE_DIRS})
if(NOT LLVM_ENABLE_EH)
add_definitions(-DBOOST_NO_EXCEPTIONS)
endif()
endif ()
endif ()
# sea-dsa specific
set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ standard to conform to")
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)
add_definitions(-Wno-redeclared-class-member)
add_definitions(-Wno-sometimes-uninitialized)
add_definitions(-Wno-deprecated-declarations)
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
add_definitions( -Wno-unused-local-typedefs)
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
add_definitions(-Wno-unused-local-typedef)
add_definitions(-Wno-inconsistent-missing-override)
endif ()
configure_file(include/seadsa/config.h.cmake
${CMAKE_BINARY_DIR}/include/seadsa/config.h)
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_BINARY_DIR}/include)
add_subdirectory(lib/seadsa)
add_subdirectory(units)
add_subdirectory(tools)
add_subdirectory(tests)
install(DIRECTORY include/seadsa DESTINATION include
FILES_MATCHING
PATTERN "*.hpp"
PATTERN "*.hh"
PATTERN "*.h"
PATTERN "CMakeFiles" EXCLUDE
PATTERN ".svn" EXCLUDE)
if (TOP_LEVEL)
install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/README.md DESTINATION .)
endif()
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
add_library(SpecLang OBJECT ${CMAKE_CURRENT_SOURCE_DIR}/lib/seadsa/SpecLang.cc)
target_compile_options(SpecLang BEFORE PRIVATE -S -emit-llvm)
install(FILES $<TARGET_OBJECTS:SpecLang>
DESTINATION lib
RENAME sea_dsa.ll)
else()
message (WARNING "Unable to build spec language \n\t Set C compiler to clang with -DCMAKE_C_COMPILER=clang")
endif()