Moving to CMAKE

This commit is contained in:
Mark Long
2025-09-28 15:37:32 -05:00
parent 27026e27cc
commit 69476215cd
5 changed files with 532 additions and 1 deletions
+11 -1
View File
@@ -6,4 +6,14 @@ compile_commands.json
.qmake.stash
qrc_resources.cpp
AppleSAWS
Makefile
Makefile
# CMake build directories and files
build/
build-*/
CMakeCache.txt
CMakeFiles/
cmake_install.cmake
*.cmake
!CMakeLists.txt
!CMakePresets.json
+204
View File
@@ -0,0 +1,204 @@
# AppleSAWS: QMake to CMake Migration Guide
## Overview
This guide documents the conversion of AppleSAWS from QMake (.pro) to CMake build system while maintaining your existing directory structure and build environment.
## Migration Benefits
- **Modern Build System**: CMake is more widely supported and actively developed
- **Better IDE Integration**: Enhanced support in VS Code, CLion, Qt Creator, and other IDEs
- **Cross-Platform**: More robust cross-platform building
- **Dependency Management**: Better integration with package managers (vcpkg, Conan)
- **Modern C++ Support**: Better support for C++20 features and modules
## Files Added/Modified
### New Files Created:
- `CMakeLists.txt` - Main CMake configuration
- `CMakePresets.json` - Build presets for different configurations
- `build.sh` - Convenience build script
- `CMAKE_MIGRATION.md` - This guide
### Modified Files:
- `.gitignore` - Added CMake build directories and files
### Preserved Files:
- `AppleSAWS.pro` - Kept for reference/backup (can be removed later)
- All source files and directory structure - unchanged
- `.vscode/` configuration - unchanged
## Build Comparison
### Old QMake Workflow:
```bash
qmake6
make -j$(nproc)
./AppleSAWS
```
### New CMake Workflow:
```bash
# Using presets (recommended)
cmake --preset default
cmake --build build --parallel $(nproc)
./build/AppleSAWS
# Or using the convenience script
./build.sh
```
### Alternative CMake Workflow:
```bash
# Manual configuration
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug
make -j$(nproc)
./AppleSAWS
```
## Configuration Equivalents
| QMake (.pro) | CMake (CMakeLists.txt) | Description |
|--------------|------------------------|-------------|
| `CONFIG += c++20 debug` | `set(CMAKE_CXX_STANDARD 20)` + Debug preset | C++20 standard |
| `QT += core gui widgets printsupport` | `find_package(Qt6 REQUIRED COMPONENTS ...)` | Qt modules |
| `INCLUDEPATH += src/...` | `include_directories(...)` | Include paths |
| `SOURCES += src/...` | `set(SOURCES ...)` | Source files |
| `HEADERS += src/...` | `set(HEADERS ...)` | Header files |
| `FORMS += src/...` | `set(UI_FILES ...)` | UI forms |
| `RESOURCES += src/...` | `set(QRC_FILES ...)` | Resource files |
| `MOC_DIR = ./.build` | `set(CMAKE_AUTOMOC_OUTPUT_DIR ...)` | MOC output |
| `DEFINES += WS_VIDEO` | `add_definitions(-DWS_VIDEO)` | Preprocessor defines |
## Build Directories
### QMake Structure:
```
AppleSAWS/
├── .build/ # Generated MOC/UI files
├── AppleSAWS # Executable in root
├── Makefile # Generated makefile
└── qrc_resources.cpp # Generated resource file
```
### CMake Structure:
```
AppleSAWS/
├── build/ # Debug build directory
│ ├── AppleSAWS # Debug executable
│ └── .build/ # Generated MOC/UI files
├── build-release/ # Release build directory (when built)
│ └── AppleSAWS # Release executable
└── CMakeCache.txt # CMake configuration cache
```
## VS Code Integration
Your existing `.vscode/` configuration should work with CMake. The CMake Tools extension will automatically detect the CMakeLists.txt and provide:
- Automatic configuration detection
- Build target selection
- Debug configuration
- IntelliSense integration
## Build Presets
The `CMakePresets.json` file provides two presets:
### Debug Preset (`default`):
- Build type: Debug
- Output: `build/AppleSAWS`
- Generates compile_commands.json for IntelliSense
### Release Preset:
- Build type: Release
- Output: `build-release/AppleSAWS`
- Optimized executable
## Testing the Migration
1. **Backup current setup** (optional):
```bash
git add -A && git commit -m "Backup before CMake migration"
```
2. **Test CMake build**:
```bash
./build.sh
```
3. **Compare executables**:
```bash
# Build with QMake
make clean && qmake6 && make -j$(nproc)
ls -la AppleSAWS
# Build with CMake
./build.sh
ls -la build/AppleSAWS
```
4. **Test functionality**:
```bash
# Test QMake version
./AppleSAWS
# Test CMake version
./build/AppleSAWS
```
## Troubleshooting
### Common Issues:
1. **Qt6 not found**:
```bash
sudo apt update && sudo apt install qt6-base-dev qt6-tools-dev
```
2. **Missing CMake version**:
```bash
cmake --version # Should be 3.20+
sudo apt install cmake # or upgrade if needed
```
3. **Build fails with missing files**:
- Check that all source files in `SOURCES` list exist
- Verify file extensions match actual files (.cxx vs .cpp)
4. **MOC/UI generation issues**:
- Ensure `CMAKE_AUTOMOC=ON` and `CMAKE_AUTOUIC=ON`
- Check that Qt6 components are properly linked
## Rollback Plan
If you need to revert to QMake:
1. The original `AppleSAWS.pro` file is preserved
2. Simply use: `qmake6 && make`
3. Remove CMake files: `rm -rf build build-release CMakeCache.txt`
## Maintenance
### Adding New Files:
1. **Source files**: Add to `SOURCES` list in CMakeLists.txt
2. **Headers**: Add to `HEADERS` list (optional, for IDE organization)
3. **UI files**: Add to `UI_FILES` list
4. **Resources**: Add to `QRC_FILES` list
### Configuration Changes:
- Edit `CMakeLists.txt` for build configuration changes
- Edit `CMakePresets.json` for preset modifications
- Use `cmake --build build --clean-first` for clean rebuilds
## Performance Notes
- CMake builds should be comparable in speed to QMake
- Parallel builds: `cmake --build build --parallel $(nproc)`
- Incremental builds are typically faster with CMake
- First-time configuration may be slower due to dependency detection
## Next Steps
Once comfortable with CMake:
1. Remove `AppleSAWS.pro` and `Makefile`
2. Consider modern CMake features (target-based configuration)
3. Explore CMake package management integration
4. Set up CI/CD with CMake support
+243
View File
@@ -0,0 +1,243 @@
cmake_minimum_required(VERSION 3.20)
project(AppleSAWS VERSION 1.0.0 LANGUAGES CXX)
# Set C++20 standard
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Set build type to Debug if not specified
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
# Enable debug information and disable optimizations for Debug builds
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
endif()
# Find required Qt6 components
find_package(Qt6 REQUIRED COMPONENTS Core Widgets Gui PrintSupport)
# Automatically handle Qt's MOC, UIC, and RCC
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
# Set custom build directory for generated files
set(CMAKE_AUTOMOC_OUTPUT_DIR ${CMAKE_BINARY_DIR}/.build)
set(CMAKE_AUTOUIC_OUTPUT_DIR ${CMAKE_BINARY_DIR}/.build)
set(CMAKE_AUTORCC_OUTPUT_DIR ${CMAKE_BINARY_DIR}/.build)
# Add compile definitions
add_definitions(-DWS_VIDEO)
# Include directories (equivalent to INCLUDEPATH in .pro file)
include_directories(
src/
src/relocatablefile
src/diskfiles
src/diskfiles/dos33
src/util
src/applesoftfile
src/intbasic
src/binaryfile
src/textfile
src/ui/viewers
src/imported
src/internals
src/ui/diskexplorer
src/ui/widgets
src/ui
src/memory
src/memory/roles
)
# Source files
set(SOURCES
src/intbasic/IntBasicFile.cxx
src/main.cxx
src/diskfiles/dos33/DiskFile.cxx
src/diskfiles/dos33/Sector.cxx
src/diskfiles/dos33/Vtoc.cxx
src/diskfiles/dos33/CatalogSector.cxx
src/diskfiles/dos33/TrackSectorList.cxx
src/diskfiles/dos33/FileDescriptiveEntry.cxx
src/diskfiles/dos33/GenericFile.cxx
src/memory/AttributedMemory.cxx
src/memory/MemoryCell.cxx
src/memory/MemRole.cxx
src/memory/roles/RoleAsmOpcode.cxx
src/memory/roles/RoleAsmOperand.cxx
src/ui/widgets/StartupDialog.cxx
src/ui/viewers/IntBasicFileViewer.cxx
src/ui/widgets/NotesDialog.cxx
src/util/AppleString.cxx
src/applesoftfile/ApplesoftFile.cxx
src/applesoftfile/ApplesoftToken.cxx
src/applesoftfile/ApplesoftFormatter.cxx
src/binaryfile/Disassembler.cxx
src/binaryfile/BinaryFile.cxx
src/textfile/TextFile.cxx
src/ui/widgets/CatalogWidget.cxx
src/ui/viewers/HiresViewer.cxx
src/ui/viewers/ApplesoftFileViewer.cxx
src/ui/viewers/DisassemblerViewer.cxx
src/ui/viewers/HexDumpViewer.cxx
src/ui/viewers/TextHexDumpViewer.cxx
src/ui/viewers/MazeViewer.cxx
src/ui/viewers/CharSetViewer.cxx
src/relocatablefile/RelocatableFile.cxx
src/binaryfile/BinaryFileMetadata.cxx
src/util/CharSet.cxx
src/ui/widgets/CharacterWidget.cxx
src/ui/viewers/ApplesoftFileDetailViewer.cxx
src/ui/widgets/HexConverter.cxx
src/ui/viewers/ViewerBase.cxx
src/ui/widgets/CharacterSetExplorer.cxx
src/ui/widgets/HiresScreenWidget.cxx
src/ui/widgets/DisassemblerMetadataDialog.cxx
src/binaryfile/EntryPointModel.cxx
src/ui/widgets/LocationInfoDialog.cxx
src/binaryfile/EntryPoints.cxx
src/binaryfile/AssemblerSymbols.cxx
src/binaryfile/AssemblerSymbolModel.cxx
src/ui/diskexplorer/DiskExplorer.cxx
src/ui/diskexplorer/DiskExplorerMapWidget.cxx
src/applesoftfile/ApplesoftRetokenizer.cxx
src/internals/JumpLineManager.cxx
src/ui/widgets/FlowLineTextBrowser.cxx
src/util/OpCodes.cxx
)
# Header files (for IDE organization, not strictly necessary for CMake)
set(HEADERS
src/diskfiles/dos33/DiskFile.h
src/diskfiles/dos33/Sector.h
src/diskfiles/dos33/Vtoc.h
src/diskfiles/dos33/CatalogSector.h
src/diskfiles/dos33/TrackSectorList.h
src/diskfiles/dos33/FileDescriptiveEntry.h
src/diskfiles/dos33/GenericFile.h
src/intbasic/IntBasicFile.h
src/memory/AttributedMemory.h
src/memory/MemoryCell.h
src/memory/MemRole.h
src/memory/roles/RoleAsmOpcode.h
src/memory/roles/RoleAsmOperand.h
src/ui/widgets/StartupDialog.h
src/ui/viewers/IntBasicFileViewer.h
src/ui/widgets/NotesDialog.h
src/util/OpCodes.h
src/util/Util.h
src/util/AppleString.h
src/applesoftfile/ApplesoftFile.h
src/applesoftfile/ApplesoftToken.h
src/binaryfile/Disassembler.h
src/binaryfile/BinaryFile.h
src/textfile/TextFile.h
src/ui/widgets/CatalogWidget.h
src/ui/viewers/HiresViewer.h
src/ui/viewers/ApplesoftFileViewer.h
src/applesoftfile/ApplesoftFormatter.h
src/applesoftfile/ApplesoftLine.h
src/ui/viewers/DisassemblerViewer.h
src/ui/viewers/HexDumpViewer.h
src/ui/viewers/TextHexDumpViewer.h
src/relocatablefile/RelocatableFile.h
src/ui/viewers/MazeViewer.h
src/binaryfile/BinaryFileMetadata.h
src/ui/widgets/CharacterWidget.h
src/util/CharSet.h
src/ui/viewers/CharSetViewer.h
src/ui/viewers/ApplesoftFileDetailViewer.h
src/ui/widgets/HexConverter.h
src/ui/widgets/HRCGControlsInfo.h
src/ui/viewers/ViewerBase.h
src/ui/viewers/FileViewerInterface.h
src/ui/widgets/CharacterSetExplorer.h
src/ui/widgets/HiresScreenWidget.h
src/ui/widgets/DisassemblerMetadataDialog.h
src/binaryfile/EntryPointModel.h
src/ui/widgets/LocationInfoDialog.h
src/binaryfile/EntryPoints.h
src/binaryfile/AssemblerSymbols.h
src/binaryfile/AssemblerSymbolModel.h
src/binaryfile/MemoryUsageMap.h
src/ui/diskexplorer/DiskExplorer.h
src/ui/diskexplorer/DiskExplorerMapWidget.h
src/applesoftfile/ApplesoftRetokenizer.h
src/util/AppleColors.h
src/internals/JumpLineManager.h
src/ui/widgets/FlowLineTextBrowser.h
src/ui/widgets/AsciiInfoDialog.h
)
# UI files (Qt Designer forms)
set(UI_FILES
src/ui/widgets/CatalogWidget.ui
src/ui/widgets/StartupDialog.ui
src/ui/viewers/ApplesoftFileViewer.ui
src/ui/viewers/DisassemblerViewer.ui
src/ui/viewers/HexDumpViewer.ui
src/ui/viewers/IntBasicFileViewer.ui
src/ui/viewers/TextHexDumpViewer.ui
src/ui/viewers/ApplesoftFileDetailViewer.ui
src/ui/widgets/HexConverter.ui
src/ui/widgets/HRCGControlsInfo.ui
src/ui/viewers/ViewerBase.ui
src/ui/widgets/CharacterSetExplorer.ui
src/ui/widgets/DisassemblerMetadataDialog.ui
src/ui/widgets/LocationInfoDialog.ui
src/ui/widgets/AsciiInfoDialog.ui
src/ui/widgets/NotesDialog.ui
)
# Resource files
set(QRC_FILES
src/resource/resources.qrc
)
# Create the executable
add_executable(AppleSAWS
${SOURCES}
${HEADERS}
${UI_FILES}
${QRC_FILES}
)
# Link Qt libraries
target_link_libraries(AppleSAWS
Qt6::Core
Qt6::Widgets
Qt6::Gui
Qt6::PrintSupport
)
# Set output directory to match your current setup
set_target_properties(AppleSAWS PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
)
# Optional: Set properties for different build types
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_definitions(AppleSAWS PRIVATE DEBUG_BUILD)
endif()
# Optional: Install target (customize as needed)
install(TARGETS AppleSAWS
RUNTIME DESTINATION bin
)
# Optional: Create a custom target for cleaning generated files
add_custom_target(clean-cmake-files
COMMAND ${CMAKE_COMMAND} -P clean-cmake-files.cmake
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Cleaning CMake generated files"
)
# Optional: Print configuration info
message(STATUS "AppleSAWS Configuration:")
message(STATUS " Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS " C++ standard: ${CMAKE_CXX_STANDARD}")
message(STATUS " Qt6 version: ${Qt6_VERSION}")
+42
View File
@@ -0,0 +1,42 @@
{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 20,
"patch": 0
},
"configurePresets": [
{
"name": "default",
"displayName": "Default Config",
"description": "Default build configuration",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
}
},
{
"name": "release",
"displayName": "Release Config",
"description": "Release build configuration",
"binaryDir": "${sourceDir}/build-release",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
}
}
],
"buildPresets": [
{
"name": "default",
"configurePreset": "default",
"displayName": "Default Build"
},
{
"name": "release",
"configurePreset": "release",
"displayName": "Release Build"
}
]
}
Executable
+32
View File
@@ -0,0 +1,32 @@
#!/bin/bash
# CMake build script for AppleSAWS
echo "=== AppleSAWS CMake Build Script ==="
# Clean previous builds
echo "Cleaning previous builds..."
rm -rf build build-release
# Configure and build Debug version
echo "Configuring Debug build..."
cmake --preset default
if [ $? -ne 0 ]; then
echo "CMake configuration failed!"
exit 1
fi
echo "Building Debug version..."
cmake --build build --parallel $(nproc)
if [ $? -ne 0 ]; then
echo "Build failed!"
exit 1
fi
echo "=== Build completed successfully! ==="
echo "Debug executable: ./build/AppleSAWS"
echo ""
echo "To build Release version, run:"
echo "cmake --preset release && cmake --build build-release --parallel $(nproc)"
echo ""
echo "To run the application:"
echo "cd build && ./AppleSAWS"