Skip to content

Migrating build system to cmake#3413

Open
hemagx wants to merge 41 commits into
masterfrom
cmake
Open

Migrating build system to cmake#3413
hemagx wants to merge 41 commits into
masterfrom
cmake

Conversation

@hemagx
Copy link
Copy Markdown
Contributor

@hemagx hemagx commented May 23, 2026

Pull Request Prelude

Changes Proposed

This Pull request changes our compilation generation tool to cmake so unify all platforms under a single umberalla, we also added conan as our dependency manager to get rid of as much of 3rdparty as possible and also the DLLs deployed for windows.

Issues addressed:

@github-advanced-security
Copy link
Copy Markdown

You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool.

What Enabling Code Scanning Means:

  • The 'Security' tab will display more code scanning analysis results (e.g., for the default branch).
  • Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results.
  • You will be able to see the analysis results for the pull request's branch on this overview once the scans have completed and the checks have passed.

For more information about GitHub Code Scanning, check out the documentation.

@hemagx hemagx added this to the Release v2026.05 milestone May 23, 2026
@hemagx hemagx changed the base branch from stable to master May 23, 2026 18:17
Copy link
Copy Markdown
Member

@MishimaHaruna MishimaHaruna left a comment

Choose a reason for hiding this comment

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

Initial review - will continue later (I'm going commit by commit, so some comments might be outdated, feel free to close them)

Comment thread CMakeLists.txt

include(CMakeDependentOption)
# Configuration options
cmake_dependent_option(ENABLE_LIBBACKTRACE "Compiles with libbacktrace. (off by default - experimental)" ON ${RUNNING_ON_LINUX} OFF)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it's more typical to express this as

-cmake_dependent_option(ENABLE_LIBBACKTRACE "Compiles with libbacktrace. (off by default - experimental)" ON ${RUNNING_ON_LINUX} OFF)
+cmake_dependent_option(ENABLE_LIBBACKTRACE "Compiles with libbacktrace. (off by default - experimental)" ON RUNNING_ON_LINUX OFF)

(let the condition parser expand the variable, so that if it were to contain weird stuff, it wouldn't break)

Comment thread CMakeLists.txt Outdated

if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
if(${ENABLE_GDB})
message(FATAL_ERROR "ENABLE_GDB can be only used in debug builds")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it might make sense to allow this in RelWithDebInfo as well

Comment thread cmake_modules/LanguageFeatureHelper.cmake Outdated
Comment thread cmake_modules/LanguageFeatureHelper.cmake Outdated
Comment thread cmake_modules/CompilerFlagHelpers.cmake Outdated
Comment thread CMakeLists.txt Outdated
Comment thread CMakeLists.txt Outdated
Comment thread CMakeLists.txt Outdated
Comment thread CMakeLists.txt Outdated
Comment thread CMakeLists.txt Outdated
Comment thread src/common/CMakeLists.txt Outdated
get_directory_property(SYSGEN_CFLAGS COMPILE_OPTIONS)
get_directory_property(SYSGEN_DEFS COMPILE_DEFINITIONS)

add_custom_command(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OS-specific, will need to be put behind a condition

Comment thread CMakeLists.txt
Comment on lines +42 to +44
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
message(FATAL_ERROR "32-bit builds are not supported. Please use a 64-bit generator/toolchain.")
endif()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The configure.ac check is not very useful, it's meant to enforce 32 bit builds when you don't want 64 bit ones, on 64 bit OSes/compilers. It can be safely removed, without replacing it with anything. People that want 32 bit builds, will provide the compiler flags themselves, or use a 32 bit cross-compiler

Comment thread src/char/CMakeLists.txt Outdated
capiif.h
)

list(APPEND CHAR_HDRS ${CONFIG_HDRS})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These should probably be included indirectly by depending on common or a dedicated library

Comment thread src/login/CMakeLists.txt Outdated
lapiif.h
)

list(APPEND LOGIN_HDRS ${CONFIG_HDRS})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same as above, these should just be a dependency on common or dedicated header-only library

Comment thread src/map/CMakeLists.txt Outdated
vending.h
)

