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