I'm trying to compile a C++ project using CMake to webassembly. I'm using emscripten and I want to use the emscripten ports for SDL2 and Freetype. Normally, when compiling with emcc, you would use the flags: -USE_SDL=2
and -USE_FREETYPE=1
, in order to include these ports. However I don't know how to achieve this using CMake.
This is my CMakeList file:
cmake_minimum_required(VERSION 3.15)
project(project)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
find_package(SDL2 REQUIRED)
find_package(Freetype REQUIRED)
include_directories(${CMAKE_SOURCE_DIR}/include ${SDL2_INCLUDE_DIRS} ${FREETYPE_INCLUDE_DIRS})
add_executable(project src/main.cpp src/glad.c src/Game.cpp src/Block.cpp include/jumpyblock/Block.h)
target_link_libraries(project ${SDL2_LIBRARIES} ${FREETYPE_LIBRARIES})
It compiles and runs successfully using regular cmake.
So far I have tried compiling with emcmake cmake . && make
, which gave me an error saying that it couldn't find a package configuration file for SDL2.
And I've tried modifying the CMakeList file to use the emcc flags for the ports:
cmake_minimum_required(VERSION 3.15)
project(project)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -USE_SDL=2 -USE_FREETYPE=1")
include_directories(${CMAKE_SOURCE_DIR}/include ${SDL2_INCLUDE_DIRS} ${FREETYPE_INCLUDE_DIRS})
add_executable(project src/main.cpp src/glad.c src/Game.cpp src/Block.cpp include/jumpyblock/Block.h )
target_link_libraries(project ${SDL2_LIBRARIES} ${FREETYPE_LIBRARIES})
With this cmake file, emcmake cmake .
runs successfully, but then make
complains that it can't find SDL2/SDL.h
.