Skip to content

Commit 2da7e26

Browse files
committed
Implement CMake build system
Signed-off-by: Panagiotis Georgiadis <[email protected]>
1 parent 2aee328 commit 2da7e26

File tree

83 files changed

+1816
-93
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1816
-93
lines changed

.github/workflows/doxygen-gh-pages.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ jobs:
3434
sudo apt-get install doxygen -y
3535
shell: bash
3636

37-
- name: "Build Doxygen Doc"
37+
- name: "Build Doxygen Doc with CMake"
3838
run: |
39-
cd pvsneslib
40-
export PVSNESLIB_HOME=`pwd`
41-
make docs
39+
cmake -B build -DPVSNESLIB_BUILD_DOCS=ON
40+
cmake --build build --target docs
4241
shell: bash
4342

4443
# 3. Déploiement sur les Github Pages

.github/workflows/pvsneslib_build_package.yml

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,23 +78,10 @@ jobs:
7878
# ------------------------------------ #
7979
# Compiling sources and create release #
8080
# ------------------------------------ #
81-
- name: Build & Release PVSNESLIB for Linux
82-
if: (matrix.name == 'linux')
81+
- name: Build & Release PVSNESLIB with CMake
8382
run: |
84-
export PVSNESLIB_HOME=$(pwd)
85-
make release | tee pvsneslib_release_${{ matrix.name }}.log
86-
- name: Build & Release PVSNESLIB for Windows
87-
if: (matrix.name == 'windows')
88-
shell: msys2 {0}
89-
run: |
90-
export PVSNESLIB_HOME=$(pwd)
91-
make release | tee pvsneslib_release_${{ matrix.name }}.log
92-
- name: Build & Release PVSNESLIB for MacOS
93-
if: (matrix.name == 'darwin')
94-
run: |
95-
export PVSNESLIB_HOME=$(pwd)
96-
export PATH="/opt/homebrew/opt/gnu-sed/libexec/gnubin:$PATH"
97-
make release | tee pvsneslib_release_${{ matrix.name }}.log
83+
cmake -B build -DPVSNESLIB_BUILD_EXAMPLES=ON -DPVSNESLIB_AUTO_SUBMODULES=ON
84+
cmake --build build --target release | tee pvsneslib_release_${{ matrix.name }}.log
9885
9986
# ------------------------------------ #
10087
# Checking libraries linking #
@@ -115,7 +102,7 @@ jobs:
115102
uses: actions/upload-artifact@v4
116103
with:
117104
name: PVSNESLIB Release for ${{ matrix.name }}
118-
path: release/pvsneslib_64b_${{ matrix.name }}.zip
105+
path: release/pvsneslib_*_${{ matrix.name }}.tar.gz
119106

120107
# ------------------------------------ #
121108
# Upload releases #

.gitignore

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,13 @@ soundbank.h
7474
*.dbg
7575

7676
# Mac OS cache files
77-
.DS_Store
77+
.DS_Store
78+
79+
# CMake build directory
80+
build/
81+
82+
# Release directory
83+
release/
84+
85+
# CMake generated files
86+
pvsneslib/source/comp_defs.asm

