Commit | Line | Data |
---|---|---|
d16005f8 PC |
1 | cmake_minimum_required(VERSION 3.0) |
2 | project(lightrec LANGUAGES C VERSION 0.3) | |
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 | list(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 | ) | |
38 | list(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 | ||
52 | option(ENABLE_FIRST_PASS "Run the interpreter as first-pass optimization" ON) | |
53 | ||
54 | option(ENABLE_THREADED_COMPILER "Enable threaded compiler" ON) | |
55 | if (ENABLE_THREADED_COMPILER) | |
a59e5536 | 56 | list(APPEND LIGHTREC_SOURCES recompiler.c reaper.c) |
d16005f8 PC |
57 | |
58 | if (NOT ENABLE_FIRST_PASS) | |
59 | message(SEND_ERROR "Threaded compiler requires first-pass optimization") | |
60 | endif (NOT ENABLE_FIRST_PASS) | |
61 | endif (ENABLE_THREADED_COMPILER) | |
62 | ||
63 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) | |
64 | ||
65 | add_library(${PROJECT_NAME} ${LIGHTREC_SOURCES} ${LIGHTREC_HEADERS}) | |
66 | set_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 | ||
75 | option(ENABLE_TINYMM "Enable optional libtinymm dependency" OFF) | |
76 | if (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}) | |
82 | endif (ENABLE_TINYMM) | |
83 | ||
84 | if (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}) | |
90 | endif (ENABLE_THREADED_COMPILER) | |
91 | ||
92 | find_library(LIBLIGHTNING lightning REQUIRED) | |
93 | find_path(LIBLIGHTNING_INCLUDE_DIR lightning.h REQUIRED) | |
94 | ||
95 | include_directories(${LIBLIGHTNING_INCLUDE_DIR}) | |
96 | target_link_libraries(${PROJECT_NAME} PRIVATE ${LIBLIGHTNING}) | |
97 | ||
98 | if (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}) | |
109 | endif() | |
110 | ||
111 | configure_file(config.h.cmakein config.h @ONLY) | |
112 | ||
113 | include(GNUInstallDirs) | |
114 | install(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 | ) |