shapes/CMakeLists.txt
2025-05-24 12:15:03 -04:00

68 lines
3.5 KiB
CMake

cmake_minimum_required(VERSION 3.15)
project(ShapePatternGenerator VERSION 1.0 LANGUAGES CXX C)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_C_STANDARD 99) # Raylib is C, so C99 is a safe bet for it
# --- Locating Raylib ---
# Option 1: Using find_package (Preferred if Raylib is installed system-wide, via vcpkg, or CMAKE_PREFIX_PATH is set)
# This relies on Raylib providing a raylib-config.cmake or RaylibConfig.cmake.
# You might need to set CMAKE_PREFIX_PATH if Raylib is installed in a custom location.
# e.g., cmake -S . -B build -DCMAKE_PREFIX_PATH=/path/to/raylib_install_dir
# Remove or adjust version number based on your Raylib installation.
find_package(raylib CONFIG)
if (raylib_FOUND)
message(STATUS "Found Raylib version ${raylib_VERSION} using find_package.")
add_executable(ShapeGenerator main.cpp)
# Modern CMake uses an imported target like raylib::raylib if provided by Raylib's CMake config
target_link_libraries(ShapeGenerator PRIVATE raylib::raylib)
else()
message(WARNING "Raylib not found via find_package(raylib CONFIG).")
message(STATUS "Attempting to build Raylib from a subdirectory (if present)...")
# Option 2: Add Raylib as a subdirectory (if you have the Raylib source code in a 'raylib' folder)
# Example: git submodule add https://github.com/raysan5/raylib.git raylib
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/raylib/CMakeLists.txt")
message(STATUS "Found Raylib source in 'raylib' subdirectory, adding it.")
# Common Raylib build options (can be customized as needed)
set(BUILD_EXAMPLES OFF CACHE BOOL "Build Raylib examples" FORCE)
set(SUPPORT_MODULE_RSHAPES OFF CACHE BOOL "Build rshapes module" FORCE) # Keep build minimal
set(SUPPORT_MODULE_RTEXTURES OFF CACHE BOOL "Build rtextures module" FORCE)
# Add other SUPPORT_MODULE_* OFF if you want to slim down Raylib further
add_subdirectory(raylib) # This will build Raylib along with your project
add_executable(ShapeGenerator main.cpp)
# 'raylib' is the target name defined by Raylib's CMakeLists.txt when built as a subdirectory
target_link_libraries(ShapeGenerator PRIVATE raylib)
else()
message(FATAL_ERROR
"Raylib not found via find_package and no 'raylib' subdirectory with Raylib source found. "
"Please ensure Raylib is correctly installed and discoverable by CMake (e.g., set CMAKE_PREFIX_PATH), "
"or clone Raylib into a 'raylib' subdirectory of your project.")
endif()
endif()
# Set the output directory for the executable (e.g., to the root of the build folder)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
# Optional: For some platforms/compilers, especially on Windows with GCC/Clang (MinGW),
# Raylib might require linking against specific system libraries.
# If using `find_package` with a proper Raylib CMake config or `add_subdirectory`,
# Raylib's own CMake script should handle these. This is just for troubleshooting.
# if (WIN32 AND (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
# target_link_libraries(ShapeGenerator PRIVATE opengl32 gdi32 winmm shell32)
# endif()
# --- Information for using Clang ---
# To use Clang, you can either:
# 1. Set environment variables before running CMake:
# export CC=clang
# export CXX=clang++
# 2. Or specify the compilers when configuring CMake:
# cmake -S . -B build -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
# CMake will then use Clang for compilation.