diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..0d5d3009dadae45b7baf8f60ff8b92efeaacf869 --- /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" +)