From 1fed1bb4a5cac2be6d9df38c4e8613e22a9afb4b Mon Sep 17 00:00:00 2001 From: Liu-Ermeng Date: Tue, 22 Apr 2025 19:00:22 -0700 Subject: [PATCH] add cmake support --- CMakeLists.txt | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..0d5d300 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,59 @@ +cmake_minimum_required(VERSION 3.10) +project(boundscheck C) + +# Find all source files +file(GLOB SOURCES "src/*.c") + +# Create shared library +add_library(boundscheck SHARED ${SOURCES}) + +# Set include directories +target_include_directories(boundscheck PUBLIC include) + +# Set compiler options +target_compile_options(boundscheck PRIVATE + -Wall + -DNDEBUG + -O2 + -fPIC + -fstack-protector-all + -D_FORTIFY_SOURCE=2 + -Wformat=2 + -Wfloat-equal + -Wshadow + -Wconversion + -Wformat-security + -Wextra + --param ssp-buffer-size=4 + -Warray-bounds + -Wpointer-arith + -Wcast-qual + -Wstrict-prototypes + -Wmissing-prototypes + -Wstrict-overflow=1 + -Wstrict-aliasing=2 + -Wswitch + -Wswitch-default +) + +# Set linker flags for Linux +if(NOT APPLE) + target_link_options(boundscheck PRIVATE + -fPIC + -s + -Wl,-z,relro,-z,now,-z,noexecstack + -fstack-protector-all + ) +endif() + +# Set output name and directory +set_target_properties(boundscheck PROPERTIES + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib +) + +# Add clean target +add_custom_target(clean-all + COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_CURRENT_SOURCE_DIR}/lib + COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_CURRENT_SOURCE_DIR}/obj + COMMENT "Cleaning up build directories" +) -- Gitee