emscripten-core / emscripten-core/emscripten

emcmake breaks CMAKE_PREFIX_PATH

Open
#19,243 7 comments 2 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

If I use emcmake, `CMAKE_PREFIX_PATH` breaks. For example, the following CMake file:

```cmake
cmake_minimum_required(VERSION 3.15...3.26)

project(CMCheck LANGUAGES CXX)

list(APPEND CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}/pre")

find_package(CheckMe CONFIG REQUIRED)
```

And the following file in `pre/CheckMeConfig.cmake`:

```cmake
message(STATUS "Found correctly")
```

Produces the expected message if run on the host CMake, but when run through emcmake, it produces:

```console
$ emcmake cmake -S . -B build
configure: cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_CROSSCOMPILING_EMULATOR=/emsdk/node/15.14.0_64bit/bin/node;--experimental-wasm-bulk-memory;--experimental-wasm-threads
CMake Error at CMakeLists.txt:7 (find_package):
Could not find a package configuration file provided by "CheckMe" with any
of the following names:

CheckMeConfig.cmake
checkme-config.cmake

Add the installation prefix of "CheckMe" to CMAKE_PREFIX_PATH or set
"CheckMe_DIR" to a directory containing one of the above files. If
"CheckMe" provides a separate development package or SDK, be sure it has
been installed.

-- Configuring incomplete, errors occurred
```

Is this expected? A bug with CMake I should report there, like faulty platform logic? Setting `CheckMe_DIR` works.

**Version of emscripten/emsdk:**

```
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.32 (eab98adf462c39f3c31d348331c4830bcaa36949)
clang version 17.0.0 (https://github.com/llvm/llvm-project df82394e7a2d06506718cafa347bf7827c79fc4f)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /emsdk/upstream/bin
```

`CMAKE_FIND_USE_CMAKE_PATH` and `CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH` are not set to false.

(This is breaking the CMake based Python build backends scikit-build-core in Pyodide, which discovers the header only pybind11 via this method, FYI)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.