Skip to content

Commit

Permalink
Merge pull request #608 from a3f/master
Browse files Browse the repository at this point in the history
 CMake: Major cleanup to support find_package(raylib)
  • Loading branch information
a3f authored Jul 29, 2018
2 parents cf021e3 + 5a94a28 commit 6905a87
Show file tree
Hide file tree
Showing 19 changed files with 377 additions and 284 deletions.
50 changes: 31 additions & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ matrix:
env: ARCH=amd64 INSTALL_GLFW=YES USE_EXTERNAL_GLFW=OFF
sudo: required
- os: linux
env: ARCH=amd64 INSTALL_GLFW=YES RELEASE=NO
env: ARCH=amd64 INSTALL_GLFW=YES OPENAL=ON STATIC=OFF RELEASE=NO
sudo: required
- os: linux
env: USE_WAYLAND=ON ARCH=amd64 RELEASE=NO
env: WAYLAND=ON ARCH=amd64 RELEASE=NO
sudo: required
addons:
apt:
Expand All @@ -46,45 +46,49 @@ matrix:
before_script:

before_install:
- if [ -z "$USE_EXTERNAL_GLFW" ]; then
export USE_EXTERNAL_GLFW=IF_POSSIBLE;
fi
- if [ -z "$SHARED" ]; then
export SHARED=ON;
- if [ -z "$USE_EXTERNAL_GLFW" ]; then export USE_EXTERNAL_GLFW=IF_POSSIBLE; fi
- if [ -z "$SHARED" ]; then export SHARED=ON ; fi
- if [ -z "$STATIC" ]; then export STATIC=ON ; fi
- if [ -z "$OPENAL" ]; then export OPENAL=OFF; fi
- if [[ "$INSTALL_GLFW" == "YES" && "$USE_EXTERNAL_GLFW" != "OFF" ]]; then
export DONT_TEST=1;
fi
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then
if [[ "$ARCH" == *-android ]]; then
export DONT_TEST=1;
export RAYLIB_PACKAGE_SUFFIX="-Android-arm64";
wget https://dl.google.com/android/repository/android-ndk-r17-linux-x86_64.zip;
unzip -qq android-ndk*.zip;
if [[ "$ARCH" == arm64-* ]]; then
export RAYLIB_PACKAGE_SUFFIX="-Android-arm64";
export TOOLCHAIN_ARCH=arm64;
export PREFIX=aarch64-linux-android-;
TOOLCHAIN_ARCH=arm64;
PREFIX=aarch64-linux-android-;
else
export RAYLIB_PACKAGE_SUFFIX="-Android-arm32";
export TOOLCHAIN_ARCH=arm;
export PREFIX=arm-linux-androideabi-;
TOOLCHAIN_ARCH=arm;
PREFIX=arm-linux-androideabi-;
fi;
android-ndk*/build/tools/make_standalone_toolchain.py --arch $TOOLCHAIN_ARCH --api 21 --install-dir /tmp/android-toolchain;
export PATH=/tmp/android-toolchain/bin:$PATH;
export CC=${PREFIX}clang;
export CXX=${PREFIX}clang++;
export CMAKE_ARCH_ARGS='-DPLATFORM=Android';
elif [ "$ARCH" == "html5" ]; then
export DONT_TEST=1;
export RAYLIB_PACKAGE_SUFFIX="-html5";
docker run --privileged=true -dit --name emscripten -v $(pwd):/src trzeci/emscripten:sdk-incoming-64bit bash;
export CMAKE_ARCH_ARGS='-DPLATFORM=Web -DCMAKE_TOOLCHAIN_FILE=../cmake/emscripten.cmake';
export RUNNER='docker exec -it emscripten cmake -E chdir build';
RUNNER='docker exec -it emscripten cmake -E chdir build';
else
sudo apt-get install -y gcc-multilib
libasound2-dev:$ARCH
libxcursor-dev:$ARCH libxinerama-dev:$ARCH mesa-common-dev:$ARCH
libx11-dev:$ARCH libxrandr-dev:$ARCH libxrandr2:$ARCH libxi-dev:$ARCH
libgl1-mesa-dev:$ARCH libglu1-mesa-dev:$ARCH;
if [ "$ARCH" == "i386" ]; then
export CMAKE_ARCH_ARGS='-DCMAKE_C_FLAGS=-m32 -DCMAKE_SYSTEM_LIBRARY_PATH=/usr/lib/i386-linux-gnu';
fi;

