-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
148 lines (134 loc) · 5.16 KB
/
CMakeLists.txt
File metadata and controls
148 lines (134 loc) · 5.16 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
cmake_minimum_required(VERSION 3.14)
project(xtensa-emulator C)
set(CMAKE_C_STANDARD 17)
# Default to Release build (enables -O3)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
endif()
# Profile-guided optimization (PGO)
# Usage:
# 1. cmake -B build-pgo -DPGO=generate && cmake --build build-pgo
# 2. ./build-pgo/xtensa-emu -q -c 100000000 -s firmware.elf firmware.bin
# 3. cmake -B build-pgo -DPGO=use && cmake --build build-pgo
option(PGO "PGO mode: 'generate' to collect profiles, 'use' to apply them" "")
set(PREDECODE_FLASH_MB "4" CACHE STRING "Pre-decode table flash coverage in MB (0=disabled, 2/4/8/16)")
# LTO and native tuning for Release builds (GCC/Clang only)
if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
include(CheckIPOSupported)
check_ipo_supported(RESULT IPO_SUPPORTED)
if(IPO_SUPPORTED AND NOT PGO)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
if(NOT MSVC)
add_compile_options(-march=native)
endif()
endif()
if(PGO STREQUAL "generate")
message(STATUS "PGO: generating profile data")
add_compile_options(-fprofile-generate)
add_link_options(-fprofile-generate)
set(PGO_NOWARN "-Wno-error")
# Disable LTO during profile generation (conflicts with PGO on some GCC versions)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE)
elseif(PGO STREQUAL "use")
message(STATUS "PGO: using profile data for optimization")
add_compile_options(-fprofile-use -fprofile-correction)
add_link_options(-fprofile-use)
set(PGO_NOWARN "-Wno-error")
# Re-enable LTO for PGO use builds
include(CheckIPOSupported)
check_ipo_supported(RESULT IPO_SUPPORTED)
if(IPO_SUPPORTED)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
endif()
# Library (core emulator)
set(LIB_SOURCES
src/xtensa.c
src/xtensa_disasm.c
src/memory.c
src/loader.c
src/peripherals.c
src/rom_stubs.c
src/elf_symbols.c
src/freertos_stubs.c
src/esp_timer_stubs.c
src/display_stubs.c
src/touch_stubs.c
src/sdcard_stubs.c
src/wifi_stubs.c
src/bt_stubs.c
src/sha_stubs.c
src/aes_stubs.c
src/mpi_stubs.c
src/flexe_session.c
src/savestate.c
src/hierarchical_trace.c
)
# JIT compiler: x86-64 only, non-MSVC
if(NOT MSVC AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64")
list(APPEND LIB_SOURCES src/jit.c)
message(STATUS "JIT compiler enabled (x86-64)")
else()
message(STATUS "JIT compiler disabled (requires x86-64, non-MSVC)")
endif()
if(MSVC)
list(APPEND LIB_SOURCES src/msvc_compat.c)
endif()
add_library(xtensa-emu-lib STATIC ${LIB_SOURCES})
target_include_directories(xtensa-emu-lib PUBLIC src/)
find_package(OpenSSL REQUIRED)
find_package(Threads REQUIRED)
if(MSVC)
find_package(ZLIB REQUIRED)
target_link_libraries(xtensa-emu-lib PUBLIC
OpenSSL::SSL OpenSSL::Crypto ZLIB::ZLIB Threads::Threads)
target_compile_options(xtensa-emu-lib PRIVATE /W4 /wd4100 /wd4244 /wd4267 /MP)
target_compile_definitions(xtensa-emu-lib PRIVATE _CRT_SECURE_NO_WARNINGS)
target_compile_definitions(xtensa-emu-lib PUBLIC PREDECODE_FLASH_MB=${PREDECODE_FLASH_MB})
else()
target_link_libraries(xtensa-emu-lib PUBLIC
m z Threads::Threads OpenSSL::SSL OpenSSL::Crypto)
target_compile_options(xtensa-emu-lib PRIVATE
-Wall -Wextra -Werror -Wno-unused-parameter ${PGO_NOWARN})
target_compile_definitions(xtensa-emu-lib PUBLIC
PREDECODE_FLASH_MB=${PREDECODE_FLASH_MB})
# Disable stack protector on hot-path files (saves ~3-4% from canary checks)
set_source_files_properties(src/xtensa.c src/memory.c src/jit.c
PROPERTIES COMPILE_OPTIONS "-fno-stack-protector")
endif()
# Main executable
add_executable(xtensa-emu src/main.c)
target_link_libraries(xtensa-emu PRIVATE xtensa-emu-lib)
if(MSVC)
target_compile_options(xtensa-emu PRIVATE /W4 /wd4100 /wd4244 /wd4267)
target_compile_definitions(xtensa-emu PRIVATE _CRT_SECURE_NO_WARNINGS)
else()
target_compile_options(xtensa-emu PRIVATE -Wall -Wextra -Werror -Wno-unused-parameter ${PGO_NOWARN})
endif()
# Test runner
add_executable(xtensa-tests tests/test_main.c)
target_link_libraries(xtensa-tests PRIVATE xtensa-emu-lib)
if(MSVC)
target_compile_options(xtensa-tests PRIVATE /W4 /wd4100 /wd4244 /wd4267)
target_compile_definitions(xtensa-tests PRIVATE _CRT_SECURE_NO_WARNINGS)
else()
target_compile_options(xtensa-tests PRIVATE -Wall -Wextra -Werror -Wno-unused-parameter ${PGO_NOWARN})
endif()
# Disassembler tool
add_executable(xt-dis tools/xt-dis.c)
target_link_libraries(xt-dis PRIVATE xtensa-emu-lib)
if(MSVC)
target_compile_options(xt-dis PRIVATE /W4 /wd4100)
target_compile_definitions(xt-dis PRIVATE _CRT_SECURE_NO_WARNINGS)
else()
target_compile_options(xt-dis PRIVATE -Wall -Wextra -Werror -Wno-unused-parameter ${PGO_NOWARN})
endif()
# Trace filter tool
add_executable(trace-filter tools/trace-filter.c)
if(MSVC)
target_compile_options(trace-filter PRIVATE /W4 /wd4100)
target_compile_definitions(trace-filter PRIVATE _CRT_SECURE_NO_WARNINGS)
else()
target_compile_options(trace-filter PRIVATE -Wall -Wextra -Werror -Wno-unused-parameter ${PGO_NOWARN})
endif()