diff options
| author | Connor Thomson <blumatrikz@gmail.com> | 2026-09-08 18:27:39 -0700 |
|---|---|---|
| committer | Connor Thomson <blumatrikz@gmail.com> | 2026-09-08 18:27:39 -0700 |
| commit | f1ddc12b68b4e4c8087962de25260470e6df2bea (patch) | |
| tree | 7d0440a6402a9b0ef75ded23fa64b68534255bba /cmake | |
| parent | 6025860a61386bf767b29c3ec5fd0d31285f1056 (diff) | |
Add tuxanci2 files
Diffstat (limited to 'cmake')
| -rw-r--r-- | cmake/CompileShaders.cmake | 142 | ||||
| -rw-r--r-- | cmake/EmbedFile.cmake | 37 | ||||
| -rw-r--r-- | cmake/FindGettext.cmake | 70 | ||||
| -rw-r--r-- | cmake/MacroAddSources.cmake | 9 | ||||
| -rw-r--r-- | cmake/cmake_uninstall.cmake.in | 21 | ||||
| -rw-r--r-- | cmake/mingw-toolchain.cmake | 29 |
6 files changed, 208 insertions, 100 deletions
diff --git a/cmake/CompileShaders.cmake b/cmake/CompileShaders.cmake new file mode 100644 index 0000000..75ee602 --- /dev/null +++ b/cmake/CompileShaders.cmake @@ -0,0 +1,142 @@ +# Tuxanci 2 - A first person shooter +# Copyright (C) 2007-2011 Tuxánci Development Team +# Copyright (C) 2025-2026 Connor Thomson +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +set(SHADER_SLANG_PROFILE "spirv_1_5") +set(SHADER_SLANG_TARGET "spirv") + +find_program(SLANGC_EXECUTABLE slangc) + +if(NOT SLANGC_EXECUTABLE) + message(FATAL_ERROR "slangc is not found. Download it from https://github.com/shader-slang/slang and make sure it is in your PATH.") +endif() + +find_program(XXD_EXECUTABLE NAMES xxd) +if(NOT XXD_EXECUTABLE) + message(FATAL_ERROR "xxd is not found. Make sure it is in your PATH.") +endif() + +set(SHADER_EMBED_SCRIPT "${CMAKE_CURRENT_LIST_DIR}/EmbedFile.cmake") + +function(target_compile_shaders TARGET_NAME) + cmake_parse_arguments(PARSE_ARGV 1 ARG "" "PROFILE;ENTRY" "SHADERS") + + if(NOT ARG_PROFILE) + set(ARG_PROFILE "${SHADER_SLANG_PROFILE}") + endif() + if(NOT ARG_ENTRY) + set(ARG_ENTRY "main") + endif() + + set(SPIRV_OUTPUTS "") + + foreach(SHADER ${ARG_SHADERS}) + get_filename_component(SHADER_ABS "${SHADER}" ABSOLUTE) + get_filename_component(SHADER_NAME "${SHADER}" NAME) + + set(_stage "") + if(SHADER_NAME MATCHES "\\.vert\\.slang$") + set(_stage "vertex") + elseif(SHADER_NAME MATCHES "\\.frag\\.slang$") + set(_stage "fragment") + elseif(SHADER_NAME MATCHES "\\.comp\\.slang$") + set(_stage "compute") + elseif(SHADER_NAME MATCHES "\\.geom\\.slang$") + set(_stage "geometry") + elseif(SHADER_NAME MATCHES "\\.tesc\\.slang$") + set(_stage "hull") + elseif(SHADER_NAME MATCHES "\\.tese\\.slang$") + set(_stage "domain") + elseif(SHADER_NAME MATCHES "\\.rgen\\.slang$") + set(_stage "raygeneration") + elseif(SHADER_NAME MATCHES "\\.rchit\\.slang$") + set(_stage "closesthit") + elseif(SHADER_NAME MATCHES "\\.rmiss\\.slang$") + set(_stage "miss") + else() + message(FATAL_ERROR "'${SHADER_NAME}' must end with .<vert|frag|comp|geom|tesc|tese|rgen|rchit|rmiss>.slang") + endif() + + set(SPIRV_OUT "${CMAKE_CURRENT_BINARY_DIR}/shaders/${SHADER_NAME}.spv") + set(SPIRV_EMBED_C_OUT "${CMAKE_CURRENT_BINARY_DIR}/shaders/${SHADER_NAME}.xxd.c") + + string(REGEX REPLACE "[^A-Za-z0-9]" "_" SHADER_SYMBASE "${SHADER_NAME}.spv") + set(SHADER_SYMBASE "file_${SHADER_SYMBASE}") + + add_custom_command( + OUTPUT ${SPIRV_OUT} + COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/shaders" + COMMAND "${SLANGC_EXECUTABLE}" "${SHADER_ABS}" + -target ${SHADER_SLANG_TARGET} + -profile ${ARG_PROFILE} + -entry ${ARG_ENTRY} + -stage ${_stage} + -o ${SPIRV_OUT} + MAIN_DEPENDENCY "${SHADER_ABS}" + COMMENT "Building SPIR-V ${SHADER_NAME}.spv" + VERBATIM + ) + + add_custom_command( + OUTPUT ${SPIRV_EMBED_C_OUT} + COMMAND ${CMAKE_COMMAND} + -D IN_FILE=${SPIRV_OUT} + -D OUT_C=${SPIRV_EMBED_C_OUT} + -D SYMBASE=${SHADER_SYMBASE} + -D XXD_EXE=${XXD_EXECUTABLE} + -P "${SHADER_EMBED_SCRIPT}" + DEPENDS ${SPIRV_OUT} "${SHADER_EMBED_SCRIPT}" + COMMENT "Building C object ${SHADER_NAME}.spv.o" + VERBATIM + ) + + list(APPEND SPIRV_OUTPUTS ${SPIRV_EMBED_C_OUT}) + endforeach() + + target_sources(${TARGET_NAME} PRIVATE ${SPIRV_OUTPUTS}) +endfunction() + +function(target_embed_files TARGET_NAME) + cmake_parse_arguments(PARSE_ARGV 1 ARG "" "" "FILES") + + set(EMBEDDED_OUTPUTS "") + foreach(ASSET ${ARG_FILES}) + get_filename_component(ASSET_ABS "${ASSET}" ABSOLUTE) + file(RELATIVE_PATH ASSET_RELATIVE "${CMAKE_SOURCE_DIR}" "${ASSET_ABS}") + string(REGEX REPLACE "[^A-Za-z0-9]" "_" ASSET_SYMBASE "${ASSET_RELATIVE}") + set(ASSET_SYMBASE "file_${ASSET_SYMBASE}") + get_filename_component(ASSET_NAME "${ASSET_RELATIVE}" NAME) + set(ASSET_EMBED_C_OUT "${CMAKE_CURRENT_BINARY_DIR}/data/${ASSET_NAME}.xxd.c") + + add_custom_command( + OUTPUT ${ASSET_EMBED_C_OUT} + COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/data" + COMMAND ${CMAKE_COMMAND} + -D IN_FILE=${ASSET_ABS} + -D OUT_C=${ASSET_EMBED_C_OUT} + -D SYMBASE=${ASSET_SYMBASE} + -D XXD_EXE=${XXD_EXECUTABLE} + -P "${SHADER_EMBED_SCRIPT}" + DEPENDS "${ASSET_ABS}" "${SHADER_EMBED_SCRIPT}" + COMMENT "Building C object ${ASSET_RELATIVE}.o" + VERBATIM + ) + + list(APPEND EMBEDDED_OUTPUTS ${ASSET_EMBED_C_OUT}) + endforeach() + + target_sources(${TARGET_NAME} PRIVATE ${EMBEDDED_OUTPUTS}) +endfunction()
\ No newline at end of file diff --git a/cmake/EmbedFile.cmake b/cmake/EmbedFile.cmake new file mode 100644 index 0000000..19e5dbe --- /dev/null +++ b/cmake/EmbedFile.cmake @@ -0,0 +1,37 @@ +# Tuxanci 2 - A first person shooter +# Copyright (C) 2007-2011 Tuxánci Development Team +# Copyright (C) 2025-2026 Connor Thomson +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +foreach(_required IN_FILE OUT_C SYMBASE XXD_EXE) + if(NOT DEFINED ${_required}) + message(FATAL_ERROR "EmbedFile.cmake: missing required -D ${_required}") + endif() +endforeach() + +execute_process( + COMMAND "${XXD_EXE}" -i -n "${SYMBASE}" "${IN_FILE}" + OUTPUT_VARIABLE _xxd_output + RESULT_VARIABLE _xxd_result + ERROR_VARIABLE _xxd_error +) +if(NOT _xxd_result EQUAL 0) + message(FATAL_ERROR "xxd failed embedding ${IN_FILE}: ${_xxd_error}") +endif() + +file(WRITE "${OUT_C}" "${_xxd_output}\n") +file(APPEND "${OUT_C}" "\nunsigned int ${SYMBASE}_size = sizeof(${SYMBASE});\n") +file(APPEND "${OUT_C}" "unsigned char *${SYMBASE}_start = ${SYMBASE};\n") +file(APPEND "${OUT_C}" "unsigned char *${SYMBASE}_end = ${SYMBASE} + sizeof(${SYMBASE});\n")
\ No newline at end of file diff --git a/cmake/FindGettext.cmake b/cmake/FindGettext.cmake deleted file mode 100644 index c293e26..0000000 --- a/cmake/FindGettext.cmake +++ /dev/null @@ -1,70 +0,0 @@ -# - Find GNU gettext tools -# This module looks for the GNU gettext tools. This module defines the -# following values: -# GETTEXT_MSGMERGE_EXECUTABLE: the full path to the msgmerge tool. -# GETTEXT_MSGFMT_EXECUTABLE: the full path to the msgfmt tool. -# GETTEXT_INCLUDES: just for including on windows, on POSIX it works just fine. -# GETTEXT_FOUND: True if gettext has been found. -# -# Additionally it provides the following macros: -# GETTEXT_CREATE_TRANSLATIONS ( outputFile [ALL] file1 ... fileN ) -# This will create a target "translations" which will convert the -# given input po files into the binary output mo file. If the -# ALL option is used, the translations will also be created when -# building the default target. - - -FIND_PATH(GETTEXT_INCLUDE_DIR libintl.h - PATHS - /usr/local/include - /usr/include - /usr/i686-pc-mingw32/sys-root/mingw/include -) - -FIND_PROGRAM(GETTEXT_MSGMERGE_EXECUTABLE msgmerge) - -FIND_PROGRAM(GETTEXT_MSGFMT_EXECUTABLE msgfmt) - -MACRO(GETTEXT_CREATE_TRANSLATIONS _potFile _firstPoFile) - - SET(_gmoFiles) - GET_FILENAME_COMPONENT(_potBasename ${_potFile} NAME_WE) - GET_FILENAME_COMPONENT(_absPotFile ${_potFile} ABSOLUTE) - - SET(_addToAll) - IF(${_firstPoFile} STREQUAL "ALL") - SET(_addToAll "ALL") - SET(_firstPoFile) - ENDIF(${_firstPoFile} STREQUAL "ALL") - - FOREACH (_currentPoFile ${ARGN}) - GET_FILENAME_COMPONENT(_absFile ${_currentPoFile} ABSOLUTE) - GET_FILENAME_COMPONENT(_abs_PATH ${_absFile} PATH) - GET_FILENAME_COMPONENT(_lang ${_absFile} NAME_WE) - SET(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${_lang}.gmo) - - ADD_CUSTOM_COMMAND( - OUTPUT ${_gmoFile} - COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} --quiet --update --backup=none -s ${_absFile} ${_absPotFile} - COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${_gmoFile} ${_absFile} - DEPENDS ${_absPotFile} ${_absFile} - ) - - INSTALL(FILES ${_gmoFile} DESTINATION share/locale/${_lang}/LC_MESSAGES RENAME ${_potBasename}.mo) - SET(_gmoFiles ${_gmoFiles} ${_gmoFile}) - - ENDFOREACH (_currentPoFile ) - - ADD_CUSTOM_TARGET(translations ${_addToAll} DEPENDS ${_gmoFiles}) - -ENDMACRO(GETTEXT_CREATE_TRANSLATIONS ) - -IF (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE ) - SET(GETTEXT_FOUND TRUE) -ELSE (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE ) - SET(GETTEXT_FOUND FALSE) - IF (GetText_REQUIRED) - MESSAGE(FATAL_ERROR "GetText not found") - ENDIF (GetText_REQUIRED) -ENDIF (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE ) - diff --git a/cmake/MacroAddSources.cmake b/cmake/MacroAddSources.cmake deleted file mode 100644 index 62c1381..0000000 --- a/cmake/MacroAddSources.cmake +++ /dev/null @@ -1,9 +0,0 @@ -# This macro is for generating the sources list from in-folder files. -MACRO(MacroAddSources) - FILE ( GLOB src ${fn}/*.c ) - FOREACH ( fle ${src} ) - GET_FILENAME_COMPONENT ( fnp ${fle} NAME_WE ) - GET_FILENAME_COMPONENT ( pth ${fle} PATH ) - SET ( SRC_${fn} ${SRC_${fn}} ${pth}/${fnp} ) - ENDFOREACH ( fle ) -ENDMACRO(MacroAddSources) diff --git a/cmake/cmake_uninstall.cmake.in b/cmake/cmake_uninstall.cmake.in deleted file mode 100644 index cd4c9d8..0000000 --- a/cmake/cmake_uninstall.cmake.in +++ /dev/null @@ -1,21 +0,0 @@ -IF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") - MESSAGE(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"") -ENDIF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") - -FILE(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) -STRING(REGEX REPLACE "\n" ";" files "${files}") -FOREACH(file ${files}) - MESSAGE(STATUS "Uninstalling: \"$ENV{DESTDIR}${file}\"") - IF(EXISTS "$ENV{DESTDIR}${file}") - EXEC_PROGRAM( - "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" - OUTPUT_VARIABLE rm_out - RETURN_VALUE rm_retval - ) - IF(NOT "${rm_retval}" STREQUAL 0) - MESSAGE(FATAL_ERROR "Problem when removing: \"$ENV{DESTDIR}${file}\"") - ENDIF(NOT "${rm_retval}" STREQUAL 0) - ELSE(EXISTS "$ENV{DESTDIR}${file}") - MESSAGE(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.") - ENDIF(EXISTS "$ENV{DESTDIR}${file}") -ENDFOREACH(file) diff --git a/cmake/mingw-toolchain.cmake b/cmake/mingw-toolchain.cmake new file mode 100644 index 0000000..7847e9b --- /dev/null +++ b/cmake/mingw-toolchain.cmake @@ -0,0 +1,29 @@ +# Tuxanci 2 - A first person shooter +# Copyright (C) 2007-2011 Tuxánci Development Team +# Copyright (C) 2025-2026 Connor Thomson +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +set(CMAKE_SYSTEM_NAME Windows) +set(TOOLCHAIN_PREFIX x86_64-w64-mingw32) + +set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc) +set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres) + +set(CMAKE_FIND_ROOT_PATH "/usr/${TOOLCHAIN_PREFIX}") + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
\ No newline at end of file |