emscripten-core / emscripten-core/emscripten

EMCMAKE is unable to find_package with a working CMakeLists.txt and an installed SDL2 library

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

Description

I have setup a SDL2 project that I want to compile to multiple platforms with CMake. The CMakeLists.txt works, for both the MSVC compiler and also for MinGW. Both the VC and MinGW development files of SDL2 are installed and can be found correctly.

Only Emscripten is having issues, even though it appears to be using MinGW under the hood as well. The message "blablabla from sdl2-config.cmake" is proof that my sdl2-config.cmake file is being found and executed by CMake - at least in the regular build. The variable SDL2_DIR is also correctly set to the MinGW development files. And still, Emscripten cannot find them for whatever reason.

**Version of emscripten/emsdk:**
```
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.0 (8e1e305519e1027726a48861a1fec5662f7e18a2)
clang version 14.0.0 (https://github.com/llvm/llvm-project 1a929525e86a20d0b3455a400d0dbed40b325a13)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: C:\System\emsdk\upstream\bin
```

**Failing command line in full:**
```
E:\Code\sdl2_test\build
λ cmake .. -G "MinGW Makefiles"
-- The C compiler identification is GNU 11.2.0
-- The CXX compiler identification is GNU 11.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/ProgramData/chocolatey/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/ProgramData/chocolatey/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- blablabla from sdl2-config.cmake
-- E:/Code/SDL2-2.0.18-devel/SDL2-2.0.18-devel-mingw/x86_64-w64-mingw32/include/SDL2
-- E:/Code/SDL2-2.0.18-devel/SDL2-2.0.18-devel-mingw/x86_64-w64-mingw32/lib/libSDL2main.aE:/Code/SDL2-2.0.18-devel/SDL2-2.0.18-devel-mingw/x86_64-w64-mingw32/lib/libSDL2.dll.a
-- Configuring done
-- Generating done
-- Build files have been written to: E:/Code/sdl2_test/build

E:\Code\sdl2_test\build
λ make
[ 50%] Building CXX object CMakeFiles/sdl2_test.dir/main.cpp.obj
[100%] Linking CXX executable sdl2_test.exe
[100%] Built target sdl2_test

E:\Code\sdl2_test\build
λ REM Success! Clearing CMake Cache at this point, starting Emscripten build:

E:\Code\sdl2_test\build
λ emcmake cmake ..
configure: cmake .. -DCMAKE_TOOLCHAIN_FILE=C:\System\emsdk\upstream\emscripten\cmake\Modules\Platform\Emscripten.cmake -DCMAKE_CROSSCOMPILING_EMULATOR=C:/System/emsdk/node/14.15.5_64bit/bin/node.exe;--experimental-wasm-threads -G "MinGW Makefiles"
CMake Error at CMakeLists.txt:17 (find_package):
By not providing "FindSDL2.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "SDL2", but
CMake did not find one.

Could not find a package configuration file provided by "SDL2" with any of
the following names:

SDL2Config.cmake
sdl2-config.cmake

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

-- Configuring incomplete, errors occurred!
See also "E:/Code/sdl2_test/build/CMakeFiles/CMakeOutput.log".
emcmake: error: 'cmake .. -DCMAKE_TOOLCHAIN_FILE=C:\System\emsdk\upstream\emscripten\cmake\Modules\Platform\Emscripten.cmake -DCMAKE_CROSSCOMPILING_EMULATOR=C:/System/emsdk/node/14.15.5_64bit/bin/node.exe;--experimental-wasm-threads -G "MinGW Makefiles"' failed (returned 1)

E:\Code\sdl2_test\build
λ cat E:/Code/sdl2_test/build/CMakeFiles/CMakeOutput.log
The target system is: Emscripten - 1 - x86
The host system is: Windows - 10.0.19043 - AMD64
```

**Copy of CMakeLists.txt file**
```
cmake_minimum_required(VERSION 3.7)

project(sdl2_test)

find_package(SDL2 REQUIRED)

add_executable(sdl2_test main.cpp)

target_link_libraries(sdl2_test PUBLIC ${SDL2_LIBRARIES})

target_include_directories(sdl2_test PUBLIC ${SDL2_INCLUDE_DIRS})

if(EMSCRIPTEN)
set(CMAKE_EXECUTABLE_SUFFIX ".html")

set(EMSCRIPTEN_FEATURES "-s INITIAL_MEMORY=268435456 -s FULL_ES2=1 -s WASM=1")

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${EMSCRIPTEN_FEATURES}")
endif()
```

**Full link command and output with `-v` appended:**
`Doesn't seem to work with "emcmake cmake"`

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.