Browse Source

CMake: Fix (Add?) Android support

Not sure if this ever worked, but now it at least compiles.
pull/546/head
Ahmad Fatoum 6 years ago
parent
commit
ad8509732c
No known key found for this signature in database GPG Key ID: C3EAC3DE9321D59B
4 changed files with 70 additions and 26 deletions
  1. +29
    -14
      .travis.yml
  2. +10
    -5
      cmake/utils.cmake
  3. +25
    -7
      src/CMakeLists.txt
  4. +6
    -0
      src/utils.c

+ 29
- 14
.travis.yml View File

@ -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

+ 10
- 5
cmake/utils.cmake View File

@ -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)

+ 25
- 7
src/CMakeLists.txt View File

@ -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

+ 6
- 0
src/utils.c View File

@ -57,6 +57,12 @@
#include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end()
#include <string.h> // Required for: strlen(), strrchr(), strcmp()
/* This should be in <stdio.h>, 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()

Loading…
Cancel
Save