Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CMake] Fix CMakeLists.txt to compile to wasm #164

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion examples/clay-official-website/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,32 @@ cmake_minimum_required(VERSION 3.27)
project(clay_official_website C)

set(CMAKE_C_STANDARD 99)
set(CMAKE_C_COMPILER clang)

# Specify WebAssembly as target
set(CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} -Wall -Werror -Os -DCLAY_WASM -mbulk-memory --target=wasm32 -nostdlib"
)
set(CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} -Wl,--strip-all,--export-dynamic,--no-entry,--export=__heap_base,--export=ACTIVE_RENDERER_INDEX,--initial-memory=6553600"
)

add_executable(clay_official_website main.c)

target_compile_options(clay_official_website PUBLIC -Wall -Werror -Wno-unknown-pragmas -Wno-error=missing-braces)
target_include_directories(clay_official_website PUBLIC .)

set(CMAKE_C_FLAGS_RELEASE "-O3")
# Adjust WebAssembly output binary name
set_target_properties(clay_official_website PROPERTIES
OUTPUT_NAME index.wasm
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/clay
)

# Custom commands to copy additional resources
add_custom_command(TARGET clay_official_website POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/index.html ${CMAKE_BINARY_DIR}/clay/index.html
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/fonts ${CMAKE_BINARY_DIR}/clay/fonts
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/images ${CMAKE_BINARY_DIR}/clay/images
)

set(CMAKE_C_FLAGS_RELEASE "-O3")