aboutsummaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi92@disroot.org>2025-07-04 00:55:59 +0200
committerXavier Del Campo Romero <xavi92@disroot.org>2025-07-06 22:21:50 +0200
commit892ecce78dec37a1b2701611dd72986442cd094d (patch)
treebbd7fb0a0229795bf52d0b8a9ff9b06251363a67 /cmake
parent99554cc243c4b2ec290639a04ebc2f189890d6dd (diff)
downloadwnix-892ecce78dec37a1b2701611dd72986442cd094d.tar.gz
Import project skeleton from rts
https://gitea.privatedns.org/xavi/rts
Diffstat (limited to 'cmake')
-rwxr-xr-xcmake/FindENET.cmake88
-rw-r--r--cmake/FindPSXSDK.cmake94
-rw-r--r--cmake/FindSDL_gfx.cmake84
-rw-r--r--cmake/fetch-libfixmath.cmake8
-rw-r--r--cmake/host.cmake8
-rw-r--r--cmake/ps1-toolchain.cmake2
-rw-r--r--cmake/ps1.cmake43
-rw-r--r--cmake/win9x-toolchain.cmake1
-rw-r--r--cmake/win9x.cmake22
9 files changed, 350 insertions, 0 deletions
diff --git a/cmake/FindENET.cmake b/cmake/FindENET.cmake
new file mode 100755
index 0000000..504aa23
--- /dev/null
+++ b/cmake/FindENET.cmake
@@ -0,0 +1,88 @@
+# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+# file Copyright.txt or https://cmake.org/licensing for details.
+
+#[=======================================================================[.rst:
+FindENET
+-----------
+
+Locate ENET library
+
+This module defines:
+
+::
+
+ ENET, the name of the target to use with target_*() commands
+ ENET_LIBRARIES, the name of the library to link against
+ ENET_INCLUDE_DIRS, where to find the headers
+ ENET_FOUND, if false, do not try to link against
+ ENET_VERSION_STRING - human-readable string containing the
+ version of ENET
+
+$ENETDIR is an environment variable that would correspond to the
+./configure --prefix=$ENETDIR used in building ENET.
+#]=======================================================================]
+
+find_path(ENET_INCLUDE_DIRS
+ NAMES
+ enet/callbacks.h
+ enet/enet.h
+ enet/list.h
+ enet/protocol.h
+ enet/time.h
+ enet/types.h
+ enet/unix.h
+ enet/utility.h
+ enet/win32.h
+ HINTS
+ ENV ENETDIR
+ PATH_SUFFIXES
+ enet
+ # path suffixes to search inside ENV{ENETDIR}
+ include
+)
+
+if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ set(VC_LIB_PATH_SUFFIX lib/x64)
+else()
+ set(VC_LIB_PATH_SUFFIX lib/x86)
+endif()
+
+find_library(ENET_LIBRARIES
+ NAMES enet
+ HINTS
+ ENV ENETDIR
+ PATH_SUFFIXES
+ lib
+ ${VC_LIB_PATH_SUFFIX}
+)
+
+if(ENET_INCLUDE_DIRS AND EXISTS "${ENET_INCLUDE_DIRS}/enet.h")
+ file(STRINGS "${ENET_INCLUDE_DIRS}/enet.h" ENET_VERSION_MAJOR_LINE REGEX "^#define[ \t]+ENET_VERSION_MAJOR[ \t]+[0-9]+$")
+ file(STRINGS "${ENET_INCLUDE_DIRS}/enet.h" ENET_VERSION_MINOR_LINE REGEX "^#define[ \t]+ENET_VERSION_MINOR[ \t]+[0-9]+$")
+ file(STRINGS "${ENET_INCLUDE_DIRS}/enet.h" ENET_VERSION_PATCH_LINE REGEX "^#define[ \t]+ENET_VERSION_PATCH[ \t]+[0-9]+$")
+ string(REGEX REPLACE "^#define[ \t]+ENET_VERSION_MAJOR[ \t]+([0-9]+)$" "\\1" ENET_VERSION_MAJOR "${ENET_VERSION_MAJOR_LINE}")
+ string(REGEX REPLACE "^#define[ \t]+ENET_VERSION_MINOR[ \t]+([0-9]+)$" "\\1" ENET_VERSION_MINOR "${ENET_VERSION_MINOR_LINE}")
+ string(REGEX REPLACE "^#define[ \t]+ENET_VERSION_PATCH[ \t]+([0-9]+)$" "\\1" ENET_VERSION_PATCH "${ENET_VERSION_PATCH_LINE}")
+ set(ENET_VERSION_STRING ${ENET_VERSION_MAJOR}.${ENET_VERSION_MINOR}.${ENET_VERSION_PATCH})
+ unset(ENET_VERSION_MAJOR_LINE)
+ unset(ENET_VERSION_MINOR_LINE)
+ unset(ENET_VERSION_PATCH_LINE)
+ unset(ENET_VERSION_MAJOR)
+ unset(ENET_VERSION_MINOR)
+ unset(ENET_VERSION_PATCH)
+endif()
+
+include(FindPackageHandleStandardArgs)
+
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(ENET
+ REQUIRED_VARS ENET_LIBRARIES ENET_INCLUDE_DIRS
+ VERSION_VAR ENET_VERSION_STRING)
+
+if(ENET_FOUND)
+ if(NOT TARGET ENET)
+ add_library(ENET INTERFACE IMPORTED)
+ set_target_properties(ENET PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${ENET_INCLUDE_DIRS}"
+ INTERFACE_LINK_LIBRARIES "${ENET_LIBRARIES}")
+ endif()
+endif()
diff --git a/cmake/FindPSXSDK.cmake b/cmake/FindPSXSDK.cmake
new file mode 100644
index 0000000..2d1982d
--- /dev/null
+++ b/cmake/FindPSXSDK.cmake
@@ -0,0 +1,94 @@
+# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+# file Copyright.txt or https://cmake.org/licensing for details.
+
+#[=======================================================================[.rst:
+FindPSXSDK
+-----------
+
+Find PSXSDK (an open source software development kit for the original
+Sony PlayStation) libraries and header files.
+
+Imported targets
+^^^^^^^^^^^^^^^^
+
+This module defines the following :prop_tgt:`IMPORTED` targets:
+
+ ``PSXSDK::PSXSDK``,
+ The PSXSDK `psx` library, if found.
+
+Result variables
+^^^^^^^^^^^^^^^^
+
+This module will set the following variables in your project:
+
+``PSXSDK_FOUND``
+ true if PSXSDK libraries and header files were found.
+``PSXSDK_VERSION``
+ PSXSDK release version
+``PSXSDK_INCLUDE_DIRS``
+ the directory containing the PSXSDK headers; note
+ ``PSXSDK_INCLUDE_DIRS`` is also required
+``PSXSDK_LIBRARIES``
+ PSXSDK libraries to be linked; note ``PSXSDK_LIBRARIES`` is also
+ required
+
+#]=======================================================================]
+
+find_path(PSXSDK_INCLUDE_DIRS
+ NAMES
+ huff.h
+ meidogte.h
+ meidogte_inline.h
+ memcard.h
+ modplay.h
+ psxbios.h
+ psxcdrom.h
+ psxgpu.h
+ psxgte.h
+ psx.h
+ psxpad.h
+ psxsio.h
+ psxspu.h
+ psxutil.h
+ runexe.h
+ search.h
+ HINTS
+ ENV PSXSDK_PATH
+ PATH_SUFFIXES
+ include
+)
+
+find_library(PSXSDK_LIBRARIES
+ NAMES psx
+ HINTS
+ ENV PSXSDK_PATH
+ PATH_SUFFIXES
+ lib
+)
+
+if(PSXSDK_INCLUDE_DIRS AND EXISTS "${PSXSDK_INCLUDE_DIRS}/psx.h")
+ set(version_regex "^#define[ \t]+PSXSDK_VERSION_STRING[ \t]+\"([0-9\.]+)\"$")
+ file(STRINGS "${PSXSDK_INCLUDE_DIRS}/psx.h" PSXSDK_VERSION_LINE REGEX ${version_regex})
+ string(REGEX REPLACE ${version_regex} "\\1" PSXSDK_VERSION "${PSXSDK_VERSION_LINE}")
+ unset(PSXSDK_VERSION_LINE)
+ unset(version_regex)
+endif()
+
+include(FindPackageHandleStandardArgs)
+
+find_package_handle_standard_args(PSXSDK
+ REQUIRED_VARS
+ PSXSDK_LIBRARIES PSXSDK_INCLUDE_DIRS
+ VERSION_VAR
+ PSXSDK_VERSION
+)
+
+if(PSXSDK_FOUND)
+ if(NOT TARGET PSXSDK::PSXSDK)
+ add_library(PSXSDK::PSXSDK INTERFACE IMPORTED)
+ target_include_directories(PSXSDK::PSXSDK
+ INTERFACE "${PSXSDK_INCLUDE_DIRS}")
+ set_target_properties(PSXSDK::PSXSDK PROPERTIES
+ IMPORTED_LOCATION "${PSXSDK_LIBRARIES}")
+ endif()
+endif()
diff --git a/cmake/FindSDL_gfx.cmake b/cmake/FindSDL_gfx.cmake
new file mode 100644
index 0000000..34ff8db
--- /dev/null
+++ b/cmake/FindSDL_gfx.cmake
@@ -0,0 +1,84 @@
+# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+# file Copyright.txt or https://cmake.org/licensing for details.
+
+#[=======================================================================[.rst:
+FindSDL_gfx
+-----------
+
+Locate SDL_gfx library
+
+This module defines:
+
+::
+
+ SDL::SDL_gfx, the name of the target to use with target_*() commands
+ SDL_GFX_LIBRARIES, the name of the library to link against
+ SDL_GFX_INCLUDE_DIRS, where to find the headers
+ SDL_GFX_FOUND, if false, do not try to link against
+ SDL_GFX_VERSION_STRING - human-readable string containing the
+ version of SDL_gfx
+
+$SDLDIR is an environment variable that would correspond to the
+./configure --prefix=$SDLDIR used in building SDL.
+#]=======================================================================]
+
+find_path(SDL_GFX_INCLUDE_DIRS
+ NAMES
+ SDL_framerate.h
+ SDL_gfxBlitFunc.h
+ SDL_gfxPrimitives.h
+ SDL_gfxPrimitives_font.h
+ SDL_imageFilter.h
+ SDL_rotozoom.h
+ HINTS
+ ENV SDLGFXDIR
+ ENV SDLDIR
+ PATH_SUFFIXES SDL
+ # path suffixes to search inside ENV{SDLDIR}
+ include/SDL include/SDL12 include/SDL11 include
+)
+
+if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ set(VC_LIB_PATH_SUFFIX lib/x64)
+else()
+ set(VC_LIB_PATH_SUFFIX lib/x86)
+endif()
+
+find_library(SDL_GFX_LIBRARIES
+ NAMES SDL_gfx
+ HINTS
+ ENV SDLGFXDIR
+ ENV SDLDIR
+ PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX}
+)
+
+if(SDL_GFX_INCLUDE_DIRS AND EXISTS "${SDL_GFX_INCLUDE_DIRS}/SDL_gfxPrimitives.h")
+ file(STRINGS "${SDL_GFX_INCLUDE_DIRS}/SDL_gfxPrimitives.h" SDL_GFX_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_GFXPRIMITIVES_MAJOR[ \t]+[0-9]+$")
+ file(STRINGS "${SDL_GFX_INCLUDE_DIRS}/SDL_gfxPrimitives.h" SDL_GFX_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_GFXPRIMITIVES_MINOR[ \t]+[0-9]+$")
+ file(STRINGS "${SDL_GFX_INCLUDE_DIRS}/SDL_gfxPrimitives.h" SDL_GFX_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_GFXPRIMITIVES_MICRO[ \t]+[0-9]+$")
+ string(REGEX REPLACE "^#define[ \t]+SDL_GFXPRIMITIVES_MAJOR[ \t]+([0-9]+)$" "\\1" SDL_GFX_VERSION_MAJOR "${SDL_GFX_VERSION_MAJOR_LINE}")
+ string(REGEX REPLACE "^#define[ \t]+SDL_GFXPRIMITIVES_MINOR[ \t]+([0-9]+)$" "\\1" SDL_GFX_VERSION_MINOR "${SDL_GFX_VERSION_MINOR_LINE}")
+ string(REGEX REPLACE "^#define[ \t]+SDL_GFXPRIMITIVES_MICRO[ \t]+([0-9]+)$" "\\1" SDL_GFX_VERSION_PATCH "${SDL_GFX_VERSION_PATCH_LINE}")
+ set(SDL_GFX_VERSION_STRING ${SDL_GFX_VERSION_MAJOR}.${SDL_GFX_VERSION_MINOR}.${SDL_GFX_VERSION_PATCH})
+ unset(SDL_GFX_VERSION_MAJOR_LINE)
+ unset(SDL_GFX_VERSION_MINOR_LINE)
+ unset(SDL_GFX_VERSION_PATCH_LINE)
+ unset(SDL_GFX_VERSION_MAJOR)
+ unset(SDL_GFX_VERSION_MINOR)
+ unset(SDL_GFX_VERSION_PATCH)
+endif()
+
+include(FindPackageHandleStandardArgs)
+
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL_gfx
+ REQUIRED_VARS SDL_GFX_LIBRARIES SDL_GFX_INCLUDE_DIRS
+ VERSION_VAR SDL_GFX_VERSION_STRING)
+
+if(SDL_gfx_FOUND)
+ if(NOT TARGET SDL::SDL_gfx)
+ add_library(SDL::SDL_gfx INTERFACE IMPORTED)
+ set_target_properties(SDL::SDL_gfx PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${SDL_GFX_INCLUDE_DIRS}"
+ INTERFACE_LINK_LIBRARIES "${SDL_GFX_LIBRARIES}")
+ endif()
+endif()
diff --git a/cmake/fetch-libfixmath.cmake b/cmake/fetch-libfixmath.cmake
new file mode 100644
index 0000000..6137dd5
--- /dev/null
+++ b/cmake/fetch-libfixmath.cmake
@@ -0,0 +1,8 @@
+find_path(libfixmath "CMakeLists.txt"
+ PATHS "${PROJECT_SOURCE_DIR}/libfixmath/"
+ NO_DEFAULT_PATH)
+
+if(${libfixmath} STREQUAL "libfixmath-NOTFOUND")
+ message(STATUS "Fetching submodules...")
+ execute_process(COMMAND git submodule update --init --recursive)
+endif()
diff --git a/cmake/host.cmake b/cmake/host.cmake
new file mode 100644
index 0000000..36d7d70
--- /dev/null
+++ b/cmake/host.cmake
@@ -0,0 +1,8 @@
+if(CMAKE_BUILD_TYPE STREQUAL "Debug")
+ set(cflags ${cflags} -Og)
+else()
+ set(cflags ${cflags} -O3)
+endif()
+
+include("${CMAKE_CURRENT_LIST_DIR}/fetch-libfixmath.cmake")
+add_subdirectory(libfixmath)
diff --git a/cmake/ps1-toolchain.cmake b/cmake/ps1-toolchain.cmake
new file mode 100644
index 0000000..26acbd9
--- /dev/null
+++ b/cmake/ps1-toolchain.cmake
@@ -0,0 +1,2 @@
+set(CMAKE_C_COMPILER psx-gcc)
+set(CMAKE_AR mipsel-unknown-elf-ar)
diff --git a/cmake/ps1.cmake b/cmake/ps1.cmake
new file mode 100644
index 0000000..bbc1c4c
--- /dev/null
+++ b/cmake/ps1.cmake
@@ -0,0 +1,43 @@
+find_package(PSXSDK 0.7.1 REQUIRED)
+
+target_compile_definitions(${PROJECT_NAME} PUBLIC FIXMATH_FAST_SIN PSXSDK_DEBUG)
+add_custom_target(exe ALL elf2exe ${PROJECT_NAME}
+ ${cdroot}/${PROJECT_NAME}.exe -mark="A homebrew game created with PSXSDK"
+ DEPENDS ${PROJECT_NAME})
+add_custom_target(iso ALL mkisofs -o ${PROJECT_NAME}.iso -V ${PROJECT_NAME}
+ -sysid PLAYSTATION ${cdroot} DEPENDS exe)
+
+set(license_prefix $ENV{PSXSDK_PATH}/share/licenses)
+
+if(VIDEO_MODE STREQUAL "VMODE_PAL")
+ set(region eur)
+elseif(VIDEO_MODE STREQUAL "VMODE_NTSC")
+ set(ntsc_regions usa jap)
+
+ if(NOT NTSC_REGION IN_LIST ntsc_regions)
+ message(FATAL_ERROR "Please define valid NTSC_REGION. Available options:\n"
+ "${ntsc_regions}\n"
+ "Run CMake again using one of the available options above e.g.:\n"
+ "cmake .. [options] -DNTSC_REGION=US")
+ endif()
+
+ set(region ${NTSC_REGION})
+endif()
+
+set(license $ENV{PSXSDK_PATH}/share/licenses/info${region}.dat)
+
+add_custom_target(bin_cue ALL mkpsxiso ${PROJECT_NAME}.iso ${PROJECT_NAME}.bin
+ ${license} -s DEPENDS iso)
+
+if(NOT EXISTS "${cdroot}/system.cnf")
+ file(COPY "src/system.cnf" DESTINATION "${cdroot}")
+endif()
+
+if(CMAKE_BUILD_TYPE STREQUAL "Debug")
+ set(cflags ${cflags} -Og)
+else()
+ set(cflags ${cflags} -Os)
+endif()
+
+set(cflags ${cflags} -fshort-enums)
+# libfixmath is already bundled with PSXSDK.
diff --git a/cmake/win9x-toolchain.cmake b/cmake/win9x-toolchain.cmake
new file mode 100644
index 0000000..27e7538
--- /dev/null
+++ b/cmake/win9x-toolchain.cmake
@@ -0,0 +1 @@
+set(CMAKE_C_COMPILER i386-mingw32-gcc)
diff --git a/cmake/win9x.cmake b/cmake/win9x.cmake
new file mode 100644
index 0000000..c66ed5e
--- /dev/null
+++ b/cmake/win9x.cmake
@@ -0,0 +1,22 @@
+add_custom_command(OUTPUT ${cdroot}/${PROJECT_NAME}.exe
+ COMMAND i386-mingw32-strip ${PROJECT_NAME}${CMAKE_EXECUTABLE_SUFFIX}
+ -o ${cdroot}/${PROJECT_NAME}.exe
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+ DEPENDS ${PROJECT_NAME}
+ VERBATIM)
+add_custom_target(stripped-exe ALL DEPENDS ${cdroot}/${PROJECT_NAME}.exe)
+
+target_link_libraries(SDL::SDL INTERFACE gdi32 user32 winmm dxguid)
+target_link_libraries(ENET INTERFACE wsock32)
+
+add_compile_options(-march=i386)
+
+if(CMAKE_BUILD_TYPE STREQUAL "Debug")
+ # i386-mingw32-gcc 3.4.5 does not support -Og.
+ set(cflags ${cflags} -O0)
+else()
+ set(cflags ${cflags} -Os)
+endif()
+
+include("${CMAKE_CURRENT_LIST_DIR}/fetch-libfixmath.cmake")
+add_subdirectory(libfixmath)