diff --git a/cmake/Modules/Platform/Emscripten.cmake b/cmake/Modules/Platform/Emscripten.cmake index cf22990a45005..bc10c7c7512ad 100644 --- a/cmake/Modules/Platform/Emscripten.cmake +++ b/cmake/Modules/Platform/Emscripten.cmake @@ -18,7 +18,12 @@ set(CMAKE_SYSTEM_NAME Emscripten) set(CMAKE_SYSTEM_VERSION 1) set(CMAKE_CROSSCOMPILING TRUE) -set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE) + +# shared library (side module) support +set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE) +set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-sSIDE_MODULE") # instead of -shared +set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-sSIDE_MODULE") # instead of -shared +set(BUILD_SHARED_LIBS OFF) # default to static libs, even if we allow shared ones # Advertise Emscripten as a 32-bit platform (as opposed to # CMAKE_SYSTEM_PROCESSOR=x86_64 for 64-bit platform), since some projects (e.g. @@ -102,6 +107,10 @@ if ("${CMAKE_RANLIB}" STREQUAL "") set(CMAKE_RANLIB "${EMSCRIPTEN_ROOT_PATH}/emranlib${EMCC_SUFFIX}" CACHE FILEPATH "Emscripten ranlib") endif() +if ("${CMAKE_STRIP}" STREQUAL "") + set(CMAKE_STRIP "${EMSCRIPTEN_ROOT_PATH}/emstrip${EMCC_SUFFIX}" CACHE FILEPATH "Emscripten strip") +endif() + if ("${CMAKE_C_COMPILER_AR}" STREQUAL "") set(CMAKE_C_COMPILER_AR "${CMAKE_AR}" CACHE FILEPATH "Emscripten ar") endif() diff --git a/tests/cmake/cpp_lib/CMakeLists.txt b/tests/cmake/cpp_lib/CMakeLists.txt index 04e12faabf7dd..370eb8b918261 100644 --- a/tests/cmake/cpp_lib/CMakeLists.txt +++ b/tests/cmake/cpp_lib/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.0) project(cpp_library) -set(CPP_LIBRARY_TYPE "SHARED" CACHE STRING "Library type to build") +set(CPP_LIBRARY_TYPE "STATIC" CACHE STRING "Library type to build") set_property(CACHE CPP_LIBRARY_TYPE PROPERTY STRINGS STATIC SHARED) add_library(cpp_lib ${CPP_LIBRARY_TYPE} lib.cpp) diff --git a/tests/test_core.py b/tests/test_core.py index 6f145486a0f94..7b36964ade3a9 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -6644,7 +6644,7 @@ def line_splitter(data): Path('codec/CMakeFiles/j2k_to_image.dir/convert.c.o'), Path('codec/CMakeFiles/j2k_to_image.dir/__/common/color.c.o'), Path('bin/libopenjpeg.a')], - configure=['cmake', '.'], + configure=['cmake', '.', '-DBUILD_SHARED_LIBS=OFF'], # configure_args=['--enable-tiff=no', '--enable-jp3d=no', '--enable-png=no'], make_args=[]) # no -j 2, since parallel builds can fail diff --git a/tests/test_other.py b/tests/test_other.py index 4f25a4619a41b..b3406449f35be 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -619,7 +619,7 @@ def test_emsize(self): 'js': ('target_js', 'test_cmake.js', ['-DCMAKE_BUILD_TYPE=Debug']), 'html': ('target_html', 'hello_world_gles.html', ['-DCMAKE_BUILD_TYPE=Release']), 'library': ('target_library', 'libtest_cmake.a', ['-DCMAKE_BUILD_TYPE=MinSizeRel']), - 'static_cpp': ('target_library', 'libtest_cmake.a', ['-DCMAKE_BUILD_TYPE=RelWithDebInfo', '-DCPP_LIBRARY_TYPE=STATIC']), + 'shared_cpp': ('target_library', 'libtest_cmake.so', ['-DCMAKE_BUILD_TYPE=RelWithDebInfo', '-DBUILD_SHARED_LIBS=ON', '-DCPP_LIBRARY_TYPE=SHARED']), 'stdproperty': ('stdproperty', 'helloworld.js', []), 'post_build': ('post_build', 'hello.js', []), })