hermes/CMakeLists.txt
Juanjo Gutiérrez cda002ad91
Some checks failed
continuous-integration/drone/push Build is failing
add fmt dependency
2025-03-28 17:42:47 +01:00

112 lines
3.6 KiB
CMake

cmake_minimum_required(VERSION 3.12)
project (hermes)
set(LOGGER_CLASS UnixLogger CACHE STRING "One of UnixLogger, FileLogger or NullLogger")
add_executable (hermes
${CMAKE_CURRENT_BINARY_DIR}/Configfile.cpp
${CMAKE_CURRENT_BINARY_DIR}/Configfile.h
src/Exception.cpp
src/hermes.cpp
src/ServerSocket.cpp
src/Utils.cpp
src/Database.cpp
src/Proxy.cpp
src/Socket.cpp)
option(BUILD_DOCS "Build documentation")
if(WIN32)
set(SOURCES ${SOURCES}
src/FileLogger.cpp
src/win32-service.cpp)
target_compile_definitions(hermes PRIVATE WIN32)
endif()
target_include_directories(hermes PRIVATE include)
target_compile_definitions(hermes PRIVATE LOGGER_CLASS=${LOGGER_CLASS})
target_sources(hermes PRIVATE src/${LOGGER_CLASS}.cpp)
# required dependency sqlite3
find_library (SQLITE3_LIBRARY REQUIRED NAMES libsqlite3 sqlite3)
find_library (FMT_LIBRARY REQUIRED NAMES fmt)
# optional dependency libspf2
find_library (SPF2_LIBRARY REQUIRED NAMES spf2 libspf2)
if(SPF2_LIB)
target_compile_definitions(hermes PRIVATE HAVE_SPF2)
target_sources(hermes PRIVATE src/Spf.cpp)
set(OPT_DEFS ${OPT_DEFS} -DHAVE_SPF2)
endif()
# optional dependency openssl
find_package (OpenSSL)
if(OPENSSL_FOUND)
target_compile_definitions(hermes PRIVATE HAVE_SSL)
set(OPT_DEFS ${OPT_DEFS} -DHAVE_SSL)
endif()
include_directories(
${CMAKE_CURRENT_BINARY_DIR}
src)
set(CONFIG_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/src/Configfile.tmpl)
# generation of various files
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Configfile.cpp
COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/scripts/generate_config.py" "${CONFIG_TEMPLATE}"
--cpp-template "${CMAKE_CURRENT_SOURCE_DIR}/src/Configfile.cpp.in"
--output-cpp "${CMAKE_CURRENT_BINARY_DIR}/Configfile.cpp"
DEPENDS ${CONFIG_TEMPLATE} src/Configfile.cpp.in)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Configfile.h
COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/scripts/generate_config.py "${CONFIG_TEMPLATE}"
--h-template "${CMAKE_CURRENT_SOURCE_DIR}/include/Configfile.h.in"
--output-h "${CMAKE_CURRENT_BINARY_DIR}/Configfile.h"
DEPENDS ${CONFIG_TEMPLATE} include/Configfile.h.in)
# DEPENDS src/Configfile.cpp.in src/Configfile.h.in src/Configfile.tmpl
# docs/hermes-options.html.in scripts/generate_config.py)
# doxygen
if (BUILD_DOCS)
add_custom_command(OUTPUT docs/hermesrc.example
COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/scripts/generate_config.py "${CONFIG_TEMPLATE}"
--output-example "${CMAKE_CURRENT_BINARY_DIR}/docs/hermesrc.example"
DEPENDS ${CONFIG_TEMPLATE})
add_custom_command(OUTPUT docs/html/hermes-options.html
COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/scripts/generate_config.py "${CONFIG_TEMPLATE}"
--html-template "${CMAKE_CURRENT_SOURCE_DIR}/docs/hermes-options.html.in"
--output-html "${CMAKE_CURRENT_BINARY_DIR}/docs/html/hermes-options.html"
DEPENDS ${CONFIG_TEMPLATE} docs/hermes-options.html.in)
find_package (Doxygen)
add_custom_target(doc ALL
doxygen "${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/docs
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/docs/html/hermes-options.html" "${CMAKE_CURRENT_BINARY_DIR}/docs/hermesrc.example")
install(
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/docs/html
TYPE DOC)
endif()
target_link_libraries(hermes
${SQLITE3_LIBRARY}
${OPENSSL_LIBRARIES}
${SPF2_LIBRARY}
${FMT_LIBRARY}
pthread)
install(TARGETS hermes
RUNTIME DESTINATION bin)
install(FILES dists/hermesrc.example
TYPE SYSCONF)
install(FILES
dists/hermesrc.example
docs/gpl.txt
docs/installing-hermes.txt
docs/hermes-options.html
TYPE DOC)