-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
114 lines (109 loc) · 3.42 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
cmake_minimum_required(VERSION 3.14)
project(lc32sim VERSION 0.1
LANGUAGES CXX)
# SDL2 is required for the display
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})
# Boost is used for config file parsing and general utilities
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.78.0 REQUIRED COMPONENTS )
include_directories(${Boost_INCLUDE_DIRS})
# Argparse is used for command line argument parsing
# This might be installed globally, in the case of a flake build. Therefore, add
# an option for that, which is off by default.
option(LC32SIM_SYSTEM_ARGPARSE "Use the version of `argparse` installed on the system" OFF)
if(NOT LC32SIM_SYSTEM_ARGPARSE)
# We have to use a custom setup for FetchContent_MakeAvailable because we
# don't want to install these dependencies.
# See: https://cmake.org/cmake/help/v3.19/module/FetchContent.html
include(FetchContent)
FetchContent_Declare(
argparse
GIT_REPOSITORY https://github.com/p-ranav/argparse.git
GIT_TAG 997da9255618311d1fcb0135ce86022729d1f1cb
)
FetchContent_GetProperties(argparse)
if(NOT argparse_POPULATED)
FetchContent_Populate(argparse)
add_subdirectory(${argparse_SOURCE_DIR} ${argparse_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
else()
find_package(argparse 2.9.0 REQUIRED)
endif()
# Need to populate variables for argparse
# Include directories are handled automatically, either by linking with the
# library or because they are found by the compiler. We only need to link with
# the target if we're using our own.
if(NOT LC32SIM_SYSTEM_ARGPARSE)
set(argparse_LIBRARIES "argparse")
endif()
set(SOURCES
src/config.cpp
src/display.cpp
src/elf_file.cpp
src/filesystem.cpp
src/instruction.cpp
src/log.cpp
src/main.cpp
src/memory.cpp
src/sim.cpp
)
# Set for all configurations
set(FLAGS
-Wextra
-Wall
-Wno-deprecated
-Wno-unknown-warning-option
-Wno-self-assign
-Wno-unused-parameter
-Wno-unused-but-set-variable
-Wold-style-cast
-Waddress-of-packed-member
)
# Set for release and release with debug info configurations
set(RELEASE_FLAGS
-Ofast
-fassociative-math
-freciprocal-math
-fno-signed-zeros
-fno-trapping-math
-flto=auto
-fuse-linker-plugin
-funroll-loops
-ffp-contract=fast
-fno-keep-static-consts
-fmerge-all-constants
-fmodulo-sched
-fmodulo-sched-allow-regmoves
-fgcse-sm
-fgcse-las
-fsched-spec-load
-fsched-spec-load-dangerous
-fsched2-use-superblocks
-fipa-pta
-ftree-loop-im
-ftree-loop-ivcanon
-fivopts
-fweb
-ftracer
-DNDEBUG
)
# Set for debug and release with debug info configurations
set(DBGINFO_FLAGS
-ggdb3
)
# Set for debug configuration only
set(DEBUG_FLAGS
-Og
)
add_executable(lc32sim ${SOURCES})
target_compile_features(lc32sim PRIVATE cxx_std_23)
target_compile_options(lc32sim PRIVATE "${FLAGS}")
target_compile_options(lc32sim PRIVATE "$<$<CONFIG:DEBUG>:${DBGINFO_FLAGS}>")
target_compile_options(lc32sim PRIVATE "$<$<CONFIG:RELEASE>:${RELEASE_FLAGS}>")
target_compile_options(lc32sim PRIVATE "$<$<CONFIG:RELEASE_DBGINFO>:${RELEASE_FLAGS}>")
target_compile_options(lc32sim PRIVATE "$<$<CONFIG:RELEASE_DBGINFO>:${DBGINFO_FLAGS}>")
target_link_libraries(lc32sim PRIVATE ${SDL2_LIBRARIES} ${Boost_LIBRARIES} ${argparse_LIBRARIES})
install(TARGETS lc32sim)