From 3ff29067829b1e47a43a9b1b7d4ba1d491d34e14 Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Mon, 14 Feb 2022 11:00:16 -0800 Subject: [PATCH 1/9] CMake Toolkit: Shared Library as Side Module Enable support to build shared libraries as side modules. This should simplify builds with CMake that currently have to reside to manual link steps. --- cmake/Modules/Platform/Emscripten.cmake | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmake/Modules/Platform/Emscripten.cmake b/cmake/Modules/Platform/Emscripten.cmake index cf22990a45005..a5f8775c29c42 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 "-s SIDE_MODULE=1") # instead of -shared +set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-s SIDE_MODULE=1") # instead of -shared +set(CMAKE_STRIP FALSE) # not supported # Advertise Emscripten as a 32-bit platform (as opposed to # CMAKE_SYSTEM_PROCESSOR=x86_64 for 64-bit platform), since some projects (e.g. From 82733b2a9b1c2da3a51582798f4bf756361948c6 Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Mon, 14 Feb 2022 16:48:11 -0800 Subject: [PATCH 2/9] Update cmake/Modules/Platform/Emscripten.cmake --- cmake/Modules/Platform/Emscripten.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/Modules/Platform/Emscripten.cmake b/cmake/Modules/Platform/Emscripten.cmake index a5f8775c29c42..9486b618aeb3f 100644 --- a/cmake/Modules/Platform/Emscripten.cmake +++ b/cmake/Modules/Platform/Emscripten.cmake @@ -24,6 +24,7 @@ set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE) set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-s SIDE_MODULE=1") # instead of -shared set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-s SIDE_MODULE=1") # instead of -shared set(CMAKE_STRIP FALSE) # not supported +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. From d3aa7f347609e0eef8b4bb76a476e4b58e9fe548 Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Mon, 14 Feb 2022 23:36:00 -0800 Subject: [PATCH 3/9] Update Tests --- tests/test_core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 4f103cb72487a0eff5e047b4bf14525ebb65691c Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Wed, 16 Feb 2022 08:36:01 -0800 Subject: [PATCH 4/9] `-s SIDE_MODULE=1` -> `-sSIDE_MODULE` --- cmake/Modules/Platform/Emscripten.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/Modules/Platform/Emscripten.cmake b/cmake/Modules/Platform/Emscripten.cmake index 9486b618aeb3f..c0fcdb32970c1 100644 --- a/cmake/Modules/Platform/Emscripten.cmake +++ b/cmake/Modules/Platform/Emscripten.cmake @@ -21,8 +21,8 @@ set(CMAKE_CROSSCOMPILING TRUE) # shared library (side module) support set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE) -set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-s SIDE_MODULE=1") # instead of -shared -set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-s SIDE_MODULE=1") # instead of -shared +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(CMAKE_STRIP FALSE) # not supported set(BUILD_SHARED_LIBS OFF) # default to static libs, even if we allow shared ones From 23cb03bc34ca22e2982c10100d62f8c9a726a0c8 Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Wed, 16 Feb 2022 08:58:17 -0800 Subject: [PATCH 5/9] other.test_cmake_* / cpp_lib: update defaults (keep static) --- tests/cmake/cpp_lib/CMakeLists.txt | 2 +- tests/test_other.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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_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', []), }) From c442b91cc3f41530c803a71426b1dba49a210e0f Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Wed, 16 Feb 2022 15:55:23 -0800 Subject: [PATCH 6/9] Set CMAKE_STRIP --- cmake/Modules/Platform/Emscripten.cmake | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmake/Modules/Platform/Emscripten.cmake b/cmake/Modules/Platform/Emscripten.cmake index c0fcdb32970c1..79015a4399d00 100644 --- a/cmake/Modules/Platform/Emscripten.cmake +++ b/cmake/Modules/Platform/Emscripten.cmake @@ -23,7 +23,6 @@ set(CMAKE_CROSSCOMPILING TRUE) 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(CMAKE_STRIP FALSE) # not supported 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 @@ -108,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}/llvm-strip" CACHE FILEPATH "Emscripten compatible strip command")) +endif() + if ("${CMAKE_C_COMPILER_AR}" STREQUAL "") set(CMAKE_C_COMPILER_AR "${CMAKE_AR}" CACHE FILEPATH "Emscripten ar") endif() From e49a8dc4dac295836c20edd8b5b7599ad2a1d2f6 Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Fri, 4 Mar 2022 14:31:08 -0800 Subject: [PATCH 7/9] fix: extra ) --- cmake/Modules/Platform/Emscripten.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Modules/Platform/Emscripten.cmake b/cmake/Modules/Platform/Emscripten.cmake index 79015a4399d00..a92044428ce6b 100644 --- a/cmake/Modules/Platform/Emscripten.cmake +++ b/cmake/Modules/Platform/Emscripten.cmake @@ -108,7 +108,7 @@ if ("${CMAKE_RANLIB}" STREQUAL "") endif() if ("${CMAKE_STRIP}" STREQUAL "") - set(CMAKE_STRIP "${EMSCRIPTEN_ROOT_PATH}/llvm-strip" CACHE FILEPATH "Emscripten compatible strip command")) + set(CMAKE_STRIP "${EMSCRIPTEN_ROOT_PATH}/llvm-strip" CACHE FILEPATH "Emscripten compatible strip command") endif() if ("${CMAKE_C_COMPILER_AR}" STREQUAL "") From 22969763d5e54541a80a7a7b1dd6ca1cc1a7f5ab Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Fri, 4 Mar 2022 14:34:37 -0800 Subject: [PATCH 8/9] CMAKE_STRIP: Use any `llvm-strip` For now, hoping/assuming the first tool found in `PATH` will be compatible. --- cmake/Modules/Platform/Emscripten.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake/Modules/Platform/Emscripten.cmake b/cmake/Modules/Platform/Emscripten.cmake index a92044428ce6b..c5d96c594f591 100644 --- a/cmake/Modules/Platform/Emscripten.cmake +++ b/cmake/Modules/Platform/Emscripten.cmake @@ -108,7 +108,8 @@ if ("${CMAKE_RANLIB}" STREQUAL "") endif() if ("${CMAKE_STRIP}" STREQUAL "") - set(CMAKE_STRIP "${EMSCRIPTEN_ROOT_PATH}/llvm-strip" CACHE FILEPATH "Emscripten compatible strip command") + # see https://github.com/emscripten-core/emscripten/issues/16430 + set(CMAKE_STRIP "llvm-strip" CACHE FILEPATH "Emscripten compatible strip command") endif() if ("${CMAKE_C_COMPILER_AR}" STREQUAL "") From afb04392f91f0feff0b0b4d2f6a3bc9db4082833 Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Wed, 20 Apr 2022 17:19:27 -0700 Subject: [PATCH 9/9] CMAKE_STRIP: Use `emstrip` --- cmake/Modules/Platform/Emscripten.cmake | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmake/Modules/Platform/Emscripten.cmake b/cmake/Modules/Platform/Emscripten.cmake index c5d96c594f591..bc10c7c7512ad 100644 --- a/cmake/Modules/Platform/Emscripten.cmake +++ b/cmake/Modules/Platform/Emscripten.cmake @@ -108,8 +108,7 @@ if ("${CMAKE_RANLIB}" STREQUAL "") endif() if ("${CMAKE_STRIP}" STREQUAL "") - # see https://github.com/emscripten-core/emscripten/issues/16430 - set(CMAKE_STRIP "llvm-strip" CACHE FILEPATH "Emscripten compatible strip command") + set(CMAKE_STRIP "${EMSCRIPTEN_ROOT_PATH}/emstrip${EMCC_SUFFIX}" CACHE FILEPATH "Emscripten strip") endif() if ("${CMAKE_C_COMPILER_AR}" STREQUAL "")