From 433e0523561c83f2c2f586a9534e5e12a2e06abb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20Ol=C3=A1h?= Date: Thu, 24 Sep 2020 16:22:25 +0000 Subject: [PATCH 1/2] Set the --shared-memory linker flag for Emscripten builds. This is only needed when building with WEBP support, which uses atomics, therefore the linker needs the --shared-memory flag. The flag cannot be added globally because not all executables link against libwebp. --- contrib/addtiffo/CMakeLists.txt | 6 ++++++ contrib/dbs/CMakeLists.txt | 11 +++++++++++ test/CMakeLists.txt | 15 +++++++++++++++ tools/CMakeLists.txt | 27 +++++++++++++++++++++++++++ 4 files changed, 59 insertions(+) diff --git a/contrib/addtiffo/CMakeLists.txt b/contrib/addtiffo/CMakeLists.txt index b7482635..45e733cd 100644 --- a/contrib/addtiffo/CMakeLists.txt +++ b/contrib/addtiffo/CMakeLists.txt @@ -32,3 +32,9 @@ include_directories(${PROJECT_SOURCE_DIR}/libtiff add_executable(addtiffo addtiffo.c tif_overview.c tif_ovrcache.c tif_ovrcache.h) target_link_libraries(addtiffo tiff port) + +if(WEBP_SUPPORT AND EMSCRIPTEN) + # Emscripten is pretty finnicky about linker flags. + # It needs --shared-memory if and only if atomics or bulk-memory is used. + target_link_options(addtiffo PUBLIC "-Wl,--shared-memory") +endif() diff --git a/contrib/dbs/CMakeLists.txt b/contrib/dbs/CMakeLists.txt index b2e809b2..ff3ce20c 100644 --- a/contrib/dbs/CMakeLists.txt +++ b/contrib/dbs/CMakeLists.txt @@ -41,3 +41,14 @@ target_link_libraries(tiff-rgb tiff port) add_subdirectory(xtiff) extra_dist(README) + +if(WEBP_SUPPORT AND EMSCRIPTEN) + # Emscripten is pretty finnicky about linker flags. + # It needs --shared-memory if and only if atomics or bulk-memory is used. + foreach(target tiff-bi + tiff-grayscale + tiff-palette + tiff-rgb) + target_link_options(${target} PUBLIC "-Wl,--shared-memory") + endforeach() +endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ff91f78b..e5d92dfe 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -220,6 +220,21 @@ target_link_libraries(defer_strile_writing tiff port) add_executable(testtypes testtypes.c) target_link_libraries(testtypes tiff port) +if(WEBP_SUPPORT AND EMSCRIPTEN) + # Emscripten is pretty finnicky about linker flags. + # It needs --shared-memory if and only if atomics or bulk-memory is used. + foreach(target ascii_tag + custom_dir + defer_strile_loading + defer_strile_writing + long_tag + rewrite + short_tag + strip_rw) + target_link_options(${target} PUBLIC "-Wl,--shared-memory") + endforeach() +endif() + set(TEST_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/output") file(MAKE_DIRECTORY "${TEST_OUTPUT}") diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 886d4549..ff2a1ddc 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -123,3 +123,30 @@ if(HAVE_OPENGL) install(TARGETS tiffgt RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}") endif() + +if(WEBP_SUPPORT AND EMSCRIPTEN) + # Emscripten is pretty finnicky about linker flags. + # It needs --shared-memory if and only if atomics or bulk-memory is used. + foreach(target fax2ps + fax2tiff + pal2rgb + ppm2tiff + raw2tiff + rgb2ycbcr + thumbnail + tiff2bw + tiff2pdf + tiff2ps + tiff2rgba + tiffcmp + tiffcp + tiffcrop + tiffdither + tiffdump + tiffinfo + tiffmedian + tiffset + tiffsplit) + target_link_options(${target} PUBLIC "-Wl,--shared-memory") + endforeach() +endif() From 2b9abce31bd445c66e8a311daf05a92e17b24df4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20Ol=C3=A1h?= Date: Thu, 24 Sep 2020 17:24:12 +0000 Subject: [PATCH 2/2] Also pass --shared-memory to raw_decode. This is needed when building for Emscripten with *both* WEBP and JPEG support. --- test/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e5d92dfe..5a1a7420 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -233,6 +233,9 @@ if(WEBP_SUPPORT AND EMSCRIPTEN) strip_rw) target_link_options(${target} PUBLIC "-Wl,--shared-memory") endforeach() + if(JPEG_SUPPORT) + target_link_options(raw_decode PUBLIC "-Wl,--shared-memory") + endif() endif() set(TEST_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/output")