aboutsummaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorAhmad Fatoum <ahmad@a3f.at>2018-05-21 01:27:17 +0200
committerGitHub <noreply@github.com>2018-05-21 01:27:17 +0200
commitcea78e4fc16a317ef7ffd7dd537c8b47f77dca57 (patch)
tree249680970621564360684968da7396fe8d9c11cb /cmake
parenta752092055ca7c6c3d9d2b74d6ab212db14d0909 (diff)
parentbd2300fed34b458e4a419a486019afccf2ab39b1 (diff)
downloadraylib-cea78e4fc16a317ef7ffd7dd537c8b47f77dca57.tar.gz
raylib-cea78e4fc16a317ef7ffd7dd537c8b47f77dca57.zip
Travis CI: Test Android configuration (#546)
I don't know if this actually works, but it compiles, which is good enough for CI.
Diffstat (limited to 'cmake')
-rw-r--r--cmake/AddIfFlagCompiles.cmake12
-rw-r--r--cmake/BuildType.cmake43
-rw-r--r--cmake/CheckFileSystemSymlinkSupport.cmake13
-rwxr-xr-xcmake/utils.cmake93
4 files changed, 161 insertions, 0 deletions
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/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/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/cmake/utils.cmake b/cmake/utils.cmake
new file mode 100755
index 00000000..a3e60fb5
--- /dev/null
+++ b/cmake/utils.cmake
@@ -0,0 +1,93 @@
+# All sorts of things that we need cross project
+cmake_minimum_required(VERSION 2.8.0)
+
+add_definitions("-DRAYLIB_CMAKE=1")
+
+# Linking for OS X -framework options
+# Will do nothing on other OSes
+if(APPLE)
+ find_library(OPENGL_LIBRARY OpenGL)
+ find_library(COCOA_LIBRARY Cocoa)
+ find_library(IOKIT_LIBRARY IOKit)
+ find_library(COREFOUNDATION_LIBRARY CoreFoundation)
+ find_library(COREVIDEO_LIBRARY CoreVideo)
+
+ set(LIBS_PRIVATE ${OPENGL_LIBRARY} ${COCOA_LIBRARY}
+ ${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)
+ if ("${OPENGL_LIBRARIES}" STREQUAL "")
+ set(OPENGL_LIBRARIES "GL")
+ endif()
+
+ include_directories(${OPENGL_INCLUDE_DIR})
+
+ if ("${CMAKE_SYSTEM_NAME}" MATCHES "(Net|Open)BSD")
+ find_library(OSS_LIBRARY ossaudio)
+ endif()
+
+ set(LIBS_PRIVATE m pthread ${OPENGL_LIBRARIES} ${OSS_LIBRARY})
+ # TODO: maybe read those out of glfw's cmake config?
+ if(USE_WAYLAND)
+ set(LIBS_PRIVATE ${LIBS_PRIVATE} wayland-client wayland-cursor wayland-egl)
+ else()
+ set(LIBS_PRIVATE ${LIBS_PRIVATE} X11 Xrandr Xinerama Xi Xxf86vm Xcursor)
+ endif()
+endif()
+
+if(${PLATFORM} MATCHES "Desktop")
+ if(USE_EXTERNAL_GLFW STREQUAL "ON")
+ find_package(glfw3 3.2.1 REQUIRED)
+ 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()
+endif()
+
+if(CMAKE_SYSTEM_NAME STREQUAL Linux)
+ set(LINUX TRUE)
+ set(LIBS_PRIVATE dl ${LIBS_PRIVATE})
+endif()
+
+foreach(L ${LIBS_PRIVATE})
+ 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(__PKG_CONFIG_LIBS_PRIVATE ${__PKG_CONFIG_LIBS_PRIVATE} ${DIR_OPT} ${FILE_OPT})
+ string (REPLACE ";" " " __PKG_CONFIG_LIBS_PRIVATE "${__PKG_CONFIG_LIBS_PRIVATE}")
+endforeach(L)
+
+
+
+# Do the linking for executables that are meant to link raylib
+function(link_libraries_to_executable executable)
+ # Link raylib
+ if (TARGET raylib_shared)
+ target_link_libraries(${executable} raylib_shared)
+ else()
+ target_link_libraries(${executable} raylib ${__PKG_CONFIG_LIBS_PRIVATE})
+ endif()
+endfunction()