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

@@ -44,7 +44,7 @@ endif()
##########################################
option(MOMO_BUILD_AS_LIBRARY "Configure and Build the sogen as a shared library (without the samples and tests)" ${MOMO_IS_SUBPROJECT})
option(SOGEN_BUILD_STATIC "Build sogen as static libraries for embedding (e.g., IDA plugins)" ${MOMO_IS_SUBPROJECT})
##########################################

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)

View File

@@ -8,7 +8,7 @@ add_subdirectory(backend-selection)
momo_add_subdirectory_and_get_targets("backends" BACKEND_TARGETS)
momo_targets_set_folder("backends" ${BACKEND_TARGETS})
if (NOT MOMO_BUILD_AS_LIBRARY)
if (NOT SOGEN_BUILD_STATIC)
add_subdirectory(analyzer)
add_subdirectory(debugger)
add_subdirectory(fuzzing-engine)

View File

@@ -8,7 +8,7 @@ file(GLOB_RECURSE SRC_FILES CONFIGURE_DEPENDS
list(SORT SRC_FILES)
if(MOMO_BUILD_AS_LIBRARY)
if(SOGEN_BUILD_STATIC)
add_library(icicle-emulator STATIC ${SRC_FILES})
else()
add_library(icicle-emulator SHARED ${SRC_FILES})

View File

@@ -12,7 +12,7 @@
namespace icicle
{
#if !MOMO_BUILD_AS_LIBRARY
#if !SOGEN_BUILD_STATIC
ICICLE_EMULATOR_DLL_STORAGE
#endif
std::unique_ptr<x86_64_emulator> create_x86_64_emulator();

View File

@@ -6,7 +6,7 @@ file(GLOB_RECURSE SRC_FILES CONFIGURE_DEPENDS
list(SORT SRC_FILES)
if(MOMO_BUILD_AS_LIBRARY)
if(SOGEN_BUILD_STATIC)
add_library(unicorn-emulator STATIC ${SRC_FILES})
else()
add_library(unicorn-emulator SHARED ${SRC_FILES})

View File

@@ -12,7 +12,7 @@
namespace unicorn
{
#if !MOMO_BUILD_AS_LIBRARY
#if !SOGEN_BUILD_STATIC
UNICORN_EMULATOR_DLL_STORAGE
#endif
std::unique_ptr<x86_64_emulator> create_x86_64_emulator();