Clarification: When I say "output" here, I'm not talking about the .o or .exe or whatever. I'm talking about the warnings and errors emitted during my failed attempt to find the Threads library.
I'm upgrading a project to support WASM using Emscripten with -s MEMORY64=1
. But when I enable it, find_package(Threads...)
fails.
I captured the --trace
output from build both with and without MEMORY64=1
, and determined that the difference is that a CHECK_C_SOURCE_COMPILES(...)
call fails when MEMORY64=1
is present.
I tried setting CHECK_C_SOURCE_COMPILES
to only compile, rather than compile and link, and found that it worked (only to fail later, turns out we really do need whatever library is missing).
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
So what I need is actually the linker output rather than the compiler output.
I also know that you can pass in a REGEX that is compared to the compiler/linker output, but all that does is change the definition of failure, it doesn't let you actually see any of it.
I tried creating a named capture group in the hopes that it would be exported as a cmake variable, but as the comment below details, that didn't work.
The compiler output can be found in your cmake/[build name]/CMakeFiles/CMakeConfigureLog.yaml
.
In this particular case I could see the linker error complaining about not being able to link a wasm32 file into a wasm64 output. I could also see from the previous command line options that the c compile was missing my -s MEMORY64=1
flag. The fix was to add it to CMAKE_C_FLAGS as well as the CMAKE_CXX_FLAGS. I was able to copy-paste the CXX line and remove the XXs.
And now it compiles. It still doesn't WORK (grr), but that's a different problem entirely.
The successful output looks remarkably like:
kind: "try_compile-v1"
backtrace:
- "/opt/homebrew/share/cmake/Modules/Internal/CheckSourceCompiles.cmake:108 (try_compile)"
- "/opt/homebrew/share/cmake/Modules/CheckCSourceCompiles.cmake:58 (cmake_check_source_compiles)"
- "/opt/homebrew/share/cmake/Modules/FindThreads.cmake:97 (CHECK_C_SOURCE_COMPILES)"
- "/opt/homebrew/share/cmake/Modules/FindThreads.cmake:163 (_threads_check_libc)"
- "Vendor/boost/CMakeLists.txt:52 (find_package)"
checks:
- "Performing Test CMAKE_HAVE_LIBC_PTHREAD"
directories:
source: "/Users/markstorer/projects/PSPDFKit/core/PSPDFCore-WASM/build/core-MinSizeRel/CMakeFiles/CMakeScratch/TryCompile-AyE6Bw"
binary: "/Users/markstorer/projects/PSPDFKit/core/PSPDFCore-WASM/build/core-MinSizeRel/CMakeFiles/CMakeScratch/TryCompile-AyE6Bw"
cmakeVariables:
CMAKE_CXX_COMPILER_CLANG_SCAN_DEPS: "CMAKE_CXX_COMPILER_CLANG_SCAN_DEPS-NOTFOUND"
CMAKE_C_FLAGS: " -sSUPPORT_LONGJMP=wasm -s MEMORY64=1"
CMAKE_EXE_LINKER_FLAGS: " --bind -sMODULARIZE=1 -sEXPORT_NAME=\"'PSPDFModuleInit'\" -s ALLOW_MEMORY_GROWTH=1 -s MEMORY64=1"
CMAKE_MODULE_PATH: "/Users/markstorer/projects/emsdk/upstream/emscripten/cmake/Modules;/Users/markstorer/projects/emsdk/upstream/emscripten/cmake/Modules;/Users/markstorer/projects/emsdk/upstream/emscripten/cmake/Modules;/Users/markstorer/projects/emsdk/upstream/emscripten/cmake/Modules;/Users/markstorer/projects/emsdk/upstream/emscripten/cmake/Modules;/Users/markstorer/projects/PSPDFKit/core/../cmake"
buildResult:
variable: "CMAKE_HAVE_LIBC_PTHREAD"
cached: true
stdout: |
Change Dir: '/Users/markstorer/projects/PSPDFKit/core/PSPDFCore-WASM/build/core-MinSizeRel/CMakeFiles/CMakeScratch/TryCompile-AyE6Bw'
Run Build Command(s): /opt/homebrew/bin/ninja -v cmTC_c057b
[1/2] /Users/markstorer/projects/emsdk/upstream/emscripten/emcc -DCMAKE_HAVE_LIBC_PTHREAD -sSUPPORT_LONGJMP=wasm -s MEMORY64=1 -MD -MT CMakeFiles/cmTC_c057b.dir/src.c.o -MF CMakeFiles/cmTC_c057b.dir/src.c.o.d -o CMakeFiles/cmTC_c057b.dir/src.c.o -c /Users/markstorer/projects/PSPDFKit/core/PSPDFCore-WASM/build/core-MinSizeRel/CMakeFiles/CMakeScratch/TryCompile-AyE6Bw/src.c
[2/2] : && /Users/markstorer/projects/emsdk/upstream/emscripten/emcc -sSUPPORT_LONGJMP=wasm -s MEMORY64=1 --bind -sMODULARIZE=1 -sEXPORT_NAME="'PSPDFModuleInit'" -s ALLOW_MEMORY_GROWTH=1 -s MEMORY64=1 CMakeFiles/cmTC_c057b.dir/src.c.o -o cmTC_c057b.js && :
Note that this was found on line 40 of a 1841 line long file. You may need to do some serious digging.