Refactor CMakeLists.txt for platform-independent build and reorganize project structure
This commit is contained in:
parent
15a6e2f736
commit
8910b73468
@ -1,39 +1,71 @@
|
|||||||
cmake_minimum_required(VERSION 3.28)
|
cmake_minimum_required(VERSION 3.28)
|
||||||
project(Prog3B)
|
project(Prog3B)
|
||||||
set(EXECUTABLE_NAME Prog3B)
|
|
||||||
set(OS_NAME windows)
|
# Set C++ standard to C++20
|
||||||
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
# Generate compile_commands.json
|
# Generate compile_commands.json
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
|
||||||
|
|
||||||
# Set the default build type if not specified
|
# Set the default build type if not specified
|
||||||
if(NOT CMAKE_BUILD_TYPE)
|
if(NOT CMAKE_BUILD_TYPE)
|
||||||
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
|
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(SRC_FILES
|
# --- Sources & Include directories ---
|
||||||
${CMAKE_CURRENT_LIST_DIR}/main.cpp
|
# Automatically include all .cpp files in the src/ folder
|
||||||
${CMAKE_CURRENT_LIST_DIR}/gamecube.cpp
|
file(GLOB SRC_FILES "src/*.cpp")
|
||||||
)
|
|
||||||
|
|
||||||
|
# Include directories for header files
|
||||||
set(INCLUDE_DIRS
|
set(INCLUDE_DIRS
|
||||||
${CMAKE_CURRENT_LIST_DIR}/linux
|
${CMAKE_CURRENT_LIST_DIR}/includes
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/raylib
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(${EXECUTABLE_NAME} ${SRC_FILES})
|
# Create the executable target
|
||||||
target_include_directories(${EXECUTABLE_NAME} PRIVATE ${INCLUDE_DIRS})
|
add_executable(${PROJECT_NAME} ${SRC_FILES})
|
||||||
target_link_libraries(${EXECUTABLE_NAME} PRIVATE
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}/${OS_NAME}/libgamematrix.a
|
# Add include directories to the target
|
||||||
${CMAKE_CURRENT_LIST_DIR}/${OS_NAME}/libraylib.a
|
target_include_directories(${PROJECT_NAME} PRIVATE ${INCLUDE_DIRS})
|
||||||
)
|
|
||||||
|
|
||||||
|
# --- Automatic platform detection ---
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
target_link_libraries(Prog3B PRIVATE winmm)
|
# Windows build
|
||||||
endif()
|
message(STATUS "Building for Windows...")
|
||||||
|
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/windows/libgamematrix.a
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/windows/libraylib.a
|
||||||
|
winmm # Windows multimedia library required by Raylib
|
||||||
|
)
|
||||||
|
|
||||||
# Checks if OSX and links appropriate frameworks (Only required on MacOS)
|
elseif(APPLE)
|
||||||
if (APPLE)
|
# macOS build
|
||||||
target_link_libraries(Prog3B "-framework IOKit")
|
message(STATUS "Building for macOS...")
|
||||||
target_link_libraries(Prog3B "-framework Cocoa")
|
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64")
|
||||||
target_link_libraries(Prog3B "-framework OpenGL")
|
set(OS_FOLDER "mac_arm")
|
||||||
|
else()
|
||||||
|
set(OS_FOLDER "mac_x86")
|
||||||
|
endif()
|
||||||
|
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/${OS_FOLDER}/libgamematrix.a
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/${OS_FOLDER}/libraylib.a
|
||||||
|
"-framework IOKit" # For device input
|
||||||
|
"-framework Cocoa" # For windows/UI
|
||||||
|
"-framework OpenGL" # For rendering
|
||||||
|
)
|
||||||
|
|
||||||
|
elseif(UNIX)
|
||||||
|
# Linux build
|
||||||
|
message(STATUS "Building for Linux...")
|
||||||
|
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/linux/libgamematrix.a
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/linux/libraylib.a
|
||||||
|
m pthread dl # Standard Linux libraries
|
||||||
|
)
|
||||||
|
|
||||||
|
else()
|
||||||
|
# Unsupported OS
|
||||||
|
message(FATAL_ERROR "Unsupported operating system.")
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "gamematrix.h"
|
#include "gamematrix.h"
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
#include <rlgl.h>
|
#include "rlgl.h"
|
||||||
|
|
||||||
struct Vec3
|
struct Vec3
|
||||||
{
|
{
|
||||||
@ -1,4 +1,4 @@
|
|||||||
#include "gamecube.h"
|
#include "../../prog_3/includes/gamecube.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user