From 20ddc6a2bb4cbd39c460d8fa5d1f7175095bba2f Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Sun, 20 May 2018 19:47:19 +0200 Subject: Move utils.cmake to separate cmake/ directory --- cmake/utils.cmake | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100755 cmake/utils.cmake (limited to 'cmake') diff --git a/cmake/utils.cmake b/cmake/utils.cmake new file mode 100755 index 00000000..27f74e68 --- /dev/null +++ b/cmake/utils.cmake @@ -0,0 +1,88 @@ +# 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... +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(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() + +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() -- cgit v1.2.3 From ae26e083b4471f1404e4f25eee71e4f71e9b13f0 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Sun, 20 May 2018 19:59:18 +0200 Subject: CMake: Add default build type if none specified Release, unless we are in a Git repo, then it's Debug. --- cmake/BuildType.cmake | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 cmake/BuildType.cmake (limited to '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. -- cgit v1.2.3 From ff55af14f98fc70895ccdbbb4dccdccd68dec9dd Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Sun, 20 May 2018 20:08:43 +0200 Subject: CMake: Move reusable code to new cmake/ directory --- cmake/AddIfFlagCompiles.cmake | 12 ++++++++++++ cmake/CheckFileSystemSymlinkSupport.cmake | 13 +++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 cmake/AddIfFlagCompiles.cmake create mode 100644 cmake/CheckFileSystemSymlinkSupport.cmake (limited to 'cmake') 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() + -- cgit v1.2.3 From ad8509732ca2a235c1735fae739577a59e17cf1c Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Sun, 20 May 2018 23:03:04 +0200 Subject: CMake: Fix (Add?) Android support Not sure if this ever worked, but now it at least compiles. --- cmake/utils.cmake | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'cmake') 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) -- cgit v1.2.3