From 4ccba49c595d2daca2e781ec8fff959d8ae69e7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ola=20S=C3=B6der?= Date: Sat, 11 Oct 2025 13:08:17 +0200 Subject: [PATCH] Make it easier to disable process executor By adding a DISALLOW_PROCESS_EXECUTOR build option it's possible to conveniently disable the usage of fork() on non-Window platforms that either don't have fork(), or have an incomplete or inefficient implementation that is to be considered a last resort only. In the same commit the DISALLOW_THREAD_EXECUTOR is used for conditionally compiling the thread executor so that both executors are treated in the same way. --- cli/processexecutor.cpp | 4 ++-- cli/threadexecutor.cpp | 4 ++++ cmake/compilerDefinitions.cmake | 4 ++++ cmake/options.cmake | 4 ++++ cmake/printInfo.cmake | 1 + lib/config.h | 6 +++++- 6 files changed, 20 insertions(+), 3 deletions(-) diff --git a/cli/processexecutor.cpp b/cli/processexecutor.cpp index b839e179750..8f514f58410 100644 --- a/cli/processexecutor.cpp +++ b/cli/processexecutor.cpp @@ -22,7 +22,7 @@ #include "processexecutor.h" -#if !defined(WIN32) && !defined(__MINGW32__) +#if !defined(DISALLOW_PROCESS_EXECUTOR) && !defined(WIN32) && !defined(__MINGW32__) #include "cppcheck.h" #include "errorlogger.h" @@ -471,4 +471,4 @@ void ProcessExecutor::reportInternalChildErr(const std::string &childname, const mErrorLogger.reportErr(errmsg); } -#endif // !WIN32 +#endif // !DISALLOW_PROCESS_EXECUTOR && !WIN32 && !__MINGW32__ diff --git a/cli/threadexecutor.cpp b/cli/threadexecutor.cpp index 75b1a4524c6..5a1ed9daafe 100644 --- a/cli/threadexecutor.cpp +++ b/cli/threadexecutor.cpp @@ -18,6 +18,8 @@ #include "threadexecutor.h" +#if !defined(DISALLOW_THREAD_EXECUTOR) + #include "config.h" #include "cppcheck.h" #include "errorlogger.h" @@ -219,3 +221,5 @@ unsigned int ThreadExecutor::check() return result; } + +#endif // !DISALLOW_THREAD_EXECUTOR diff --git a/cmake/compilerDefinitions.cmake b/cmake/compilerDefinitions.cmake index 6ad938fa009..aa40c5e143d 100644 --- a/cmake/compilerDefinitions.cmake +++ b/cmake/compilerDefinitions.cmake @@ -52,6 +52,10 @@ if(DISALLOW_THREAD_EXECUTOR) add_definitions(-DDISALLOW_THREAD_EXECUTOR) endif() +if(DISALLOW_PROCESS_EXECUTOR) + add_definitions(-DDISALLOW_PROCESS_EXECUTOR) +endif() + if(MSVC AND DISABLE_CRTDBG_MAP_ALLOC) add_definitions(-DDISABLE_CRTDBG_MAP_ALLOC) endif() diff --git a/cmake/options.cmake b/cmake/options.cmake index 5765f9a9595..3c093bd7eaa 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -92,6 +92,10 @@ option(DISALLOW_THREAD_EXECUTOR "Disallow usage of ThreadExecutor for -j" if(DISALLOW_THREAD_EXECUTOR AND WIN32) message(FATAL_ERROR "Cannot disable usage of ThreadExecutor on Windows as no other executor implementation is currently available") endif() +option(DISALLOW_PROCESS_EXECUTOR "Disallow usage of ProcessExecutor for -j" OFF) +if(DISALLOW_THREAD_EXECUTOR AND DISALLOW_PROCESS_EXECUTOR) + message(FATAL_ERROR "Cannot disable both ThreadExecutor and ProcessExecutor") +endif() set(USE_BOOST "Auto" CACHE STRING "Usage of Boost") set_property(CACHE USE_BOOST PROPERTY STRINGS Auto Off On) option(USE_BOOST_INT128 "Usage of Boost.Multiprecision 128-bit integer for Mathlib" OFF) diff --git a/cmake/printInfo.cmake b/cmake/printInfo.cmake index 76c8112ce8a..8315e414485 100644 --- a/cmake/printInfo.cmake +++ b/cmake/printInfo.cmake @@ -78,6 +78,7 @@ if(HAVE_RULES) endif() message(STATUS) message(STATUS "DISALLOW_THREAD_EXECUTOR = ${DISALLOW_THREAD_EXECUTOR}") +message(STATUS "DISALLOW_PROCESS_EXECUTOR = ${DISALLOW_PROCESS_EXECUTOR}") message(STATUS "CMAKE_THREAD_LIBS_INIT = ${CMAKE_THREAD_LIBS_INIT}") message(STATUS) message(STATUS "USE_BUNDLED_TINYXML2 = ${USE_BUNDLED_TINYXML2}") diff --git a/lib/config.h b/lib/config.h index 55e180512e0..28e44c32734 100644 --- a/lib/config.h +++ b/lib/config.h @@ -164,12 +164,16 @@ static const std::string emptyString; #define HAS_THREADING_MODEL_THREAD #define STDCALL __stdcall #elif ((defined(__GNUC__) || defined(__sun)) && !defined(__MINGW32__)) || defined(__CPPCHECK__) +#if !defined(DISALLOW_PROCESS_EXECUTOR) #define HAS_THREADING_MODEL_FORK +#endif #if !defined(DISALLOW_THREAD_EXECUTOR) #define HAS_THREADING_MODEL_THREAD #endif #define STDCALL -#else +#endif + +#if !defined(HAS_THREADING_MODEL_FORK) && !defined(HAS_THREADING_MODEL_THREAD) #error "No threading model defined" #endif