CMakeLists.txt

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
project(PVSnesLib VERSION 4.4.0 LANGUAGES C CXX)
3+
4+
# Set C standard
5+
set(CMAKE_C_STANDARD 90)
6+
set(CMAKE_C_STANDARD_REQUIRED ON)
7+
8+
# Set C++ standard for tools that need it
9+
set(CMAKE_CXX_STANDARD 11)
10+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
11+
12+
# Pure CMake build system - no Make dependencies
13+
option(PVSNESLIB_BUILD_EXAMPLES "Build SNES examples" ON)
14+
option(PVSNESLIB_AUTO_SUBMODULES "Automatically initialize submodules" ON)
15+
option(PVSNESLIB_BUILD_DOCS "Build documentation (requires Doxygen)" ON)
16+
17+
# Set PVSNESLIB_HOME - support both environment variable and local builds
18+
if(DEFINED ENV{PVSNESLIB_HOME})
19+
set(PVSNESLIB_HOME $ENV{PVSNESLIB_HOME} CACHE PATH "PVSnesLib home directory")
20+
message(STATUS "Using PVSNESLIB_HOME from environment: ${PVSNESLIB_HOME}")
21+
else()
22+
set(PVSNESLIB_HOME ${CMAKE_SOURCE_DIR} CACHE PATH "PVSnesLib home directory")
23+
message(STATUS "Using local PVSnesLib build: ${PVSNESLIB_HOME}")
24+
endif()
25+
26+
# Platform detection (mirroring existing Makefile logic)
27+
if(WIN32)
28+
set(PVSNESLIB_OS "windows")
29+
elseif(CMAKE_SYSTEM_NAME MATCHES "MINGW")
30+
set(PVSNESLIB_OS "mingw")
31+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
32+
set(PVSNESLIB_OS "darwin")
33+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
34+
set(PVSNESLIB_OS "linux")
35+
elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
36+
set(PVSNESLIB_OS "freebsd")
37+
else()
38+
message(FATAL_ERROR "Unsupported operating system: ${CMAKE_SYSTEM_NAME}")
39+
endif()
40+
41+
# Architecture detection (improved over hardcoded 64b)
42+
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64")
43+
set(PVSNESLIB_ARCH "arm64")
44+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64")
45+
set(PVSNESLIB_ARCH "x64")
46+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "i386|i686")
47+
set(PVSNESLIB_ARCH "x86")
48+
else()
49+
# Fallback to original naming for unknown architectures
50+
set(PVSNESLIB_ARCH "64b")
51+
endif()
52+
53+
message(STATUS "Building PVSnesLib for: ${PVSNESLIB_ARCH}_${PVSNESLIB_OS}")
54+
message(STATUS "PVSnesLib home: ${PVSNESLIB_HOME}")
55+
message(STATUS "Detected architecture: ${CMAKE_SYSTEM_PROCESSOR}${PVSNESLIB_ARCH}")
56+
57+
message(STATUS "Using pure CMake build system")
58+
59+
# Include ExternalProject for handling submodules
60+
include(ExternalProject)
61+
62+
# Add our CMake modules
63+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
64+
65+
# Automatically initialize and update submodules if requested
66+
if(PVSNESLIB_AUTO_SUBMODULES)
67+
message(STATUS "Synchronizing submodules to match superproject...")
68+
69+
find_package(Git REQUIRED)
70+
execute_process(
71+
COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
72+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
73+
RESULT_VARIABLE GIT_RESULT
74+
OUTPUT_VARIABLE GIT_OUTPUT
75+
ERROR_VARIABLE GIT_ERROR
76+
)
77+
78+
if(NOT GIT_RESULT EQUAL 0)
79+
message(WARNING "Failed to synchronize submodules.")
80+
message(WARNING "Please run manually: git submodule update --init --recursive")
81+
message(WARNING "Git output: ${GIT_OUTPUT}")
82+
message(WARNING "Git error: ${GIT_ERROR}")
83+
else()
84+
message(STATUS "Submodules synchronized successfully!")
85+
endif()
86+
endif()
87+
88+
# Create directories that match existing structure
89+
file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/devkitsnes/bin)
90+
file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/devkitsnes/tools)
91+
92+
# Add subdirectories in dependency order (matching existing Makefile)
93+
add_subdirectory(compiler)
94+
add_subdirectory(tools)
95+
add_subdirectory(pvsneslib)
96+
97+
if(PVSNESLIB_BUILD_EXAMPLES)
98+
add_subdirectory(snes-examples)
99+
endif()
100+
101+
102+
# Documentation is handled in pvsneslib/CMakeLists.txt
103+
104+
#=============================================================================
105+
# ESSENTIAL TARGETS - Only 3 Things You Need
106+
#=============================================================================
107+
108+
# 1. Absolute minimum to write SNES programs and make ROMs
109+
add_custom_target(minimal
110+
DEPENDS compiler tools library
111+
COMMENT "🔧 Minimal SNES development environment (compiler + tools + library only)"
112+
)
113+
114+
# 2. Build examples only (assumes minimal is already built)
115+
add_custom_target(examples_only
116+
DEPENDS examples audio_examples games_examples logo_examples sram_examples objects_examples input_examples advanced_examples
117+
COMMENT "🎮 Build working SNES examples (40+ ROMs)"
118+
)
119+
120+
# 3. Build absolutely everything
121+
add_custom_target(everything
122+
DEPENDS compiler tools library examples audio_examples games_examples logo_examples sram_examples objects_examples input_examples advanced_examples
123+
COMMENT "🚀 Build everything (minimal + working examples)"
124+
)
125+
126+
# Note: Clean aliases (compiler, tools, library) are defined in their respective subdirectories
127+
128+
#=============================================================================
129+
# RELEASE SYSTEM - Complete Package Creation
130+
#=============================================================================
131+
132+
# Release target that matches and improves upon original Makefile release
133+
add_custom_target(release
134+
# Prerequisites: Build everything and generate documentation
135+
DEPENDS everything docs
136+
137+
# Create release directory structure
138+
COMMAND ${CMAKE_COMMAND} -E remove_directory release
139+
COMMAND ${CMAKE_COMMAND} -E make_directory release/pvsneslib
140+
141+
# Copy core development tools (compiler and utilities)
142+
COMMAND ${CMAKE_COMMAND} -E copy_directory devkitsnes release/
143+
144+
# Copy library components
145+
COMMAND ${CMAKE_COMMAND} -E copy_directory pvsneslib/include release/pvsneslib
146+
COMMAND ${CMAKE_COMMAND} -E copy_directory pvsneslib/lib release/pvsneslib
147+
COMMAND ${CMAKE_COMMAND} -E copy_directory pvsneslib/docs/html release/pvsneslib
148+
149+
# Copy library metadata and documentation
150+
COMMAND ${CMAKE_COMMAND} -E copy pvsneslib/PVSnesLib_Logo.png release/pvsneslib/
151+
COMMAND ${CMAKE_COMMAND} -E copy pvsneslib/pvsneslib_license.txt release/pvsneslib/
152+
COMMAND ${CMAKE_COMMAND} -E copy pvsneslib/pvsneslib_snesmod.txt release/pvsneslib/
153+
COMMAND ${CMAKE_COMMAND} -E copy pvsneslib/pvsneslib_version.txt release/pvsneslib/
154+
155+
# Copy examples and CMake system for external projects
156+
COMMAND ${CMAKE_COMMAND} -E copy_directory snes-examples release/snes-examples
157+
COMMAND ${CMAKE_COMMAND} -E copy_directory cmake release/cmake
158+
159+
# Create release archive with version and platform info
160+
COMMAND ${CMAKE_COMMAND} -E chdir release tar czf pvsneslib_${PROJECT_VERSION}_${PVSNESLIB_ARCH}_${PVSNESLIB_OS}.tar.gz pvsneslib cmake
161+
162+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
163+
COMMENT "🚀 Creating PVSnesLib ${PROJECT_VERSION} release package for ${PVSNESLIB_ARCH}_${PVSNESLIB_OS}"
164+
VERBATIM
165+
)
166+
167+
# Version information target
168+
add_custom_target(version
169+
COMMAND ${CMAKE_COMMAND} -E echo ""
170+
COMMAND ${CMAKE_COMMAND} -E echo "🎮 PVSnesLib Version Information"
171+
COMMAND ${CMAKE_COMMAND} -E echo "================================="
172+
COMMAND ${CMAKE_COMMAND} -E echo "Library Version: ${PROJECT_VERSION}"
173+
COMMAND ${CMAKE_COMMAND} -E echo "Build Platform: ${PVSNESLIB_OS}"
174+
COMMAND ${CMAKE_COMMAND} -E echo "Architecture: ${PVSNESLIB_ARCH}"
175+
COMMAND ${CMAKE_COMMAND} -E echo "Release Name: pvsneslib_${PROJECT_VERSION}_${PVSNESLIB_ARCH}_${PVSNESLIB_OS}.tar.gz"
176+
COMMAND ${CMAKE_COMMAND} -E echo "CMake Version: ${CMAKE_VERSION}"
177+
COMMAND ${CMAKE_COMMAND} -E echo "Build Type: ${CMAKE_BUILD_TYPE}"
178+
COMMAND ${CMAKE_COMMAND} -E echo ""
179+
COMMENT "Display PVSnesLib version information"
180+
)
181+
182+
#=============================================================================
183+
# CUSTOM HELP TARGET - User-Friendly Target Overview
184+
#=============================================================================
185+
186+
add_custom_target(guide
187+
COMMAND ${CMAKE_COMMAND} -E echo ""
188+
COMMAND ${CMAKE_COMMAND} -E echo "🎮 PVSnesLib - 3 Essential Targets"
189+
COMMAND ${CMAKE_COMMAND} -E echo "=================================="
190+
COMMAND ${CMAKE_COMMAND} -E echo ""
191+
COMMAND ${CMAKE_COMMAND} -E echo "🔧 1. MINIMAL - Absolute minimum to write SNES programs:"
192+
COMMAND ${CMAKE_COMMAND} -E echo " cmake --build build --target minimal"
193+
COMMAND ${CMAKE_COMMAND} -E echo " Result: C compiler + assembler + tools + library"
194+
COMMAND ${CMAKE_COMMAND} -E echo " Use this: To write your own SNES programs"
195+
COMMAND ${CMAKE_COMMAND} -E echo ""
196+
COMMAND ${CMAKE_COMMAND} -E echo "🎮 2. EXAMPLES_ONLY - Build all example ROMs:"
197+
COMMAND ${CMAKE_COMMAND} -E echo " cmake --build build --target examples_only"
198+
COMMAND ${CMAKE_COMMAND} -E echo " Result: 60+ example SNES ROMs"
199+
COMMAND ${CMAKE_COMMAND} -E echo " Use this: To learn from existing examples"
200+
COMMAND ${CMAKE_COMMAND} -E echo ""
201+
COMMAND ${CMAKE_COMMAND} -E echo "🚀 3. EVERYTHING - Build absolutely everything:"
202+
COMMAND ${CMAKE_COMMAND} -E echo " cmake --build build --target everything"
203+
COMMAND ${CMAKE_COMMAND} -E echo " Result: Complete development environment + all examples"
204+
COMMAND ${CMAKE_COMMAND} -E echo " Use this: For complete setup"
205+
COMMAND ${CMAKE_COMMAND} -E echo ""
206+
COMMAND ${CMAKE_COMMAND} -E echo "📋 QUICK START:"
207+
COMMAND ${CMAKE_COMMAND} -E echo " cmake -B build -DPVSNESLIB_BUILD_EXAMPLES=ON"
208+
COMMAND ${CMAKE_COMMAND} -E echo " cmake --build build --target everything"
209+
COMMAND ${CMAKE_COMMAND} -E echo ""
210+
COMMAND ${CMAKE_COMMAND} -E echo "📖 4. DOCUMENTATION - Generate API docs [requires Doxygen]:"
211+
COMMAND ${CMAKE_COMMAND} -E echo " cmake --build build --target docs"
212+
COMMAND ${CMAKE_COMMAND} -E echo " cmake --build build --target docspdf # HTML + PDF manual"
213+
COMMAND ${CMAKE_COMMAND} -E echo " Result: HTML documentation in pvsneslib/docs/html/"
214+
COMMAND ${CMAKE_COMMAND} -E echo " Use this: To browse the complete API reference"
215+
COMMAND ${CMAKE_COMMAND} -E echo ""
216+
COMMAND ${CMAKE_COMMAND} -E echo "🚀 5. RELEASE - Create distribution package:"
217+
COMMAND ${CMAKE_COMMAND} -E echo " cmake --build build --target release"
218+
COMMAND ${CMAKE_COMMAND} -E echo " Result: pvsneslib_${PROJECT_VERSION}_${PVSNESLIB_ARCH}_${PVSNESLIB_OS}.tar.gz"
219+
COMMAND ${CMAKE_COMMAND} -E echo " Use this: To create release packages for distribution"
220+
COMMAND ${CMAKE_COMMAND} -E echo ""
221+
COMMAND ${CMAKE_COMMAND} -E echo "ℹ️ 6. VERSION INFO - Display version information:"
222+
COMMAND ${CMAKE_COMMAND} -E echo " cmake --build build --target version"
223+
COMMAND ${CMAKE_COMMAND} -E echo ""
224+
COMMAND ${CMAKE_COMMAND} -E echo "🎯 INDIVIDUAL COMPONENTS - if needed:"
225+
COMMAND ${CMAKE_COMMAND} -E echo " compiler, tools, library, examples, hello_world, effects, etc."
226+
COMMAND ${CMAKE_COMMAND} -E echo ""
227+
COMMENT "Displaying PVSnesLib essential targets"
228+
)
229+
230+
# Print build summary
231+
message(STATUS "")
232+
message(STATUS "PVSnesLib ${PROJECT_VERSION} build configuration:")
233+
message(STATUS " OS: ${PVSNESLIB_OS}")
234+
message(STATUS " Build examples: ${PVSNESLIB_BUILD_EXAMPLES}")
235+
message(STATUS " Build docs: ${PVSNESLIB_BUILD_DOCS}")
236+
message(STATUS " Install prefix: ${CMAKE_INSTALL_PREFIX}")
237+
message(STATUS "")
File renamed without changes.

0 commit comments

Comments
 (0)