Skip to content

CMake find_package module for users of raylib-cpp #302

@Roy-Fokker

Description

@Roy-Fokker

Perhaps folks would like somewhat easier mechanism to consume this library.

I've hacked together a simple CMake module file as below:
FindRaylib_Cpp.cmake

# Check that project is already consuming raylib
find_package(raylib CONFIG REQUIRED)

# if not consuming raylib error out
if (NOT raylib_FOUND)
	message(FATAL_ERROR "[Error]: Could not find raylib.")
endif()

# load fetchcontent cmake
include(FetchContent)

# get appropriate version of raylib-cpp from github.
set(RAYLIB_CPP_VERSION v5.0.1)  # git commit hash: f865785fee2cb18da6ad6a9012a2993a73f2a2b1
FetchContent_Declare(
	raylib_cpp
	GIT_REPOSITORY https://github.com/RobLoach/raylib-cpp.git
	GIT_TAG ${RAYLIB_CPP_VERSION}
	FIND_PACKAGE_ARGS NAMES raylib_cpp # tell cmake to make it available via find_package
)
# make it available to project
FetchContent_MakeAvailable(raylib_cpp)

message("\n"
	"The package raylib_cpp ${RAYLIB_CPP_VERSION} provides CMake targets: \n\n"
	"	find_package(raylib_cpp)\n"
	"	target_link_libraries(main PRIVATE raylib_cpp)\n"
)

This can then be consumed as:
CMakeLists.txt

find_package(raylib_cpp)
...
target_link_libraries(my_exe_name PRIVATE raylib_cpp)

If you configure CMAKE_MODULE_PATH within your project to be something like <project folder>/cmake/' and place the FindRaylib_Cpp.cmake` with in it.

CMake will find it, download the raylib-cpp src from github and make it available for use.

few caveats

  • I am assuming users have seperately configured raylib for their project. Hence the FATAL_ERROR if it hasn't been.
  • Above logic uses GIT TAG of v5.0.1, so that might need to change for future.

Hopefully others find this useful. Sorry if this is not appropriate location for such.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions