Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

raylib: use external glfw + fix CMake imported target #4499

Merged
merged 10 commits into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 46 additions & 6 deletions recipes/raylib/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class RaylibConan(ConanFile):
default_options = { "shared": False, "fPIC": True }

exports_sources = ["CMakeLists.txt"]
generators = "cmake"
generators = "cmake", "cmake_find_package_multi"
_cmake = None

@property
Expand All @@ -36,6 +36,7 @@ def configure(self):
del self.settings.compiler.cppstd

def requirements(self):
self.requires("glfw/3.3.2")
self.requires("opengl/system")
if self.settings.os == "Linux":
self.requires("xorg/system")
Expand All @@ -44,14 +45,23 @@ def source(self):
tools.get(**self.conan_data["sources"][self.version])
os.rename(self.name + "-" + self.version, self._source_subfolder)

def _patch_sources(self):
# avoid symbols conflicts with Win SDK
tools.replace_in_file(os.path.join(self._source_subfolder, "src", "core.c"),
"#define GLFW_EXPOSE_NATIVE_WIN32", "")

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["BUILD_EXAMPLES"] = False
self._cmake.definitions["WITH_PIC"] = self.options.get_safe("fPIC", True)
self._cmake.definitions["USE_EXTERNAL_GLFW"] = "ON"
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake

def build(self):
self._patch_sources()
cmake = self._configure_cmake()
cmake.build()

Expand All @@ -61,14 +71,44 @@ def package(self):
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
self._create_cmake_module_alias_targets(
os.path.join(self.package_folder, self._module_subfolder, self._module_file),
{"raylib": "raylib::raylib"}
)

@staticmethod
def _create_cmake_module_alias_targets(module_file, targets):
content = ""
for alias, aliased in targets.items():
content += (
"if(TARGET {aliased} AND NOT TARGET {alias})\n"
" add_library({alias} INTERFACE IMPORTED)\n"
" set_property(TARGET {alias} PROPERTY INTERFACE_LINK_LIBRARIES {aliased})\n"
"endif()\n"
).format(alias=alias, aliased=aliased)
tools.save(module_file, content)

@property
def _module_subfolder(self):
return os.path.join("lib", "cmake")

@property
def _module_file(self):
return "conan-official-{}-targets.cmake".format(self.name)

def package_info(self):
self.cpp_info.names["cmake_find_package"] = "raylib"
self.cpp_info.names["cmake_find_package_multi"] = "raylib"
self.cpp_info.libs = tools.collect_libs(self)
self.cpp_info.names["pkg_config"] = "raylib"
self.cpp_info.builddirs = [self._module_subfolder]
self.cpp_info.build_modules = [os.path.join(self._module_subfolder, self._module_file)]
libname = "raylib"
if self.settings.compiler == "Visual Studio" and not self.options.shared:
libname += "_static"
self.cpp_info.libs = [libname]
if self.settings.compiler == "Visual Studio" and self.options.shared:
self.cpp_info.defines.append("USE_LIBTYPE_SHARED")
if self.settings.os == "Linux":
self.cpp_info.system_libs.extend(["m", "pthread", "dl", "rt"])
self.cpp_info.system_libs.extend(["m", "pthread"])
elif self.settings.os == "Windows":
self.cpp_info.system_libs.extend(["gdi32", "winmm"])
elif self.settings.os == "Macos":
self.cpp_info.frameworks.extend(["Cocoa", "IOKit", "CoreVideo"])
self.cpp_info.system_libs.append("winmm")
6 changes: 3 additions & 3 deletions recipes/raylib/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
cmake_minimum_required(VERSION 3.1)
project(test_package CXX)
project(test_package C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(raylib REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} raylib::raylib)
add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} raylib)
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include <iostream>

#include "raylib.h"

#include <stdio.h>

int main(void) {
Vector3 center = {0, 0, 0};
float r = 1.0;
if (CheckCollisionSpheres(center, r, center, r)) {
std::cout << "unit sphere collides with itself!" << std::endl;
printf("unit sphere collides with itself!\n");
}
return 0;
}