From 11040a004be5d6842cd263fa6822e7baa188c6a9 Mon Sep 17 00:00:00 2001 From: Miguel Villa Floran Date: Mon, 21 Oct 2024 13:52:20 -0700 Subject: [PATCH] Update CMakeLists.txt --- CMakeLists.txt | 31 +++++++------ README.md | 115 +++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 130 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a9746e9..2280bd1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,8 @@ if(CMAKE_CUDA_COMPILER) set(CMAKE_CUDA_STANDARD 14) target_compile_definitions(${PROJECT_NAME} PRIVATE USE_CUDA) set(CUDA_FOUND TRUE) + # Setting our CUDA sources + file(GLOB_RECURSE CUDA_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/src/*.cu") message(STATUS "CUDA found. Building with CUDA support.") else() set(CUDA_FOUND FALSE) @@ -26,21 +28,24 @@ else() endif() # Check for Apple Metal (only if CUDA is not found) -# if(NOT CUDA_FOUND AND APPLE) -# find_library(METAL_LIBRARY Metal) -# find_library(FOUNDATION_LIBRARY Foundation) -# if(METAL_LIBRARY AND FOUNDATION_LIBRARY) -# set(METAL_FOUND TRUE) -# target_compile_definitions(${PROJECT_NAME} PRIVATE USE_METAL) -# message(STATUS "Apple Metal found. Building with Metal support.") -# else() -# message(WARNING "Neither CUDA nor Apple Metal found. Building without GPU acceleration.") -# endif() -# endif() +if(NOT CUDA_FOUND AND APPLE) + find_library(METAL_LIBRARY Metal) + find_library(FOUNDATION_LIBRARY Foundation) + if(METAL_LIBRARY AND FOUNDATION_LIBRARY) + set(METAL_FOUND TRUE) + target_compile_definitions(${PROJECT_NAME} PRIVATE USE_METAL) + target_link_libraries(${PROJECT_NAME} ${METAL_LIBRARY}) + # Setting our Metal sources + file(GLOB_RECURSE METAL_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/src/*.metal") + message(STATUS "Apple Metal found. Building with Metal support.") + else() + message(WARNING "Neither CUDA nor Apple Metal found. Building without GPU acceleration.") + endif() +endif() # Adding our source files -file(GLOB_RECURSE PROJECT_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/src/*.c" "${CMAKE_CURRENT_LIST_DIR}/src/*.cpp" "${CMAKE_CURRENT_LIST_DIR}/src/*.cc" "${CMAKE_CURRENT_LIST_DIR}/src/*.cxx" "${CMAKE_CURRENT_LIST_DIR}/src/*.cu") # Define PROJECT_SOURCES as a list of all source files -target_sources(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCES}) +file(GLOB_RECURSE PROJECT_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/src/*.c" "${CMAKE_CURRENT_LIST_DIR}/src/*.cpp" "${CMAKE_CURRENT_LIST_DIR}/src/*.cc" "${CMAKE_CURRENT_LIST_DIR}/src/*.cxx") +target_sources(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCES} ${CUDA_SOURCES} ${METAL_SOURCES}) # Adding our include files target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include) diff --git a/README.md b/README.md index 891cd5a..d5ad7bf 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,116 @@ -# cpp-template + -A template for creating C++ projects. + + +
+ +[![Contributors][contributors-shield]][contributors-url] +[![Forks][forks-shield]][forks-url] +[![Stargazers][stars-shield]][stars-url] + +
+ + + C++ Logo + + +
+

~cpp-template

+
+ + + +A template for creating C++13 projects accelerated with CUDA/Apple Metal + +### Built With + +[![C++][C++-shield]][C++-url] +[![CUDA][CUDA-shield]][CUDA-url] +[![Apple][Apple-shield]][Apple-url] +[![GitHub Actions][github-actions-shield]][github-actions-url] + + +## Preview + +

+ Video demonstration +

+ + +## Getting Started + +### Prerequisites + +Before attempting to build this project, make sure you have [GNU Make](https://www.gnu.org/software/make/), and [CMake](https://cmake.org) installed on your machine. + +Additionally, if you wish to utilize the GPU acceleration features, you will need to have [CUDA Toolkit](https://developer.nvidia.com/cuda-downloads) or [Apple Metal](https://developer.apple.com/metal/cpp/) installed on your machine. + + +you will need a C++ compiler that supports C++13, and a CUDA compatible GPU if you wish to use the CUDA acceleration features. + +### Installation + +To get a local copy of the project up and running on your machine, follow these simple steps: + +1. Clone the project repository + + ```sh + git clone https://github.com/Kaweees/cpp-template.git + cd graphics + ``` + +2. Build and execute the project + ```sh + clear && cmake CMakeLists.txt && make && ./target/release/cpp-template + ``` + + +## Project Structure ```sh -clear && cmake CMakeLists.txt && make && ./target/release/cpp-template +graphics/ +├── .github/ - GitHub Actions CI/CD workflows +├── include/ - project header files +├── src/ - project source files +│ └── main.c - Entry point, main function +├── CMakeLists.txt - CMake build script +├── LICENSE - project license +└── README.md - you are here ``` + +## License + +The source code for my website is distributed under the terms of the GNU General Public License v3.0, as I firmly believe that collaborating on free and open-source software fosters innovations that mutually and equitably beneficial to both collaborators and users alike. See [`LICENSE`](./LICENSE) for details and more information. + + + + +[contributors-shield]: https://img.shields.io/github/contributors/Kaweees/cpp-template.svg?style=for-the-badge +[contributors-url]: https://github.com/Kaweees/cpp-template/graphs/contributors +[forks-shield]: https://img.shields.io/github/forks/Kaweees/cpp-template.svg?style=for-the-badge +[forks-url]: https://github.com/Kaweees/cpp-template/network/members +[stars-shield]: https://img.shields.io/github/stars/Kaweees/cpp-template.svg?style=for-the-badge +[stars-url]: https://github.com/Kaweees/cpp-template/stargazers + + + +[C++-shield]: https://img.shields.io/badge/C++-%23008080.svg?style=for-the-badge&logo=c%2B%2B&logoColor=004482&labelColor=222222&color=004482 +[C++-url]: https://isocpp.org/ +[CUDA-shield]: https://img.shields.io/badge/cuda-%23008080.svg?style=for-the-badge&logo=nVIDIA&logoColor=76B900&labelColor=222222&color=76B900 +[CUDA-url]: https://developer.nvidia.com/cuda-zone +[Apple-shield]: https://img.shields.io/badge/metal-%23008080.svg?style=for-the-badge&logo=apple&logoColor=white&labelColor=222222&color=white +[Apple-url]: https://developer.apple.com/metal/ +[github-actions-shield]: https://img.shields.io/badge/github%20actions-%232671E5.svg?style=for-the-badge&logo=githubactions&logoColor=2671E5&labelColor=222222&color=2671E5 +[github-actions-url]: https://github.com/features/actions