I've been trying to compile a huge C++ project, that uses CMake to build the project, to wasm. I have almost no experience with CMake files and I am fighting this battle for months now.
First I tried to install the webassembly compiler in my machine, following this link. I successfully installed it and ran the "hello world" project. But when a tried to build the project, changing the cmake
and make
commands to emcmake
and emmake
, but it began complains about missing dependency libraries (boost and lua).
Then I tried with a docker image, and I built the following Dockerfile
:
FROM trzeci/emscripten AS builder
RUN apt-get update && \
apt-get install -y build-essential \
cmake \
git-core \
libboost-atomic-dev \
libboost-chrono-dev \
libboost-date-time-dev \
libboost-filesystem-dev \
libboost-system-dev \
libboost-thread-dev \
libglew-dev \
liblua5.1-0-dev \
libncurses5-dev \
libopenal-dev \
libssl-dev \
libvorbis-dev \
mercurial \
zlib1g-dev && \
apt-get clean && apt-get autoclean
WORKDIR /
RUN hg clone -r stable-3.0 http://hg.icculus.org/icculus/physfs/
WORKDIR /physfs/build/
RUN cmake ..
RUN make -j$(nproc)
RUN make install
COPY ./src/ /otclient/src/.
COPY CMakeLists.txt /otclient/.
WORKDIR /otclient/build/
RUN emconfigure cmake -DCMAKE_CXX_LINK_FLAGS=-no-pie -DCMAKE_BUILD_TYPE=Release -DEMSCRIPTEN_GENERATE_BITCODE_STATIC_LIBRARIES=1 ..
RUN make -j$(nproc)
FROM trzeci/emscripten
RUN apt-get update; \
apt-get install -y \
libglew2.0 \
libopenal1; \
apt-get clean && apt-get autoclean
COPY --from=builder /otclient/build/otclient /otclient/bin/otclient
COPY ./data/ /otclient/data/.
COPY ./mods/ /otclient/mods/.
COPY ./modules/ /otclient/modules/.
COPY ./init.lua /otclient/.
WORKDIR /otclient
EXPOSE 8080:8080
RUN npm install http-server -g
CMD ["http-server", "./bin/", "-p", "8080"]
But the same error appears, missing libraries.
CMake Error at /opt/cmake/share/cmake-3.14/Modules/FindBoost.cmake:2147 (message):
Unable to find the requested Boost libraries.
Unable to find the Boost header files. Please set BOOST_ROOT to the root
directory containing Boost or BOOST_INCLUDEDIR to the directory containing
Boost's headers.
Call Stack (most recent call first):
src/framework/CMakeLists.txt:205 (find_package)
CMakeLists.txt:36 (include)
CMake Error at /opt/cmake/share/cmake-3.14/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find Lua (missing: LUA_LIBRARY LUA_INCLUDE_DIR)
Call Stack (most recent call first):
/opt/cmake/share/cmake-3.14/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
src/framework/cmake/FindLua.cmake:17 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
src/framework/CMakeLists.txt:217 (find_package)
CMakeLists.txt:36 (include)
I already tried to follow this and this links and nothing. Someone with experience with CMake/WebAssembly could help me, please?
The project link is this. The CMake files are too big to post here...
Edit
Logs from after adding -DBoost_DEBUG=ON
option:
Step 12/24 : RUN emconfigure cmake -DCMAKE_CXX_LINK_FLAGS=-no-pie -DCMAKE_BUILD_TYPE=Release -DEMSCRIPTEN_GENERATE_BITCODE_STATIC_LIBRARIES=1 -DBoost_DEBUG=ON ..
---> Running in e0ea96547712
CMake Error at CMakeLists.txt:21 (set):
set given invalid arguments for CACHE mode.
-- Setting compilation target to WASM
CMake Warning (dev) at src/framework/CMakeLists.txt:152 (set):
implicitly converting 'Git commit string (intended for releases)' to
'STRING' type.
Call Stack (most recent call first):
CMakeLists.txt:36 (include)
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at src/framework/CMakeLists.txt:153 (set):
implicitly converting 'Git revision string (intended for releases)' to
'STRING' type.
Call Stack (most recent call first):
CMakeLists.txt:36 (include)
This warning is for project developers. Use -Wno-dev to suppress it.
-- Performing Test COMPILER_KNOWS_CXX11
-- Performing Test COMPILER_KNOWS_CXX11 - Success
-- Performing Test COMPILER_KNOWS_STDLIB
-- Performing Test COMPILER_KNOWS_STDLIB - Success
-- Link to static libraries: ON
-- Build type: Release
-- Build commit: devel
-- Build revision: 0
-- [ /opt/cmake/share/cmake-3.14/Modules/FindBoost.cmake:1196 ] _boost_TEST_VERSIONS = 1.70.0;1.70;1.69.0;1.69;1.68.0;1.68;1.67.0;1.67;1.66.0;1.66;1.65.1;1.65.0;1.65;1.64.0;1.64;1.63.0;1.63;1.62.0;1.62;1.61.0;1.61;1.60.0;1.60;1.59.0;1.59;1.58.0;1.58;1.57.0;1.57;1.56.0;1.56;1.55.0;1.55;1.54.0;1.54;1.53.0;1.53;1.52.0;1.52;1.51.0;1.51;1.50.0;1.50;1.49.0;1.49;1.48.0;1.48
-- [ /opt/cmake/share/cmake-3.14/Modules/FindBoost.cmake:1198 ] Boost_USE_MULTITHREADED = ON
-- [ /opt/cmake/share/cmake-3.14/Modules/FindBoost.cmake:1200 ] Boost_USE_STATIC_LIBS = ON
-- [ /opt/cmake/share/cmake-3.14/Modules/FindBoost.cmake:1202 ] Boost_USE_STATIC_RUNTIME =
-- [ /opt/cmake/share/cmake-3.14/Modules/FindBoost.cmake:1204 ] Boost_ADDITIONAL_VERSIONS =
-- [ /opt/cmake/share/cmake-3.14/Modules/FindBoost.cmake:1206 ] Boost_NO_SYSTEM_PATHS =
-- [ /opt/cmake/share/cmake-3.14/Modules/FindBoost.cmake:1274 ] Declared as CMake or Environmental Variables:
-- [ /opt/cmake/share/cmake-3.14/Modules/FindBoost.cmake:1276 ] BOOST_ROOT =
-- [ /opt/cmake/share/cmake-3.14/Modules/FindBoost.cmake:1278 ] BOOST_INCLUDEDIR =
-- [ /opt/cmake/share/cmake-3.14/Modules/FindBoost.cmake:1280 ] BOOST_LIBRARYDIR =
-- [ /opt/cmake/share/cmake-3.14/Modules/FindBoost.cmake:1282 ] _boost_TEST_VERSIONS = 1.70.0;1.70;1.69.0;1.69;1.68.0;1.68;1.67.0;1.67;1.66.0;1.66;1.65.1;1.65.0;1.65;1.64.0;1.64;1.63.0;1.63;1.62.0;1.62;1.61.0;1.61;1.60.0;1.60;1.59.0;1.59;1.58.0;1.58;1.57.0;1.57;1.56.0;1.56;1.55.0;1.55;1.54.0;1.54;1.53.0;1.53;1.52.0;1.52;1.51.0;1.51;1.50.0;1.50;1.49.0;1.49;1.48.0;1.48
-- [ /opt/cmake/share/cmake-3.14/Modules/FindBoost.cmake:1357 ] Include debugging info:
-- [ /opt/cmake/share/cmake-3.14/Modules/FindBoost.cmake:1359 ] _boost_INCLUDE_SEARCH_DIRS = PATHS;C:/boost/include;C:/boost;/sw/local/include
-- [ /opt/cmake/share/cmake-3.14/Modules/FindBoost.cmake:1361 ] _boost_PATH_SUFFIXES = boost-1_70_0;boost_1_70_0;boost/boost-1_70_0;boost/boost_1_70_0;boost-1_70;boost_1_70;boost/boost-1_70;boost/boost_1_70;boost-1_69_0;boost_1_69_0;boost/boost-1_69_0;boost/boost_1_69_0;boost-1_69;boost_1_69;boost/boost-1_69;boost/boost_1_69;boost-1_68_0;boost_1_68_0;boost/boost-1_68_0;boost/boost_1_68_0;boost-1_68;boost_1_68;boost/boost-1_68;boost/boost_1_68;boost-1_67_0;boost_1_67_0;boost/boost-1_67_0;boost/boost_1_67_0;boost-1_67;boost_1_67;boost/boost-1_67;boost/boost_1_67;boost-1_66_0;boost_1_66_0;boost/boost-1_66_0;boost/boost_1_66_0;boost-1_66;boost_1_66;boost/boost-1_66;boost/boost_1_66;boost-1_65_1;boost_1_65_1;boost/boost-1_65_1;boost/boost_1_65_1;boost-1_65_0;boost_1_65_0;boost/boost-1_65_0;boost/boost_1_65_0;boost-1_65;boost_1_65;boost/boost-1_65;boost/boost_1_65;boost-1_64_0;boost_1_64_0;boost/boost-1_64_0;boost/boost_1_64_0;boost-1_64;boost_1_64;boost/boost-1_64;boost/boost_1_64;boost-1_63_0;boost_1_63_0;boost/boost-1_63_0;boost/boost_1_63_0;boost-1_63;boost_1_63;boost/boost-1_63;boost/boost_1_63;boost-1_62_0;boost_1_62_0;boost/boost-1_62_0;boost/boost_1_62_0;boost-1_62;boost_1_62;boost/boost-1_62;boost/boost_1_62;boost-1_61_0;boost_1_61_0;boost/boost-1_61_0;boost/boost_1_61_0;boost-1_61;boost_1_61;boost/boost-1_61;boost/boost_1_61;boost-1_60_0;boost_1_60_0;boost/boost-1_60_0;boost/boost_1_60_0;boost-1_60;boost_1_60;boost/boost-1_60;boost/boost_1_60;boost-1_59_0;boost_1_59_0;boost/boost-1_59_0;boost/boost_1_59_0;boost-1_59;boost_1_59;boost/boost-1_59;boost/boost_1_59;boost-1_58_0;boost_1_58_0;boost/boost-1_58_0;boost/boost_1_58_0;boost-1_58;boost_1_58;boost/boost-1_58;boost/boost_1_58;boost-1_57_0;boost_1_57_0;boost/boost-1_57_0;boost/boost_1_57_0;boost-1_57;boost_1_57;boost/boost-1_57;boost/boost_1_57;boost-1_56_0;boost_1_56_0;boost/boost-1_56_0;boost/boost_1_56_0;boost-1_56;boost_1_56;boost/boost-1_56;boost/boost_1_56;boost-1_55_0;boost_1_55_0;boost/boost-1_55_0;boost/boost_1_55_0;boost-1_55;boost_1_55;boost/boost-1_55;boost/boost_1_55;boost-1_54_0;boost_1_54_0;boost/boost-1_54_0;boost/boost_1_54_0;boost-1_54;boost_1_54;boost/boost-1_54;boost/boost_1_54;boost-1_53_0;boost_1_53_0;boost/boost-1_53_0;boost/boost_1_53_0;boost-1_53;boost_1_53;boost/boost-1_53;boost/boost_1_53;boost-1_52_0;boost_1_52_0;boost/boost-1_52_0;boost/boost_1_52_0;boost-1_52;boost_1_52;boost/boost-1_52;boost/boost_1_52;boost-1_51_0;boost_1_51_0;boost/boost-1_51_0;boost/boost_1_51_0;boost-1_51;boost_1_51;boost/boost-1_51;boost/boost_1_51;boost-1_50_0;boost_1_50_0;boost/boost-1_50_0;boost/boost_1_50_0;boost-1_50;boost_1_50;boost/boost-1_50;boost/boost_1_50;boost-1_49_0;boost_1_49_0;boost/boost-1_49_0;boost/boost_1_49_0;boost-1_49;boost_1_49;boost/boost-1_49;boost/boost_1_49;boost-1_48_0;boost_1_48_0;boost/boost-1_48_0;boost/boost_1_48_0;boost-1_48;boost_1_48;boost/boost-1_48;boost/boost_1_48
-- [ /opt/cmake/share/cmake-3.14/Modules/FindBoost.cmake:1462 ] Boost_LIB_PREFIX =
-- [ /opt/cmake/share/cmake-3.14/Modules/FindBoost.cmake:1464 ] Boost_NAMESPACE = boost
-- [ /opt/cmake/share/cmake-3.14/Modules/FindBoost.cmake:1499 ] guessed _boost_COMPILER = -clang60
-- [ /opt/cmake/share/cmake-3.14/Modules/FindBoost.cmake:1509 ] _boost_MULTITHREADED = -mt
-- [ /opt/cmake/share/cmake-3.14/Modules/FindBoost.cmake:1593 ] _boost_RELEASE_ABI_TAG = -
-- [ /opt/cmake/share/cmake-3.14/Modules/FindBoost.cmake:1595 ] _boost_DEBUG_ABI_TAG = -d
-- [ /opt/cmake/share/cmake-3.14/Modules/FindBoost.cmake:1658 ] _boost_LIBRARY_SEARCH_DIRS_RELEASE = Boost_INCLUDE_DIR-NOTFOUND/lib;Boost_INCLUDE_DIR-NOTFOUND/../lib;Boost_INCLUDE_DIR-NOTFOUND/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib_boost_LIBRARY_SEARCH_DIRS_DEBUG = Boost_INCLUDE_DIR-NOTFOUND/lib;Boost_INCLUDE_DIR-NOTFOUND/../lib;Boost_INCLUDE_DIR-NOTFOUND/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE
-- [ /opt/cmake/share/cmake-3.14/Modules/FindBoost.cmake:1852 ] Searching for SYSTEM_LIBRARY_RELEASE: boost_system-clang60-mt-;boost_system-clang60-mt;boost_system-clang60-mt;boost_system-mt-;boost_system-mt;boost_system-mt;boost_system-mt;boost_system
-- [ /opt/cmake/share/cmake-3.14/Modules/FindBoost.cmake:1909 ] Searching for SYSTEM_LIBRARY_DEBUG: boost_system-clang60-mt-d-;boost_system-clang60-mt-d;boost_system-clang60-mt-d;boost_system-mt-d-;boost_system-mt-d;boost_system-mt-d;boost_system-mt;boost_system
-- [ /opt/cmake/share/cmake-3.14/Modules/FindBoost.cmake:1852 ] Searching for THREAD_LIBRARY_RELEASE: boost_thread-clang60-mt-;boost_thread-clang60-mt;boost_thread-clang60-mt;boost_thread-mt-;boost_thread-mt;boost_thread-mt;boost_thread-mt;boost_thread
-- [ /opt/cmake/share/cmake-3.14/Modules/FindBoost.cmake:1909 ] Searching for THREAD_LIBRARY_DEBUG: boost_thread-clang60-mt-d-;boost_thread-clang60-mt-d;boost_thread-clang60-mt-d;boost_thread-mt-d-;boost_thread-mt-d;boost_thread-mt-d;boost_thread-mt;boost_thread
-- [ /opt/cmake/share/cmake-3.14/Modules/FindBoost.cmake:1852 ] Searching for FILESYSTEM_LIBRARY_RELEASE: boost_filesystem-clang60-mt-;boost_filesystem-clang60-mt;boost_filesystem-clang60-mt;boost_filesystem-mt-;boost_filesystem-mt;boost_filesystem-mt;boost_filesystem-mt;boost_filesystem
-- [ /opt/cmake/share/cmake-3.14/Modules/FindBoost.cmake:1909 ] Searching for FILESYSTEM_LIBRARY_DEBUG: boost_filesystem-clang60-mt-d-;boost_filesystem-clang60-mt-d;boost_filesystem-clang60-mt-d;boost_filesystem-mt-d-;boost_filesystem-mt-d;boost_filesystem-mt-d;boost_filesystem-mt;boost_filesystem
CMake Error at /opt/cmake/share/cmake-3.14/Modules/FindBoost.cmake:2147 (message):
Unable to find the requested Boost libraries.
Unable to find the Boost header files. Please set BOOST_ROOT to the root
directory containing Boost or BOOST_INCLUDEDIR to the directory containing
Boost's headers.
Call Stack (most recent call first):
src/framework/CMakeLists.txt:205 (find_package)
CMakeLists.txt:36 (include)
CMake Error at /opt/cmake/share/cmake-3.14/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find Lua (missing: LUA_LIBRARY LUA_INCLUDE_DIR)
Call Stack (most recent call first):
/opt/cmake/share/cmake-3.14/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
src/framework/cmake/FindLua.cmake:17 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
src/framework/CMakeLists.txt:217 (find_package)
CMakeLists.txt:36 (include)
-- Configuring incomplete, errors occurred!
See also "/otclient/build/CMakeFiles/CMakeOutput.log".
The command '/bin/sh -c emconfigure cmake -DCMAKE_CXX_LINK_FLAGS=-no-pie -DCMAKE_BUILD_TYPE=Release -DEMSCRIPTEN_GENERATE_BITCODE_STATIC_LIBRARIES=1 -DBoost_DEBUG=ON ..' returned a non-zero code: 1
I ran into the same problem, and I believe that it is related to this Emscripten issue:
https://github.com/emscripten-core/emscripten/issues/10078
FindBoost.cmake
calls find_path()
to find the location of boost/config.hpp
in a number of alternative paths (specified in HINTS
, which is synonymous with PATHS)
Apparently there is currently a bug in Emscripten (I am using version 1.39.6), in that it does not respect the PATHS
/HINTS
variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With