git subrepo pull --force deps/lightrec
[pcsx_rearmed.git] / deps / lightrec / CMakeLists.txt
1 cmake_minimum_required(VERSION 3.5)
2 project(lightrec LANGUAGES C VERSION 0.8)
3
4 set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries")
5 if (NOT BUILD_SHARED_LIBS)
6         add_definitions(-DLIGHTREC_STATIC)
7 endif (NOT BUILD_SHARED_LIBS)
8
9 if (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)
12 endif()
13
14 if (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)
19 endif()
20
21 string(TOUPPER ${LOG_LEVEL} LIGHTREC_LOG_LEVEL)
22 add_definitions(-DLOG_LEVEL=${LIGHTREC_LOG_LEVEL}_L)
23
24 if (CMAKE_COMPILER_IS_GNUCC)
25         add_compile_options(-fvisibility=hidden)
26 endif()
27
28 set(HAS_DEFAULT_ELM ${CMAKE_COMPILER_IS_GNUCC})
29
30 list(APPEND LIGHTREC_SOURCES
31         blockcache.c
32         constprop.c
33         emitter.c
34         interpreter.c
35         lightrec.c
36         memmanager.c
37         optimizer.c
38         regcache.c
39 )
40 list(APPEND LIGHTREC_HEADERS
41         blockcache.h
42         constprop.h
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
55 option(ENABLE_FIRST_PASS "Run the interpreter as first-pass optimization" ON)
56
57 option(ENABLE_THREADED_COMPILER "Enable threaded compiler" ON)
58 if (ENABLE_THREADED_COMPILER)
59         list(APPEND LIGHTREC_SOURCES recompiler.c reaper.c)
60
61         if (NOT ENABLE_FIRST_PASS)
62                 message(SEND_ERROR "Threaded compiler requires first-pass optimization")
63         endif (NOT ENABLE_FIRST_PASS)
64 endif (ENABLE_THREADED_COMPILER)
65
66 option(OPT_REMOVE_DIV_BY_ZERO_SEQ "(optimization) Remove div-by-zero check sequence" ON)
67 option(OPT_REPLACE_MEMSET "(optimization) Detect and replace memset with host variant" ON)
68 option(OPT_DETECT_IMPOSSIBLE_BRANCHES "(optimization) Detect impossible branches" ON)
69 option(OPT_HANDLE_LOAD_DELAYS "(optimization) Detect load delays" ON)
70 option(OPT_TRANSFORM_OPS "(optimization) Transform opcodes" ON)
71 option(OPT_LOCAL_BRANCHES "(optimization) Detect local branches" ON)
72 option(OPT_SWITCH_DELAY_SLOTS "(optimization) Switch delay slots" ON)
73 option(OPT_FLAG_IO "(optimization) Flag I/O opcodes when the target can be detected" ON)
74 option(OPT_FLAG_MULT_DIV "(optimization) Flag MULT/DIV that only use one of HI/LO" ON)
75 option(OPT_EARLY_UNLOAD "(optimization) Unload registers early" ON)
76 option(OPT_PRELOAD_PC "(optimization) Preload PC value into register" ON)
77
78 include_directories(${CMAKE_CURRENT_BINARY_DIR})
79
80 add_library(${PROJECT_NAME} ${LIGHTREC_SOURCES} ${LIGHTREC_HEADERS})
81 set_target_properties(${PROJECT_NAME} PROPERTIES
82         VERSION ${PROJECT_VERSION}
83         SOVERSION ${PROJECT_VERSION_MAJOR}
84         PUBLIC_HEADER lightrec.h
85         C_STANDARD 11
86         C_STANDARD_REQUIRED ON
87         C_EXTENSIONS OFF
88 )
89
90 if (CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
91         target_compile_options(${PROJECT_NAME} PRIVATE -Wall)
92 endif()
93 if (CMAKE_C_COMPILER_ID STREQUAL "Clang")
94         target_compile_options(${PROJECT_NAME} PRIVATE -Wno-initializer-overrides)
95 endif()
96
97 if (ENABLE_THREADED_COMPILER)
98         find_library(PTHREAD_LIBRARIES pthread REQUIRED)
99         find_path(PTHREAD_INCLUDE_DIR pthread.h REQUIRED)
100
101         include_directories(${PTHREAD_INCLUDE_DIR})
102         target_link_libraries(${PROJECT_NAME} PRIVATE ${PTHREAD_LIBRARIES})
103 endif (ENABLE_THREADED_COMPILER)
104
105 option(ENABLE_CODE_BUFFER "Enable external code buffer" ON)
106 if (ENABLE_CODE_BUFFER)
107         target_sources(${PROJECT_NAME} PRIVATE tlsf/tlsf.c)
108         target_include_directories(${PROJECT_NAME} PRIVATE tlsf)
109 endif (ENABLE_CODE_BUFFER)
110
111 find_library(LIBLIGHTNING lightning REQUIRED)
112 find_path(LIBLIGHTNING_INCLUDE_DIR lightning.h REQUIRED)
113
114 include_directories(${LIBLIGHTNING_INCLUDE_DIR})
115 target_link_libraries(${PROJECT_NAME} PRIVATE ${LIBLIGHTNING})
116
117 if (LOG_LEVEL STREQUAL Debug)
118         set(ENABLE_DISASSEMBLER ON)
119         target_sources(${PROJECT_NAME} PRIVATE disassembler.c)
120 endif()
121
122 configure_file(lightrec-config.h.cmakein lightrec-config.h @ONLY)
123
124 include(GNUInstallDirs)
125 install(TARGETS ${PROJECT_NAME}
126         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
127         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
128         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
129         PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
130 )