2022-02-11 07:23:33 +03:00
|
|
|
|
cmake_minimum_required(VERSION 3.7)
|
2023-02-26 23:38:23 +03:00
|
|
|
|
|
|
|
|
|
if(${CMAKE_VERSION} VERSION_LESS 3.22)
|
|
|
|
|
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
|
|
|
|
|
else()
|
|
|
|
|
cmake_policy(VERSION 3.22)
|
|
|
|
|
endif()
|
2014-04-03 23:54:43 +04:00
|
|
|
|
|
2016-07-13 04:01:47 +03:00
|
|
|
|
# for debugging
|
|
|
|
|
#set(CMAKE_VERBOSE_MAKEFILE on)
|
|
|
|
|
|
2023-02-26 23:38:23 +03:00
|
|
|
|
# paths
|
|
|
|
|
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules")
|
|
|
|
|
set(CMAKE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/..")
|
|
|
|
|
|
|
|
|
|
set(LIBI2PD_SRC_DIR ${CMAKE_SOURCE_DIR}/libi2pd)
|
|
|
|
|
set(LIBI2PD_CLIENT_SRC_DIR ${CMAKE_SOURCE_DIR}/libi2pd_client)
|
|
|
|
|
set(LANG_SRC_DIR ${CMAKE_SOURCE_DIR}/i18n)
|
|
|
|
|
set(DAEMON_SRC_DIR ${CMAKE_SOURCE_DIR}/daemon)
|
|
|
|
|
|
|
|
|
|
include(Version)
|
|
|
|
|
set_version("${LIBI2PD_SRC_DIR}/version.h" PROJECT_VERSION)
|
|
|
|
|
|
|
|
|
|
project(
|
|
|
|
|
i2pd
|
|
|
|
|
VERSION ${PROJECT_VERSION}
|
|
|
|
|
HOMEPAGE_URL "https://i2pd.website/"
|
2023-11-04 14:24:33 +03:00
|
|
|
|
LANGUAGES C CXX
|
2023-02-26 23:38:23 +03:00
|
|
|
|
)
|
2020-05-20 12:17:54 +03:00
|
|
|
|
|
2020-11-15 01:31:20 +03:00
|
|
|
|
# configurable options
|
|
|
|
|
option(WITH_AESNI "Use AES-NI instructions set" ON)
|
2020-05-20 12:17:54 +03:00
|
|
|
|
option(WITH_HARDENING "Use hardening compiler flags" OFF)
|
|
|
|
|
option(WITH_LIBRARY "Build library" ON)
|
|
|
|
|
option(WITH_BINARY "Build binary" ON)
|
|
|
|
|
option(WITH_STATIC "Static build" OFF)
|
|
|
|
|
option(WITH_UPNP "Include support for UPnP client" OFF)
|
2022-06-21 03:03:29 +03:00
|
|
|
|
option(WITH_GIT_VERSION "Use git commit info as version" OFF)
|
2020-05-20 12:17:54 +03:00
|
|
|
|
option(WITH_ADDRSANITIZER "Build with address sanitizer unix only" OFF)
|
|
|
|
|
option(WITH_THREADSANITIZER "Build with thread sanitizer unix only" OFF)
|
2022-11-23 06:28:33 +03:00
|
|
|
|
option(BUILD_TESTING "Build tests" OFF)
|
|
|
|
|
|
|
|
|
|
IF(BUILD_TESTING)
|
|
|
|
|
enable_testing()
|
|
|
|
|
ENDIF()
|
2016-10-20 16:12:15 +03:00
|
|
|
|
|
2022-11-23 06:28:33 +03:00
|
|
|
|
# Handle paths nicely
|
2021-07-02 19:43:41 +03:00
|
|
|
|
include(GNUInstallDirs)
|
|
|
|
|
|
2023-02-26 23:38:23 +03:00
|
|
|
|
# Architecture
|
2017-12-20 16:54:02 +03:00
|
|
|
|
include(TargetArch)
|
2017-12-20 16:49:47 +03:00
|
|
|
|
target_architecture(ARCHITECTURE)
|
|
|
|
|
|
2023-02-26 23:38:23 +03:00
|
|
|
|
include(CheckAtomic)
|
2017-04-21 13:33:45 +03:00
|
|
|
|
|
2023-03-01 09:52:40 +03:00
|
|
|
|
if(WITH_STATIC)
|
|
|
|
|
if(MSVC)
|
|
|
|
|
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
2017-04-21 13:33:45 +03:00
|
|
|
|
include_directories(${LIBI2PD_SRC_DIR})
|
2021-05-26 13:15:17 +03:00
|
|
|
|
FILE(GLOB LIBI2PD_SRC ${LIBI2PD_SRC_DIR}/*.cpp)
|
2015-11-12 06:24:53 +03:00
|
|
|
|
add_library(libi2pd ${LIBI2PD_SRC})
|
2016-03-09 01:58:51 +03:00
|
|
|
|
set_target_properties(libi2pd PROPERTIES PREFIX "")
|
2018-03-11 19:20:47 +03:00
|
|
|
|
|
2020-05-20 12:17:54 +03:00
|
|
|
|
if(WITH_LIBRARY)
|
2018-03-11 19:20:47 +03:00
|
|
|
|
install(TARGETS libi2pd
|
|
|
|
|
EXPORT libi2pd
|
2021-07-02 19:43:41 +03:00
|
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
2018-03-11 19:20:47 +03:00
|
|
|
|
COMPONENT Libraries)
|
|
|
|
|
endif()
|
2015-05-11 12:56:13 +03:00
|
|
|
|
|
2023-02-26 23:38:23 +03:00
|
|
|
|
include_directories(${LIBI2PD_CLIENT_SRC_DIR})
|
2021-05-26 13:15:17 +03:00
|
|
|
|
FILE(GLOB CLIENT_SRC ${LIBI2PD_CLIENT_SRC_DIR}/*.cpp)
|
2018-03-05 16:55:54 +03:00
|
|
|
|
add_library(libi2pdclient ${CLIENT_SRC})
|
|
|
|
|
set_target_properties(libi2pdclient PROPERTIES PREFIX "")
|
2018-03-11 19:20:47 +03:00
|
|
|
|
|
2020-05-20 12:17:54 +03:00
|
|
|
|
if(WITH_LIBRARY)
|
2018-03-11 19:20:47 +03:00
|
|
|
|
install(TARGETS libi2pdclient
|
|
|
|
|
EXPORT libi2pdclient
|
2021-07-02 19:43:41 +03:00
|
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
2018-03-11 19:20:47 +03:00
|
|
|
|
COMPONENT Libraries)
|
|
|
|
|
endif()
|
2015-11-12 06:24:53 +03:00
|
|
|
|
|
2023-02-26 23:38:23 +03:00
|
|
|
|
include_directories(${LANG_SRC_DIR})
|
2021-05-26 13:15:17 +03:00
|
|
|
|
FILE(GLOB LANG_SRC ${LANG_SRC_DIR}/*.cpp)
|
2021-06-26 23:59:34 +03:00
|
|
|
|
add_library(libi2pdlang ${LANG_SRC})
|
|
|
|
|
set_target_properties(libi2pdlang PROPERTIES PREFIX "")
|
|
|
|
|
|
|
|
|
|
if(WITH_LIBRARY)
|
|
|
|
|
install(TARGETS libi2pdlang
|
|
|
|
|
EXPORT libi2pdlang
|
2021-07-02 19:43:41 +03:00
|
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
2021-06-26 23:59:34 +03:00
|
|
|
|
COMPONENT Libraries)
|
|
|
|
|
endif()
|
2021-05-23 15:39:29 +03:00
|
|
|
|
|
2023-02-26 23:38:23 +03:00
|
|
|
|
include_directories(${DAEMON_SRC_DIR})
|
|
|
|
|
|
2020-05-20 12:17:54 +03:00
|
|
|
|
set(DAEMON_SRC
|
2017-04-21 13:33:45 +03:00
|
|
|
|
"${DAEMON_SRC_DIR}/Daemon.cpp"
|
|
|
|
|
"${DAEMON_SRC_DIR}/HTTPServer.cpp"
|
|
|
|
|
"${DAEMON_SRC_DIR}/I2PControl.cpp"
|
2022-08-28 14:15:02 +03:00
|
|
|
|
"${DAEMON_SRC_DIR}/I2PControlHandlers.cpp"
|
2017-04-21 13:33:45 +03:00
|
|
|
|
"${DAEMON_SRC_DIR}/i2pd.cpp"
|
|
|
|
|
"${DAEMON_SRC_DIR}/UPnP.cpp"
|
2014-12-12 16:46:07 +03:00
|
|
|
|
)
|
|
|
|
|
|
2023-02-26 23:38:23 +03:00
|
|
|
|
if(WIN32)
|
|
|
|
|
set(WIN32_SRC_DIR ${CMAKE_SOURCE_DIR}/Win32)
|
|
|
|
|
include_directories(${WIN32_SRC_DIR})
|
|
|
|
|
|
|
|
|
|
list(APPEND DAEMON_SRC
|
|
|
|
|
"${WIN32_SRC_DIR}/DaemonWin32.cpp"
|
|
|
|
|
"${WIN32_SRC_DIR}/Win32App.cpp"
|
|
|
|
|
"${WIN32_SRC_DIR}/Win32Service.cpp"
|
|
|
|
|
"${WIN32_SRC_DIR}/Win32NetState.cpp"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
file(GLOB WIN32_RC ${WIN32_SRC_DIR}/*.rc)
|
2023-10-15 18:08:15 +03:00
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWIN32_APP -DWIN32_LEAN_AND_MEAN -DNOMINMAX")
|
2023-02-26 23:38:23 +03:00
|
|
|
|
|
|
|
|
|
endif()
|
|
|
|
|
|
2020-05-20 12:17:54 +03:00
|
|
|
|
if(WITH_UPNP)
|
2015-06-06 21:53:22 +03:00
|
|
|
|
add_definitions(-DUSE_UPNP)
|
2020-05-20 12:17:54 +03:00
|
|
|
|
endif()
|
|
|
|
|
|
2022-06-21 03:03:29 +03:00
|
|
|
|
if(WITH_GIT_VERSION)
|
|
|
|
|
include(GetGitRevisionDescription)
|
|
|
|
|
git_describe(GIT_VERSION)
|
2023-02-26 23:38:23 +03:00
|
|
|
|
add_definitions(-DGITVER=${GIT_VERSION})
|
2022-06-21 03:03:29 +03:00
|
|
|
|
endif()
|
|
|
|
|
|
2022-02-14 23:53:55 +03:00
|
|
|
|
if(APPLE)
|
2022-02-14 22:58:56 +03:00
|
|
|
|
add_definitions(-DMAC_OSX)
|
|
|
|
|
endif()
|
|
|
|
|
|
2023-09-28 22:30:38 +03:00
|
|
|
|
if(HAIKU)
|
|
|
|
|
add_definitions(-D_DEFAULT_SOURCE -D_GNU_SOURCE)
|
|
|
|
|
endif()
|
|
|
|
|
|
2023-03-01 09:52:40 +03:00
|
|
|
|
if(MSVC)
|
2023-03-01 23:41:31 +03:00
|
|
|
|
add_definitions(-DWINVER=0x0600)
|
|
|
|
|
add_definitions(-D_WIN32_WINNT=0x0600)
|
2020-02-28 23:28:41 +03:00
|
|
|
|
else()
|
2023-03-01 09:52:40 +03:00
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Winvalid-pch -Wno-unused-parameter -Wno-uninitialized")
|
|
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -pedantic")
|
|
|
|
|
# TODO: The following is incompatible with static build and enabled hardening for OpenWRT.
|
|
|
|
|
# Multiple definitions of __stack_chk_fail(libssp & libc)
|
2023-03-10 04:32:07 +03:00
|
|
|
|
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
|
|
|
|
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -flto -s")
|
|
|
|
|
endif()
|
|
|
|
|
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -ffunction-sections -fdata-sections")
|
2023-03-01 09:52:40 +03:00
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "-Wl,--gc-sections") # -flto is added from above
|
|
|
|
|
|
2024-08-28 18:34:07 +03:00
|
|
|
|
# check for с++20 & c++17 & c++11 support
|
2023-03-01 09:52:40 +03:00
|
|
|
|
include(CheckCXXCompilerFlag)
|
|
|
|
|
|
2024-08-28 18:34:07 +03:00
|
|
|
|
CHECK_CXX_COMPILER_FLAG("-std=c++20" CXX20_SUPPORTED)
|
2023-03-01 09:52:40 +03:00
|
|
|
|
CHECK_CXX_COMPILER_FLAG("-std=c++17" CXX17_SUPPORTED)
|
|
|
|
|
CHECK_CXX_COMPILER_FLAG("-std=c++11" CXX11_SUPPORTED)
|
|
|
|
|
|
2024-08-28 18:34:07 +03:00
|
|
|
|
if(CXX20_SUPPORTED)
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20")
|
|
|
|
|
elseif(CXX17_SUPPORTED)
|
2023-03-01 09:52:40 +03:00
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
|
|
|
|
|
elseif(CXX11_SUPPORTED)
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
|
|
|
|
else()
|
2024-08-28 18:34:07 +03:00
|
|
|
|
message(SEND_ERROR "C++20 nor C++17 nor C++11 standard not seems to be supported by compiler. Too old version?")
|
2023-03-01 09:52:40 +03:00
|
|
|
|
endif()
|
2020-02-28 23:28:41 +03:00
|
|
|
|
endif()
|
2014-09-23 02:36:06 +04:00
|
|
|
|
|
2020-05-20 12:17:54 +03:00
|
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pipe")
|
|
|
|
|
if(WITH_HARDENING)
|
|
|
|
|
add_definitions("-D_FORTIFY_SOURCE=2")
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat -Wformat-security -Werror=format-security")
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector --param ssp-buffer-size=4")
|
|
|
|
|
endif()
|
|
|
|
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
2014-09-23 02:36:06 +04:00
|
|
|
|
# more tweaks
|
2020-05-20 12:17:54 +03:00
|
|
|
|
if(LINUX)
|
|
|
|
|
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -stdlib=libstdc++") # required for <atomic>
|
2017-10-09 01:32:15 +03:00
|
|
|
|
list(APPEND CMAKE_REQUIRED_LIBRARIES "stdc++") # required to link with -stdlib=libstdc++
|
2018-06-27 17:47:22 +03:00
|
|
|
|
endif()
|
2020-05-20 12:17:54 +03:00
|
|
|
|
if(NOT APPLE)
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-const-variable -Wno-overloaded-virtual -Wno-c99-extensions")
|
2017-10-09 01:32:15 +03:00
|
|
|
|
endif()
|
2020-05-20 12:17:54 +03:00
|
|
|
|
endif()
|
2015-12-07 05:45:44 +03:00
|
|
|
|
|
2020-05-20 12:17:54 +03:00
|
|
|
|
# compiler flags customization(by system)
|
|
|
|
|
if(UNIX)
|
|
|
|
|
list(APPEND DAEMON_SRC "${DAEMON_SRC_DIR}/UnixDaemon.cpp")
|
|
|
|
|
if(NOT(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" OR APPLE))
|
2018-01-05 16:20:31 +03:00
|
|
|
|
# "'sleep_for' is not a member of 'std::this_thread'" in gcc 4.7/4.8
|
2020-05-20 12:17:54 +03:00
|
|
|
|
add_definitions("-D_GLIBCXX_USE_NANOSLEEP=1")
|
|
|
|
|
endif()
|
2014-09-17 04:16:39 +04:00
|
|
|
|
endif()
|
2014-04-05 03:52:40 +04:00
|
|
|
|
|
2020-11-15 01:31:20 +03:00
|
|
|
|
# Note: AES-NI and AVX is available on x86-based CPU's.
|
|
|
|
|
# Here also ARM64 implementation, but currently we don't support it.
|
2023-08-31 19:52:51 +03:00
|
|
|
|
# MSVC is not supported due to different ASM processing, so we hope OpenSSL has its own checks to run optimized code.
|
2020-11-15 01:31:20 +03:00
|
|
|
|
if(WITH_AESNI AND (ARCHITECTURE MATCHES "x86_64" OR ARCHITECTURE MATCHES "i386"))
|
2023-08-31 19:52:51 +03:00
|
|
|
|
if(NOT MSVC)
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maes")
|
|
|
|
|
endif()
|
2020-11-15 01:31:20 +03:00
|
|
|
|
add_definitions(-D__AES__)
|
2020-05-20 12:17:54 +03:00
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(WITH_ADDRSANITIZER)
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
|
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
|
2016-09-17 11:00:21 +03:00
|
|
|
|
endif()
|
|
|
|
|
|
2020-05-20 12:17:54 +03:00
|
|
|
|
if(WITH_THREADSANITIZER)
|
|
|
|
|
if(WITH_ADDRSANITIZER)
|
|
|
|
|
message(FATAL_ERROR "thread sanitizer option cannot be combined with address sanitizer")
|
|
|
|
|
else()
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
|
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread")
|
2016-10-03 23:24:22 +03:00
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
2022-11-26 01:35:28 +03:00
|
|
|
|
# Use std::atomic instead of GCC builtins on macOS PowerPC:
|
|
|
|
|
# For more information refer to: https://github.com/PurpleI2P/i2pd/issues/1726#issuecomment-1306335111
|
2023-02-15 07:04:30 +03:00
|
|
|
|
# This has been fixed in Boost 1.81, nevertheless we retain the setting for the sake of compatibility.
|
2022-11-26 01:35:28 +03:00
|
|
|
|
if(APPLE AND CMAKE_OSX_ARCHITECTURES MATCHES "ppc")
|
2022-11-20 08:40:03 +03:00
|
|
|
|
add_definitions(-DBOOST_SP_USE_STD_ATOMIC)
|
|
|
|
|
endif()
|
|
|
|
|
|
2014-09-17 04:16:39 +04:00
|
|
|
|
# libraries
|
2015-06-10 09:07:39 +03:00
|
|
|
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
2022-05-31 21:56:53 +03:00
|
|
|
|
find_package(Threads REQUIRED)
|
2014-04-03 23:54:43 +04:00
|
|
|
|
|
2020-05-20 12:17:54 +03:00
|
|
|
|
if(WITH_STATIC)
|
2023-03-08 14:41:01 +03:00
|
|
|
|
if(NOT MSVC)
|
|
|
|
|
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
|
|
|
|
|
endif()
|
2023-02-26 23:38:23 +03:00
|
|
|
|
|
2015-06-06 11:33:15 +03:00
|
|
|
|
set(Boost_USE_STATIC_LIBS ON)
|
2023-03-01 09:52:40 +03:00
|
|
|
|
if(MSVC)
|
|
|
|
|
set(Boost_USE_STATIC_RUNTIME ON)
|
|
|
|
|
else()
|
|
|
|
|
set(Boost_USE_STATIC_RUNTIME OFF)
|
|
|
|
|
endif()
|
2023-02-26 23:38:23 +03:00
|
|
|
|
|
2023-03-08 14:41:01 +03:00
|
|
|
|
if(MSVC)
|
|
|
|
|
set(OPENSSL_MSVC_STATIC_RT ON)
|
|
|
|
|
endif()
|
2022-06-21 03:03:29 +03:00
|
|
|
|
set(OPENSSL_USE_STATIC_LIBS ON)
|
2023-02-26 23:38:23 +03:00
|
|
|
|
|
|
|
|
|
set(ZLIB_USE_STATIC_LIBS ON)
|
2023-03-08 14:41:01 +03:00
|
|
|
|
if(MSVC)
|
|
|
|
|
set(ZLIB_NAMES zlibstatic zlibstat)
|
|
|
|
|
else()
|
|
|
|
|
set(ZLIB_NAMES libz zlibstatic zlibstat zlib z)
|
|
|
|
|
endif()
|
2023-02-26 23:38:23 +03:00
|
|
|
|
|
|
|
|
|
if(WITH_UPNP)
|
|
|
|
|
set(MINIUPNPC_USE_STATIC_LIBS ON)
|
|
|
|
|
add_definitions(-DMINIUPNP_STATICLIB)
|
|
|
|
|
endif()
|
|
|
|
|
|
2015-06-10 09:07:39 +03:00
|
|
|
|
set(BUILD_SHARED_LIBS OFF)
|
2023-02-26 23:38:23 +03:00
|
|
|
|
|
2020-05-20 12:17:54 +03:00
|
|
|
|
if(${CMAKE_CXX_COMPILER} MATCHES ".*-openwrt-.*")
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
|
|
|
|
|
# set(CMAKE_THREAD_LIBS_INIT "gcc_eh -Wl,--whole-archive -lpthread -Wl,--no-whole-archive")
|
|
|
|
|
set(CMAKE_THREAD_LIBS_INIT "gcc_eh -Wl,-u,pthread_create,-u,pthread_once,-u,pthread_mutex_lock,-u,pthread_mutex_unlock,-u,pthread_join,-u,pthread_equal,-u,pthread_detach,-u,pthread_cond_wait,-u,pthread_cond_signal,-u,pthread_cond_destroy,-u,pthread_cond_broadcast,-u,pthread_cancel")
|
|
|
|
|
endif()
|
2015-06-10 09:07:39 +03:00
|
|
|
|
else()
|
2020-05-20 12:17:54 +03:00
|
|
|
|
# TODO: Consider separate compilation for LIBI2PD_SRC for library.
|
|
|
|
|
# No need in -fPIC overhead for binary if not interested in library
|
|
|
|
|
# HINT: revert c266cff CMakeLists.txt: compilation speed up
|
2023-03-08 14:41:01 +03:00
|
|
|
|
if(NOT MSVC)
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
|
|
|
|
|
endif()
|
2024-08-26 03:18:55 +03:00
|
|
|
|
add_definitions(-DBOOST_ATOMIC_DYN_LINK -DBOOST_SYSTEM_DYN_LINK -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_PROGRAM_OPTIONS_DYN_LINK)
|
2023-03-13 00:41:07 +03:00
|
|
|
|
if(WIN32)
|
|
|
|
|
set(Boost_USE_STATIC_LIBS OFF)
|
|
|
|
|
set(Boost_USE_STATIC_RUNTIME OFF)
|
|
|
|
|
endif()
|
2020-05-20 12:17:54 +03:00
|
|
|
|
endif()
|
2015-06-06 11:33:15 +03:00
|
|
|
|
|
2024-08-26 03:18:55 +03:00
|
|
|
|
find_package(Boost REQUIRED COMPONENTS system filesystem program_options OPTIONAL_COMPONENTS atomic)
|
2023-03-13 00:41:07 +03:00
|
|
|
|
if(NOT DEFINED Boost_FOUND)
|
2018-07-10 12:39:21 +03:00
|
|
|
|
message(SEND_ERROR "Boost is not found, or your boost version was below 1.46. Please download Boost!")
|
2014-04-04 03:54:21 +04:00
|
|
|
|
endif()
|
|
|
|
|
|
2020-05-20 12:17:54 +03:00
|
|
|
|
find_package(OpenSSL REQUIRED)
|
2023-03-13 00:41:07 +03:00
|
|
|
|
if(NOT DEFINED OPENSSL_FOUND)
|
2015-11-11 22:46:29 +03:00
|
|
|
|
message(SEND_ERROR "Could not find OpenSSL. Please download and install it first!")
|
2014-04-04 03:54:21 +04:00
|
|
|
|
endif()
|
|
|
|
|
|
2022-02-11 07:23:33 +03:00
|
|
|
|
if(OPENSSL_VERSION VERSION_GREATER_EQUAL "3.0.0")
|
2022-05-24 15:06:01 +03:00
|
|
|
|
add_definitions(-DOPENSSL_SUPPRESS_DEPRECATED)
|
2022-02-11 07:00:30 +03:00
|
|
|
|
endif()
|
|
|
|
|
|
2020-05-20 12:17:54 +03:00
|
|
|
|
if(WITH_UPNP)
|
|
|
|
|
find_package(MiniUPnPc REQUIRED)
|
|
|
|
|
if(NOT MINIUPNPC_FOUND)
|
|
|
|
|
message(SEND_ERROR "Could not find MiniUPnPc. Please download and install it first!")
|
2015-12-07 23:53:38 +03:00
|
|
|
|
else()
|
2020-05-20 12:17:54 +03:00
|
|
|
|
include_directories(SYSTEM ${MINIUPNPC_INCLUDE_DIR})
|
2015-12-07 23:53:38 +03:00
|
|
|
|
endif()
|
2020-05-20 12:17:54 +03:00
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
find_package(ZLIB)
|
|
|
|
|
if(ZLIB_FOUND)
|
2018-01-05 16:20:31 +03:00
|
|
|
|
link_directories(${ZLIB_ROOT}/lib)
|
2020-05-20 12:17:54 +03:00
|
|
|
|
endif()
|
2015-11-11 22:46:29 +03:00
|
|
|
|
|
2014-09-17 04:16:39 +04:00
|
|
|
|
# load includes
|
2020-05-20 12:17:54 +03:00
|
|
|
|
include_directories(SYSTEM ${Boost_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR})
|
2016-06-29 16:37:38 +03:00
|
|
|
|
|
2014-09-17 04:16:39 +04:00
|
|
|
|
# show summary
|
|
|
|
|
message(STATUS "---------------------------------------")
|
|
|
|
|
message(STATUS "Build type : ${CMAKE_BUILD_TYPE}")
|
2014-09-17 07:00:18 +04:00
|
|
|
|
message(STATUS "Compiler vendor : ${CMAKE_CXX_COMPILER_ID}")
|
2014-09-23 02:36:29 +04:00
|
|
|
|
message(STATUS "Compiler version : ${CMAKE_CXX_COMPILER_VERSION}")
|
2014-09-17 07:00:18 +04:00
|
|
|
|
message(STATUS "Compiler path : ${CMAKE_CXX_COMPILER}")
|
2017-12-20 16:49:47 +03:00
|
|
|
|
message(STATUS "Architecture : ${ARCHITECTURE}")
|
2014-09-17 04:16:39 +04:00
|
|
|
|
message(STATUS "Install prefix: : ${CMAKE_INSTALL_PREFIX}")
|
|
|
|
|
message(STATUS "Options:")
|
|
|
|
|
message(STATUS " AESNI : ${WITH_AESNI}")
|
|
|
|
|
message(STATUS " HARDENING : ${WITH_HARDENING}")
|
2014-12-12 16:46:07 +03:00
|
|
|
|
message(STATUS " LIBRARY : ${WITH_LIBRARY}")
|
2014-12-31 21:41:05 +03:00
|
|
|
|
message(STATUS " BINARY : ${WITH_BINARY}")
|
2014-12-12 16:46:07 +03:00
|
|
|
|
message(STATUS " STATIC BUILD : ${WITH_STATIC}")
|
2015-06-06 21:53:22 +03:00
|
|
|
|
message(STATUS " UPnP : ${WITH_UPNP}")
|
2023-04-24 14:07:12 +03:00
|
|
|
|
if(WITH_GIT_VERSION)
|
|
|
|
|
message(STATUS " GIT VERSION : ${WITH_GIT_VERSION} (${GIT_VERSION})")
|
|
|
|
|
else()
|
2022-06-21 03:03:29 +03:00
|
|
|
|
message(STATUS " GIT VERSION : ${WITH_GIT_VERSION}")
|
2023-04-24 14:07:12 +03:00
|
|
|
|
endif()
|
2016-09-17 11:00:21 +03:00
|
|
|
|
message(STATUS " ADDRSANITIZER : ${WITH_ADDRSANITIZER}")
|
2017-09-18 22:24:53 +03:00
|
|
|
|
message(STATUS " THREADSANITIZER : ${WITH_THREADSANITIZER}")
|
2014-09-17 04:16:39 +04:00
|
|
|
|
message(STATUS "---------------------------------------")
|
2014-04-04 03:54:21 +04:00
|
|
|
|
|
2020-05-20 12:17:54 +03:00
|
|
|
|
if(WITH_BINARY)
|
2023-02-26 23:38:23 +03:00
|
|
|
|
if(WIN32)
|
|
|
|
|
add_executable("${PROJECT_NAME}" WIN32 ${DAEMON_SRC} ${WIN32_RC})
|
|
|
|
|
else()
|
|
|
|
|
add_executable("${PROJECT_NAME}" ${DAEMON_SRC})
|
|
|
|
|
endif()
|
|
|
|
|
|
2023-03-08 14:41:01 +03:00
|
|
|
|
if(WIN32)
|
|
|
|
|
list(APPEND MINGW_EXTRA "wsock32" "ws2_32" "iphlpapi")
|
|
|
|
|
# OpenSSL may require Crypt32 library on MSVC build, which is not added by CMake lesser than 3.21
|
|
|
|
|
if(MSVC AND ${CMAKE_VERSION} VERSION_LESS 3.21)
|
|
|
|
|
list(APPEND MINGW_EXTRA "crypt32")
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
2020-05-20 12:17:54 +03:00
|
|
|
|
|
|
|
|
|
if(WITH_STATIC)
|
2023-03-01 09:52:40 +03:00
|
|
|
|
if(NOT MSVC)
|
|
|
|
|
set_target_properties("${PROJECT_NAME}" PROPERTIES LINK_FLAGS "-static")
|
|
|
|
|
endif()
|
2016-03-10 09:12:46 +03:00
|
|
|
|
endif()
|
2014-04-03 23:54:43 +04:00
|
|
|
|
|
2020-05-20 12:17:54 +03:00
|
|
|
|
if(WITH_HARDENING AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
|
|
|
|
set_target_properties("${PROJECT_NAME}" PROPERTIES LINK_FLAGS "-z relro -z now")
|
|
|
|
|
endif()
|
2014-04-03 23:54:43 +04:00
|
|
|
|
|
2015-06-10 09:07:39 +03:00
|
|
|
|
# FindBoost pulls pthread for thread which is broken for static linking at least on Ubuntu 15.04
|
|
|
|
|
list(GET Boost_LIBRARIES -1 LAST_Boost_LIBRARIES)
|
|
|
|
|
if(${LAST_Boost_LIBRARIES} MATCHES ".*pthread.*")
|
|
|
|
|
list(REMOVE_AT Boost_LIBRARIES -1)
|
|
|
|
|
endif()
|
2015-11-25 23:06:26 +03:00
|
|
|
|
|
2023-02-26 23:38:23 +03:00
|
|
|
|
# synchronization library is incompatible with Windows 7
|
|
|
|
|
if(WIN32)
|
|
|
|
|
get_target_property(BOOSTFSLIBS Boost::filesystem INTERFACE_LINK_LIBRARIES)
|
|
|
|
|
list(REMOVE_ITEM BOOSTFSLIBS synchronization)
|
2023-03-01 09:52:40 +03:00
|
|
|
|
set_target_properties(Boost::filesystem PROPERTIES INTERFACE_LINK_LIBRARIES "${BOOSTFSLIBS}")
|
2023-02-26 23:38:23 +03:00
|
|
|
|
endif()
|
|
|
|
|
|
2020-05-20 12:17:54 +03:00
|
|
|
|
if(WITH_STATIC)
|
2016-08-16 17:25:56 +03:00
|
|
|
|
set(DL_LIB ${CMAKE_DL_LIBS})
|
|
|
|
|
endif()
|
2020-05-20 12:17:54 +03:00
|
|
|
|
|
2023-03-13 21:34:45 +03:00
|
|
|
|
target_link_libraries("${PROJECT_NAME}" libi2pd libi2pdclient libi2pdlang ${Boost_LIBRARIES} OpenSSL::SSL OpenSSL::Crypto ${MINIUPNPC_LIBRARY} ZLIB::ZLIB Threads::Threads ${MINGW_EXTRA} ${DL_LIB} ${CMAKE_REQUIRED_LIBRARIES})
|
2014-09-17 04:16:39 +04:00
|
|
|
|
|
2015-12-12 05:15:48 +03:00
|
|
|
|
install(TARGETS "${PROJECT_NAME}" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime)
|
2020-05-20 12:17:54 +03:00
|
|
|
|
set(APPS "\${CMAKE_INSTALL_PREFIX}/bin/${PROJECT_NAME}${CMAKE_EXECUTABLE_SUFFIX}")
|
|
|
|
|
set(DIRS "${Boost_LIBRARY_DIR};${OPENSSL_INCLUDE_DIR}/../bin;${ZLIB_INCLUDE_DIR}/../bin;/mingw32/bin")
|
2015-12-12 05:15:48 +03:00
|
|
|
|
endif()
|
2022-11-23 06:28:33 +03:00
|
|
|
|
|
|
|
|
|
if(BUILD_TESTING)
|
|
|
|
|
add_subdirectory(${CMAKE_SOURCE_DIR}/tests ${CMAKE_CURRENT_BINARY_DIR}/tests)
|
|
|
|
|
endif()
|