Minimize logs when loading a cheevos-compatible content
[pcsx_rearmed.git] / deps / lightrec / CMakeLists.txt
CommitLineData
d16005f8
PC
1cmake_minimum_required(VERSION 3.0)
2project(lightrec LANGUAGES C VERSION 0.3)
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
28list(APPEND LIGHTREC_SOURCES
29 blockcache.c
30 disassembler.c
31 emitter.c
32 interpreter.c
33 lightrec.c
34 memmanager.c
35 optimizer.c
36 regcache.c
37)
38list(APPEND LIGHTREC_HEADERS
39 blockcache.h
40 debug.h
41 disassembler.h
42 emitter.h
43 interpreter.h
44 lightrec-private.h
45 lightrec.h
46 memmanager.h
47 optimizer.h
48 recompiler.h
49 regcache.h
50)
51
52option(ENABLE_FIRST_PASS "Run the interpreter as first-pass optimization" ON)
53
54option(ENABLE_THREADED_COMPILER "Enable threaded compiler" ON)
55if (ENABLE_THREADED_COMPILER)
56 list(APPEND LIGHTREC_SOURCES recompiler.c)
57
58 if (NOT ENABLE_FIRST_PASS)
59 message(SEND_ERROR "Threaded compiler requires first-pass optimization")
60 endif (NOT ENABLE_FIRST_PASS)
61endif (ENABLE_THREADED_COMPILER)
62
63include_directories(${CMAKE_CURRENT_BINARY_DIR})
64
65add_library(${PROJECT_NAME} ${LIGHTREC_SOURCES} ${LIGHTREC_HEADERS})
66set_target_properties(${PROJECT_NAME} PROPERTIES
67 VERSION ${PROJECT_VERSION}
68 SOVERSION ${PROJECT_VERSION_MAJOR}
69 PUBLIC_HEADER lightrec.h
70 C_STANDARD 11
71 C_STANDARD_REQUIRED ON
72 C_EXTENSIONS OFF
73)
74
75option(ENABLE_TINYMM "Enable optional libtinymm dependency" OFF)
76if (ENABLE_TINYMM)
77 find_library(TINYMM_LIBRARIES tinymm REQUIRED)
78 find_path(TINYMM_INCLUDE_DIR tinymm.h REQUIRED)
79
80 include_directories(${TINYMM_INCLUDE_DIR})
81 target_link_libraries(${PROJECT_NAME} PRIVATE ${TINYMM_LIBRARIES})
82endif (ENABLE_TINYMM)
83
84if (ENABLE_THREADED_COMPILER)
85 find_library(PTHREAD_LIBRARIES pthread REQUIRED)
86 find_path(PTHREAD_INCLUDE_DIR pthread.h REQUIRED)
87
88 include_directories(${PTHREAD_INCLUDE_DIR})
89 target_link_libraries(${PROJECT_NAME} PRIVATE ${PTHREAD_LIBRARIES})
90endif (ENABLE_THREADED_COMPILER)
91
92find_library(LIBLIGHTNING lightning REQUIRED)
93find_path(LIBLIGHTNING_INCLUDE_DIR lightning.h REQUIRED)
94
95include_directories(${LIBLIGHTNING_INCLUDE_DIR})
96target_link_libraries(${PROJECT_NAME} PRIVATE ${LIBLIGHTNING})
97
98if (LOG_LEVEL STREQUAL Debug)
99 find_library(LIBOPCODES NAMES opcodes-multiarch opcodes)
100 find_path(LIBOPCODES_INCLUDE_DIR dis-asm.h)
101
102 if (NOT LIBOPCODES OR NOT LIBOPCODES_INCLUDE_DIR)
103 message(SEND_ERROR "Debug log level requires libopcodes (from binutils) to be installed.")
104 endif ()
105
106 set(ENABLE_DISASSEMBLER ON)
107 include_directories(${LIBOPCODES_INCLUDE_DIR})
108 target_link_libraries(${PROJECT_NAME} PRIVATE ${LIBOPCODES})
109endif()
110
111configure_file(config.h.cmakein config.h @ONLY)
112
113include(GNUInstallDirs)
114install(TARGETS ${PROJECT_NAME}
115 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
116 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
117 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
118 PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
119)