Commit 19923c26 authored by Ghislain MARY's avatar Ghislain MARY

Add strict compilation options when building with CMake.

parent b139a063
......@@ -26,9 +26,26 @@ set(BZRTP_VERSION 1.0.3)
option(ENABLE_STATIC "Build static library (default is shared library)." NO)
option(ENABLE_STRICT "Build with strict compile options." YES)
option(ENABLE_TESTS "Enable compilation of unit tests." NO)
macro(apply_compile_flags SOURCE_FILES)
if(${SOURCE_FILES})
set(options "")
foreach(a ${ARGV})
if(STRICT_OPTIONS_${a})
string(REPLACE ";" " " options_${a} "${STRICT_OPTIONS_${a}}")
set(options "${options} ${options_${a}}")
endif()
endforeach()
if(options)
set_source_files_properties(${${SOURCE_FILES}} PROPERTIES COMPILE_FLAGS "${options}")
endif()
endif()
endmacro()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(MSVC_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/MSVC")
......@@ -60,6 +77,21 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/config.h PROPERTIES GENERATED ON)
add_definitions("-DHAVE_CONFIG_H")
set(STRICT_OPTIONS_CPP )
if(NOT MSVC)
list(APPEND STRICT_OPTIONS_CPP "-Wall")
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
list(APPEND STRICT_OPTIONS_CPP "-Qunused-arguments")
endif()
if(ENABLE_STRICT)
list(APPEND STRICT_OPTIONS_CPP "-Werror")
endif()
endif()
if(STRICT_OPTIONS_CPP)
list(REMOVE_DUPLICATES STRICT_OPTIONS_CPP)
string(REPLACE ";" " " STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP}")
endif()
include_directories(
include
......
......@@ -30,6 +30,8 @@ set(SOURCE_FILES
zidCache.c
)
apply_compile_flags(SOURCE_FILES "CPP")
if(ENABLE_STATIC)
add_library(bzrtp STATIC ${SOURCE_FILES})
target_link_libraries(bzrtp ${LIBS})
......
......@@ -35,13 +35,11 @@ set(TEST_SOURCES
../src/zidCache.c
)
apply_compile_flags(TEST_SOURCES "CPP")
add_executable(bzrtpTest ${TEST_SOURCES})
set_target_properties(bzrtpTest PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
if("${CMAKE_VERSION}" VERSION_GREATER "2.8.10")
target_include_directories(bzrtpTest PUBLIC ${CUNIT_INCLUDE_DIR})
else()
include_directories(${CUNIT_INCLUDE_DIR})
endif()
target_include_directories(bzrtpTest PUBLIC ${CUNIT_INCLUDE_DIR})
target_link_libraries(bzrtpTest ${CUNIT_LIBRARIES} bzrtp)
if(HAVE_SQRT)
target_link_libraries(bzrtpTest m)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment