CMake: finish options for configuring languages

* AUDIO_LANGUAGES and TEXT_LANGUAGES are now validated against
  supported languages
* Alternately, "all" can be specified to include all languages
  (default for TEXT_LANGUAGES)
* Also fixed linker script not regenerating on language change

CMake builds now have parity with the Makefile (and more!)
This commit is contained in:
Matt Penny 2024-11-14 23:52:36 -05:00
parent 8853940a2a
commit 771c06d934
12 changed files with 121 additions and 17 deletions

View File

@ -3,12 +3,16 @@ project(portal64 C ASM)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
include(AddExternalProjectExecutable)
include(ListOption)
set(AUDIO_LANGUAGES "english" CACHE STRING "Game audio languages to include")
string(REPLACE "," ";" AUDIO_LANGUAGE_LIST "${AUDIO_LANGUAGES}")
set(TEXT_LANGUAGES "english" CACHE STRING "Text languages to include")
string(REPLACE "," ";" TEXT_LANGUAGE_LIST "${TEXT_LANGUAGES}")
list_option(AUDIO_LANGUAGES "english"
"Game audio languages to include"
"${SUPPORTED_AUDIO_LANGUAGES}"
)
list_option(TEXT_LANGUAGES "all"
"Text languages to include"
"${SUPPORTED_TEXT_LANGUAGES}"
)
# Programs used in build
find_package(Blender 3.6 EXACT REQUIRED)

View File

