summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt260
1 files changed, 166 insertions, 94 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 155e995..55cee2b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,34 +6,28 @@ 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()
if(LIBASAN)
- message(STATUS "Libasan found.")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address")
-else()
- message(STATUS "Libasan NOT found.")
endif()
if(LIBUBSAN)
- message(STATUS "Libubsan found.")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=undefined")
-else()
- message(STATUS "Libubsan NOT found.")
endif()
-
#
-## Look for external libraries
-#
-set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
-
-#
-## 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})
@@ -62,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)
@@ -94,28 +80,57 @@ if (NOT PANDOC_EXECUTABLE)
endif()
mark_as_advanced(PANDOC_EXECUTABLE)
-# Look for litesql and enable the database if found
-if(WITH_LITESQL)
- find_package(LITESQL REQUIRED)
-elseif(NOT WITHOUT_LITESQL)
- find_package(LITESQL)
+#
+## 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(LITESQL_FOUND)
- LITESQL_GENERATE_CPP("database/database.xml"
- "biboudb"
- LITESQL_GENERATED_SOURCES)
+if(WITH_SYSTEMD)
+ find_package(SYSTEMD REQUIRED)
+elseif(NOT WITHOUT_SYSTEMD)
+ find_package(SYSTEMD)
+endif()
- set(source_database src/database/database.cpp ${LITESQL_GENERATED_SOURCES})
- set(USE_DATABASE TRUE)
-else()
- set(source_database)
+if(WITH_BOTAN)
+ find_package(BOTAN REQUIRED)
+elseif(NOT WITHOUT_BOTAN)
+ find_package(BOTAN)
endif()
-add_subdirectory("louloulibs")
-include_directories("louloulibs")
+if(NOT BOTAN_FOUND)
+ find_package(GCRYPT REQUIRED)
+endif()
-# If they are found in louloulibs CMakeLists.txt, we inherite these values
+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()
+
+#
+## 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(SYSTEMD_FOUND)
include_directories(${SYSTEMD_INCLUDE_DIRS})
endif()
@@ -126,70 +141,92 @@ if(UDNS_FOUND)
include_directories(${UDNS_INCLUDE_DIRS})
endif()
-#
-## utils
-#
-file(GLOB source_src_utils
- src/utils/*.[hc]pp)
+# 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})
+
file(GLOB source_irc
- src/irc/*.[hc]pp)
+ src/irc/*.[hc]pp)
+add_library(irc OBJECT ${source_irc})
-#
-## xmpp
-#
file(GLOB source_xmpp
- src/xmpp/*.[hc]pp)
+ src/xmpp/*.[hc]pp)
+add_library(xmpp OBJECT ${source_xmpp})
-#
-## identd
-#
file(GLOB source_identd
- src/identd/*.[hc]pp)
+ src/identd/*.[hc]pp)
+add_library(identd OBJECT ${source_identd})
-#
-## bridge
-#
file(GLOB source_bridge
- src/bridge/*.[hc]pp)
+ src/bridge/*.[hc]pp)
+add_library(bridge OBJECT ${source_bridge})
-#
-## Main executable
-#
-add_executable(${PROJECT_NAME} src/main.cpp
- ${source_utils}
- ${source_config}
- ${source_logger}
- ${source_network}
- ${source_xmpplib}
- ${source_xmpp}
- ${source_src_utils}
- ${source_bridge}
- ${source_irc}
- ${source_identd}
- ${source_database})
+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})
+
+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}
- ${source_utils}
- ${source_config}
- ${source_logger}
- ${source_network}
- ${source_xmpplib}
- ${source_xmpp}
- ${source_src_utils}
- ${source_bridge}
- ${source_irc}
- ${source_identd}
- ${source_database})
+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}
@@ -230,6 +267,9 @@ foreach(file ${source_all})
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"
@@ -247,17 +287,16 @@ 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_check
@@ -278,7 +317,6 @@ if(CMAKE_BUILD_TYPE MATCHES Debug)
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
-
endif()
#
@@ -315,8 +353,9 @@ add_custom_target(rpm
COMMAND rpmbuild --define "_topdir `pwd`/rpmbuild/" --define "_sourcedir `pwd`" -ba biboumi.spec
)
-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)
@@ -334,7 +373,6 @@ 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)
# Force the format of the date output
set(ENV{LANG} "C")
@@ -342,4 +380,38 @@ 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)