Convert plain Makefile into cmake
The package can be configured with 4 different options: -DWITH_REDIS=ON Enable support for Redis DB -DWITH_JSON=ON Enable support for JSON based output -DENABLE_DEVELOPMENT=ON Enable all warnings and make them fatal -DENABLE_HARDENING=ON Compile and link with some hardening Use the new system by creating a build directory and change into that. And then call the following cmake -DWITH_REDIS=OFF -DWITH_JSON=ON -DENABLE_DEVELOPMENT=ON -DENABLE_HARDENING=ON /path/to/source/dir/ make make DESTDIR="/..." install Signed-off-by: Justin Lecher <jlec@gentoo.org> Merged by David Adrian - Remove src/Makefile - Updated .gitignore for CMake
This commit is contained in:
committed by
David Adrian
parent
4a37dba56f
commit
154fb01525
@@ -0,0 +1,72 @@
|
||||
cmake_minimum_required (VERSION 2.6)
|
||||
project (ZMAP C)
|
||||
|
||||
option(WITH_REDIS "Build with support for Redis DB" OFF)
|
||||
option(WITH_JSON "Build with support for JSON" OFF)
|
||||
option(ENABLE_DEVELOPMENT "Enable development specific compiler and linker flags" OFF)
|
||||
option(ENABLE_HARDENING "Add hardening specific compiler and linker flags" OFF)
|
||||
|
||||
if(ENABLE_DEVELOPMENT)
|
||||
# Hardening and warnings for building with gcc
|
||||
# Maybe add -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations
|
||||
set(GCCWARNINGS
|
||||
"-Wall -Wformat=2 -Wno-format-nonliteral"
|
||||
"-pedantic -fno-strict-aliasing"
|
||||
"-Wextra"
|
||||
"-Wfloat-equal -Wundef -Wwrite-strings -Wredundant-decls"
|
||||
"-Wnested-externs -Wbad-function-cast -Winit-self"
|
||||
"-Wmissing-noreturn -Wnormalized=id"
|
||||
"-Wstack-protector"
|
||||
"-Werror"
|
||||
)
|
||||
|
||||
# Fix line breaks
|
||||
string(REPLACE ";" " " GCCWARNINGS "${GCCWARNINGS}")
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GCCWARNINGS} -g")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -g")
|
||||
endif()
|
||||
|
||||
if(ENABLE_HARDENING)
|
||||
set(GCCHARDENING "-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fstack-protector-all -fwrapv -fPIC --param ssp-buffer-size=1")
|
||||
set(LDHARDENING "-z relro -z now")
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GCCHARDENING}")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LDHARDENING}")
|
||||
endif()
|
||||
|
||||
if(WITH_REDIS)
|
||||
set(REDIS_LIBS hiredis)
|
||||
add_definitions("-DREDIS")
|
||||
endif()
|
||||
|
||||
if(WITH_JSON)
|
||||
include(FindPkgConfig)
|
||||
pkg_check_modules(JSON json-c)
|
||||
if(NOT JSON_FOUND)
|
||||
set(JSON_CFLAGS "")
|
||||
set(JSON_LIBS "-ljson-c")
|
||||
include_directories("/usr/local/include/json-c/")
|
||||
endif()
|
||||
|
||||
add_definitions("-DJSON")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${JSON_CFLAGS}")
|
||||
endif()
|
||||
|
||||
# Standard FLAGS
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread")
|
||||
|
||||
# Extra target FLAGS
|
||||
set(CMAKE_C_FLAGS_DEBUG "-O2 -g")
|
||||
set(CMAKE_C_FLAGS_RELEASE "-O2")
|
||||
|
||||
add_subdirectory(src)
|
||||
|
||||
# Install conf files
|
||||
FILE(GLOB CONF_FILES "conf/*")
|
||||
install(
|
||||
FILES
|
||||
${CONF_FILES}
|
||||
DESTINATION "/etc/zmap/"
|
||||
)
|
||||
Reference in New Issue
Block a user