Commit 4fe7773c authored by Ghislain MARY's avatar Ghislain MARY

Improve handling of compile flags with CMake.

parent 0201d4af
......@@ -43,6 +43,22 @@ option(ENABLE_TUNNEL "Enable tunnel support" OFF)
option(ENABLE_TESTS "Enable compilation of tests" ON)
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()
include(CheckLibraryExists)
include(CheckSymbolExists)
include(CheckCSourceCompiles)
......@@ -161,6 +177,7 @@ endif()
add_definitions("-DHAVE_CONFIG_H")
set(STRICT_OPTIONS_CPP )
set(STRICT_OPTIONS_C )
set(STRICT_OPTIONS_OBJC "-fmodules")
if(NOT MSVC)
list(APPEND STRICT_OPTIONS_CPP "-Wall" "-Wuninitialized")
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
......@@ -175,10 +192,12 @@ if(NOT MSVC)
list(APPEND STRICT_OPTIONS_CPP "-Werror" "-Wno-error=unknown-pragmas" "-Wuninitialized" "-fno-strict-aliasing")
list(APPEND STRICT_OPTIONS_C "-Wdeclaration-after-statement")
endif()
endif()
if(STRICT_OPTIONS_CPP)
list(REMOVE_DUPLICATES STRICT_OPTIONS_CPP)
if(STRICT_OPTIONS_C)
list(REMOVE_DUPLICATES STRICT_OPTIONS_C)
endif()
endif()
if(STRICT_OPTIONS_C)
list(REMOVE_DUPLICATES STRICT_OPTIONS_C)
endif()
set(LINK_FLAGS )
if(APPLE)
......
......@@ -41,34 +41,34 @@ if(WIN32)
list(APPEND LIBS ws2_32)
endif()
set(SDP_GENERATED_SOURCE_FILES
set(SDP_GENERATED_SOURCE_FILES_C
${CMAKE_CURRENT_BINARY_DIR}/grammars/belle_sdpLexer.c
${CMAKE_CURRENT_BINARY_DIR}/grammars/belle_sdpLexer.h
${CMAKE_CURRENT_BINARY_DIR}/grammars/belle_sdpParser.c
${CMAKE_CURRENT_BINARY_DIR}/grammars/belle_sdpParser.h
)
add_custom_command(
OUTPUT ${SDP_GENERATED_SOURCE_FILES}
OUTPUT ${SDP_GENERATED_SOURCE_FILES_C}
COMMAND ${ANTLR3_COMMAND} -make -Xmultithreaded -Xconversiontimeout 10000 -fo ${CMAKE_CURRENT_BINARY_DIR}/grammars ${CMAKE_CURRENT_SOURCE_DIR}/grammars/belle_sdp.g
DEPENDS grammars/belle_sdp.g
)
set(SIP_MESSAGE_GENERATED_SOURCE_FILES
set(SIP_MESSAGE_GENERATED_SOURCE_FILES_C
${CMAKE_CURRENT_BINARY_DIR}/grammars/belle_sip_messageLexer.c
${CMAKE_CURRENT_BINARY_DIR}/grammars/belle_sip_messageLexer.h
${CMAKE_CURRENT_BINARY_DIR}/grammars/belle_sip_messageParser.c
${CMAKE_CURRENT_BINARY_DIR}/grammars/belle_sip_messageParser.h
)
add_custom_command(
OUTPUT ${SIP_MESSAGE_GENERATED_SOURCE_FILES}
OUTPUT ${SIP_MESSAGE_GENERATED_SOURCE_FILES_C}
COMMAND ${ANTLR3_COMMAND} -make -Xmultithreaded -Xconversiontimeout 10000 -fo ${CMAKE_CURRENT_BINARY_DIR}/grammars ${CMAKE_CURRENT_SOURCE_DIR}/grammars/belle_sip_message.g
DEPENDS grammars/belle_sip_message.g
)
set_source_files_properties(${GRAMMARS_SOURCE_FILES} ${SIP_MESSAGE_GENERATED_SOURCE_FILES} PROPERTIES GENERATED TRUE)
set_source_files_properties(${SDP_GENERATED_SOURCE_FILES_C} ${SIP_MESSAGE_GENERATED_SOURCE_FILES_C} PROPERTIES GENERATED TRUE)
if(ENABLE_TLS)
set(TLS_SOURCE_FILES
set(TLS_SOURCE_FILES_C
transports/tls_listeningpoint_polarssl.c
transports/tls_channel_polarssl.c
)
......@@ -77,16 +77,17 @@ if(ENABLE_TLS)
endif()
if(ENABLE_TUNNEL)
set(TUNNEL_SOURCE_FILES
set(TUNNEL_SOURCE_FILES_C
transports/tunnel_listeningpoint.c
transports/tunnel_channel.c
)
set(TUNNEL_SOURCE_FILES_CXX
transports/tunnel_wrapper.cc
)
set_source_files_properties(transports/tunnel_wrapper.cc PROPERTIES LANGUAGE CXX)
list(APPEND LIBS ${TUNNEL_LIBRARIES})
endif()
set(BELLE_SIP_SOURCE_FILES
set(BELLE_SIP_SOURCE_FILES_C
auth_event.c
auth_helper.c
belle_sdp_impl.c
......@@ -135,20 +136,31 @@ set(BELLE_SIP_SOURCE_FILES
transports/udp_listeningpoint.c
grammars/belle_sip_message.g
grammars/belle_sdp.g
${SDP_GENERATED_SOURCE_FILES}
${SIP_MESSAGE_GENERATED_SOURCE_FILES}
${TLS_SOURCE_FILES}
${TUNNEL_SOURCE_FILES}
${SDP_GENERATED_SOURCE_FILES_C}
${SIP_MESSAGE_GENERATED_SOURCE_FILES_C}
${TLS_SOURCE_FILES_C}
${TUNNEL_SOURCE_FILES_C}
)
set(BELLE_SIP_SOURCE_FILES_CXX
${TUNNEL_SOURCE_FILES_CXX}
)
if(APPLE)
list(APPEND BELLE_SIP_SOURCE_FILES backgroundtask.m)
set_source_files_properties(backgroundtask.m PROPERTIES COMPILE_FLAGS "-fmodules")
set(BELLE_SIP_SOURCE_FILES_OBJC
backgroundtask.m
)
endif()
apply_compile_flags(BELLE_SIP_SOURCE_FILES_C "CPP" "C")
apply_compile_flags(BELLE_SIP_SOURCE_FILES_OBJC "CPP" "OBJC")
if(BELLE_SIP_SOURCE_FILES_CXX)
set_source_files_properties(${BELLE_SIP_SOURCE_FILES_CXX} PROPERTIES LANGUAGE CXX)
apply_compile_flags(BELLE_SIP_SOURCE_FILES_CXX "CPP" "CXX")
endif()
if(ENABLE_STATIC)
add_library(bellesip STATIC ${BELLE_SIP_HEADER_FILES} ${BELLE_SIP_SOURCE_FILES})
add_library(bellesip STATIC ${BELLE_SIP_HEADER_FILES} ${BELLE_SIP_SOURCE_FILES_C} ${BELLE_SIP_SOURCE_FILES_CXX} ${BELLE_SIP_SOURCE_FILES_OBJC})
else()
add_library(bellesip SHARED ${BELLE_SIP_HEADER_FILES} ${BELLE_SIP_SOURCE_FILES})
add_library(bellesip SHARED ${BELLE_SIP_HEADER_FILES} ${BELLE_SIP_SOURCE_FILES_C} ${BELLE_SIP_SOURCE_FILES_CXX} ${BELLE_SIP_SOURCE_FILES_OBJC})
set_target_properties(bellesip PROPERTIES VERSION 0.0.0 SOVERSION 0)
if(MSVC)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
......@@ -166,7 +178,6 @@ if(NOT "${LINK_FLAGS_STR}" STREQUAL "")
endif()
target_include_directories(bellesip PUBLIC ${INCLUDES})
target_link_libraries(bellesip ${LIBS})
target_compile_options(bellesip PRIVATE ${STRICT_OPTIONS_CPP} ${STRICT_OPTIONS_C})
install(TARGETS bellesip EXPORT ${EXPORT_TARGETS_NAME}Targets
RUNTIME DESTINATION bin
......
......@@ -45,31 +45,31 @@ add_definitions(-DBC_CONFIG_FILE="config.h")
string(REPLACE ";" " " LINK_FLAGS_STR "${LINK_FLAGS}")
apply_compile_flags(TESTER_SOURCES "CPP" "C")
add_executable(belle_sip_tester ${TESTER_SOURCES})
if(NOT "${LINK_FLAGS_STR}" STREQUAL "")
set_target_properties(belle_sip_tester PROPERTIES LINK_FLAGS "${LINK_FLAGS_STR}")
endif()
target_include_directories(belle_sip_tester PUBLIC ${CUNIT_INCLUDE_DIR} PRIVATE common)
target_link_libraries(belle_sip_tester ${CUNIT_LIBRARIES} bellesip)
target_compile_options(belle_sip_tester PRIVATE ${STRICT_OPTIONS_CPP} ${STRICT_OPTIONS_C})
add_test(NAME belle_sip_tester COMMAND belle_sip_tester --verbose)
set(OBJECT_DESCRIBE_SOURCES describe.c)
apply_compile_flags(OBJECT_DESCRIBE_SOURCES "CPP" "C")
add_executable(belle_sip_object_describe ${OBJECT_DESCRIBE_SOURCES})
if(NOT "${LINK_FLAGS_STR}" STREQUAL "")
set_target_properties(belle_sip_object_describe PROPERTIES LINK_FLAGS "${LINK_FLAGS_STR}")
endif()
target_link_libraries(belle_sip_object_describe bellesip)
target_compile_options(belle_sip_object_describe PRIVATE ${STRICT_OPTIONS_CPP} ${STRICT_OPTIONS_C})
set(PARSE_SOURCES parse.c)
apply_compile_flags(PARSE_SOURCES "CPP" "C")
add_executable(belle_sip_parse ${PARSE_SOURCES})
if(NOT "${LINK_FLAGS_STR}" STREQUAL "")
set_target_properties(belle_sip_parse PROPERTIES LINK_FLAGS "${LINK_FLAGS_STR}")
endif()
target_link_libraries(belle_sip_parse bellesip)
target_compile_options(belle_sip_parse PRIVATE ${STRICT_OPTIONS_CPP} ${STRICT_OPTIONS_C})
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