@ -60,3 +60,6 @@ add_custom_command(
add_custom_target(anims_linker_script
DEPENDS ${ANIMS_LINKER_SCRIPT}
)
set_target_properties(anims_linker_script PROPERTIES
OUTPUT "${ANIMS_LINKER_SCRIPT}"
)

View File

@ -55,7 +55,7 @@ endfunction()
set(FONT_FILES "")
_add_convert_font_command(DejaVuSans "${DEJAVU_SANS_FILES}" FONT_FILES)
_add_convert_font_command(DejaVuSans "${DEJAVU_SANS_FILES}" FONT_FILES)
_add_convert_font_command(LiberationMono "${LIBERATION_MONO_FILES}" FONT_FILES)
add_custom_target(fonts

View File

@ -364,3 +364,6 @@ add_custom_command(
add_custom_target(models_dynamic_linker_script
DEPENDS ${DYNAMIC_MODELS_LINKER_SCRIPT}
)
set_target_properties(models_dynamic_linker_script PROPERTIES
OUTPUT "${DYNAMIC_MODELS_LINKER_SCRIPT}"
)

View File

@ -365,7 +365,7 @@ endforeach()
# Localized sounds
# Sounds within a language must be contiguous, so loop over languages first
foreach(LANGUAGE ${AUDIO_LANGUAGE_LIST})
foreach(LANGUAGE ${AUDIO_LANGUAGES_LIST})
foreach(SOUND_SCRIPT ${LOCALIZED_SOUND_SCRIPTS})
cmake_path(
REMOVE_EXTENSION SOUND_SCRIPT

View File

@ -241,3 +241,6 @@ add_custom_command(
add_custom_target(level_linker_script
DEPENDS ${LEVEL_LINKER_SCRIPT}
)
set_target_properties(level_linker_script PROPERTIES
OUTPUT "${LEVEL_LINKER_SCRIPT}"
)

View File

@ -1,5 +1,6 @@
set(BUILD_AUDIO_DIR "${PROJECT_BINARY_DIR}/src/audio")
set(FONT_DEF "${PROJECT_SOURCE_DIR}/assets/fonts/dejavu_sans/dejavu_sans_all.json")
set(GENERATE_STRINGS "${PROJECT_SOURCE_DIR}/tools/text/subtitle_generate.py")
##################
@ -16,7 +17,7 @@ set(STRING_LOOKUP_TABLE_FILES
)
set(STRING_DATA_TABLE_FILES "")
foreach(LANGUAGE ${TEXT_LANGUAGE_LIST})
foreach(LANGUAGE ${TEXT_LANGUAGES_LIST})
list(APPEND STRING_INPUT_FILES
"${VPK_DIR}/Portal/hl2/resource/gameui_${LANGUAGE}.txt"
"${VPK_DIR}/Portal/hl2/resource/valve_${LANGUAGE}.txt"
@ -32,7 +33,7 @@ endforeach()
add_custom_command(
DEPENDS
${STRING_DEPENDENCIES} ${GENERATE_STRINGS}
${STRING_INPUT_FILES} ${FONT_DEF} ${GENERATE_STRINGS}
OUTPUT
${STRING_LOOKUP_TABLE_FILES}
${STRING_DATA_TABLE_FILES}
@ -42,6 +43,7 @@ add_custom_command(
--game-root-dir ${VPK_DIR}
--extra-translations-dir ${CMAKE_CURRENT_SOURCE_DIR}
--output-dir ${BUILD_AUDIO_DIR}
--check-font ${FONT_DEF}
COMMENT
"Generating strings"
VERBATIM
@ -88,3 +90,6 @@ add_custom_command(
add_custom_target(string_linker_script
DEPENDS ${STRING_LINKER_SCRIPT}
)
set_target_properties(string_linker_script PROPERTIES
OUTPUT "${STRING_LINKER_SCRIPT}"
)

85
cmake/ListOption.cmake Normal file
View File

@ -0,0 +1,85 @@
#############################
## Set list cache variable ##
#############################
set(SUPPORTED_AUDIO_LANGUAGES
english
french
german
russian
spanish
)
set(SUPPORTED_TEXT_LANGUAGES
english
brazilian
bulgarian
czech
danish
german
spanish
latam
greek
french
italian
polish
hungarian
dutch
norwegian
portuguese
russian
romanian
finnish
swedish
turkish
ukrainian
)
function(_comma_separated_to_list COMMA_LIST OUTPUT_VARIABLE)
string(TOLOWER "${COMMA_LIST}" ${OUTPUT_VARIABLE})
string(REPLACE "," ";" ${OUTPUT_VARIABLE} "${${OUTPUT_VARIABLE}}")
return(PROPAGATE ${OUTPUT_VARIABLE})
endfunction()
# Define a list cache variable, which is validated against a set of choices.
# The string "all" can also be specified as a shortcut for all choices.
# The parsed list is returned in <VAR>_LIST.
function(list_option LIST_NAME DEFAULT_VALUE DESCRIPTION CHOICES_LIST)
set(${LIST_NAME} ${DEFAULT_VALUE} CACHE STRING ${DESCRIPTION})
_comma_separated_to_list("${${LIST_NAME}}" INPUT_LIST)
# Need at least one entry
if (NOT INPUT_LIST)
message(FATAL_ERROR
"No values specified for list '${LIST_NAME}'. "
"Valid entries: ${CHOICES} - or 'all'"
)
endif()
# Expand "all" to all valid choices
if ("all" IN_LIST INPUT_LIST)
list(LENGTH INPUT_LIST INPUT_LENGTH)
if (INPUT_LENGTH GREATER 1)
message(FATAL_ERROR
"Invalid entries in list '${LIST_NAME}'. "
"Cannot specify 'all' with other entries."
)
endif()
set(INPUT_LIST ${CHOICES_LIST})
endif()
# Handle individual entries
foreach(ENTRY ${INPUT_LIST})
if (NOT ${ENTRY} IN_LIST CHOICES_LIST)
string(REPLACE ";" ", " CHOICES "${CHOICES_LIST}")
message(FATAL_ERROR
"Invalid entry '${ENTRY}' in list '${LIST_NAME}'. "
"Valid entries: ${CHOICES} - or 'all'"
)
endif()
endforeach()
set(${LIST_NAME}_LIST ${INPUT_LIST})
return(PROPAGATE ${LIST_NAME}_LIST)
endfunction()

View File

@ -9,10 +9,10 @@ set(OUTPUT_LINKER_SCRIPT "${LINKER_SCRIPT_DIR}/portal.ld")
add_custom_command(
DEPENDS
${LINKER_SCRIPT}
anims_linker_script
level_linker_script
models_dynamic_linker_script
string_linker_script
anims_linker_script "$<TARGET_PROPERTY:anims_linker_script,OUTPUT>"
level_linker_script "$<TARGET_PROPERTY:level_linker_script,OUTPUT>"
models_dynamic_linker_script "$<TARGET_PROPERTY:models_dynamic_linker_script,OUTPUT>"
string_linker_script "$<TARGET_PROPERTY:string_linker_script,OUTPUT>"
OUTPUT
${OUTPUT_LINKER_SCRIPT}
COMMAND

View File

@ -2,9 +2,9 @@
## Game code ##
###############
set(DEBUGGER OFF CACHE BOOL "Build with support for hardware debugging")
set(GFX_VALIDATOR OFF CACHE BOOL "Build with display list validator")
set(RSP_PROFILER OFF CACHE BOOL "Build with RSP performance profiler")
option(DEBUGGER "Build with support for hardware debugging")
option(GFX_VALIDATOR "Build with display list validator")
option(RSP_PROFILER "Build with RSP performance profiler")
add_library(engine INTERFACE)

View File

@ -6,6 +6,7 @@
// - Settings used by game fonts: layout=optimized box, padding=1px right
// - Each image must be smaller than 4 KB
// - Name each JSON file <font>_0.json, <font>_1.json, ..., <font>_N.json
// - Name the font directory the same as the font
//
// 2. Also generate a single font with all characters on the same line
// - Name the JSON file <font>_all.json

View File

@ -65,7 +65,7 @@ _add_vpk_extract_command("${VPKS_HL2_MISC}" ${PAK_DIR} VPK_STAMP_FILES)
_add_vpk_extract_command("${VPKS_HL2_SOUND_MISC}" ${PAK_DIR} VPK_STAMP_FILES)
# Extract audio for each selected additional non-English locale
foreach(LANGUAGE ${AUDIO_LANGUAGE_LIST})
foreach(LANGUAGE ${AUDIO_LANGUAGES_LIST})
if (LANGUAGE STREQUAL "english")
# English audio is included in the base VPKs
continue()