list(APPEND MAP_HDRS ${CONFIG_HDRS})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same as above

Comment thread CMakeLists.txt Outdated
message(FATAL_ERROR "In-source builds are not allowed. Please create a separate build directory.")
endif()

if(NOT CMAKE_INSTALL_PREFIX)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment thread cmake_modules/GeneralHelpers.cmake Outdated

# Appends a list of headers to global property ALL_HDRS with their absloute path
# _headers list of headers
function(add_header_all_list _headers)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What do we need this for? Can we avoid messing with lists of headers like this?


# Appends a list of headers to global property ALL_CONFIG_HDRS with their absloute path
# _headers list of headers
function(add_header_all_config_list _headers)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be nice not to have to mess with lists of files like this. What do we need this for, and can we get rid of it?

Comment thread src/plugins/HPMHooking/CMakeLists.txt Outdated
# List of include files
set(HPMHOOKING_INCLUDES "")

file(GLOB include_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.inc)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Might be better to remove the glob since we know the names we expect

Comment thread src/plugins/sample.c
Comment on lines -28 to -36
// check is TESTVAR defined from custom compile flags
#ifndef TESTVAR
#error TESTVAR not defined
#endif

// check is TESTVAR2 defined to value 2 from custom compile flags
#if !(TESTVAR2 == 2)
#error TESTVAR2 not defined
#endif
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd keep these checks to demonstrate/test that the flags are added


/// Sample Hercules Plugin

#include "plugins/sample/sample.h"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If this requires a full path, then we're doing something wrong in the cmake. We should ensure that each plugin has its own folder in its include path

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

oh it doesn't require that that's a little screw up.

Comment on lines +23 to +31
// check is TESTVAR defined from custom compile flags
#ifndef TESTVAR
#error TESTVAR not defined
#endif

// check is TESTVAR2 defined to value 2 from custom compile flags
#if !(TESTVAR2 == 2)
#error TESTVAR2 not defined
#endif
Copy link
Copy Markdown
Member

@MishimaHaruna MishimaHaruna May 23, 2026

Choose a reason for hiding this comment

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

I don't think this needs to be in a header, it can be in the plugin's main .c file in my opinion (it's not defining anything that it needs to share)

If you want to show an example of a plugin that has its own .h file, then maybe add something defined or declared here that is used in the .c file

echo
"Preprocessing files"
COMMAND
./preprocess.py
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This kind of invocation is a bit specific to unix systems, so the whole thing should probably go behind a check to prevent it from choking on windows.

Alternatively (and probably better), this could call python explicitly, like it does for perl below. That way it should probably run on any OS.

Also, since it checks for perl's presence it should also check for python

Comment thread 3rdparty/libconfig/CMakeLists.txt Outdated
${HERC_LIBCONF_HDRS}
)

target_compile_options(hercules-libconfig PRIVATE -Wno-null-dereference)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

gcc/clang-specific option, will require a conditional

@MishimaHaruna MishimaHaruna force-pushed the cmake branch 5 times, most recently from fe1bc9f to 38981ef Compare May 24, 2026 23:33
hemagx added 5 commits May 25, 2026 01:48
…n empty `./configure` run

Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
…ng on our own

Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
… 3rdparty source folder

Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
…hrough conan

Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
hemagx added 2 commits May 25, 2026 02:06
Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
Signed-off-by: Haru <haru@dotalux.com>
…t being empty

Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
hemagx added 27 commits May 25, 2026 02:07
…n CMakeFileLists.txt file

This would allow for more complex multi-file plugins and better customized build rules per plugin.
Due to this change any plugin that includes HPMHooks using path `plugins/HPMHooking.h` will now have to include it as `plugins/HPMHooking/HPMHooking.h`

Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
…ile tends to have possible false positives

Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
…d unnecessirly

Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
…nflict with windows setup and corrected the RPATH for plugins to reflect directory structure

Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
…oesn't depend on libbacktrace now the core will save current executable path to core->executable_path

Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
…d change its name to herc-plugins

Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
…changes for a 64bit build

Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
… sanitizer build as conan doesn't support preview releases

Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
Comment thread src/common/core.c
# include <unistd.h>
#else
#endif
#if defined(WIN32)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

