summaryrefslogtreecommitdiffhomepage
path: root/cmake/raylib-config.cmake
diff options
context:
space:
mode:
authorAhmad Fatoum <[email protected]>2018-07-28 16:08:41 +0200
committerAhmad Fatoum <[email protected]>2018-07-29 12:35:35 +0200
commit3f097263310c3993a742891bce4dc00892aa5c3d (patch)
tree0edbf1dec83be178ebe2978aecd29dcf5828030a /cmake/raylib-config.cmake
parent3e5093eab0ef4949e9e08fda5de0cd3d31b7e2c1 (diff)
downloadraylib-3f097263310c3993a742891bce4dc00892aa5c3d.tar.gz
raylib-3f097263310c3993a742891bce4dc00892aa5c3d.zip
CMake: Major cleanup to support find_package(raylib)
Remove that link_libraries_to_executable() hack and defines a proper raylib target that can be used with target_link_libraries. The same target is also available for external (user) code by using find_package(raylib). This results in: - Remove hardcoded build directories from examples and games CMakeLists.txt - Allow rlgl_standalone and other special examples to be built easily - Allow CMake projects to find_package(raylib instead of fiddling with pkg-config - Makes code a little more maintainable - Fixes #471, #606. - Makes code less confusing by removing the double use of PLATFORM (#584). Note that this is still not _The Right Way_(TM), because normally raylib-config.cmake (or its includes) would be automatically generated. I didn't manage to get that to work though, so I went the easier route of just wrapping pkg_check_modules for consumption by find_package.
Diffstat (limited to 'cmake/raylib-config.cmake')
-rw-r--r--cmake/raylib-config.cmake68
1 files changed, 68 insertions, 0 deletions
diff --git a/cmake/raylib-config.cmake b/cmake/raylib-config.cmake
new file mode 100644
index 00000000..e2e5e9ae
--- /dev/null
+++ b/cmake/raylib-config.cmake
@@ -0,0 +1,68 @@
+# - Try to find raylib
+# Options:
+# raylib_USE_STATIC_LIBS - OFF by default
+# raylib_VERBOSE - OFF by default
+# Once done, this defines a raylib target that can be passed to
+# target_link_libraries as well as following variables:
+#
+# raylib_FOUND - System has raylib installed
+# raylib_INCLUDE_DIRS - The include directories for the raylib header(s)
+# raylib_LIBRARIES - The libraries needed to use raylib
+# raylib_LDFLAGS - The linker flags needed with raylib
+# raylib_DEFINITIONS - Compiler switches required for using raylib
+
+set(XPREFIX PC_RAYLIB)
+if (raylib_USE_STATIC_LIBS)
+ set(XPREFIX ${XPREFIX}_STATIC)
+endif()
+
+find_package(PkgConfig)
+pkg_check_modules(${XPREFIX} REQUIRED raylib)
+set(raylib_DEFINITIONS ${${XPREFIX}_CFLAGS})
+
+find_path(raylib_INCLUDE_DIR
+ NAMES raylib.h
+ HINTS ${${XPREFIX}_INCLUDE_DIRS}
+)
+
+find_library(raylib_LIBRARY
+ NAMES raylib
+ HINTS ${${XPREFIX}_LIBRARY_DIRS}
+)
+
+set(raylib_LIBRARIES ${raylib_LIBRARY})
+set(raylib_LIBRARY_DIRS ${${XPREFIX}_LIBRARY_DIRS})
+set(raylib_LIBRARY_DIR ${raylib_LIBRARY_DIRS})
+set(raylib_INCLUDE_DIRS ${raylib_INCLUDE_DIR})
+set(raylib_LDFLAGS ${${XPREFIX}_LDFLAGS})
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(raylib DEFAULT_MSG
+ raylib_LIBRARY
+ raylib_INCLUDE_DIR
+)
+
+mark_as_advanced(raylib_LIBRARY raylib_INCLUDE_DIR)
+
+if (raylib_USE_STATIC_LIBS)
+ add_library(raylib STATIC IMPORTED GLOBAL)
+else()
+ add_library(raylib SHARED IMPORTED GLOBAL)
+endif()
+string (REPLACE ";" " " raylib_LDFLAGS "${raylib_LDFLAGS}")
+
+set_target_properties(raylib
+ PROPERTIES
+ IMPORTED_LOCATION "${raylib_LIBRARIES}"
+ INTERFACE_INCLUDE_DIRECTORIES "${raylib_INCLUDE_DIRS}"
+ INTERFACE_LINK_LIBRARIES "${raylib_LDFLAGS}"
+ INTERFACE_COMPILE_OPTIONS "${raylib_DEFINITIONS}"
+)
+
+if (raylib_VERBOSE)
+ message(STATUS "raylib_FOUND: ${raylib_FOUND}")
+ message(STATUS "raylib_INCLUDE_DIRS: ${raylib_INCLUDE_DIRS}")
+ message(STATUS "raylib_LIBRARIES: ${raylib_LIBRARIES}")
+ message(STATUS "raylib_LDFLAGS: ${raylib_LDFLAGS}")
+ message(STATUS "raylib_DEFINITIONS: ${raylib_DEFINITIONS}")
+endif()