1 cmake_minimum_required(VERSION 3.0)
2 project(lightrec LANGUAGES C VERSION 0.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)
10 set(LOG_LEVEL Info CACHE STRING "Log level" FORCE)
11 set_property(CACHE LOG_LEVEL PROPERTY STRINGS NoLog Error Warning Info Debug)
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."
18 set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS None Debug Release RelWithDebInfo MinSizeRel)
21 string(TOUPPER ${LOG_LEVEL} LIGHTREC_LOG_LEVEL)
22 add_definitions(-DLOG_LEVEL=${LIGHTREC_LOG_LEVEL}_L)
24 if (CMAKE_COMPILER_IS_GNUCC)
25 add_compile_options(-fvisibility=hidden)
28 list(APPEND LIGHTREC_SOURCES
38 list(APPEND LIGHTREC_HEADERS
52 option(ENABLE_FIRST_PASS "Run the interpreter as first-pass optimization" ON)
54 option(ENABLE_THREADED_COMPILER "Enable threaded compiler" ON)
55 if (ENABLE_THREADED_COMPILER)
56 list(APPEND LIGHTREC_SOURCES recompiler.c reaper.c)
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)
63 include_directories(${CMAKE_CURRENT_BINARY_DIR})
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
71 C_STANDARD_REQUIRED ON
75 option(ENABLE_TINYMM "Enable optional libtinymm dependency" OFF)
77 find_library(TINYMM_LIBRARIES tinymm REQUIRED)
78 find_path(TINYMM_INCLUDE_DIR tinymm.h REQUIRED)
80 include_directories(${TINYMM_INCLUDE_DIR})
81 target_link_libraries(${PROJECT_NAME} PRIVATE ${TINYMM_LIBRARIES})
84 if (ENABLE_THREADED_COMPILER)
85 find_library(PTHREAD_LIBRARIES pthread REQUIRED)
86 find_path(PTHREAD_INCLUDE_DIR pthread.h REQUIRED)
88 include_directories(${PTHREAD_INCLUDE_DIR})
89 target_link_libraries(${PROJECT_NAME} PRIVATE ${PTHREAD_LIBRARIES})
90 endif (ENABLE_THREADED_COMPILER)
92 find_library(LIBLIGHTNING lightning REQUIRED)
93 find_path(LIBLIGHTNING_INCLUDE_DIR lightning.h REQUIRED)
95 include_directories(${LIBLIGHTNING_INCLUDE_DIR})
96 target_link_libraries(${PROJECT_NAME} PRIVATE ${LIBLIGHTNING})
98 if (LOG_LEVEL STREQUAL Debug)
99 find_library(LIBOPCODES NAMES opcodes-multiarch opcodes)
100 find_path(LIBOPCODES_INCLUDE_DIR dis-asm.h)
102 if (NOT LIBOPCODES OR NOT LIBOPCODES_INCLUDE_DIR)
103 message(SEND_ERROR "Debug log level requires libopcodes (from binutils) to be installed.")
106 set(ENABLE_DISASSEMBLER ON)
107 include_directories(${LIBOPCODES_INCLUDE_DIR})
108 target_link_libraries(${PROJECT_NAME} PRIVATE ${LIBOPCODES})
111 configure_file(config.h.cmakein config.h @ONLY)
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}