From 20ddc6a2bb4cbd39c460d8fa5d1f7175095bba2f Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Sun, 20 May 2018 19:47:19 +0200 Subject: [PATCH 1/5] Move utils.cmake to separate cmake/ directory --- utils.cmake => cmake/utils.cmake | 0 examples/CMakeLists.txt | 2 +- games/CMakeLists.txt | 2 +- games/drturtle/CMakeLists.txt | 2 +- games/just_do/CMakeLists.txt | 2 +- games/koala_seasons/CMakeLists.txt | 2 +- games/light_my_ritual/CMakeLists.txt | 2 +- games/skully_escape/CMakeLists.txt | 2 +- games/wave_collector/CMakeLists.txt | 2 +- src/CMakeLists.txt | 2 +- 10 files changed, 9 insertions(+), 9 deletions(-) rename utils.cmake => cmake/utils.cmake (100%) diff --git a/utils.cmake b/cmake/utils.cmake similarity index 100% rename from utils.cmake rename to cmake/utils.cmake diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 1f05d529..ae882444 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,7 +1,7 @@ # Setup the project and settings project(examples) -include("../utils.cmake") +include("../cmake/utils.cmake") # Make sure raylib has been built # TODO `build` directory should maybe be something else... diff --git a/games/CMakeLists.txt b/games/CMakeLists.txt index 278d1330..35c99139 100644 --- a/games/CMakeLists.txt +++ b/games/CMakeLists.txt @@ -1,7 +1,7 @@ # Setup the project and settings project(games) -include("../utils.cmake") +include("../cmake/utils.cmake") # Make sure raylib has been built # TODO `build` directory should maybe be something else... diff --git a/games/drturtle/CMakeLists.txt b/games/drturtle/CMakeLists.txt index 59813fb3..bdd91970 100644 --- a/games/drturtle/CMakeLists.txt +++ b/games/drturtle/CMakeLists.txt @@ -1,7 +1,7 @@ # Setup the project and settings project(drturtle) -include("../../utils.cmake") +include("../../cmake/utils.cmake") # Make sure raylib has been built diff --git a/games/just_do/CMakeLists.txt b/games/just_do/CMakeLists.txt index 11644008..4c5e1ee4 100644 --- a/games/just_do/CMakeLists.txt +++ b/games/just_do/CMakeLists.txt @@ -1,7 +1,7 @@ # Setup the project and settings project(just_do) -include("../../utils.cmake") +include("../../cmake/utils.cmake") # Make sure raylib has been built diff --git a/games/koala_seasons/CMakeLists.txt b/games/koala_seasons/CMakeLists.txt index 16069a7e..f79ab911 100644 --- a/games/koala_seasons/CMakeLists.txt +++ b/games/koala_seasons/CMakeLists.txt @@ -1,7 +1,7 @@ # Setup the project and settings project(koala_seasons) -include("../../utils.cmake") +include("../../cmake/utils.cmake") # Make sure raylib has been built diff --git a/games/light_my_ritual/CMakeLists.txt b/games/light_my_ritual/CMakeLists.txt index 1e2cafe1..11d2e4f4 100644 --- a/games/light_my_ritual/CMakeLists.txt +++ b/games/light_my_ritual/CMakeLists.txt @@ -1,7 +1,7 @@ # Setup the project and settings project(light_my_ritual) -include("../../utils.cmake") +include("../../cmake/utils.cmake") # Make sure raylib has been built diff --git a/games/skully_escape/CMakeLists.txt b/games/skully_escape/CMakeLists.txt index d14f52d9..337e1db5 100644 --- a/games/skully_escape/CMakeLists.txt +++ b/games/skully_escape/CMakeLists.txt @@ -1,7 +1,7 @@ # Setup the project and settings project(skully_escape) -include("../../utils.cmake") +include("../../cmake/utils.cmake") # Make sure raylib has been built diff --git a/games/wave_collector/CMakeLists.txt b/games/wave_collector/CMakeLists.txt index c16bd426..ca6c37b8 100644 --- a/games/wave_collector/CMakeLists.txt +++ b/games/wave_collector/CMakeLists.txt @@ -1,7 +1,7 @@ # Setup the project and settings project(wave_collector) -include("../../utils.cmake") +include("../../cmake/utils.cmake") # Make sure raylib has been built diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 458b9606..4b32de10 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -39,7 +39,7 @@ if(NOT glfw3_FOUND) list(APPEND raylib_sources $) endif() -include("../utils.cmake") +include("../cmake/utils.cmake") if(USE_AUDIO) file(GLOB stb_vorbis external/stb_vorbis.c) From ae26e083b4471f1404e4f25eee71e4f71e9b13f0 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Sun, 20 May 2018 19:59:18 +0200 Subject: [PATCH 2/5] CMake: Add default build type if none specified Release, unless we are in a Git repo, then it's Debug. --- cmake/BuildType.cmake | 43 +++++++++++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 4 +++- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 cmake/BuildType.cmake diff --git a/cmake/BuildType.cmake b/cmake/BuildType.cmake new file mode 100644 index 00000000..80ccdee2 --- /dev/null +++ b/cmake/BuildType.cmake @@ -0,0 +1,43 @@ +# Set a default build type if none was specified +set(default_build_type "Release") +if(EXISTS "${CMAKE_SOURCE_DIR}/.git") + set(default_build_type "Debug") +endif() + +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + message(STATUS "Setting build type to '${default_build_type}' as none was specified.") + set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE + STRING "Choose the type of build." FORCE) + # Set the possible values of build type for cmake-gui + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" + "MinSizeRel" "RelWithDebInfo") +endif() + +# Taken from the https://github.com/OpenChemistry/tomviz project +# Copyright (c) 2014-2017, Kitware, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4b32de10..f6f867e2 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,12 +1,14 @@ # Setup the project and settings project(raylib) include(GNUInstallDirs) +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake") set(PROJECT_VERSION 2.0.0) set(API_VERSION 2) set(RAYLIB raylib) # Name of the generated library include("CMakeOptions.txt") +include(BuildType) configure_file(config.h.in ${CMAKE_BINARY_DIR}/cmake/config.h) include_directories(${CMAKE_BINARY_DIR}) @@ -39,7 +41,7 @@ if(NOT glfw3_FOUND) list(APPEND raylib_sources $) endif() -include("../cmake/utils.cmake") +include(utils) if(USE_AUDIO) file(GLOB stb_vorbis external/stb_vorbis.c) From ff55af14f98fc70895ccdbbb4dccdccd68dec9dd Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Sun, 20 May 2018 20:08:43 +0200 Subject: [PATCH 3/5] CMake: Move reusable code to new cmake/ directory --- CMakeLists.txt | 45 ++++++----------------- cmake/AddIfFlagCompiles.cmake | 12 ++++++ cmake/CheckFileSystemSymlinkSupport.cmake | 13 +++++++ src/CMakeLists.txt | 2 +- 4 files changed, 38 insertions(+), 34 deletions(-) create mode 100644 cmake/AddIfFlagCompiles.cmake create mode 100644 cmake/CheckFileSystemSymlinkSupport.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 38d98c35..34411b46 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,5 @@ cmake_minimum_required(VERSION 3.0) +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) # Config options option(BUILD_EXAMPLES "Build the examples." ON) @@ -15,47 +16,25 @@ else() set (CMAKE_C_STANDARD 99) endif() -include(CheckCCompilerFlag) -function(add_if_flag_works flag) - CHECK_C_COMPILER_FLAG("${flag}" COMPILER_HAS_THOSE_TOGGLES) - set(outcome "Failed") - if(COMPILER_HAS_THOSE_TOGGLES) - foreach(var ${ARGN}) - set(${var} "${flag} ${${var}}" PARENT_SCOPE) - endforeach() - set(outcome "works") - endif() - message(STATUS "Testing if ${flag} can be used -- ${outcome}") -endfunction() - -add_if_flag_works(-Werror=pointer-arith CMAKE_C_FLAGS) -add_if_flag_works(-Werror=implicit-function-declaration CMAKE_C_FLAGS) +include(AddIfFlagCompiles) +add_if_flag_compiles(-Werror=pointer-arith CMAKE_C_FLAGS) +add_if_flag_compiles(-Werror=implicit-function-declaration CMAKE_C_FLAGS) # src/external/jar_xm.h does shady stuff -add_if_flag_works(-fno-strict-aliasing CMAKE_C_FLAGS) +add_if_flag_compiles(-fno-strict-aliasing CMAKE_C_FLAGS) -message(STATUS "Testing if file system supports symlinks") -execute_process( - COMMAND ${CMAKE_COMMAND} -E create_symlink CMakeLists.txt "${CMAKE_CURRENT_BINARY_DIR}/TestingIfSymlinkWorks" - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - RESULT_VARIABLE FILESYSTEM_LACKS_SYMLINKS -) -If (FILESYSTEM_LACKS_SYMLINKS) - message(STATUS "Testing if file system supports symlinks -- unsupported") -else() - message(STATUS "Testing if file system supports symlinks -- supported") -endif() +include(CheckFileSystemSymlinkSupport) if (ENABLE_ASAN) - add_if_flag_works(-fno-omit-frame-pointer CMAKE_C_FLAGS CMAKE_LINKER_FLAGS) - add_if_flag_works(-fsanitize=address CMAKE_C_FLAGS CMAKE_LINKER_FLAGS) + add_if_flag_compiles(-fno-omit-frame-pointer CMAKE_C_FLAGS CMAKE_LINKER_FLAGS) + add_if_flag_compiles(-fsanitize=address CMAKE_C_FLAGS CMAKE_LINKER_FLAGS) endif() if (ENABLE_UBSAN) - add_if_flag_works(-fno-omit-frame-pointer CMAKE_C_FLAGS CMAKE_LINKER_FLAGS) - add_if_flag_works(-fsanitize=undefined CMAKE_C_FLAGS CMAKE_LINKER_FLAGS) + add_if_flag_compiles(-fno-omit-frame-pointer CMAKE_C_FLAGS CMAKE_LINKER_FLAGS) + add_if_flag_compiles(-fsanitize=undefined CMAKE_C_FLAGS CMAKE_LINKER_FLAGS) endif() if (ENABLE_MSAN) - add_if_flag_works(-fno-omit-frame-pointer CMAKE_C_FLAGS CMAKE_LINKER_FLAGS) - add_if_flag_works(-fsanitize=memory CMAKE_C_FLAGS CMAKE_LINKER_FLAGS) + add_if_flag_compiles(-fno-omit-frame-pointer CMAKE_C_FLAGS CMAKE_LINKER_FLAGS) + add_if_flag_compiles(-fsanitize=memory CMAKE_C_FLAGS CMAKE_LINKER_FLAGS) endif() if (ENABLE_MSAN AND ENABLE_ASAN) diff --git a/cmake/AddIfFlagCompiles.cmake b/cmake/AddIfFlagCompiles.cmake new file mode 100644 index 00000000..403607b5 --- /dev/null +++ b/cmake/AddIfFlagCompiles.cmake @@ -0,0 +1,12 @@ +include(CheckCCompilerFlag) +function(add_if_flag_compiles flag) + CHECK_C_COMPILER_FLAG("${flag}" COMPILER_HAS_THOSE_TOGGLES) + set(outcome "Failed") + if(COMPILER_HAS_THOSE_TOGGLES) + foreach(var ${ARGN}) + set(${var} "${flag} ${${var}}" PARENT_SCOPE) + endforeach() + set(outcome "compiles") + endif() + message(STATUS "Testing if ${flag} can be used -- ${outcome}") +endfunction() diff --git a/cmake/CheckFileSystemSymlinkSupport.cmake b/cmake/CheckFileSystemSymlinkSupport.cmake new file mode 100644 index 00000000..798840ef --- /dev/null +++ b/cmake/CheckFileSystemSymlinkSupport.cmake @@ -0,0 +1,13 @@ +# Populates a ${FILESYSTEM_LACKS_SYMLINKS} variable +message(STATUS "Testing if file system supports symlinks") +execute_process( + COMMAND ${CMAKE_COMMAND} -E create_symlink CMakeLists.txt "${CMAKE_CURRENT_BINARY_DIR}/TestingIfSymlinkWorks" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + RESULT_VARIABLE FILESYSTEM_LACKS_SYMLINKS +) +If (FILESYSTEM_LACKS_SYMLINKS) + message(STATUS "Testing if file system supports symlinks -- unsupported") +else() + message(STATUS "Testing if file system supports symlinks -- supported") +endif() + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f6f867e2..1f7689c8 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,7 +1,7 @@ # Setup the project and settings project(raylib) include(GNUInstallDirs) -set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake") +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake") set(PROJECT_VERSION 2.0.0) set(API_VERSION 2) From ad8509732ca2a235c1735fae739577a59e17cf1c Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Sun, 20 May 2018 23:03:04 +0200 Subject: [PATCH 4/5] CMake: Fix (Add?) Android support Not sure if this ever worked, but now it at least compiles. --- .travis.yml | 43 +++++++++++++++++++++++++++++-------------- cmake/utils.cmake | 15 ++++++++++----- src/CMakeLists.txt | 32 +++++++++++++++++++++++++------- src/utils.c | 6 ++++++ 4 files changed, 70 insertions(+), 26 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3cfce867..30994015 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,24 +29,39 @@ matrix: - libegl1-mesa-dev - os: osx env: ARCH=universal + - os: linux + env: ARCH=arm64-android + sudo: required before_script: before_install: + - export PLATFORM=Desktop - if [ "$TRAVIS_OS_NAME" == "linux" ]; then - 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; - export RAYLIB_PACKAGE_SUFFIX="-Linux-$ARCH"; - if [ "$GLFW" == "SYSTEM" ]; then - wget 'http://ftp.de.debian.org/debian/pool/main/g/glfw3/libglfw3_3.2.1-1_amd64.deb'; - wget 'http://ftp.de.debian.org/debian/pool/main/g/glfw3/libglfw3-dev_3.2.1-1_amd64.deb'; - sudo dpkg -i libglfw3_3.2.1-1_amd64.deb libglfw3-dev_3.2.1-1_amd64.deb; + if [[ "$ARCH" == *-android ]]; then + 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; + android-ndk*/build/tools/make_standalone_toolchain.py --arch arm64 --api 21 --install-dir /tmp/android-toolchain; + export PATH=/tmp/android-toolchain/bin:$PATH; + export PLATFORM=Android; + export CC=aarch64-linux-android-clang; + export CXX=aarch64-linux-android-clang++; + 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; + export RAYLIB_PACKAGE_SUFFIX="-Linux-$ARCH"; + if [ "$GLFW" == "SYSTEM" ]; then + wget 'http://ftp.de.debian.org/debian/pool/main/g/glfw3/libglfw3_3.2.1-1_amd64.deb'; + wget 'http://ftp.de.debian.org/debian/pool/main/g/glfw3/libglfw3-dev_3.2.1-1_amd64.deb'; + sudo dpkg -i libglfw3_3.2.1-1_amd64.deb libglfw3-dev_3.2.1-1_amd64.deb; + fi; fi; fi - if [ "$TRAVIS_OS_NAME" == "osx" ]; then @@ -66,7 +81,7 @@ script: git checkout 1.12 && ./autogen.sh --prefix=/usr && make && sudo make install; popd; fi - - cmake $CMAKE_ARCH_ARGS -DMACOS_FATLIB=ON -DSTATIC=ON -DSHARED=ON -DBUILD_EXAMPLES=ON -DBUILD_GAMES=ON -DUSE_EXTERNAL_GLFW=IF_POSSIBLE -DUSE_WAYLAND=${USE_WAYLAND} .. + - cmake $CMAKE_ARCH_ARGS -DMACOS_FATLIB=ON -DSTATIC=ON -DSHARED=ON -DBUILD_EXAMPLES=ON -DBUILD_GAMES=ON -DUSE_EXTERNAL_GLFW=IF_POSSIBLE -DUSE_WAYLAND=${USE_WAYLAND} -DPLATFORM=${PLATFORM} .. - make VERBOSE=1 - if [ "$GLFW" != "SYSTEM" ]; then make package; fi; - sudo make install diff --git a/cmake/utils.cmake b/cmake/utils.cmake index 27f74e68..a3e60fb5 100755 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -16,6 +16,9 @@ if(APPLE) ${IOKIT_LIBRARY} ${COREFOUNDATION_LIBRARY} ${COREVIDEO_LIBRARY}) elseif(WIN32) # no pkg-config --static on Windows yet... +elseif(${PLATFORM} MATCHES "Android") + find_library(OPENGL_LIBRARY OpenGL) + set(LIBS_PRIVATE m log android EGL GLESv2 OpenSLES atomic c) else() find_library(pthread NAMES pthread) find_package(OpenGL QUIET) @@ -38,13 +41,15 @@ else() endif() endif() -if(USE_EXTERNAL_GLFW STREQUAL "ON") +if(${PLATFORM} MATCHES "Desktop") + if(USE_EXTERNAL_GLFW STREQUAL "ON") find_package(glfw3 3.2.1 REQUIRED) -elseif(USE_EXTERNAL_GLFW STREQUAL "IF_POSSIBLE") + elseif(USE_EXTERNAL_GLFW STREQUAL "IF_POSSIBLE") find_package(glfw3 3.2.1 QUIET) -endif() -if (glfw3_FOUND) - set(LIBS_PRIVATE ${LIBS_PRIVATE} glfw) + endif() + if (glfw3_FOUND) + set(LIBS_PRIVATE ${LIBS_PRIVATE} glfw) + endif() endif() if(CMAKE_SYSTEM_NAME STREQUAL Linux) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1f7689c8..41b417a0 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -11,6 +11,7 @@ include("CMakeOptions.txt") include(BuildType) configure_file(config.h.in ${CMAKE_BINARY_DIR}/cmake/config.h) include_directories(${CMAKE_BINARY_DIR}) +include_directories(SYSTEM .) if(MACOS_FATLIB) if (CMAKE_OSX_ARCHITECTURES) @@ -24,7 +25,7 @@ endif() file(GLOB raylib_sources *.c) list(REMOVE_ITEM raylib_sources ${CMAKE_CURRENT_SOURCE_DIR}/rglfw.c) -if(NOT glfw3_FOUND) +if(NOT glfw3_FOUND AND "${PLATFORM}" MATCHES "Desktop") set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) @@ -53,6 +54,8 @@ else() set(sources ${raylib_sources}) endif() +include(AddIfFlagCompiles) + ### Config options ### # Translate the config options to what raylib wants if(${PLATFORM} MATCHES "Desktop") @@ -92,14 +95,27 @@ elseif(${PLATFORM} MATCHES "Web") elseif(${PLATFORM} MATCHES "Android") set(PLATFORM "PLATFORM_ANDROID") set(GRAPHICS "GRAPHICS_API_OPENGL_ES2") + add_if_flag_compiles(-ffunction-sections CMAKE_C_FLAGS) + add_if_flag_compiles(-funwind-tables CMAKE_C_FLAGS) + add_if_flag_compiles(-fstack-protector-strong CMAKE_C_FLAGS) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) + add_if_flag_compiles(-Wa,--noexecstack CMAKE_C_FLAGS) + add_if_flag_compiles(-no-canonical-prefixes CMAKE_C_FLAGS) + add_definitions(-DANDROID -D__ANDROID_API__=21) + include_directories(external/android/native_app_glue ) + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--exclude-libs,libatomic.a -Wl,--build-id -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--warn-shared-textrel -Wl,--fatal-warnings -uANativeActivity_onCreate") + elseif(${PLATFORM} MATCHES "Raspberry Pi") set(PLATFORM "PLATFORM_RPI") set(GRAPHICS "GRAPHICS_API_OPENGL_ES2") endif() # Which platform? -if(${PLATFORM} MATCHES "PLATFORM_DESKTOP") +if(${PLATFORM} MATCHES "PLATFORM_WEB") + # For the web. + add_executable(${RAYLIB} ${sources}) +else() if(${SHARED}) add_library(${RAYLIB}_shared SHARED ${sources}) @@ -113,7 +129,10 @@ if(${PLATFORM} MATCHES "PLATFORM_DESKTOP") set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) set(CMAKE_MACOSX_RPATH ON) - target_link_libraries(${RAYLIB}_shared ${LIBS_PRIVATE} glfw ${GLFW_LIBRARIES}) + target_link_libraries(${RAYLIB}_shared ${LIBS_PRIVATE}) + if (${PLATFORM} MATCHES "Desktop") + target_link_libraries(${RAYLIB}_shared glfw ${GLFW_LIBRARIES}) + endif() if (UNIX AND ${FILESYSTEM_LACKS_SYMLINKS}) MESSAGE(WARNING "Can't version UNIX shared library on file system without symlink support") else() @@ -150,7 +169,9 @@ if(${PLATFORM} MATCHES "PLATFORM_DESKTOP") ) set(PKG_CONFIG_LIBS_PRIVATE ${__PKG_CONFIG_LIBS_PRIVATE}) - target_link_libraries(${RAYLIB} glfw ${GLFW_LIBRARIES}) + if (${PLATFORM} MATCHES "Desktop") + target_link_libraries(${RAYLIB} glfw ${GLFW_LIBRARIES}) + endif() if (WITH_PIC) set_property(TARGET ${RAYLIB} PROPERTY POSITION_INDEPENDENT_CODE ON) @@ -171,9 +192,6 @@ if(${PLATFORM} MATCHES "PLATFORM_DESKTOP") file(COPY "physac.h" DESTINATION ".") file(COPY "raymath.h" DESTINATION ".") file(COPY "audio.h" DESTINATION ".") -elseif(${PLATFORM} MATCHES "PLATFORM_WEB") - # For the web. - add_executable(${RAYLIB} ${sources}) endif() # Print the flags for the user diff --git a/src/utils.c b/src/utils.c index 9d9d8b55..cd75e695 100644 --- a/src/utils.c +++ b/src/utils.c @@ -57,6 +57,12 @@ #include // Required for: va_list, va_start(), vfprintf(), va_end() #include // Required for: strlen(), strrchr(), strcmp() +/* This should be in , but Travis doesn't find it... */ +FILE *funopen(const void *cookie, int (*readfn)(void *, char *, int), + int (*writefn)(void *, const char *, int), + fpos_t (*seekfn)(void *, fpos_t, int), int (*closefn)(void *)); + + #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) #define STB_IMAGE_WRITE_IMPLEMENTATION #include "external/stb_image_write.h" // Required for: stbi_write_bmp(), stbi_write_png() From bd2300fed34b458e4a419a486019afccf2ab39b1 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Mon, 21 May 2018 00:58:49 +0200 Subject: [PATCH 5/5] CMake+Android: Skip tests with SetCameraMode src/core.c does explicitly skip including on Android and tests fail. Therefore skip these failing tests. Closes #507. --- .travis.yml | 4 +++- examples/CMakeLists.txt | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 30994015..82f73e8d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -86,7 +86,9 @@ script: - if [ "$GLFW" != "SYSTEM" ]; then make package; fi; - sudo make install - pkg-config --static --libs raylib - - nm -g release/libraylib.a | grep glfwGetProcAddress || (echo "libraylib.a doesn't contain GLFW symbols! Aborting..." && false) + - if [[ "$ARCH" != *-android ]]; then + nm -g release/libraylib.a | grep glfwGetProcAddress || (echo "libraylib.a doesn't contain GLFW symbols! Aborting..." && false); + fi deploy: provider: releases diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index ae882444..fd65a74b 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -40,6 +40,29 @@ if(NOT HAVE_OCULUS_CAPI) endif() list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/others/standard_lighting.c) +if(${PLATFORM} MATCHES "Android") + list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/others/rlgl_standalone.c) + list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/core/core_3d_picking.c) + list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/core/core_vr_simulator.c) + list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/core/core_3d_camera_free.c) + list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/core/core_3d_camera_first_person.c) + list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/core/core_world_screen.c) + + list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_mesh_picking.c) + list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_material_pbr.c) + list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_cubicmap.c) + list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_skybox.c) + list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_mesh_picking.c) + list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_mesh_generation.c) + list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_heightmap.c) + list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_billboard.c) + + list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shaders_custom_uniform.c) + list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shaders_model_shader.c) + list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shaders_postprocessing.c) + +endif() + # Do each example foreach(example_source ${example_sources})