56 lines
2.6 KiB
CMake
56 lines
2.6 KiB
CMake
cmake_minimum_required(VERSION 3.16)
|
|
|
|
project(douwco_hivemind CXX)
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
|
|
|
|
# Generate compile commands
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
|
|
# Set the Emscripten toolchain
|
|
set(CMAKE_TOOLCHAIN_FILE ${EMSCRIPTEN_ROOT}/cmake/Modules/Platform/Emscripten.cmake CACHE STRING "")
|
|
|
|
# set(COMPILE_FLAGS --cache ${CMAKE_BINARY_DIR}/cache)
|
|
set(LINK_FLAGS -sASSERTIONS=0 -sMALLOC=emmalloc)
|
|
add_compile_options(${COMPILE_FLAGS})
|
|
add_link_options(${COMPILE_FLAGS} ${LINK_FLAGS})
|
|
|
|
add_subdirectory(screepsxx)
|
|
|
|
|
|
# If you change TARGET_NAME, please, make corresponding changes in main.js.
|
|
set(TARGET_NAME douwco_hivemind)
|
|
|
|
include_directories(${CMAKE_SOURCE_DIR}/douwco_hivemind/include)
|
|
|
|
file(GLOB SRC_FILES ${CMAKE_SOURCE_DIR}/douwco_hivemind/src/*.cpp
|
|
${CMAKE_SOURCE_DIR}/douwco_hivemind/src/*/*.cpp)
|
|
add_executable(${TARGET_NAME} ${SRC_FILES})
|
|
target_link_libraries(${TARGET_NAME} screepsxx)
|
|
target_link_options(${TARGET_NAME} PUBLIC -sMODULARIZE=1 --no-entry --bind -sEXPORT_ES6=0)
|
|
|
|
# Post-process compile_commands.json to remove Emscripten flags
|
|
add_custom_command(
|
|
TARGET ${TARGET_NAME} POST_BUILD
|
|
COMMAND ${CMAKE_COMMAND} -E echo "Cleaning compile_commands.json for clangd..."
|
|
COMMAND python3 ${CMAKE_SOURCE_DIR}/clean_compile_commands.py
|
|
${CMAKE_BINARY_DIR}/compile_commands.json
|
|
COMMENT "Post-processing compile_commands.json for clangd compatibility"
|
|
)
|
|
|
|
# Symlink compile_commands.json to project root for clangd
|
|
add_custom_command(
|
|
TARGET ${TARGET_NAME} POST_BUILD
|
|
COMMAND ${CMAKE_COMMAND} -E create_symlink
|
|
${CMAKE_BINARY_DIR}/compile_commands.json
|
|
${CMAKE_SOURCE_DIR}/compile_commands.json
|
|
COMMENT "Symlinking compile_commands.json to project root for clangd"
|
|
)
|
|
|
|
# Collect all artifacts in 'dist' directory
|
|
# WASM-module and corresponding JS-module must have different base names in order to use them in Screeps, so we add suffixes.
|
|
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/${TARGET_NAME}.wasm ${CMAKE_SOURCE_DIR}/dist/${TARGET_NAME}_module.wasm)
|
|
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/${TARGET_NAME}.js ${CMAKE_SOURCE_DIR}/dist/${TARGET_NAME}_loader.js)
|
|
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/js/main.js ${CMAKE_SOURCE_DIR}/dist/main.js)
|
|
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/js/wasm_loader.js ${CMAKE_SOURCE_DIR}/dist/wasm_loader.js) |