Skip to content

Commit b421edb

Browse files
committed
Fix static CRT linking with CMake policy and fallback flags
Changes: - Increase minimum CMake version to 3.15 (required for CMAKE_MSVC_RUNTIME_LIBRARY) - Enable CMP0091 policy for proper MSVC runtime selection - Add fallback: Replace /MD with /MT in compiler flags directly - This ensures static runtime linking works on all CMake versions The fallback method manually replaces /MD (dynamic) with /MT (static) in all compiler flags, ensuring compatibility.
1 parent 993a134 commit b421edb

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
cmake_minimum_required(VERSION 3.10)
1+
cmake_minimum_required(VERSION 3.15)
22
project(GhostInjector VERSION 1.0.2 LANGUAGES C CXX)
33

4+
# Enable new policy for MSVC runtime library selection
5+
cmake_policy(SET CMP0091 NEW)
6+
47
set(CMAKE_CXX_STANDARD 11)
58
set(CMAKE_CXX_STANDARD_REQUIRED ON)
69
set(CMAKE_CXX_EXTENSIONS OFF)
@@ -9,6 +12,19 @@ set(CMAKE_CXX_EXTENSIONS OFF)
912
# This embeds the runtime into the executable (no VCRUNTIME/MSVCP DLLs needed)
1013
if(MSVC)
1114
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
15+
16+
# Alternative: Set compiler flags directly for older CMake versions
17+
set(CompilerFlags
18+
CMAKE_CXX_FLAGS
19+
CMAKE_CXX_FLAGS_DEBUG
20+
CMAKE_CXX_FLAGS_RELEASE
21+
CMAKE_C_FLAGS
22+
CMAKE_C_FLAGS_DEBUG
23+
CMAKE_C_FLAGS_RELEASE
24+
)
25+
foreach(CompilerFlag ${CompilerFlags})
26+
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
27+
endforeach()
1228
endif()
1329

1430
add_subdirectory(Neptune)

0 commit comments

Comments
 (0)