-
Notifications
You must be signed in to change notification settings - Fork 16
/
CMakeLists.txt
85 lines (70 loc) · 2.19 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
cmake_minimum_required(VERSION 3.15)
project(nyxstone VERSION 0.1.0)
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
message(FATAL_ERROR "In-tree builds are not supported. Run CMake from a separate directory: cmake -B build")
endif()
set(PROJECT_IS_TOP_LEVEL OFF)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(PROJECT_IS_TOP_LEVEL ON)
# Enable folder support
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
endif()
option(NYXSTONE_BUILD_EXAMPLES "Build nyxstone examples" ${PROJECT_IS_TOP_LEVEL})
option(NYXSTONE_SANITIZERS "Enable sanitizers" OFF)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
if(DEFINED ENV{NYXSTONE_LLVM_PREFIX})
# Ignore LLVM_ROOT variables
set(CMAKE_FIND_USE_PACKAGE_ROOT_PATH OFF)
set(CMAKE_PREFIX_PATH $ENV{NYXSTONE_LLVM_PREFIX})
endif()
find_package(LLVM-Wrapper COMPONENTS
core
mc
AllTargetsCodeGens
AllTargetsAsmParsers
AllTargetsDescs
AllTargetsDisassemblers
AllTargetsInfos
AllTargetsMCAs
)
file(GLOB_RECURSE nyxstone_SOURCES
"src/*.cpp"
"src/*.h"
"include/*.h"
"include/*.hpp"
)
if(NYXSTONE_SANITIZERS)
add_compile_options(-fsanitize=address,undefined)
add_link_options(-fsanitize=address,undefined)
endif()
add_library(nyxstone ${nyxstone_SOURCES})
add_library(nyxstone::nyxstone ALIAS nyxstone)
target_compile_features(nyxstone PUBLIC
cxx_std_17
)
target_include_directories(nyxstone PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/vendor>
)
target_link_libraries(nyxstone PUBLIC
LLVM-Wrapper
)
set_target_properties(nyxstone PROPERTIES
COMPILE_PDB_NAME nyxstone-lib.pdb
)
if(NYXSTONE_BUILD_EXAMPLES)
add_executable(nyxstone-bin examples/nyxstone-cli.cpp)
set_target_properties(nyxstone-bin PROPERTIES
OUTPUT_NAME nyxstone
)
target_link_libraries(nyxstone-bin PRIVATE
nyxstone::nyxstone
)
add_executable(example examples/example.cpp)
target_link_libraries(example PRIVATE
nyxstone::nyxstone
)
include(CTest)
add_test(NAME TestExample COMMAND $<TARGET_FILE:example>)
add_test(NAME TestCLI COMMAND "${CMAKE_CURRENT_LIST_DIR}/tool/test-cli.sh")
endif()