if [ "$OPENAL" == "ON" ]; then sudo apt-get install -y libopenal-dev; fi;
if [ "$ARCH" == "i386" ]; then export CMAKE_ARCH_ARGS='-DCMAKE_C_FLAGS=-m32 -DCMAKE_SYSTEM_LIBRARY_PATH=/usr/lib/i386-linux-gnu -DSUPPORT_FILEFORMAT_FLAC=OFF'; fi;

export RAYLIB_PACKAGE_SUFFIX="-Linux-$ARCH";
if [ "$INSTALL_GLFW" == "YES" ]; then
wget 'http://ftp.de.debian.org/debian/pool/main/g/glfw3/libglfw3_3.2.1-1_amd64.deb';
Expand All @@ -102,19 +106,27 @@ before_install:

script:
- cd build
- if test -n "${USE_WAYLAND}";
- if test -n "$WAYLAND";
then wget https://mirrors.kernel.org/ubuntu/pool/universe/e/extra-cmake-modules/extra-cmake-modules_5.38.0a-0ubuntu1_amd64.deb;
sudo dpkg -i extra-cmake-modules_5.38.0a-0ubuntu1_amd64.deb;
git clone git://anongit.freedesktop.org/wayland/wayland-protocols;
pushd wayland-protocols;
git checkout 1.12 && ./autogen.sh --prefix=/usr && make && sudo make install;
popd;
fi
- $RUNNER cmake $CMAKE_ARCH_ARGS -DMACOS_FATLIB=ON -DSTATIC=ON -DSHARED=$SHARED -DBUILD_EXAMPLES=ON -DBUILD_GAMES=ON -DUSE_EXTERNAL_GLFW=$USE_EXTERNAL_GLFW -DUSE_WAYLAND=${USE_WAYLAND} ..
- $RUNNER cmake $CMAKE_ARCH_ARGS
-DMACOS_FATLIB=ON
-DSTATIC=$STATIC -DSHARED=$SHARED
-DBUILD_EXAMPLES=ON -DBUILD_GAMES=ON
-DUSE_EXTERNAL_GLFW=$USE_EXTERNAL_GLFW
-DUSE_WAYLAND=$WAYLAND
-DUSE_OPENAL_BACKEND=$OPENAL
-DINCLUDE_EVERYTHING=ON
..
- $RUNNER make VERBOSE=1
- if [ "$RELEASE" != "NO" ]; then $RUNNER make package; fi;
- if [ "$RELEASE" != "NO" ]; then $RUNNER make package; fi
- sudo $RUNNER make install
- if [[ "$ARCH" != *-android && "$ARCH" != html5 ]]; then
- if [ ! "$DONT_TEST" ]; then
pkg-config --static --libs raylib;
nm -g release/libraylib.a | grep glfwGetProcAddress || (echo "libraylib.a doesn't contain GLFW symbols! Aborting..." && false);
ctest --output-on-failure;
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ option(BUILD_EXAMPLES "Build the examples." ON)
option(BUILD_GAMES "Build the example games." ON)
option(ENABLE_ASAN "Enable AddressSanitizer (ASAN) for debugging (degrades performance)" OFF)
option(ENABLE_UBSAN "Enable UndefinedBehaviorSanitizer (UBSan) for debugging" OFF)
option(ENABLE_MSAN "Enable MemorySanitizer (MSan) for debugging (not recommended for run with ASAN)" OFF)
option(ENABLE_MSAN "Enable MemorySanitizer (MSan) for debugging (not recommended to run with ASAN)" OFF)

if(CMAKE_VERSION VERSION_LESS "3.1")
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ before_build:
- cd build

build_script:
- cmake -G %GENERATOR% -DSTATIC=ON -DSHARED=ON -DBUILD_EXAMPLES=%examples% -DBUILD_GAMES=%examples% ..
- cmake -G %GENERATOR% -DSTATIC=ON -DSHARED=ON -DBUILD_EXAMPLES=%examples% -DBUILD_GAMES=%examples% -DINCLUDE_EVERYTHING=ON ..
- cmake --build . --target install

after_build:
Expand Down
24 changes: 24 additions & 0 deletions cmake/LibraryPathToLinkerFlags.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function(library_path_to_linker_flags LD_FLAGS LIB_PATHS)
foreach(L ${LIB_PATHS})
get_filename_component(DIR ${L} PATH)
get_filename_component(LIBFILE ${L} NAME_WE)
STRING(REGEX REPLACE "^lib" "" FILE ${LIBFILE})

if (${L} MATCHES "[.]framework$")
set(FILE_OPT "-framework ${FILE}")
set(DIR_OPT "-F${DIR}")
else()
set(FILE_OPT "-l${FILE}")
set(DIR_OPT "-L${DIR}")
endif()

if ("${DIR}" STREQUAL "" OR "${DIR}" STREQUAL "${LASTDIR}")
set (DIR_OPT "")
endif()

set(LASTDIR ${DIR})

set(${LD_FLAGS} ${${LD_FLAGS}} ${DIR_OPT} ${FILE_OPT} PARENT_SCOPE)
string (REPLACE ";" " " ${LD_FLAGS} "${${LD_FLAGS}}")
endforeach()
endfunction()
11 changes: 11 additions & 0 deletions cmake/PopulateConfigVariablesLocally.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
macro(populate_config_variables_locally target)
get_property(raylib_INCLUDE_DIRS TARGET ${target} PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
#get_property(raylib_LIBRARIES TARGET ${target} PROPERTY LOCATION) # only works for SHARED
get_property(raylib_LDFLAGS TARGET ${target} PROPERTY INTERFACE_LINK_LIBRARIES)
get_property(raylib_DEFINITIONS TARGET ${target} PROPERTY DEFINITIONS)

set(raylib_INCLUDE_DIRS "${raylib_INCLUDE_DIRS}" PARENT_SCOPE)
#set(raylib_LIBRARIES "${raylib_INCLUDE_DIRS}" PARENT_SCOPE)
set(raylib_LDFLAGS "${raylib_LDFLAGS}" PARENT_SCOPE)
set(raylib_DEFINITIONS "${raylib_DEFINITIONS}" PARENT_SCOPE)
endmacro()
21 changes: 21 additions & 0 deletions cmake/raylib-config-version.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
set(PACKAGE_VERSION "@PROJECT_VERSION@")

if(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION)
set(PACKAGE_VERSION_EXACT TRUE)
endif()
if(NOT PACKAGE_FIND_VERSION VERSION_GREATER PACKAGE_VERSION)
set(PACKAGE_VERSION_COMPATIBLE TRUE)
else(NOT PACKAGE_FIND_VERSION VERSION_GREATER PACKAGE_VERSION)
set(PACKAGE_VERSION_UNSUITABLE TRUE)
endif(NOT PACKAGE_FIND_VERSION VERSION_GREATER PACKAGE_VERSION)

# if the installed or the using project don't have CMAKE_SIZEOF_VOID_P set, ignore it:
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "" OR "@CMAKE_SIZEOF_VOID_P@" STREQUAL "")
return()
endif()

if(NOT CMAKE_SIZEOF_VOID_P STREQUAL "@CMAKE_SIZEOF_VOID_P@")
math(EXPR installedBits "8 * 8")
set(PACKAGE_VERSION "${PACKAGE_VERSION} (${installedBits}bit)")
set(PACKAGE_VERSION_UNSUITABLE TRUE)
endif()
68 changes: 68 additions & 0 deletions cmake/raylib-config.cmake
Original file line number Diff line number Diff line change
@@ -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()
85 changes: 0 additions & 85 deletions cmake/utils.cmake

This file was deleted.

Loading

0 comments on commit 6905a87

Please sign in to comment.