Skip to content

Commit

Permalink
rebuild_PC: move to cmake (adding submodule dependencies fallback) (#114
Browse files Browse the repository at this point in the history
)

* rebuild_PC: adopt thirdparty as submodules

* rebuild_PC: drop nested PsyCross files

* rebuild_PC: update PsyCross in VCXPROJ

* move to cmake (adding vendored dependencies fallback)

* ci: fetch submodules

* ci: build with submodules

* rebuild_PC: fix mingw
  • Loading branch information
PedroHLC authored Apr 11, 2024
1 parent b201442 commit 0a217a9
Show file tree
Hide file tree
Showing 45 changed files with 164 additions and 8,167 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ end_of_line = lf
indent_style = space
indent_size = 2

[CMakeLists.txt]
insert_final_newline = true
end_of_line = lf
indent_style = space
indent_size = 2

[*.{c,C,h,H}]
indent_style = tab
indent_size = 4
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Build
run: nix build -L --no-link --keep-going .#all
run: nix build -L --no-link --keep-going '.?submodules=1#all'
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule "rebuild_PC/thirdparty/PsyCross"]
path = rebuild_PC/thirdparty/PsyCross
url = https://github.com/OpenDriver2/PsyCross.git
[submodule "rebuild_PC/thirdparty/SDL"]
path = rebuild_PC/thirdparty/SDL
url = https://github.com/libsdl-org/SDL.git
[submodule "rebuild_PC/thirdparty/openal-soft"]
path = rebuild_PC/thirdparty/openal-soft
url = https://github.com/kcat/openal-soft.git
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
};
mingw32 = with pkgsCross.mingw32; {
gcc = callPackage ./rebuild_PC { ctrModSDK = self; };
clang = callPackage ./rebuild_PC { ctrModSDK = self; stdenv = clangStdenv; };
clang = callPackage ./rebuild_PC { ctrModSDK = self; stdenv = clangStdenv; trustCompiler = true; };
};
all = stdenvNoCC.mkDerivation {
name = "ctr-join";
Expand Down
111 changes: 111 additions & 0 deletions rebuild_PC/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
cmake_minimum_required(VERSION 3.20)
project(CTR-PC)

# === OPTIONS ===

set(CTR_16BY9 ON)
set(CTR_60FPS ON)
set(CTR_NEW2P ON)
set(CTR_PRIM 0)

# === BASICS ===

set_source_files_properties("CrashTeamRacingPC.c" PROPERTIES LANGUAGE C)
add_executable(ctr_bin "CrashTeamRacingPC.c")
set_target_properties(ctr_bin PROPERTIES OUTPUT_NAME "CrashTeamRacingPC")
target_include_directories(ctr_bin PUBLIC "../include")

# === COMPILER OPTIONS ===

set_property(TARGET ctr_bin PROPERTY C_STANDARD 99)
target_compile_options(ctr_bin PUBLIC -DUSE_EXTENDED_PRIM_POINTERS=${CTR_PRIM})

if(CTR_16BY9)
target_compile_options(ctr_bin PUBLIC -DUSE_16BY9 -DUSE_NEW2P)
endif()
if(CTR_60FPS)
target_compile_options(ctr_bin PUBLIC -DUSE_60FPS)
endif()

# Clang is rigorous
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
target_compile_options(ctr_bin PUBLIC -Wno-int-conversion -Wno-incompatible-function-pointer-types -Wno-implicit-function-declaration -Wno-return-type)
if(MINGW OR CYGWIN)
if(NOT CMAKE_VERSION VERSION_LESS "3.13")
target_link_options(ctr_bin PUBLIC -static-libgcc)
endif()
endif()
endif()

if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
target_compile_options(ctr_bin PUBLIC -g -gdwarf-2 -O0)
else()
target_compile_options(ctr_bin PUBLIC -O2)
endif()

# === LINKER OPTIONS ===

# Clang always needs "no-pie", but some distros might add PIE to GCC too.
target_link_options(ctr_bin PUBLIC -fno-pie -no-pie -Wl,-Ttext,0x00D00000)

# === DEPENDENCIES ===

find_package(SDL2 QUIET)
if(NOT SDL2_FOUND)
add_subdirectory("thirdparty/SDL")
set(SDL2_LIBRARIES SDL2 SDL2main)
set(SDL2_INCLUDE_DIR "thirdparty/SDL/include")
endif()

target_link_libraries(ctr_bin ${SDL2_LIBRARIES})
target_include_directories(ctr_bin PRIVATE ${SDL2_INCLUDE_DIRS})

find_package(OpenAL QUIET)
if(NOT OpenAL_FOUND)
add_subdirectory("thirdparty/openal-soft")
set(OPENAL_LIBRARY OpenAL)
set(OPENAL_INCLUDE_DIR "thirdparty/openal-soft/include")
endif()

# === PsyCross ===

file(GLOB_RECURSE PSYCROSS_SRCS_C
"thirdparty/PsyCross/*.c" "thirdparty/PsyCross/*.C"
)

file(GLOB_RECURSE PSYCROSS_SRCS_CPP
"thirdparty/PsyCross/*.cpp"
)

set_source_files_properties(${PSYCROSS_SRCS_C} PROPERTIES LANGUAGE C)
set_source_files_properties(${PSYCROSS_SRCS_CPP} PROPERTIES LANGUAGE CXX)

add_library(psycross_static STATIC ${PSYCROSS_SRCS_C} ${PSYCROSS_SRCS_CPP})
set_target_properties(psycross_static PROPERTIES OUTPUT_NAME "psycross")
target_include_directories(psycross_static PUBLIC "thirdparty/PsyCross/include")

target_compile_options(psycross_static PRIVATE -Wno-narrowing)

target_link_libraries(psycross_static ${SDL2_LIBRARIES})
target_include_directories(psycross_static PRIVATE ${SDL2_INCLUDE_DIRS})

target_link_libraries(psycross_static ${OPENAL_LIBRARY})
target_include_directories(psycross_static PRIVATE ${OPENAL_INCLUDE_DIR})

# === OUR PsyCross USAGE ===

target_compile_options(psycross_static PUBLIC -DUSE_EXTENDED_PRIM_POINTERS=${CTR_PRIM} -O2)

if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
target_compile_options(psycross_static PUBLIC -g -gdwarf-2)
endif()

# Clang is rigorous
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
target_compile_options(psycross_static PRIVATE -Wno-int-conversion -Wno-implicit-function-declaration)
endif()

target_link_libraries(ctr_bin psycross_static)
target_include_directories(ctr_bin PRIVATE ${PsyCross_SOURCE_DIR}/include)

#target_link_libraries(ctr_bin stdc++ m)
4 changes: 2 additions & 2 deletions rebuild_PC/CrashTeamRacingPC.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(ProjectDir)\PsyCross\include;$(ProjectDir)\..\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ProjectDir)\thirdparty\PsyCross\include;$(ProjectDir)\..\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -96,7 +96,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(ProjectDir)\PsyCross\include;$(ProjectDir)\..\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ProjectDir)\thirdparty\PsyCross\include;$(ProjectDir)\..\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down
20 changes: 0 additions & 20 deletions rebuild_PC/Makefile

This file was deleted.

77 changes: 0 additions & 77 deletions rebuild_PC/PsyCross.nix

This file was deleted.

21 changes: 0 additions & 21 deletions rebuild_PC/PsyCross/LICENSE

This file was deleted.

39 changes: 0 additions & 39 deletions rebuild_PC/PsyCross/README.md

This file was deleted.

16 changes: 0 additions & 16 deletions rebuild_PC/PsyCross/include/PsyX/PsyX_config.h

This file was deleted.

35 changes: 0 additions & 35 deletions rebuild_PC/PsyCross/include/PsyX/PsyX_globals.h

This file was deleted.

Loading

0 comments on commit 0a217a9

Please sign in to comment.