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.5)
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         emitter.c
33         interpreter.c
34         lightrec.c
35         memmanager.c
36         optimizer.c
37         regcache.c
38 )
39 list(APPEND LIGHTREC_HEADERS
40         blockcache.h
41         debug.h
42         disassembler.h
43         emitter.h
44         interpreter.h
45         lightrec-private.h
46         lightrec.h
47         memmanager.h
48         optimizer.h
49         recompiler.h
50         regcache.h
51 )
52
53 option(ENABLE_FIRST_PASS "Run the interpreter as first-pass optimization" ON)
54
55 option(ENABLE_THREADED_COMPILER "Enable threaded compiler" ON)
56 if (ENABLE_THREADED_COMPILER)
57         list(APPEND LIGHTREC_SOURCES recompiler.c reaper.c)
58
59         if (NOT ENABLE_FIRST_PASS)
60                 message(SEND_ERROR "Threaded compiler requires first-pass optimization")
61         endif (NOT ENABLE_FIRST_PASS)
62 endif (ENABLE_THREADED_COMPILER)
63
64 option(OPT_REMOVE_DIV_BY_ZERO_SEQ "(optimization) Remove div-by-zero check sequence" ON)
65 option(OPT_REPLACE_MEMSET "(optimization) Detect and replace memset with host variant" ON)
66 option(OPT_DETECT_IMPOSSIBLE_BRANCHES "(optimization) Detect impossible branches" ON)
67 option(OPT_TRANSFORM_OPS "(optimization) Transform opcodes" ON)
68 option(OPT_LOCAL_BRANCHES "(optimization) Detect local branches" ON)
69 option(OPT_SWITCH_DELAY_SLOTS "(optimization) Switch delay slots" ON)
70 option(OPT_FLAG_STORES "(optimization) Flag stores that don't require invalidation" ON)
71 option(OPT_FLAG_IO "(optimization) Flag I/O opcodes whose target is known" ON)
72 option(OPT_FLAG_MULT_DIV "(optimization) Flag MULT/DIV that only use one of HI/LO" ON)
73 option(OPT_EARLY_UNLOAD "(optimization) Unload registers early" ON)
74
75 include_directories(${CMAKE_CURRENT_BINARY_DIR})
76
77 add_library(${PROJECT_NAME} ${LIGHTREC_SOURCES} ${LIGHTREC_HEADERS})
78 set_target_properties(${PROJECT_NAME} PROPERTIES
79         VERSION ${PROJECT_VERSION}
80         SOVERSION ${PROJECT_VERSION_MAJOR}
81         PUBLIC_HEADER lightrec.h
82         C_STANDARD 11
83         C_STANDARD_REQUIRED ON
84         C_EXTENSIONS OFF
85 )
86
87 if (CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
88         target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wno-parentheses)
89 endif()
90 if (CMAKE_C_COMPILER_ID STREQUAL "Clang")
91         target_compile_options(${PROJECT_NAME} PRIVATE -Wno-initializer-overrides)
92 endif()
93
94 option(ENABLE_TINYMM "Enable optional libtinymm dependency" OFF)
95 if (ENABLE_TINYMM)
96         find_library(TINYMM_LIBRARIES tinymm REQUIRED)
97         find_path(TINYMM_INCLUDE_DIR tinymm.h REQUIRED)
98
99         include_directories(${TINYMM_INCLUDE_DIR})
100         target_link_libraries(${PROJECT_NAME} PRIVATE ${TINYMM_LIBRARIES})
101 endif (ENABLE_TINYMM)
102
103 if (ENABLE_THREADED_COMPILER)
104         find_library(PTHREAD_LIBRARIES pthread REQUIRED)
105         find_path(PTHREAD_INCLUDE_DIR pthread.h REQUIRED)
106
107         include_directories(${PTHREAD_INCLUDE_DIR})
108         target_link_libraries(${PROJECT_NAME} PRIVATE ${PTHREAD_LIBRARIES})
109 endif (ENABLE_THREADED_COMPILER)
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 )