-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
156 lines (131 loc) · 5.3 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
cmake_minimum_required(VERSION 3.21.1)
project(Scribe C CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if("${DISABLE_INSTALL_MSG}" STREQUAL "true")
message("-- Install messages are now lazily shown")
set(CMAKE_INSTALL_MESSAGE LAZY)
endif()
if(DEFINED ENV{PREFIX_DIR} AND NOT "$ENV{PREFIX_DIR}" STREQUAL "")
set(CMAKE_INSTALL_PREFIX "$ENV{PREFIX_DIR}")
else()
set(CMAKE_INSTALL_PREFIX "$ENV{HOME}/.scribe")
endif()
set(CMAKE_PREFIX_PATH "${CMAKE_INSTALL_PREFIX};${CMAKE_BINARY_DIR}")
add_definitions(-DINSTALL_PREFIX=${CMAKE_INSTALL_PREFIX})
message("-- Using PREFIX = ${CMAKE_INSTALL_PREFIX}")
# add cmake_modules path
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake_modules")
set(COMPILER_VERSION_MAJOR 0)
set(COMPILER_VERSION_MINOR 0)
set(COMPILER_VERSION_PATCH 1)
execute_process(COMMAND date "+%a %b %d, %Y at %H:%M:%S" OUTPUT_VARIABLE BUILD_DATE OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND git config --get remote.origin.url OUTPUT_VARIABLE REPO_URL OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND git log --format=%H -n 1 OUTPUT_VARIABLE COMMIT_ID OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND git diff --quiet RESULT_VARIABLE ret)
if(ret EQUAL 0)
set(TREE_STATUS "Clean")
else()
set(TREE_STATUS "Dirty")
endif()
set(ORIGIN "$ORIGIN")
if(APPLE)
set(ORIGIN "@loader_path")
endif()
set(CMAKE_INSTALL_RPATH "${ORIGIN}/../lib/scribe;${ORIGIN}/.")
set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR TRUE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_MACOSX_RPATH TRUE)
include(CheckCXXCompilerFlag)
# For libGMP on macOS and BSD
if(APPLE OR ${CMAKE_SYSTEM_NAME} MATCHES ".*BSD.*")
include_directories(/usr/local/include)
endif()
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
if(CMAKE_USE_PTHREADS_INIT)
message("-- Using thread flags: -pthread")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread")
else()
message("-- Using thread flags: ${CMAKE_THREAD_LIBS_INIT}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_THREAD_LIBS_INIT}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_THREAD_LIBS_INIT}")
endif()
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
message("-- Using ccache")
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES ".*BSD.*")
add_definitions(-D_WITH_GETLINE)
endif()
# Generally, disabled for CI purposes
# Also needed when running valgrind as valgrind does not support instruction bytes for Vector<bool>
if(NOT DEFINED ENV{DISABLE_MARCH_NATIVE} OR "$ENV{DISABLE_MARCH_NATIVE}" STREQUAL "")
check_cxx_compiler_flag(-march=native COMPILER_SUPPORTS_MARCH_NATIVE)
if(COMPILER_SUPPORTS_MARCH_NATIVE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
endif()
endif()
# Force DWARF4 as valgrind does not support anything newer (clang-14 defaults to DWARF5).
if(NOT CMAKE_BUILD_TYPE STREQUAL "Release")
check_cxx_compiler_flag(-gdwarf-4 COMPILER_SUPPORTS_GDWARF4)
if(COMPILER_SUPPORTS_GDWARF4)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -gdwarf-4")
endif()
endif()
# Because Android has issues with dlopen()'s RTLD_GLOBAL; See:
# https://android.googlesource.com/platform/bionic/+/master/android-changes-for-ndk-developers.md#changes-to-library-search-order
# https://android.googlesource.com/platform/bionic/+/30b17e32f0b403a97cef7c4d1fcab471fa316340/linker/linker_namespaces.cpp#100
# https://android-ndk.narkive.com/iNWj05IV/weak-symbol-linking-when-loading-dynamic-libraries
set(EXTRA_LD_FLAGS "")
if(ANDROID)
set(EXTRA_LD_FLAGS "-z global")
endif()
if(CMAKE_COMPILER_IS_GNUCXX AND DEFINED WITH_COVERAGE)
set(WITH_COVERAGE "-D_WITH_COVERAGE")
include(CodeCoverage)
APPEND_COVERAGE_COMPILER_FLAGS()
setup_target_for_coverage_gcovr_html(NAME scribe_cov EXECUTABLE ${PROJECT_SOURCE_DIR}/codecov.sh ${PROJECT_SOURCE_DIR})
endif()
# Finally! The sources!!!!!
# Set Config.hpp.in template
configure_file("${PROJECT_SOURCE_DIR}/include/Config.hpp.in" "${PROJECT_SOURCE_DIR}/include/Config.hpp" @ONLY)
# Install CMake modules
# install(DIRECTORY "${CMAKE_SOURCE_DIR}/cmake_modules/"
# DESTINATION "${CMAKE_INSTALL_PREFIX}/cmake_modules"
# )
# Install C++ Includes
# install(DIRECTORY "${CMAKE_SOURCE_DIR}/include/"
# DESTINATION "${CMAKE_INSTALL_PREFIX}/include/scribe/compiler"
# FILES_MATCHING PATTERN "*.hpp"
# )
# Install Scribe Includes
install(DIRECTORY "${CMAKE_SOURCE_DIR}/headers/"
DESTINATION "${CMAKE_INSTALL_PREFIX}/include/scribe"
FILES_MATCHING PATTERN "*.sc"
)
# Scribe Compiler
file(GLOB_RECURSE INCS RELATIVE "${PROJECT_SOURCE_DIR}" "include/*.hpp")
file(GLOB_RECURSE SRCS RELATIVE "${PROJECT_SOURCE_DIR}" "src/*.cpp")
list(REMOVE_ITEM SRCS "src/Main.cpp")
add_executable(scribe "${PROJECT_SOURCE_DIR}/src/Main.cpp" ${SRCS} ${INCS})
target_include_directories(scribe PRIVATE ${PROJECT_SOURCE_DIR}/include)
# Link against LLVM libraries
# target_link_libraries(scribe ${llvm_libs})
set_target_properties(scribe
PROPERTIES
OUTPUT_NAME scribe
LINK_FLAGS "${EXTRA_LD_FLAGS}"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
INSTALL_RPATH_USE_LINK_PATH TRUE
)
install(TARGETS scribe
RUNTIME
DESTINATION bin
COMPONENT Binaries
)