diff options
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 367 |
1 files changed, 237 insertions, 130 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 9575cbd..581782e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,26 +2,32 @@ cmake_minimum_required(VERSION 3.0) project(biboumi) -set(${PROJECT_NAME}_VERSION_MAJOR 4) -set(${PROJECT_NAME}_VERSION_MINOR 1) -set(${PROJECT_NAME}_VERSION_SUFFIX "") +set(${PROJECT_NAME}_VERSION_MAJOR 5) +set(${PROJECT_NAME}_VERSION_MINOR 0) +set(${PROJECT_NAME}_VERSION_SUFFIX "~dev") +# +## Find optional instrumentation libraries that will be used in debug only +# +find_library(LIBASAN NAMES asan libasan.so.3 libasan.so.2 libasan.so.1) +find_library(LIBUBSAN NAMES ubsan libubsan.so.0) + +# +## Set various debug flags (instrumentation libs, coverage, …) +# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y -pedantic -Wall -Wextra") if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage --coverage") endif() - -# Define a __FILENAME__ macro to get the filename of each file, instead of -# the full path as in __FILE__ -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILENAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'") - -# -## Look for external libraries -# -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/") +if(LIBASAN) + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address") +endif() +if(LIBUBSAN) + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=undefined") +endif() # -## Get the software version +## Set the software version, archive name, RPM name etc # set(ARCHIVE_NAME ${CMAKE_PROJECT_NAME}-${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}) set(RPM_VERSION ${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}) @@ -50,16 +56,8 @@ endif() set(SOFTWARE_VERSION ${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}${${PROJECT_NAME}_VERSION_SUFFIX}) -include(CheckFunctionExists) -check_function_exists(ppoll HAVE_PPOLL_FUNCTION) - -# To be able to include the config.h and other files generated by cmake -include_directories("${CMAKE_CURRENT_BINARY_DIR}/src/") -include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/") -include_directories("${CMAKE_CURRENT_BINARY_DIR}/") - # -## Documentation +## The rule that generates the documentation # execute_process(COMMAND "date" "+%Y-%m-%d" OUTPUT_VARIABLE DOC_DATE OUTPUT_STRIP_TRAILING_WHITESPACE) @@ -82,122 +80,201 @@ if (NOT PANDOC_EXECUTABLE) endif() mark_as_advanced(PANDOC_EXECUTABLE) -# Look for litesql and enable the database if found +# +## Set this search path for cmake, to find our custom search modules +# +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/") +find_package(ICONV REQUIRED) +find_package(LIBUUID REQUIRED) +find_package(EXPAT REQUIRED) + +# +## Find all the libraries (optional or not) +# +if(WITH_LIBIDN) + find_package(LIBIDN REQUIRED) +elseif(NOT WITHOUT_LIBIDN) + find_package(LIBIDN) +endif() + +if(WITH_SYSTEMD) + find_package(SYSTEMD REQUIRED) +elseif(NOT WITHOUT_SYSTEMD) + find_package(SYSTEMD) +endif() + +if(WITH_BOTAN) + find_package(BOTAN REQUIRED) +elseif(NOT WITHOUT_BOTAN) + find_package(BOTAN) +endif() + +if(NOT BOTAN_FOUND) + find_package(GCRYPT REQUIRED) +endif() + +if(WITH_UDNS) + find_package(UDNS REQUIRED) +elseif(NOT WITHOUT_UDNS) + find_package(UDNS) +endif() + if(WITH_LITESQL) find_package(LITESQL REQUIRED) elseif(NOT WITHOUT_LITESQL) find_package(LITESQL) endif() -if(LITESQL_FOUND) - LITESQL_GENERATE_CPP("database/database.xml" - "biboudb" - LITESQL_GENERATED_SOURCES) - - add_library(database STATIC src/database/database.cpp - ${LITESQL_GENERATED_SOURCES}) - target_link_libraries(database ${LITESQL_LIBRARIES} utils) - if(BOTAN_FOUND) - target_link_libraries(database ${BOTAN_LIBRARIES}) - endif() - set(USE_DATABASE TRUE) -endif() - -add_subdirectory("louloulibs") -include_directories("louloulibs") - +# +## Set all the include directories, depending on what libraries are used +# include_directories(${EXPAT_INCLUDE_DIRS}) include_directories(${ICONV_INCLUDE_DIRS}) include_directories(${LIBUUID_INCLUDE_DIRS}) - -# If they are found in louloulibs CMakeLists.txt, we inherite these values if(SYSTEMD_FOUND) include_directories(${SYSTEMD_INCLUDE_DIRS}) endif() if(BOTAN_FOUND) include_directories(SYSTEM ${BOTAN_INCLUDE_DIRS}) endif() -if(CARES_FOUND) - include_directories(${CARES_INCLUDE_DIRS}) +if(UDNS_FOUND) + include_directories(${UDNS_INCLUDE_DIRS}) endif() -# -## utils -# -file(GLOB source_src_utils - src/utils/*.[hc]pp) -# Todo, switch to target_sources(utils) when we go cmake >=3.1 only -add_library(src_utils STATIC ${source_src_utils}) -target_link_libraries(src_utils logger config) -if(USE_DATABASE) - target_link_libraries(src_utils database) -endif() +# To be able to include the config.h and other files generated by cmake +include_directories("${CMAKE_CURRENT_BINARY_DIR}/src/") +include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/") +include_directories("${CMAKE_CURRENT_BINARY_DIR}/") # -## irclib +## Define all the modules # + +file(GLOB source_utils + src/utils/*.[hc]pp) +add_library(utils OBJECT ${source_utils}) +add_dependencies(utils database) + file(GLOB source_irc - src/irc/*.[hc]pp) -add_library(irc STATIC ${source_irc}) -target_link_libraries(irc network utils logger) + src/irc/*.[hc]pp) +add_library(irc OBJECT ${source_irc}) +add_dependencies(irc database) -# -## xmpp -# file(GLOB source_xmpp - src/xmpp/*.[hc]pp) -add_library(xmpp STATIC ${source_xmpp}) -target_link_libraries(xmpp xmpplib bridge network utils src_utils logger) + src/xmpp/*.[hc]pp) +add_library(xmpp OBJECT ${source_xmpp}) +add_dependencies(xmpp database) -if(USE_DATABASE) - target_link_libraries(xmpp database) - target_link_libraries(irc database) -endif() +file(GLOB source_identd + src/identd/*.[hc]pp) +add_library(identd OBJECT ${source_identd}) -# -## bridge -# file(GLOB source_bridge - src/bridge/*.[hc]pp) -add_library(bridge STATIC ${source_bridge}) -target_link_libraries(bridge xmpp irc utils logger) + src/bridge/*.[hc]pp) +add_library(bridge OBJECT ${source_bridge}) +add_dependencies(bridge database) -# -## Main executable -# -add_executable(${PROJECT_NAME} src/main.cpp) -target_link_libraries(${PROJECT_NAME} - xmpp - irc - bridge - utils - src_utils - config) -if(SYSTEMD_FOUND) - target_link_libraries(xmpp ${SYSTEMD_LIBRARIES}) +file(GLOB source_config + src/config/*.[hc]pp) +add_library(config OBJECT ${source_config}) + +file(GLOB source_logger + src/logger/*.[hc]pp) +add_library(logger OBJECT ${source_logger}) + +file(GLOB source_network + src/network/*.[hc]pp) +add_library(network OBJECT ${source_network}) +add_dependencies(network database) + +if(LITESQL_FOUND) + LITESQL_GENERATE_CPP("database/database.xml" + "biboudb" + LITESQL_GENERATED_SOURCES) + + add_library(database OBJECT src/database/database.cpp + ${LITESQL_GENERATED_SOURCES}) + set(USE_DATABASE TRUE) +else() + add_library(database OBJECT "") endif() # -## Tests +## Define the executables # + +## main +add_executable(${PROJECT_NAME} src/main.cpp + $<TARGET_OBJECTS:utils> + $<TARGET_OBJECTS:config> + $<TARGET_OBJECTS:logger> + $<TARGET_OBJECTS:network> + $<TARGET_OBJECTS:xmpp> + $<TARGET_OBJECTS:bridge> + $<TARGET_OBJECTS:irc> + $<TARGET_OBJECTS:identd> + $<TARGET_OBJECTS:database>) + +## test_suite file(GLOB source_tests tests/*.cpp) -add_executable(test_suite EXCLUDE_FROM_ALL - ${source_tests}) +add_executable(test_suite ${source_tests} + $<TARGET_OBJECTS:utils> + $<TARGET_OBJECTS:config> + $<TARGET_OBJECTS:logger> + $<TARGET_OBJECTS:network> + $<TARGET_OBJECTS:xmpp> + $<TARGET_OBJECTS:bridge> + $<TARGET_OBJECTS:irc> + $<TARGET_OBJECTS:identd> + $<TARGET_OBJECTS:database>) + +# +## Link the executables with their libraries +# +target_link_libraries(${PROJECT_NAME} + ${ICONV_LIBRARIES} + ${LIBUUID_LIBRARIES} + ${EXPAT_LIBRARY}) target_link_libraries(test_suite - xmpplib - xmpp - irc - bridge - utils - config - logger - network) + ${ICONV_LIBRARIES} + ${LIBUUID_LIBRARIES} + ${EXPAT_LIBRARY}) +if(SYSTEMD_FOUND) + target_link_libraries(${PROJECT_NAME} ${SYSTEMD_LIBRARIES}) + target_link_libraries(test_suite ${SYSTEMD_LIBRARIES}) +endif() +if(BOTAN_FOUND) + target_link_libraries(${PROJECT_NAME} ${BOTAN_LIBRARIES}) + target_link_libraries(test_suite ${BOTAN_LIBRARIES}) +elseif(GCRYPT_FOUND) + target_link_libraries(${PROJECT_NAME} ${GCRYPT_LIBRARIES}) + target_link_libraries(test_suite ${GCRYPT_LIBRARIES}) +endif() +if(UDNS_FOUND) + target_link_libraries(${PROJECT_NAME} ${UDNS_LIBRARIES}) + target_link_libraries(test_suite ${UDNS_LIBRARIES}) +endif() +if(LIBIDN_FOUND) + target_link_libraries(${PROJECT_NAME} ${LIBIDN_LIBRARIES}) + target_link_libraries(test_suite ${LIBIDN_LIBRARIES}) +endif() if(USE_DATABASE) - target_link_libraries(test_suite - database) + target_link_libraries(${PROJECT_NAME} ${LITESQL_LIBRARIES}) + target_link_libraries(test_suite ${LITESQL_LIBRARIES}) endif() +# Define a __FILENAME__ macro with the relative path (from the base project directory) +# of each source file +file(GLOB_RECURSE source_all src/*.[hc]pp tests/*.[hc]pp) +foreach(file ${source_all}) + file(RELATIVE_PATH shorter_file ${CMAKE_CURRENT_SOURCE_DIR} ${file}) + set_property(SOURCE ${file} APPEND PROPERTY COMPILE_DEFINITIONS __FILENAME__="${shorter_file}") +endforeach() + +# +## Add a rule to download the catch unit test framework +# include(ExternalProject) ExternalProject_Add(catch GIT_REPOSITORY "https://lab.louiz.org/louiz/Catch.git" @@ -215,27 +292,36 @@ if(NOT EXISTS ${CMAKE_SOURCE_DIR}/tests/catch.hpp) ) add_dependencies(test_suite catch) endif() + +# +## Add some custom rules to launch the tests +# add_custom_target(check COMMAND "test_suite" DEPENDS test_suite biboumi) add_custom_target(e2e COMMAND "python3" "${CMAKE_CURRENT_SOURCE_DIR}/tests/end_to_end/" DEPENDS biboumi) add_custom_target(e2e_valgrind COMMAND "E2E_BIBOUMI_SUPP_DIR=${CMAKE_CURRENT_SOURCE_DIR}/tests/end_to_end/" "E2E_BIBOUMI_VALGRIND=1" "python3" "${CMAKE_CURRENT_SOURCE_DIR}/tests/end_to_end/" DEPENDS biboumi) - - -# -## Code coverage -# if(CMAKE_BUILD_TYPE MATCHES Debug) include(CodeCoverage) - SETUP_TARGET_FOR_COVERAGE(coverage - test_suite - coverage - ) + SETUP_TARGET_FOR_COVERAGE(coverage_check + ./test_suite + coverage_test_suite) + add_dependencies(coverage_check test_suite) + SETUP_TARGET_FOR_COVERAGE(coverage_e2e - make + python3 coverage_e2e - e2e) + ${CMAKE_CURRENT_SOURCE_DIR}/tests/end_to_end/) + add_dependencies(coverage_e2e biboumi) + + ADD_CUSTOM_TARGET(coverage + COMMAND ${LCOV_PATH} -a coverage_e2e.info -a coverage_test_suite.info -o coverage_total.info + + COMMAND ${GENHTML_PATH} -o coverage_total coverage_total.info + + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) endif() # @@ -272,21 +358,9 @@ add_custom_target(rpm COMMAND rpmbuild --define "_topdir `pwd`/rpmbuild/" --define "_sourcedir `pwd`" -ba biboumi.spec ) -if(BOTAN_FOUND) - set(STR_WITH_BOTAN "Botan: yes") -else() - set(STR_WITH_BOTAN "Botan: no") -endif() -if(CARES_FOUND) - set(STR_WITH_CARES "c-ares: yes") -else() - set(STR_WITH_CARES "c-ares: no") -endif() -add_custom_target(PrintBuildParameters ALL - ${CMAKE_COMMAND} -E cmake_echo_color --cyan "Compiling ${PROJECT_NAME} with ${STR_WITH_BOTAN}, ${STR_WITH_CARES}") - -configure_file(biboumi.h.cmake src/biboumi.h) - +# +## Set some variables that will be used in the cmake-generated files +# set(SYSTEMD_SERVICE_TYPE_DOCSTRING "The value used as the Type= in the systemd unit file.") set(WATCHDOG_SEC_DOCSTRING "The value used as WatchdogSec= in the systemd unit file.") if(SYSTEMD_FOUND) @@ -304,12 +378,45 @@ set(SERVICE_GROUP_DOCSTRING "The value used as the Group= in the systemd unit fi if(NOT DEFINED SERVICE_GROUP) set(SERVICE_GROUP "nobody" CACHE STRING ${SERVICE_GROUP_DOCSTRING}) endif() -configure_file(unit/biboumi.service.cmake biboumi.service) -# The date MUST be in english format -set(ENV{LANG} "en_US.utf-8") +# Force the format of the date output +set(ENV{LANG} "C") execute_process(COMMAND "date" "+%a %b %d %Y" OUTPUT_VARIABLE RPM_DATE OUTPUT_STRIP_TRAILING_WHITESPACE) unset(ENV{LANG}) +set(POLLER_DOCSTRING "Choose the poller between POLL and EPOLL (Linux-only)") +if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + set(POLLER "EPOLL" CACHE STRING ${POLLER_DOCSTRING}) +else() + set(POLLER "POLL" CACHE STRING ${POLLER_DOCSTRING}) +endif() +if((NOT ${POLLER} MATCHES "POLL") AND +(NOT ${POLLER} MATCHES "EPOLL")) + message(FATAL_ERROR "POLLER must be either POLL or EPOLL") +endif() + +# +## Check if we have std::get_time and put_time +# +include(CheckCXXSourceCompiles) + +check_cxx_source_compiles(" + #include <iomanip> + int main() + { std::get_time(nullptr, \"\"); }" + HAS_GET_TIME) + +mark_as_advanced(HAS_GET_TIME) + +check_cxx_source_compiles(" + #include <iomanip> + int main() + { std::put_time(nullptr, \"\"); }" + HAS_PUT_TIME) + +mark_as_advanced(HAS_PUT_TIME) + +configure_file(unit/biboumi.service.cmake biboumi.service) configure_file(packaging/biboumi.spec.cmake biboumi.spec) +configure_file(biboumi.h.cmake src/biboumi.h) |