-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
156 lines (129 loc) · 4.92 KB
/
Copy pathCMakeLists.txt
File metadata and controls
156 lines (129 loc) · 4.92 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
cmake_minimum_required(VERSION 3.15)
project(Mavis)
if(NOT DEFINED MAVIS_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 20)
else()
set(CMAKE_CXX_STANDARD ${MAVIS_CXX_STANDARD})
endif()
set (CMAKE_EXPORT_COMPILE_COMMANDS ON)
find_package (Boost 1.75.0 REQUIRED COMPONENTS program_options json)
message (STATUS "Using BOOST ${Boost_VERSION_STRING}")
# Copied from https://cliutils.gitlab.io/modern-cmake/chapters/projects/submodule.html
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
# Update submodules as needed
option(GIT_SUBMODULE "Check submodules during build" ON)
if(GIT_SUBMODULE)
message(STATUS "Submodule update")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
endif()
endif()
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/elfio/CMakeLists.txt")
message(FATAL_ERROR "The elfio submodule was not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
endif()
add_subdirectory(elfio)
add_library(mavis
impl/ExtractorRegistry.cpp
impl/FormRegistry.cpp
impl/InstMetaData.cpp
impl/forms/CommonForms.cpp
impl/forms/CompressedForms.cpp
impl/forms/VectorForms.cpp
)
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 14.0)
target_compile_options(mavis PRIVATE -Wno-template-id-cdtor)
endif()
endif()
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/softfloat.cmake)
target_include_directories(mavis PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(mavis PUBLIC elfio Boost::json softfloat)
include(CheckSourceCompiles)
include(CMakePushCheckState)
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_QUIET True)
# Check if std::bitset can be constexpr
check_source_compiles(CXX [[
#include <bitset>
#ifndef __cpp_lib_constexpr_bitset
#error "no constexpr bitset support"
#endif
int main()
{
}
]] COMPILER_SUPPORTS_CONSTEXPR_BITSET)
cmake_pop_check_state()
# Bring in the bitset2 library if std::bitset isn't constexpr
if(NOT COMPILER_SUPPORTS_CONSTEXPR_BITSET)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/bitset2.cmake)
target_include_directories(mavis PUBLIC "${bitset2_SOURCE_DIR}")
endif()
# Set up test infrastructure
# Only enable tests if Mavis is the top-level project
if (PROJECT_IS_TOP_LEVEL)
include(CTest)
include(ProcessorCount)
ProcessorCount(NUM_CORES)
if (NUM_CORES GREATER 8) # Max of 8 cores
set(NUM_CORE, 8)
endif()
if (NOT NUM_CORES EQUAL 0)
set(CTEST_BUILD_FLAGS -j${NUM_CORES})
set(ctest_test_args ${ctest_test_args} PARALLEL_LEVEL ${NUM_CORES})
endif()
add_custom_target(regress)
add_custom_command(TARGET regress POST_BUILD COMMAND ${CMAKE_CTEST_COMMAND})
set(ENABLE_MAVIS_TESTS True)
else()
set(ENABLE_MAVIS_TESTS False)
endif()
function (mavis_test name target)
if (ENABLE_MAVIS_TESTS)
add_dependencies(regress ${target})
add_test(NAME ${name} COMMAND ${ARGN})
endif()
endfunction (mavis_test)
# Setup common compiler options for the tests and examples
add_library(mavis_test_lib INTERFACE)
target_link_libraries (mavis_test_lib INTERFACE mavis)
target_compile_options (mavis_test_lib INTERFACE -g -Werror -fPIC
-Wall -Wextra -Winline -Winit-self -Wno-unused-function
-Wuninitialized -Wno-sequence-point -Wno-inline -Wno-unknown-pragmas
-Wno-unused-parameter -Wno-missing-field-initializers -pipe
-Winvalid-pch -Woverloaded-virtual)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(mavis_test_lib INTERFACE -Wpedantic -Wno-gnu-zero-variadic-macro-arguments)
endif ()
if (CMAKE_BUILD_TYPE MATCHES "^[Dd]ebug")
target_compile_options (mavis_test_lib INTERFACE -O0)
endif()
# For tests that use the Inst class in test/basic/Inst.h
add_library(mavis_test_inst_lib INTERFACE)
target_include_directories(mavis_test_inst_lib INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/test/basic)
add_subdirectory(example EXCLUDE_FROM_ALL)
add_subdirectory(test EXCLUDE_FROM_ALL)
target_compile_options(mavis PUBLIC -fPIC)
set(CMAKE_CXX_FLAGS_DEBUG "-U_FORTIFY_SOURCE -O0 -g")
set(CMAKE_CXX_FLAGS_FASTDEBUG "-O3 -g")
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/internal.cmake OPTIONAL)
if(NOT CLANGFORMAT_EXECUTABLE)
set(CLANGFORMAT_EXECUTABLE clang-format)
endif()
if(PROJECT_IS_TOP_LEVEL)
add_custom_target(clangformat
git ls-files "*.hpp" "*.cpp" "*.h" "*.tcc" > clang-format-files.out
COMMAND
${CLANGFORMAT_EXECUTABLE} -i --files=clang-format-files.out
COMMAND
rm -f clang-format-files.out
WORKING_DIRECTORY
${CMAKE_SOURCE_DIR}
COMMENT
"Formatting with ${CLANGFORMAT_EXECUTABLE} ..."
)
endif()