From d4b32b8389dbff9a33510da3cd5dd2449544b998 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Fri, 22 May 2026 11:17:15 -0700 Subject: [PATCH] Use cmake standard `BUILD_SHARED_LIBS` setting See https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html I'm not sure why we made up our own setting here rather than using the standard one. --- CMakeLists.txt | 16 ++++++++-------- src/binaryen-c.h | 4 +++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 109d5c8f784..ebf2b85cd0d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,11 +52,11 @@ if(EMSCRIPTEN) set(BUILD_LLVM_DWARF OFF) endif() -option(BUILD_STATIC_LIB "Build as a static library" OFF) +option(BUILD_SHARED_LIBS "Build using shared libraries" ON) if(MSVC OR EMSCRIPTEN) # We don't have dllexport declarations set up for Windows yet. # With emscripten we require a static library to create binaryen_js correctly. - set(BUILD_STATIC_LIB ON) + set(BUILD_SHARED_LIBS OFF) endif() # Advised to turn on when statically linking against musl libc (e.g., in the @@ -451,18 +451,18 @@ else() # MSVC endif() # Declare libbinaryen +# This will be either be STATIC or SHARED depending on BUILD_SHARED_LIBS +add_library(binaryen) -if(BUILD_STATIC_LIB) - message(STATUS "Building libbinaryen as statically linked library.") - add_library(binaryen STATIC) - add_definitions(-DBUILD_STATIC_LIBRARY) -else() +if(BUILD_SHARED_LIBS) + add_definitions(-DBUILD_SHARED_LIBS) message(STATUS "Building libbinaryen as shared library.") - add_library(binaryen SHARED) if(CMAKE_SYSTEM_NAME STREQUAL "Linux") # Disable interposition and resolve Binaryen symbols locally. add_link_flag("-Bsymbolic") endif() +else() + message(STATUS "Building libbinaryen as statically linked library.") endif() target_link_libraries(binaryen PUBLIC Threads::Threads) binaryen_setup_rpath(binaryen) diff --git a/src/binaryen-c.h b/src/binaryen-c.h index fbde9d2a08d..f798496ad1c 100644 --- a/src/binaryen-c.h +++ b/src/binaryen-c.h @@ -58,7 +58,9 @@ #if defined(__EMSCRIPTEN__) #include #define BINARYEN_API EMSCRIPTEN_KEEPALIVE -#elif defined(_MSC_VER) && !defined(BUILD_STATIC_LIBRARY) +#elif defined(_MSC_VER) && defined(BUILD_SHARED_LIBS) +// TODO: This is not yet used since we disabled BUILD_SHARED_LIBS under +// _MSC_VER in CMakeLists.txt #define BINARYEN_API __declspec(dllexport) #else #define BINARYEN_API