From bc108a64bd7d3f5b6bf835d6056d7b2578daa37d Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Thu, 29 Dec 2016 22:05:16 +1000 Subject: [PATCH] * update cmake files * add option WITH_HARDENING * add option WITH_TOOLS --- CMakeLists.txt | 24 +++++++++++++++++++++++- src/CMakeLists.txt | 24 +++++++++++++----------- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 325b8a2..409361a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,11 +5,33 @@ project($CNAME C) cmake_minimum_required(VERSION 2.6) include(CTest) +include(GNUInstallDirs) + +option(WITH_HARDENING "Enable hardening options" ON) +option(WITH_TOOLS "Build library management tools" ON) set(CMAKE_INSTALL_PREFIX "/usr/local") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic -std=c99") add_definitions("-D_XOPEN_SOURCE=500") -add_subdirectory(src) +if (WITH_HARDENING) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat -Wformat-security -Werror=format-security" ) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector --param ssp-buffer-size=4" ) + add_definitions("-D_FORTIFY_SOURCE=2") +endif () + +message(STATUS "Project : ${CNAME} v${VERSION}") +message(STATUS "Compiler : ${CMAKE_C_COMPILER} (${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION})") +message(STATUS "- CFLAGS : ${CMAKE_C_FLAGS}") +message(STATUS "Paths:") +message(STATUS "- prefix : ${CMAKE_INSTALL_PREFIX}") +message(STATUS "- binary : ${CMAKE_INSTALL_FULL_BINDIR}") +message(STATUS "- library : ${CMAKE_INSTALL_FULL_LIBDIR}") +message(STATUS "Build type : ${CMAKE_BUILD_TYPE}") +message(STATUS "Options:") +message(STATUS "- WITH_HARDENING : ${WITH_HARDENING}") +message(STATUS "- WITH_TOOLS : ${WITH_TOOLS}") + +add_subdirectory("src") add_subdirectory("tests") set_property(DIRECTORY "tests" PROPERTY COMPILE_FLAGS "-g;-ggdb;-Wall;-Wextra;-pedantic;-O0") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 21776a7..ebc9d3c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,17 +4,19 @@ add_library("simdb" SHARED ${LIB_SOURCES}) set_property(TARGET "simdb" PROPERTY SONAME ${VERSION}) install(TARGETS "simdb" LIBRARY DESTINATION "lib") -add_executable("simdb-1to2" "simdb-1to2.c") -install(TARGETS "simdb-1to2" RUNTIME DESTINATION "bin") +if (WITH_TOOLS) + add_executable("simdb-1to2" "simdb-1to2.c") + install(TARGETS "simdb-1to2" RUNTIME DESTINATION "bin") -add_executable("simdb-query" "simdb-query.c") -target_link_libraries("simdb-query" "simdb") -install(TARGETS "simdb-query" RUNTIME DESTINATION "bin") + add_executable("simdb-query" "simdb-query.c") + target_link_libraries("simdb-query" "simdb") + install(TARGETS "simdb-query" RUNTIME DESTINATION "bin") -find_package(ImageMagick COMPONENTS MagickCore MagickWand) + find_package(ImageMagick COMPONENTS MagickCore MagickWand) -add_executable("simdb-write" "simdb-write.c" "sample.c") -target_link_libraries("simdb-write" "simdb") -target_link_libraries("simdb-write" ${ImageMagick_MagickCore_LIBRARY}) -target_link_libraries("simdb-write" ${ImageMagick_MagickWand_LIBRARY}) -install(TARGETS "simdb-write" RUNTIME DESTINATION "bin") + add_executable("simdb-write" "simdb-write.c" "sample.c") + target_link_libraries("simdb-write" "simdb") + target_link_libraries("simdb-write" ${ImageMagick_MagickCore_LIBRARY}) + target_link_libraries("simdb-write" ${ImageMagick_MagickWand_LIBRARY}) + install(TARGETS "simdb-write" RUNTIME DESTINATION "bin") +endif ()