mirror of
https://github.com/raysan5/raylib.git
synced 2026-01-28 17:59:17 -05:00
Updated Working with CMake (markdown)
@ -1,16 +1,27 @@
|
|||||||
Besides the `games/` and `examples/` that are built along raylib by default, there's also a sample CMake project at `projects/CMake`:
|
## Requiring raylib to be installed
|
||||||
|
If you know that anyone who builds your project, has raylib already installed, a simple `CMakeLists.txt` could look like this:
|
||||||
|
```cmake
|
||||||
|
cmake_minimum_required(VERSION 3.15)
|
||||||
|
project(my_project)
|
||||||
|
|
||||||
|
find_package(raylib REQUIRED) # Uses the latest installed version
|
||||||
|
|
||||||
|
set(CMAKE_C_STANDARD 11)
|
||||||
|
|
||||||
|
add_executable(my_project main.c)
|
||||||
|
|
||||||
|
target_link_libraries(my_project main raylib)
|
||||||
```
|
```
|
||||||
cd projects/CMake # You can also just download the CMakeLists.txt and the core_basic_window.c file separately
|
To build, use these commands:
|
||||||
mkdir build # Create an out-of-tree build directory. That way build artifacts aren't mixed with source code
|
```cmake
|
||||||
cd build # enter it
|
mkdir build # Create a build directory
|
||||||
cmake .. # run cmake on the parent directory
|
cd build && cmake .. # Build from that directory so the build files are in one place
|
||||||
cmake --build . # kick off the build process
|
cmake --build . # Actually build the project
|
||||||
```
|
```
|
||||||
|
|
||||||
The `CMakeLists.txt` is self contained and will arrange to probe whether raylib has been installed and if not, it's downloaded, built and linked statically into the `core_basic_window` example application.
|
## Loading raylib inside cmake
|
||||||
|
If you want someone who builds your project to be able to download and build raylib with it, the [CMakeLists.txt at projects/CMake](https://github.com/raysan5/raylib/blob/master/projects/CMake/CMakeLists.txt)
|
||||||
If you want to conserve bandwidth by not downloading raylib for each project, consider installing raylib systemwide by running `cmake --build . --target install` in the raylib build directory.
|
will help you.
|
||||||
|
|
||||||
## Use from within an IDE
|
## Use from within an IDE
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user