cmake: rename MOMO_BUILD_AS_LIBRARY to SOGEN_BUILD_STATIC

Also adds FATAL_ERROR guard when SOGEN_STATIC_CRT=ON without SOGEN_BUILD_STATIC=ON,
since static CRT with shared libraries causes heap corruption (each DLL gets its own
allocator but sogen passes ownership across boundaries).

These options are designed to be used together for full static linking, useful for
embedding sogen in projects like IDA Pro plugins.
This commit is contained in:
Elias Bachaalany
2025-12-02 16:24:27 -08:00
parent d4166a5c8d
commit 7a42bc7ad3
7 changed files with 16 additions and 9 deletions

View File

@@ -31,10 +31,10 @@ endif()
##########################################
if(MOMO_BUILD_AS_LIBRARY)
add_compile_definitions(MOMO_BUILD_AS_LIBRARY=1)
if(SOGEN_BUILD_STATIC)
add_compile_definitions(SOGEN_BUILD_STATIC=1)
else()
add_compile_definitions(MOMO_BUILD_AS_LIBRARY=0)
add_compile_definitions(SOGEN_BUILD_STATIC=0)
endif()
##########################################
@@ -230,6 +230,13 @@ endif()
option(SOGEN_STATIC_CRT "Use static CRT (/MT) instead of dynamic (/MD)" OFF)
if(SOGEN_STATIC_CRT AND NOT SOGEN_BUILD_STATIC)
message(FATAL_ERROR
"SOGEN_STATIC_CRT=ON requires SOGEN_BUILD_STATIC=ON.\n"
"Static CRT with shared libraries causes heap corruption - "
"each DLL gets its own allocator, but sogen passes ownership across boundaries.")
endif()
if(SOGEN_STATIC_CRT)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
elseif(DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)