Files
hiload/CMakeLists.txt

102 lines
2.6 KiB
CMake

cmake_minimum_required(VERSION 3.21)
project(Hiload)
# I just like to have this with my tooling. Also might be required for proper hotreloading.
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED)
# Conditionally define _GNU_SOURCE for Linux systems
if(UNIX AND NOT APPLE)
# This checks for Linux (UNIX but not macOS)
add_compile_definitions(_GNU_SOURCE)
message(STATUS "Defining _GNU_SOURCE for Unix build")
endif()
# Common compile options
# Hide everything by default to keep libraries smaller.
add_compile_options("-fvisibility=hidden")
# hiload library
# ##############
add_library(hiload SHARED
src/hiload.c
src/symbols.c
src/files.c
src/memmap.c
src/logger.c
src/moduler.c
src/hielf.c
src/histring.c
src/filewatcher/filewatcher.c
src/filewatcher/filewatch.c
# dependencies
3rd/sc/logger/sc_log.c
)
# TODO: Get -Wpadded back by refactoring sc_array or just surround
# all type sc_array declarations with the ignore pragma
target_compile_options(hiload PRIVATE
$<$<C_COMPILER_ID:GNU>:-Wall -Wextra -Wpedantic>
$<$<C_COMPILER_ID:Clang>:-Wall -Wextra -Wpedantic>
$<$<COMPILE_LANGUAGE:C>:-Wno-declaration-after-statement -Wno-padded>
)
target_link_libraries(hiload dl elf)
# Specify the public headers location
target_include_directories(hiload PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> # During build
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src> # During build
$<INSTALL_INTERFACE:include> # When installed
)
install(TARGETS hiload
EXPORT hiloadTargets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
# Install header files
install(DIRECTORY include/ DESTINATION include)
# Export the library for find_package()
install(EXPORT hiloadTargets
FILE hiloadConfig.cmake
DESTINATION lib/cmake/hiload
)
export(TARGETS hiload FILE hiloadConfig.cmake)
# Auditor libraries
# ###############
# TODO: Move auditor to its own project, possibly even out of this repo.
# It has only been a side product
add_library(auditor-x86_64 SHARED
solib-auditors/auditor-x86_64.c
)
target_compile_options(auditor-x86_64 PRIVATE
$<$<C_COMPILER_ID:GNU>:-Wall -Wextra -Wpedantic>
$<$<C_COMPILER_ID:Clang>:-Wall -Wextra -Wpedantic>
)
target_compile_options(auditor-x86_64 PRIVATE
-Wno-unused-parameter)
install(TARGETS auditor-x86_64
EXPORT auditor-x86_64Targets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
# tests and test projects
# #######################
add_subdirectory(test)