dev-release: try to make it work
[pcsx_rearmed.git] / deps / lightrec / CMakeLists.txt
CommitLineData
2476185f 1cmake_minimum_required(VERSION 3.10)
878e6cda 2project(lightrec LANGUAGES C VERSION 0.9)
98fa08a5 3
d16005f8
PC
4list(APPEND LIGHTREC_SOURCES
5 blockcache.c
9259d748 6 constprop.c
d16005f8
PC
7 emitter.c
8 interpreter.c
9 lightrec.c
10 memmanager.c
11 optimizer.c
12 regcache.c
13)
14list(APPEND LIGHTREC_HEADERS
15 blockcache.h
9259d748 16 constprop.h
d16005f8
PC
17 debug.h
18 disassembler.h
19 emitter.h
20 interpreter.h
21 lightrec-private.h
22 lightrec.h
23 memmanager.h
24 optimizer.h
25 recompiler.h
26 regcache.h
27)
28
878e6cda
PC
29add_library(lightrec ${LIGHTREC_SOURCES} ${LIGHTREC_HEADERS})
30set_target_properties(lightrec PROPERTIES
31 VERSION ${PROJECT_VERSION}
32 SOVERSION ${PROJECT_VERSION_MAJOR}
33 PUBLIC_HEADER lightrec.h
34 C_STANDARD 11
35 C_STANDARD_REQUIRED ON
36 C_EXTENSIONS OFF
37)
38
39set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries")
40if (NOT BUILD_SHARED_LIBS)
41 target_compile_definitions(lightrec PRIVATE LIGHTREC_STATIC)
42endif (NOT BUILD_SHARED_LIBS)
43
44if (NOT LOG_LEVEL)
45 set(LOG_LEVEL Info CACHE STRING "Log level" FORCE)
46 set_property(CACHE LOG_LEVEL PROPERTY STRINGS NoLog Error Warning Info Debug)
47endif()
48
49if (NOT CMAKE_BUILD_TYPE)
50 set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
51 "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel."
52 FORCE)
53 set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS None Debug Release RelWithDebInfo MinSizeRel)
54endif()
55
56string(TOUPPER ${LOG_LEVEL} LIGHTREC_LOG_LEVEL)
57target_compile_definitions(lightrec PRIVATE LOG_LEVEL=${LIGHTREC_LOG_LEVEL}_L)
58
59if (CMAKE_COMPILER_IS_GNUCC)
60 target_compile_options(lightrec PRIVATE -fvisibility=hidden)
61endif()
62
63set(HAS_DEFAULT_ELM ${CMAKE_COMPILER_IS_GNUCC})
64
d16005f8
PC
65option(ENABLE_FIRST_PASS "Run the interpreter as first-pass optimization" ON)
66
a5a6f7b8 67option(ENABLE_THREADED_COMPILER "Enable threaded compiler" ON)
d16005f8 68if (ENABLE_THREADED_COMPILER)
878e6cda 69 target_sources(lightrec PRIVATE recompiler.c reaper.c)
d16005f8
PC
70
71 if (NOT ENABLE_FIRST_PASS)
72 message(SEND_ERROR "Threaded compiler requires first-pass optimization")
73 endif (NOT ENABLE_FIRST_PASS)
74endif (ENABLE_THREADED_COMPILER)
75
98fa08a5
PC
76option(OPT_REMOVE_DIV_BY_ZERO_SEQ "(optimization) Remove div-by-zero check sequence" ON)
77option(OPT_REPLACE_MEMSET "(optimization) Detect and replace memset with host variant" ON)
78option(OPT_DETECT_IMPOSSIBLE_BRANCHES "(optimization) Detect impossible branches" ON)
cb72ea13 79option(OPT_HANDLE_LOAD_DELAYS "(optimization) Detect load delays" ON)
98fa08a5
PC
80option(OPT_TRANSFORM_OPS "(optimization) Transform opcodes" ON)
81option(OPT_LOCAL_BRANCHES "(optimization) Detect local branches" ON)
82option(OPT_SWITCH_DELAY_SLOTS "(optimization) Switch delay slots" ON)
cb72ea13 83option(OPT_FLAG_IO "(optimization) Flag I/O opcodes when the target can be detected" ON)
98fa08a5
PC
84option(OPT_FLAG_MULT_DIV "(optimization) Flag MULT/DIV that only use one of HI/LO" ON)
85option(OPT_EARLY_UNLOAD "(optimization) Unload registers early" ON)
684432ad 86option(OPT_PRELOAD_PC "(optimization) Preload PC value into register" ON)
98fa08a5 87
5eecf06d
PC
88if (CMAKE_SYSTEM_PROCESSOR MATCHES "SH4|sh4")
89 option(OPT_SH4_USE_GBR "(SH4 optimization) Use GBR register for the state pointer" OFF)
90endif()
91
878e6cda 92target_include_directories(lightrec PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
d16005f8 93
98fa08a5 94if (CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
878e6cda 95 target_compile_options(lightrec PRIVATE -Wall)
98fa08a5
PC
96endif()
97if (CMAKE_C_COMPILER_ID STREQUAL "Clang")
878e6cda 98 target_compile_options(lightrec PRIVATE -Wno-initializer-overrides)
98fa08a5
PC
99endif()
100
d16005f8 101if (ENABLE_THREADED_COMPILER)
878e6cda
PC
102 include(FindThreads)
103
104 if (NOT CMAKE_USE_PTHREADS_INIT)
105 message(SEND_ERROR "Could not find compatible threads library")
106 endif()
d16005f8 107
878e6cda 108 target_link_libraries(lightrec PUBLIC Threads::Threads)
d16005f8
PC
109endif (ENABLE_THREADED_COMPILER)
110
9259d748 111option(ENABLE_CODE_BUFFER "Enable external code buffer" ON)
02487de7 112if (ENABLE_CODE_BUFFER)
878e6cda
PC
113 target_sources(lightrec PRIVATE tlsf/tlsf.c)
114 target_include_directories(lightrec PRIVATE tlsf)
02487de7
PC
115endif (ENABLE_CODE_BUFFER)
116
d16005f8
PC
117find_library(LIBLIGHTNING lightning REQUIRED)
118find_path(LIBLIGHTNING_INCLUDE_DIR lightning.h REQUIRED)
119
878e6cda
PC
120target_include_directories(lightrec PUBLIC ${LIBLIGHTNING_INCLUDE_DIR})
121target_link_libraries(lightrec PUBLIC ${LIBLIGHTNING})
d16005f8
PC
122
123if (LOG_LEVEL STREQUAL Debug)
d16005f8 124 set(ENABLE_DISASSEMBLER ON)
878e6cda 125 target_sources(lightrec PRIVATE disassembler.c)
d16005f8
PC
126endif()
127
98fa08a5 128configure_file(lightrec-config.h.cmakein lightrec-config.h @ONLY)
d16005f8
PC
129
130include(GNUInstallDirs)
878e6cda 131install(TARGETS lightrec
d16005f8
PC
132 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
133 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
134 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
135 PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
136)