testing for WIN32 right after testing for _WIN32 will look odd to those in the future who will git blame this and end up finding this commit.

I would instead group all the unix checks within the else branch:

#if defined(WIN32)
#include "common/winapi.h"
#else
#include <unistd.h>
#if defined(__sun)
 //...
#elif // ...
#endif
#endif

Comment thread 3rdparty/libconfig/libconfig.h
Comment thread src/common/sysinfo.c
#include <stdlib.h> // atoi
#ifdef WIN32
# include <windows.h>
# include <winternl.h>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What's this header providing here? It might be worth adding a comment to it since it's a quite unusual (and not very recommended) header to include

Comment thread CMakeLists.txt
option(ENABLE_CLASSIC_AUTOSPELL "Enables classic auto spell list" OFF)

if(ENABLE_TESTING)
enable_testing()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should probably not be part of this commit since it's not mentioned in the commit message.

It's also called twice (the second time in the src/test CMakeLists)

Comment thread src/common/atomic.h
Comment thread src/common/atomic.h
Comment thread tools/ci/travis.sh
# run_test spinlock # Not running the spinlock test for the time being (too time consuming)
# run_test libconfig
# run_test chunked
run_test spinlock
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Was this uncommented accidentally?

Comment thread tools/ci/travis.sh
run_server ./map-server "$PLUGINS --load-plugin db2sql --mobdb2sql"
run_server ./bin/map-server "$PLUGINS --load-plugin db2sql --db2sql"
run_server ./bin/map-server "$PLUGINS --load-plugin db2sql --itemdb2sql"
run_server ./bin/map-server "$PLUGINS --load-plugin db2sql --mobdb2sql"
# look like works on windows only
# echo "run all servers with dbghelpplug"
# run_server ./login-server "$PLUGINS --load-plugin dbghelpplug"
# run_server ./char-server "$PLUGINS --load-plugin dbghelpplug"
# run_server ./map-server "$PLUGINS --load-plugin dbghelpplug"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These lines should be removed along with the dbghelpplug plugin

Comment thread .gitignore
Comment on lines +131 to +132
!/src/plugins/dbghelpplug/
!/src/plugins/dbghelpplug/*
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These lines should be removed along with the dbghelpplug plugin

Comment thread CMakeLists.txt
@@ -0,0 +1,570 @@
# This file is part of Hercules.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This script requires that the user passes some arguments (in particular the conan ones), that might be hard to remember. They should be documented in the project readme, and perhaps it would be nice to provide a convenience script (.sh and .bat/.ps1) with reasonable defaults

Comment thread CMakeLists.txt
Comment thread CMakeLists.txt
add_compile_definitions(WIN32 _WIN32 __WIN32 _CRT_SECURE_NO_DEPRECATE _CRT_NONSTDC_NO_DEPRECATE FD_SETSIZE=4096 WIN32_LEAN_AND_MEAN)
# Define arch
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
add_compile_definitions(_X86_)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't see this macro used anywhere in the code. Is it necessary?

Comment thread CMakeLists.txt
endif()

if(ENABLE_WERROR)
testadd_warning_compiler_flag(error REQUIRED)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This flag is gcc/clang-specific. The MSVC equivalent is /WX.
Perhaps this option could be renamed to WARNINGS_ARE_ERRORS and made it work across compilers instead?

Comment thread CMakeLists.txt
endif()

if(ENABLE_LTO)
testadd_compiler_flag(flto REQUIRED)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

gcc/clang-specific flags - this will fail with unexplanatory error messages on MSVC, so it could perhaps go into an if else with a proper message(FATAL_ERROR

Comment thread CMakeLists.txt
endif()

if(ENABLE_SANITIZE)
add_compile_definitions(SANITIZE)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

gcc/clang-specific flags - this will silently do nothing on MSVC, so it could perhaps go into an if else with a proper message(FATAL_ERROR) so that the user doesn't have any false expectations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants