emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.6k stars 3.28k forks source link

emcmake cannot find Boost #17039

Open mpconte opened 2 years ago

mpconte commented 2 years ago

Please include the following in your bug report:

Version of emscripten/emsdk: emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.11 (85c8b762740b866884088ba3832cb8b20e277873) clang version 15.0.0 (https://github.com/llvm/llvm-project 295d032762ad284068c72cc1904680a4db5e80d3) Target: wasm32-unknown-emscripten Thread model: posix InstalledDir: /root/emsdk/upstream/bin

When running standard cmake, the find_package command in my CMakeLists.txtseems to find all boost libraries fine, but the same CMakeLists.txt when run via emcmake cmake, I get the following error:

configure: cmake .. -DCMAKE_TOOLCHAIN_FILE=/root/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_CROSSCOMPILING_EMULATOR=/root/emsdk/node/14.18.2_64bit/bin/node;--experimental-wasm-threads
CMake Error at /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146 (message):
  Could NOT find Boost (missing: Boost_INCLUDE_DIR iostreams program_options
  filesystem)
Call Stack (most recent call first):
  /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:393 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake-3.16/Modules/FindBoost.cmake:2179 (find_package_handle_standard_args)
  CMakeLists.txt:55 (find_package)

-- Configuring incomplete, errors occurred!
See also "/root/sample/bin/CMakeFiles/CMakeOutput.log".
emcmake: error: 'cmake .. -DCMAKE_TOOLCHAIN_FILE=/root/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_CROSSCOMPILING_EMULATOR=/root/emsdk/node/14.18.2_64bit/bin/node;--experimental-wasm-threads' failed (returned 1)

As per the requirement, I have installed libboost-all-dev on my debian distro container first to ensure boost was installed on my machine

mpconte commented 2 years ago

I've discovered that my issue was resolved by excluding the COMPONENTS portion of the Boost find_package line in the CMakeLists.txt below (commented out). Seems like a strange workaround for what otherwised worked in the standard cmake (v 3.16.3)

cmake_minimum_required (VERSION 3.5)
project (SAMPLE)

# Use C++ 17 compiler standard
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBOOST_BIND_GLOBAL_PLACEHOLDERS")

# include support for modern C++ language features across the build
if (WIN32 OR MSVC)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4996 /wd4251")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4996")
    set(CMAKE_MODULE_PATH "${CMAKE_PREFIX_PATH}; C:/Program Files (x86)/GnuWin32")
elseif (ARM)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os -Wall -Wextra -Wno-unused-parameter -Wno-unknown-pragmas")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Os ")
else ()
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os -Wall -Wextra -Wno-unused-parameter -Wno-unknown-pragmas")
    set(CMAKE_CXX_FLAGS_DEBUG="-g -O0 -Wall -Wextra -Wno-unused-parameter -Wno-unknown-pragmas")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Os ")
    set(CMAKE_C_FLAGS_DEBUG="${CMAKE_C_FLAGS} -g -O0 ")
endif(WIN32 OR MSVC)

include_directories("${PROJECT_BINARY_DIR}")

# Find python and numpy
#find_package(Python3 COMPONENTS Interpreter Development NumPy REQUIRED )
#include_directories(${Python3_INCLUDE_DIRS})
#include_directories(${Python3_Numpy_INCLUDE_DIRS})

# Find pthread
find_library(PTHREAD_LIBRARIES pthread)

# we need to tell the linker to use the sysroot (although the compiler does this automatically).
if (CMAKE_SYSROOT)
    set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --sysroot=${CMAKE_SYSROOT} -lrt -lpthread -lresolv")
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --sysroot=${CMAKE_SYSROOT} -lrt -lpthread -lresolv")
endif()

# tell the installer where to put our output files. DESTDIR will be prefixed to this.
if (WIN32 OR MSVC)
    set (CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR})
    set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
    set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
endif(WIN32 OR MSVC)

# Find Boost
#Set(Boost_INSTALL_DIR ${CONAN_BOOST_ROOT})
# Set(Boost_NO_BOOST_CMAKE ON) # Enable to disable search for boost-cmake since boost-cmake wasn't used to build boost
if (WIN32 OR MSVC)
    find_package(Boost COMPONENTS unit_test_framework iostreams system serialization thread program_options python numpy filesystem REQUIRED )
elseif (arm)
    find_package(Boost 1.65.1 REQUIRED unit_test_framework iostreams system serialization thread program_options python numpy filesystem)
else ()
    find_package(Boost REQUIRED )# COMPONENTS iostreams program_options filesystem  )
endif(WIN32 OR MSVC)
include_directories(${Boost_INCLUDE_DIRS})
include_directories(${PROJECT_SOURCE_DIR})
include_directories(${PROJECT_SOURCE_DIR}/code)

# Now we invoke each of our project sub-directories (they must each have a CMakeLists.txt file).
add_subdirectory(code)
wizard-123 commented 3 months ago

I have the same problem,but only use find_package(Boost REQUIRED ),it's also not work