Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
31 changes: 31 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
# Files created by the auto* tools
build*/

# Files created by CMake
CMakeCache.txt
CMakeFiles/
cmake_install.cmake
CTestTestfile.cmake

# macOS app bundles
aMule.app/
aMuleGUI.app/

# Build logs
*.log

# Test executables
unittests/tests/CTagTest
unittests/tests/CUInt128Test
unittests/tests/FileDataIOTest
unittests/tests/FormatTest
unittests/tests/ModernLoggingTest
unittests/tests/NetworkFunctionsTest
unittests/tests/PathTest
unittests/tests/RangeMapTest
unittests/tests/StringFunctionsTest
unittests/tests/TextFileTest

ABOUT-NLS
aclocal.m4
autom4te.cache/
Expand Down Expand Up @@ -72,3 +99,7 @@ platforms/Windows/*/libs/libGeoIP/GeoIP_X.c
# User files (should go into .git/info/exclude)
Makefile.user
*.vcxproj.user
cpp20_build/
.vscode/

.codeartsdoer
100 changes: 83 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
cmake_minimum_required (VERSION 3.5)
project (amule)
cmake_minimum_required(VERSION 3.20)
project(amule)

# Modern C++ configuration
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# Optional flag to disable 'register' keyword warnings
option(DISABLE_REGISTER_WARNING "Disable warnings about deprecated 'register' keyword" OFF)
if(DISABLE_REGISTER_WARNING AND (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang"))
add_compile_options(-Wno-register)
set (MIN_BOOST_VERSION 1.47)
set (MIN_CRYPTOPP_VERSION 5.6)
set (MIN_GDLIB_VERSION 2.0.0)
Expand All @@ -19,29 +29,72 @@ if (EXISTS "${CMAKE_SOURCE_DIR}/.git")
set (DEFAULT_BUILD_TYPE "Debug")
endif()

# Set the possible values of build type for cmake-gui
if (CMAKE_CONFIGURATION_TYPES)
set (CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE
STRING "Semicolon separated list of supported configuration types, only supports debug and release, anything else will be ignored" FORCE
)
# Coroutine support check
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(-fcoroutines HAS_COROUTINES)
if(HAS_COROUTINES)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fcoroutines>)
add_compile_definitions(USE_CPP20 HAS_COROUTINES)
else()
message(WARNING "Compiler does not support coroutines")
endif()
endif()

set_property (CACHE CMAKE_CONFIGURATION_TYPES PROPERTY STRINGS
"Debug" "Release"
)
# Suppress 'register' keyword warnings in generated C++ lexer files
# if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
# add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:-Wno-register>")
# endif()

# Package configuration
set(MIN_BOOST_VERSION 1.47)
set(MIN_CRYPTOPP_VERSION 5.6)
set(MIN_GDLIB_VERSION 2.0.0)
set(MIN_WX_VERSION 3.1.0)
set(PACKAGE "amule")
set(PACKAGE_BUGREPORT "admin@amule.org")
set(PACKAGE_NAME "aMule")
set(PACKAGE_STRING "aMule SVN")
set(PACKAGE_TARNAME "amule")
set(PACKAGE_URL "")
set(PACKAGE_VERSION "SVN")
set(VERSION "GIT")
set(DEFAULT_BUILD_TYPE "Release")
set(RECONF_COMMAND ${CMAKE_COMMAND})

if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
set(DEFAULT_BUILD_TYPE "Debug")
endif()

if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message (STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified.")
set (CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE
STRING "Choose the type of build." FORCE
)
# Set the possible values of build type for cmake-gui
if(CMAKE_CONFIGURATION_TYPES)
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE
STRING "Semicolon separated list of supported configuration types, only supports debug and release, anything else will be ignored" FORCE
)

set_property(CACHE CMAKE_CONFIGURATION_TYPES PROPERTY STRINGS
"Debug" "Release"
)
endif()

if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified.")
set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE
STRING "Choose the type of build." FORCE
)
endif()

include (cmake/CmDaB.cmake)
include (cmake/manpage_install.cmake)
include (cmake/options.cmake)
include (cmake/search-dirs.cmake)

# ICU for better encoding detection
option(ENABLE_ICU "Enable ICU for better encoding detection" ON)
if(ENABLE_ICU)
include(cmake/icu.cmake)
endif()

if (BUILD_AMULECMD OR BUILD_WEBSERVER)
include (cmake/FindReadline.cmake)
endif()
Expand All @@ -64,7 +117,7 @@ if (BUILD_WEBSERVER)
endif()

if (ENABLE_BOOST)
include (cmake/boost.cmake)
include (cmake/boost.cmake)
endif()

if (ENABLE_IP2COUNTRY)
Expand Down Expand Up @@ -113,6 +166,13 @@ configure_file (
config.h
)

# Search window debug logging
if(ENABLE_SEARCH_WINDOW_DEBUG)
add_compile_definitions(ENABLE_SEARCH_WINDOW_DEBUG=1)
else()
add_compile_definitions(ENABLE_SEARCH_WINDOW_DEBUG=0)
endif()

if (WIN32)
configure_file (
version.rc.in
Expand Down Expand Up @@ -213,7 +273,13 @@ endif()
message (" libintl ${ENABLE_NLS}")

if (ENABLE_IP2COUNTRY)
message (" libGeoIP ${GEOIP_LIB}")
if (maxminddb_FOUND)
message (" libmaxminddb ${maxminddb_VERSION}")
endif()
endif()

if (ICU_FOUND)
message (" libicu ${ICU_VERSION}")
endif()

if (BUILD_WEBSERVER)
Expand Down
5 changes: 4 additions & 1 deletion cmake/boost.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
include (FindBoost)
# Suppress CMP0167 warning about FindBoost module
cmake_policy(SET CMP0167 NEW)
# Use modern Boost find approach
find_package(Boost REQUIRED)

if (NOT ASIO_SOCKETS)
include (CheckIncludeFiles)
Expand Down
4 changes: 3 additions & 1 deletion cmake/cryptopp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ if (WIN32)
endif()
endif()

if (CRYPTOPP_LIBRARY_DEBUG)
if (CRYPTOPP_LIBRARY_DEBUG AND NOT CRYPTOPP_LIBRARY_DEBUG_ALREADY_FOUND)
message (STATUS "CRYPTOPP_LIBRARY_DEBUG in ${CRYPTOPP_LIBRARY_DEBUG}")
set (CRYPTOPP_LIBRARY_DEBUG_ALREADY_FOUND TRUE CACHE INTERNAL "CRYPTOPP_LIBRARY_DEBUG already found")
set_property (TARGET CRYPTOPP::CRYPTOPP
PROPERTY IMPORTED_LOCATION_DEBUG ${CRYPTOPP_LIBRARY_DEBUG}
)
Expand Down
83 changes: 83 additions & 0 deletions cmake/icu.cmake
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not bumping min version to 3.7 and using FindICU?

Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Find ICU (International Components for Unicode)
# This module finds the ICU libraries and defines:
# ICU_FOUND - True if ICU was found
# ICU_INCLUDE_DIRS - Include directories for ICU
# ICU_LIBRARIES - Libraries to link against
# ICU_VERSION - Version of ICU

find_package(PkgConfig)
if(PKG_CONFIG_FOUND)
pkg_check_modules(ICU_UC icu-uc)
pkg_check_modules(ICU_I18N icu-i18n)
endif()

# If pkg-config didn't find ICU, try manual search
if(NOT ICU_UC_FOUND)
find_path(ICU_INCLUDE_DIR
NAMES unicode/utypes.h
PATHS
/usr/include
/usr/local/include
/opt/local/include
)

find_library(ICU_UC_LIB
NAMES icuuc icuucd
PATHS
/usr/lib
/usr/local/lib
/opt/local/lib
/usr/lib/x86_64-linux-gnu
)

find_library(ICU_I18N_LIB
NAMES icui18n icui18nd
PATHS
/usr/lib
/usr/local/lib
/opt/local/lib
/usr/lib/x86_64-linux-gnu
)

if(ICU_INCLUDE_DIR AND ICU_UC_LIB AND ICU_I18N_LIB)
set(ICU_UC_FOUND TRUE)
set(ICU_I18N_FOUND TRUE)
set(ICU_UC_INCLUDE_DIRS ${ICU_INCLUDE_DIR})
set(ICU_UC_LIBRARIES ${ICU_UC_LIB})
set(ICU_I18N_LIBRARIES ${ICU_I18N_LIB})
endif()
endif()

# Combine results
if(ICU_UC_FOUND AND ICU_I18N_FOUND)
set(ICU_FOUND TRUE)
set(ICU_INCLUDE_DIRS ${ICU_UC_INCLUDE_DIRS})
set(ICU_LIBRARIES ${ICU_UC_LIBRARIES} ${ICU_I18N_LIBRARIES})

if(DEFINED ICU_UC_VERSION)
set(ICU_VERSION ${ICU_UC_VERSION})
else()
# Try to get version from header file
if(EXISTS "${ICU_INCLUDE_DIR}/unicode/uversion.h")
file(READ "${ICU_INCLUDE_DIR}/unicode/uversion.h" ICU_VERSION_H)
string(REGEX MATCH "U_ICU_VERSION_MAJOR_NUM ([0-9]+)" _ ${ICU_VERSION_H})
set(ICU_VERSION_MAJOR ${CMAKE_MATCH_1})
string(REGEX MATCH "U_ICU_VERSION_MINOR_NUM ([0-9]+)" _ ${ICU_VERSION_H})
set(ICU_VERSION_MINOR ${CMAKE_MATCH_1})
set(ICU_VERSION "${ICU_VERSION_MAJOR}.${ICU_VERSION_MINOR}")
endif()
endif()

message(STATUS "Found ICU: ${ICU_INCLUDE_DIRS}, ${ICU_LIBRARIES}")
message(STATUS "ICU Version: ${ICU_VERSION}")
else()
set(ICU_FOUND FALSE)
message(STATUS "ICU not found, will use wxWidgets encoding fallback")
endif()

# Hide cache variables from GUI
mark_as_advanced(
ICU_INCLUDE_DIR
ICU_UC_LIB
ICU_I18N_LIB
)
87 changes: 55 additions & 32 deletions cmake/ip2country.cmake
Original file line number Diff line number Diff line change
@@ -1,42 +1,65 @@
if (GEOIP_INCLUDE_DIR)
set (CMAKE_REQUIRED_INCLUDES ${GEOIP_INCLUDE_DIR})
# MaxMind DB implementation for IP2Country
find_package(maxminddb QUIET)
if (NOT maxminddb_FOUND)
# Try alternative spelling
find_package(MaxMindDB QUIET)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be needed as upstream creates maxminddb-config.cmake that's the right spelling, if anyone (any Distro/Packagemanager) renames it, not our problem.

endif()

if (NOT GEOIP_LIB)
include (CheckIncludeFile)
if (maxminddb_FOUND)
message(STATUS "MaxMind DB found: ${maxminddb_VERSION}")
else()
# Try to find manually
find_path(MAXMINDDB_INCLUDE_DIR maxminddb.h)
find_library(MAXMINDDB_LIBRARY NAMES maxminddb)

if (MAXMINDDB_INCLUDE_DIR AND MAXMINDDB_LIBRARY)
set(maxminddb_FOUND TRUE)
set(maxminddb_INCLUDE_DIRS ${MAXMINDDB_INCLUDE_DIR})
set(maxminddb_LIBRARIES ${MAXMINDDB_LIBRARY})

check_include_file (GeoIP.h GEOIP_H)
# Get version from pkg-config
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
execute_process(
COMMAND pkg-config --modversion libmaxminddb
OUTPUT_VARIABLE maxminddb_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
if(maxminddb_VERSION)
message(STATUS "MaxMind DB version from pkg-config: ${maxminddb_VERSION}")
endif()
endif()

if (GEOIP_H)
find_library (GEOIP_LIB GeoIP)

if (NOT GEOIP_LIB AND GEOIP_INCLUDE_DIR)
find_library (GEOIP_LIB GeoIP
PATHS ${GEOIP_INCLUDE_DIR}
)
endif()

if (NOT GEOIP_LIB)
set (ENABLE_IP2COUNTRY FALSE)
message (STATUS "GeoIP lib not found, disabling support")
else()
message (STATUS "GeoIP found useable")
endif()
else()
set (ENABLE_IP2COUNTRY FALSE)
message (STATUS "GeoIP headers not found, disabling support")
endif()
message(STATUS "MaxMind DB found manually")
else()
if (ENABLE_IP2COUNTRY)
message(FATAL_ERROR "**************************************************")
message(FATAL_ERROR "libmaxminddb not found but ENABLE_IP2COUNTRY is enabled")
message(FATAL_ERROR "Please install: sudo apt install libmaxminddb-dev")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt this command is portable, just "please install" should be enough

message(FATAL_ERROR "**************************************************")
else()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this file isn't even included when ENABLE-IP2COUNTRY is not set, the else branch is never reaches, so the complete if can be omitted.

message(STATUS "MaxMind DB not found - GeoIP/country flags will be disabled")
message(STATUS "To enable, install: sudo apt install libmaxminddb-dev")
set(maxminddb_FOUND FALSE)
endif()
endif()
endif()

if (ENABLE_IP2COUNTRY)
add_library (GeoIP::Shared UNKNOWN IMPORTED)
if (maxminddb_FOUND)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both if's can be omitted here, as this isn't reached if one of them is false.

# MaxMind DB implementation
add_library(maxminddb::maxminddb UNKNOWN IMPORTED)

set_target_properties (GeoIP::Shared PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "ENABLE_IP2COUNTRY"
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_REQUIRED_INCLUDES}"
IMPORTED_LOCATION "${GEOIP_LIB}"
)
set_target_properties(maxminddb::maxminddb PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "ENABLE_IP2COUNTRY"
INTERFACE_INCLUDE_DIRECTORIES "${maxminddb_INCLUDE_DIRS}"
IMPORTED_LOCATION "${maxminddb_LIBRARIES}"
)
message(STATUS "Using MaxMind DB implementation")
else()
# No MaxMind DB library found, disable support
set(ENABLE_IP2COUNTRY FALSE)
message(STATUS "MaxMind DB not found, disabling IP2Country support")
endif()
endif()

unset (CMAKE_REQUIRED_INCLUDES)
Loading
Loading