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 add_compile_options("-fvisibility=hidden") # Handle 3rd party dependencies # ############################# set(COPY_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/scripts/copy_dependencies.sh) execute_process( COMMAND bash ${COPY_SCRIPT} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} RESULT_VARIABLE SCRIPT_RESULT OUTPUT_VARIABLE SCRIPT_OUTPUT ERROR_VARIABLE SCRIPT_ERROR ) # Check if the script executed successfully if(NOT SCRIPT_RESULT EQUAL 0) message(WARNING "Script execution failed: ${SCRIPT_ERROR}") else() message(STATUS "Running script ${COPY_SCRIPT}:\n${SCRIPT_OUTPUT}") endif() # hiload library # ############## add_library(hiload SHARED src/hiload.c src/symbols.c src/files.c src/memory.c src/string/string.c src/logger/logger.c src/filewatcher/filewatcher.c src/filewatcher/filewatch.c # dependencies src/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> $<$:-Weverything> $<$:-Wno-declaration-after-statement -Wno-padded> ) target_link_libraries(hiload dl) # 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) # auditor libraries # ############### add_library(auditor-x86_64 SHARED src/auditor/auditor-x86_64.c ) target_compile_options(auditor-x86_64 PRIVATE $<$:-Wall -Wextra> $<$:-Weverything> ) 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)