git subrepo pull --force deps/lightrec
[pcsx_rearmed.git] / deps / lightrec / CMakeLists.txt
1 cmake_minimum_required(VERSION 3.0)
2 project(lightrec LANGUAGES C VERSION 0.7)
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" OFF)
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
77 include_directories(${CMAKE_CURRENT_BINARY_DIR})
78
79 add_library(${PROJECT_NAME} ${LIGHTREC_SOURCES} ${LIGHTREC_HEADERS})
80 set_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
89 if (CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
90         target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wno-parentheses)
91 endif()
92 if (CMAKE_C_COMPILER_ID STREQUAL "Clang")
93         target_compile_options(${PROJECT_NAME} PRIVATE -Wno-initializer-overrides)
94 endif()
95
96 if (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})
102 endif (ENABLE_THREADED_COMPILER)
103
104 option(ENABLE_CODE_BUFFER "Enable external code buffer" ON)
105 if (ENABLE_CODE_BUFFER)
106         target_sources(${PROJECT_NAME} PRIVATE tlsf/tlsf.c)
107         target_include_directories(${PROJECT_NAME} PRIVATE tlsf)
108 endif (ENABLE_CODE_BUFFER)
109
110 find_library(LIBLIGHTNING lightning REQUIRED)
111 find_path(LIBLIGHTNING_INCLUDE_DIR lightning.h REQUIRED)
112
113 include_directories(${LIBLIGHTNING_INCLUDE_DIR})
114 target_link_libraries(${PROJECT_NAME} PRIVATE ${LIBLIGHTNING})
115
116 if (LOG_LEVEL STREQUAL Debug)
117         set(ENABLE_DISASSEMBLER ON)
118         target_sources(${PROJECT_NAME} PRIVATE disassembler.c)
119 endif()
120
121 configure_file(lightrec-config.h.cmakein lightrec-config.h @ONLY)
122
123 include(GNUInstallDirs)
124 install(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 )