108 lines
3.7 KiB
CMake
108 lines
3.7 KiB
CMake
cmake_minimum_required(VERSION 3.21)
|
||
project("Industrial Genesis" VERSION "0.0.1")
|
||
|
||
find_package(Gettext REQUIRED)
|
||
find_package(Threads REQUIRED)
|
||
|
||
file(GLOB PO_FILES "${CMAKE_SOURCE_DIR}/po/*.po")
|
||
|
||
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
||
set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/release" CACHE PATH
|
||
"Default install prefix" FORCE)
|
||
endif()
|
||
|
||
foreach(po_file IN LISTS PO_FILES)
|
||
get_filename_component(lang ${po_file} NAME_WE)
|
||
# 编译产物放在 mo/ 而不是 locale/:locale/ 是 POST_BUILD 的拷贝目标,
|
||
# 两者同目录会变成"把目录拷到自己身上"。
|
||
set(mo_file "${CMAKE_CURRENT_BINARY_DIR}/mo/${lang}/LC_MESSAGES/${PROJECT_NAME}.mo")
|
||
|
||
add_custom_command(
|
||
OUTPUT ${mo_file}
|
||
COMMAND ${CMAKE_COMMAND} -E make_directory
|
||
"${CMAKE_CURRENT_BINARY_DIR}/mo/${lang}/LC_MESSAGES"
|
||
COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${mo_file} ${po_file}
|
||
DEPENDS ${po_file}
|
||
COMMENT "Compiling translation for ${lang}"
|
||
)
|
||
|
||
# 将每个 mo 文件加入一个目标依赖,并方便后续安装
|
||
list(APPEND MO_FILES ${mo_file})
|
||
endforeach()
|
||
|
||
add_subdirectory(lib/raylib-6.0)
|
||
add_subdirectory(lib/json-c-json-c-0.19-20260627)
|
||
|
||
add_executable(Industrial_Genesis
|
||
src/main.c
|
||
src/json.c
|
||
src/ui.c
|
||
src/texture.c
|
||
src/timer.c
|
||
src/tools.c
|
||
# 时间与天文
|
||
src/astro.c
|
||
src/weather.c
|
||
src/hydro.c
|
||
# 世界生成
|
||
src/terrain.c
|
||
src/chunk.c
|
||
src/compound.c
|
||
src/noise.c
|
||
src/random.c
|
||
src/climate.c
|
||
src/river.c
|
||
# 世界状态与地图视图
|
||
src/world.c
|
||
src/map.c
|
||
src/landing.c
|
||
# 局部游戏层(1 格 = 1 米)
|
||
src/game.c
|
||
)
|
||
target_compile_definitions(Industrial_Genesis PRIVATE _RELEASE_)
|
||
target_include_directories(Industrial_Genesis PRIVATE lib/raylib-6.0/src/)
|
||
target_include_directories(Industrial_Genesis PRIVATE lib/json-c-json-c-0.19-20260627/)
|
||
target_include_directories(Industrial_Genesis PRIVATE lib/libuv-1.52.1/)
|
||
target_link_libraries(Industrial_Genesis PRIVATE raylib)
|
||
target_link_libraries(Industrial_Genesis PRIVATE json-c)
|
||
target_link_libraries(Industrial_Genesis PRIVATE uv)
|
||
target_link_libraries(Industrial_Genesis PRIVATE Threads::Threads)
|
||
|
||
add_custom_target(translations ALL DEPENDS ${MO_FILES})
|
||
|
||
# 没有这行时,`cmake --build build --target Industrial_Genesis` 不会碰
|
||
# translations,运行时用的还是上一次的旧 .mo。
|
||
add_dependencies(Industrial_Genesis translations)
|
||
|
||
add_custom_command(TARGET Industrial_Genesis POST_BUILD
|
||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||
"${CMAKE_CURRENT_SOURCE_DIR}/assets"
|
||
"$<TARGET_FILE_DIR:Industrial_Genesis>/assets"
|
||
COMMENT "Copying assets to executable directory"
|
||
)
|
||
|
||
add_custom_command(TARGET Industrial_Genesis POST_BUILD
|
||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||
"${CMAKE_CURRENT_BINARY_DIR}/mo"
|
||
"$<TARGET_FILE_DIR:Industrial_Genesis>/locale"
|
||
COMMENT "Copying locale files to runtime directory"
|
||
)
|
||
|
||
add_custom_command(TARGET Industrial_Genesis POST_BUILD
|
||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||
"${CMAKE_CURRENT_SOURCE_DIR}/default_config"
|
||
"$<TARGET_FILE_DIR:Industrial_Genesis>/config"
|
||
COMMENT "Copying default config files to runtime directory"
|
||
)
|
||
|
||
install(TARGETS Industrial_Genesis RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/)
|
||
install(DIRECTORY assets DESTINATION .)
|
||
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mo/ DESTINATION locale)
|
||
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/config DESTINATION .)
|
||
|
||
install(CODE "
|
||
if(EXISTS \"\${CMAKE_INSTALL_PREFIX}/include\")
|
||
file(REMOVE_RECURSE \"\${CMAKE_INSTALL_PREFIX}/include\")
|
||
message(STATUS \"Removed installed include directory\")
|
||
endif()
|
||
") |