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) set(BUILD_AUDITOR OFF CACHE BOOL "Build the independent auditor library.") set(BUILD_TESTS OFF CACHE BOOL "Build tests.") # 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 $<$:-Wall -Wextra -Wpedantic> $<$:-Wall -Wextra -Wpedantic> $<$:-Wno-declaration-after-statement -Wno-padded> ) target_link_libraries(hiload dl elf) # Specify the public headers location target_include_directories(hiload PUBLIC $ # During build $ # During build $ # 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) if (BUILD_AUDITOR) # 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 $<$:-Wall -Wextra -Wpedantic> $<$:-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 ) endif() # tests and test projects # ####################### if (BUILD_TESTS) add_subdirectory(test) endif()