Squashed 'external/sdl/SDL/' content from commit b8d91252c
git-subtree-dir: external/sdl/SDL git-subtree-split: b8d91252c6488cf9c645aba447b56bb9dbd9609a
This commit is contained in:
118
cmake/3rdparty.cmake
Normal file
118
cmake/3rdparty.cmake
Normal file
@ -0,0 +1,118 @@
|
||||
function(get_clang_tidy_ignored_files OUTVAR)
|
||||
set(3RD_PARTY_SOURCES
|
||||
# Public GL headers
|
||||
"SDL_egl.h"
|
||||
"SDL_hidapi.h"
|
||||
"SDL_opengl.h"
|
||||
"SDL_opengl_glext.h"
|
||||
"SDL_opengles2_gl2.h"
|
||||
"SDL_opengles2_gl2ext.h"
|
||||
"SDL_opengles2_gl2platform.h"
|
||||
"SDL_opengles2_khrplatform.h"
|
||||
# stdlib
|
||||
"SDL_malloc.c"
|
||||
"SDL_qsort.c"
|
||||
"SDL_strtokr.c"
|
||||
# edid
|
||||
"edid-parse.c"
|
||||
"edid.h"
|
||||
# imKStoUCS
|
||||
"imKStoUCS.c"
|
||||
"imKStoUCS.h"
|
||||
# Joystick controller type
|
||||
"controller_type.h"
|
||||
"controller_type.c"
|
||||
# HIDAPI Steam controller
|
||||
"controller_constants.h"
|
||||
"controller_structs.h"
|
||||
# Nokia Pixman
|
||||
"pixman-arm-asm.h"
|
||||
"pixman-arm-neon-asm.h"
|
||||
"pixman-arm-simd-asm.h"
|
||||
# YUV2RGB
|
||||
"yuv_rgb.c"
|
||||
"yuv_rgb_lsx_func.h"
|
||||
"yuv_rgb_sse_func.h"
|
||||
"yuv_rgb_std_func.h"
|
||||
# LIBM
|
||||
"e_atan2.c"
|
||||
"e_exp.c"
|
||||
"e_fmod.c"
|
||||
"e_log10.c"
|
||||
"e_log.c"
|
||||
"e_pow.c"
|
||||
"e_rem_pio2.c"
|
||||
"e_sqrt.c"
|
||||
"k_cos.c"
|
||||
"k_rem_pio2.c"
|
||||
"k_sin.c"
|
||||
"k_tan.c"
|
||||
"s_atan.c"
|
||||
"s_copysign.c"
|
||||
"s_cos.c"
|
||||
"s_fabs.c"
|
||||
"s_floor.c"
|
||||
"s_scalbn.c"
|
||||
"s_sin.c"
|
||||
"s_tan.c"
|
||||
"math_private.h"
|
||||
"math_libm.h"
|
||||
# EGL
|
||||
"egl.h"
|
||||
"eglext.h"
|
||||
"eglplatform.h"
|
||||
# GLES2
|
||||
"gl2.h"
|
||||
"gl2ext.h"
|
||||
"gl2platform.h"
|
||||
# KHR
|
||||
"khrplatform.h"
|
||||
# Vulkan
|
||||
"vk_icd.h"
|
||||
"vk_layer.h"
|
||||
"vk_platform.h"
|
||||
"vk_sdk_platform.h"
|
||||
"vulkan_android.h"
|
||||
"vulkan_beta.h"
|
||||
"vulkan_core.h"
|
||||
"vulkan_directfb.h"
|
||||
"vulkan_fuchsia.h"
|
||||
"vulkan_ggp.h"
|
||||
"vulkan_ios.h"
|
||||
"vulkan_macos.h"
|
||||
"vulkan_metal.h"
|
||||
"vulkan_screen.h"
|
||||
"vulkan_vi.h"
|
||||
"vulkan_wayland.h"
|
||||
"vulkan_win32.h"
|
||||
"vulkan_xcb.h"
|
||||
"vulkan_xlib_xrandr.h"
|
||||
"vulkan_xlib.h"
|
||||
"vulkan.h"
|
||||
"vulkan_enums.hpp"
|
||||
"vulkan_format_traits.hpp"
|
||||
"vulkan_funcs.hpp"
|
||||
"vulkan_handles.hpp"
|
||||
"vulkan_hash.hpp"
|
||||
"vulkan_raii.hpp"
|
||||
"vulkan_static_assertions.hpp"
|
||||
"vulkan_structs.hpp"
|
||||
"vulkan_to_string.hpp"
|
||||
"vulkan.hpp"
|
||||
# HIDAPI
|
||||
"hid.c"
|
||||
"hid.cpp"
|
||||
"hid.m"
|
||||
"hidraw.cpp"
|
||||
"hidusb.cpp"
|
||||
"hidapi.h")
|
||||
|
||||
foreach(SOURCE_FILE ${3RD_PARTY_SOURCES})
|
||||
list(APPEND IGNORED_LIST "{\"name\":\"${SOURCE_FILE}\",\"lines\":[[1,1]]}")
|
||||
endforeach()
|
||||
|
||||
string(REPLACE ";" "," IGNORED_FILES "${IGNORED_LIST}")
|
||||
set(${OUTVAR}
|
||||
"${IGNORED_FILES}"
|
||||
PARENT_SCOPE)
|
||||
endfunction()
|
36
cmake/CPackProjectConfig.cmake.in
Normal file
36
cmake/CPackProjectConfig.cmake.in
Normal file
@ -0,0 +1,36 @@
|
||||
if(CPACK_PACKAGE_FILE_NAME MATCHES ".*-src$")
|
||||
message(FATAL_ERROR "Creating source archives for SDL @PROJECT_VERSION@ is not supported.")
|
||||
endif()
|
||||
|
||||
set(PROJECT_SOURCE_DIR "@PROJECT_SOURCE_DIR@")
|
||||
set(SDL_CMAKE_PLATFORM "@SDL_CMAKE_PLATFORM@")
|
||||
set(SDL_CPU_NAMES "@SDL_CPU_NAMES@")
|
||||
list(SORT SDL_CPU_NAMES)
|
||||
|
||||
string(REPLACE ";" "-" SDL_CPU_NAMES_WITH_DASHES "${SDL_CPU_NAMES}")
|
||||
if(SDL_CPU_NAMES_WITH_DASHES)
|
||||
set(SDL_CPU_NAMES_WITH_DASHES "-${SDL_CPU_NAMES_WITH_DASHES}")
|
||||
endif()
|
||||
|
||||
string(TOLOWER "${SDL_CMAKE_PLATFORM}" lower_sdl_cmake_platform)
|
||||
string(TOLOWER "${SDL_CPU_NAMES}" lower_sdl_cpu_names)
|
||||
if(lower_sdl_cmake_platform STREQUAL lower_sdl_cpu_names)
|
||||
set(SDL_CPU_NAMES_WITH_DASHES)
|
||||
endif()
|
||||
|
||||
set(MSVC @MSVC@)
|
||||
set(MINGW @MINGW@)
|
||||
if(MSVC)
|
||||
set(SDL_CMAKE_PLATFORM "${SDL_CMAKE_PLATFORM}-VC")
|
||||
elseif(MINGW)
|
||||
set(SDL_CMAKE_PLATFORM "${SDL_CMAKE_PLATFORM}-mingw")
|
||||
endif()
|
||||
|
||||
|
||||
set(CPACK_PACKAGE_FILE_NAME "SDL@PROJECT_VERSION_MAJOR@-@PROJECT_VERSION@-${SDL_CMAKE_PLATFORM}${SDL_CPU_NAMES_WITH_DASHES}")
|
||||
|
||||
if(CPACK_GENERATOR STREQUAL "DragNDrop")
|
||||
set(CPACK_DMG_VOLUME_NAME "SDL@PROJECT_VERSION_MAJOR@ @PROJECT_VERSION@")
|
||||
# FIXME: use pre-built/create .DS_Store through AppleScript (CPACK_DMG_DS_STORE/CPACK_DMG_DS_STORE_SETUP_SCRIPT)
|
||||
set(CPACK_DMG_DS_STORE "${PROJECT_SOURCE_DIR}/Xcode/SDL/pkg-support/resources/SDL_DS_Store")
|
||||
endif()
|
48
cmake/CheckCPUArchitecture.cmake
Normal file
48
cmake/CheckCPUArchitecture.cmake
Normal file
@ -0,0 +1,48 @@
|
||||
include(CheckCSourceCompiles)
|
||||
include(CMakePushCheckState)
|
||||
|
||||
function(_internal_check_cpu_architecture macro_check NAME VARIABLE)
|
||||
cmake_push_check_state()
|
||||
string(TOUPPER "${NAME}" UPPER_NAME)
|
||||
set(CACHE_VARIABLE "CHECK_CPU_ARCHITECTURE_${UPPER_NAME}")
|
||||
set(test_src "
|
||||
int main(int argc, char *argv[]) {
|
||||
#if ${macro_check}
|
||||
return 0;
|
||||
#else
|
||||
choke
|
||||
#endif
|
||||
}
|
||||
")
|
||||
check_c_source_compiles("${test_src}" "${CACHE_VARIABLE}")
|
||||
cmake_pop_check_state()
|
||||
if(${CACHE_VARIABLE})
|
||||
set(${VARIABLE} "TRUE" PARENT_SCOPE)
|
||||
else()
|
||||
set(${VARIABLE} "FALSE" PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(check_cpu_architecture ARCH VARIABLE)
|
||||
if(ARCH STREQUAL "x86")
|
||||
_internal_check_cpu_architecture("defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) ||defined( __i386) || defined(_M_IX86)" x86 ${VARIABLE})
|
||||
elseif(ARCH STREQUAL "x64")
|
||||
_internal_check_cpu_architecture("defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64)" x64 ${VARIABLE})
|
||||
elseif(ARCH STREQUAL "arm32")
|
||||
_internal_check_cpu_architecture("defined(__arm__) || defined(_M_ARM)" arm32 ${VARIABLE})
|
||||
elseif(ARCH STREQUAL "arm64")
|
||||
_internal_check_cpu_architecture("defined(__aarch64__) || defined(_M_ARM64)" arm64 ${VARIABLE})
|
||||
elseif(ARCH STREQUAL "loongarch64")
|
||||
_internal_check_cpu_architecture("defined(__loongarch64)" loongarch64 ${VARIABLE})
|
||||
elseif(ARCH STREQUAL "emscripten")
|
||||
_internal_check_cpu_architecture("defined(__EMSCRIPTEN__)" emscripten ${VARIABLE})
|
||||
elseif(ARCH STREQUAL "powerpc64")
|
||||
_internal_check_cpu_architecture("defined(__PPC64__) || defined(__powerpc64__)" powerpc64 ${VARIABLE})
|
||||
elseif(ARCH STREQUAL "powerpc32")
|
||||
_internal_check_cpu_architecture("(defined(__PPC__) || defined(__powerpc__)) && !defined(__powerpc64__)" powerpc32 ${VARIABLE})
|
||||
else()
|
||||
message(WARNING "Unknown CPU architectures (${ARCH}).")
|
||||
set("${VARIABLE}" FALSE)
|
||||
endif()
|
||||
set("${VARIABLE}" "${${VARIABLE}}" PARENT_SCOPE)
|
||||
endfunction()
|
75
cmake/FindRPi_BcmHost.cmake
Normal file
75
cmake/FindRPi_BcmHost.cmake
Normal file
@ -0,0 +1,75 @@
|
||||
include(FeatureSummary)
|
||||
set_package_properties(RPi_BcmHost PROPERTIES
|
||||
URL "https://github.com/raspberrypi/firmware"
|
||||
DESCRIPTION "Broadcom VideoCore host API library"
|
||||
)
|
||||
|
||||
set(RPi_BcmHost_PKG_CONFIG_SPEC bcm_host)
|
||||
|
||||
find_package(PkgConfig QUIET)
|
||||
pkg_check_modules(PC_RPi_BcmHost QUIET ${RPi_BcmHost_PKG_CONFIG_SPEC})
|
||||
|
||||
find_library(RPi_BcmHost_bcm_host_LIBRARY
|
||||
NAMES bcm_host
|
||||
HINTS
|
||||
${PC_RPi_BcmHost_LIBRARY_DIRS}
|
||||
/opt/vc/lib
|
||||
)
|
||||
|
||||
find_path(RPi_BcmHost_bcm_host_h_PATH
|
||||
NAMES bcm_host.h
|
||||
HINTS
|
||||
${PC_RPi_BcmHost_INCLUDE_DIRS}
|
||||
/opt/vc/include
|
||||
)
|
||||
|
||||
if(PC_RPi_BcmHost_FOUND)
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/PkgConfigHelper.cmake")
|
||||
get_flags_from_pkg_config("${RPi_BcmHost_bcm_host_LIBRARY}" "PC_RPi_BcmHost" "_RPi_BcmHost")
|
||||
else()
|
||||
set(_RPi_BcmHost_include_dirs
|
||||
/opt/vc/include
|
||||
/opt/vc/include/interface/vcos/pthreads
|
||||
/opt/vc/include/interface/vmcs_host/linux
|
||||
)
|
||||
set(_RPi_BcmHost_compile_options
|
||||
-DUSE_VCHIQ_ARM
|
||||
)
|
||||
set(_RPi_BcmHost_link_libraries
|
||||
-lvcos -lvchiq_arm
|
||||
)
|
||||
set(_RPi_BcmHost_link_options
|
||||
-pthread
|
||||
)
|
||||
set(_RPi_BcmHost_link_directories
|
||||
/opt/vc/lib
|
||||
)
|
||||
endif()
|
||||
|
||||
set(RPi_BcmHost_INCLUDE_DIRS "${_RPi_BcmHost_include_dirs}" CACHE STRING "Extra include dirs of bcm_host")
|
||||
|
||||
set(RPi_BcmHost_COMPILE_OPTIONS "${_RPi_BcmHost_compile_options}" CACHE STRING "Extra compile options of bcm_host")
|
||||
|
||||
set(RPi_BcmHost_LINK_LIBRARIES "${_RPi_BcmHost_link_libraries}" CACHE STRING "Extra link libraries of bcm_host")
|
||||
|
||||
set(RPi_BcmHost_LINK_OPTIONS "${_RPi_BcmHost_link_options}" CACHE STRING "Extra link flags of bcm_host")
|
||||
|
||||
set(RPi_BcmHost_LINK_DIRECTORIES "${_RPi_BcmHost_link_directories}" CACHE PATH "Extra link directories of bcm_host")
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(RPi_BcmHost
|
||||
REQUIRED_VARS RPi_BcmHost_bcm_host_LIBRARY RPi_BcmHost_bcm_host_h_PATH
|
||||
)
|
||||
|
||||
if(RPi_BcmHost_FOUND)
|
||||
if(NOT TARGET RPi_BcmHost::RPi_BcmHost)
|
||||
add_library(RPi_BcmHost::RPi_BcmHost INTERFACE IMPORTED)
|
||||
set_target_properties(RPi_BcmHost::RPi_BcmHost PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${RPi_BcmHost_INCLUDE_DIRS}"
|
||||
INTERFACE_COMPILE_OPTIONS "${RPi_BcmHost_COMPILE_OPTIONS}"
|
||||
INTERFACE_LINK_LIBRARIES "${RPi_BcmHost_LINK_LIBRARIES}"
|
||||
INTERFACE_LINK_OPTIONS "${RPi_BcmHost_LINK_OPTIONS}"
|
||||
INTERFACE_LINK_DIRECTORIES "${RPi_BcmHost_LINK_DIRECTORIES}"
|
||||
)
|
||||
endif()
|
||||
endif()
|
59
cmake/FindRPi_BrcmEGL.cmake
Normal file
59
cmake/FindRPi_BrcmEGL.cmake
Normal file
@ -0,0 +1,59 @@
|
||||
include(FeatureSummary)
|
||||
set_package_properties(RPi_BrcmEGL PROPERTIES
|
||||
URL "https://github.com/raspberrypi/firmware"
|
||||
DESCRIPTION "Fake brcmEGL package for RPi"
|
||||
)
|
||||
|
||||
set(RPi_BrcmEGL_PKG_CONFIG_SPEC brcmegl)
|
||||
|
||||
find_package(PkgConfig QUIET)
|
||||
pkg_check_modules(PC_RPi_BrcmEGL QUIET ${RPi_BrcmEGL_PKG_CONFIG_SPEC})
|
||||
|
||||
find_package(RPi_BcmHost)
|
||||
|
||||
find_library(RPi_BrcmEGL_brcmEGL_LIBRARY
|
||||
NAMES brcmEGL
|
||||
HINTS
|
||||
${PC_RPi_BrcmEGL_LIBRARY_DIRS}
|
||||
/opt/vc/lib
|
||||
)
|
||||
|
||||
find_path(RPi_BrcmEGL_EGL_eglplatform_h_PATH
|
||||
NAMES EGL/eglplatform.h
|
||||
HINTS
|
||||
${PC_RPi_BrcmEGL_INCLUDE_DIRS}
|
||||
/opt/vc/include
|
||||
)
|
||||
|
||||
if(PC_RPi_BrcmEGL_FOUND)
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/PkgConfigHelper.cmake")
|
||||
get_flags_from_pkg_config("${RPi_BrcmEGL_brcmEGL_LIBRARY}" "PC_RPi_BrcmEGL" "_RPi_BrcmEGL")
|
||||
endif()
|
||||
|
||||
set(RPi_BrcmEGL_INCLUDE_DIRS "${_RPi_BrcmEGL_include_dirs}" CACHE STRING "Extra include dirs of brcmEGL")
|
||||
|
||||
set(RPi_BrcmEGL_COMPILE_OPTIONS "${_RPi_BrcmEGL_compile_options}" CACHE STRING "Extra compile options of brcmEGL")
|
||||
|
||||
set(RPi_BrcmEGL_LINK_LIBRARIES "${_RPi_BrcmEGL_link_libraries}" CACHE STRING "Extra link libraries of brcmEGL")
|
||||
|
||||
set(RPi_BrcmEGL_LINK_OPTIONS "${_RPi_BrcmEGL_link_options}" CACHE STRING "Extra link flags of brcmEGL")
|
||||
|
||||
set(RPi_BrcmEGL_LINK_DIRECTORIES "${_RPi_BrcmEGL_link_directories}" CACHE PATH "Extra link directories of brcmEGL")
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(RPi_BrcmEGL
|
||||
REQUIRED_VARS RPi_BrcmEGL_brcmEGL_LIBRARY RPi_BrcmEGL_EGL_eglext_brcm_h_PATH RPi_BcmHost_FOUND
|
||||
)
|
||||
|
||||
if(RPi_BrcmEGL_FOUND)
|
||||
if(NOT TARGET RPi_BcmHost::RPi_BcmHost)
|
||||
add_library(RPi_BcmHost::RPi_BcmHost INTERFACE IMPORTED)
|
||||
set_target_properties(RPi_BcmHost::RPi_BcmHost PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${RPi_BrcmEGL_INCLUDE_DIRS}"
|
||||
INTERFACE_COMPILE_OPTIONS "${RPi_BrcmEGL_COMPILE_OPTIONS}"
|
||||
INTERFACE_LINK_LIBRARIES "${RPi_BrcmEGL_LINK_LIBRARIES};RPi_BcmHost::RPi_BcmHost"
|
||||
INTERFACE_LINK_OPTIONS "${RPi_BrcmEGL_LINK_OPTIONS}"
|
||||
INTERFACE_LINK_DIRECTORIES "${RPi_BrcmEGL_LINK_DIRECTORIES}"
|
||||
)
|
||||
endif()
|
||||
endif()
|
284
cmake/GetGitRevisionDescription.cmake
Normal file
284
cmake/GetGitRevisionDescription.cmake
Normal file
@ -0,0 +1,284 @@
|
||||
# - Returns a version string from Git
|
||||
#
|
||||
# These functions force a re-configure on each git commit so that you can
|
||||
# trust the values of the variables in your build system.
|
||||
#
|
||||
# get_git_head_revision(<refspecvar> <hashvar> [ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR])
|
||||
#
|
||||
# Returns the refspec and sha hash of the current head revision
|
||||
#
|
||||
# git_describe(<var> [<additional arguments to git describe> ...])
|
||||
#
|
||||
# Returns the results of git describe on the source tree, and adjusting
|
||||
# the output so that it tests false if an error occurs.
|
||||
#
|
||||
# git_describe_working_tree(<var> [<additional arguments to git describe> ...])
|
||||
#
|
||||
# Returns the results of git describe on the working tree (--dirty option),
|
||||
# and adjusting the output so that it tests false if an error occurs.
|
||||
#
|
||||
# git_get_exact_tag(<var> [<additional arguments to git describe> ...])
|
||||
#
|
||||
# Returns the results of git describe --exact-match on the source tree,
|
||||
# and adjusting the output so that it tests false if there was no exact
|
||||
# matching tag.
|
||||
#
|
||||
# git_local_changes(<var>)
|
||||
#
|
||||
# Returns either "CLEAN" or "DIRTY" with respect to uncommitted changes.
|
||||
# Uses the return code of "git diff-index --quiet HEAD --".
|
||||
# Does not regard untracked files.
|
||||
#
|
||||
# Requires CMake 2.6 or newer (uses the 'function' command)
|
||||
#
|
||||
# Original Author:
|
||||
# 2009-2020 Ryan Pavlik <ryan.pavlik@gmail.com> <abiryan@ryand.net>
|
||||
# http://academic.cleardefinition.com
|
||||
#
|
||||
# Copyright 2009-2013, Iowa State University.
|
||||
# Copyright 2013-2020, Ryan Pavlik
|
||||
# Copyright 2013-2020, Contributors
|
||||
# SPDX-License-Identifier: BSL-1.0
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
if(__get_git_revision_description)
|
||||
return()
|
||||
endif()
|
||||
set(__get_git_revision_description YES)
|
||||
|
||||
# We must run the following at "include" time, not at function call time,
|
||||
# to find the path to this module rather than the path to a calling list file
|
||||
get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
|
||||
|
||||
# Function _git_find_closest_git_dir finds the next closest .git directory
|
||||
# that is part of any directory in the path defined by _start_dir.
|
||||
# The result is returned in the parent scope variable whose name is passed
|
||||
# as variable _git_dir_var. If no .git directory can be found, the
|
||||
# function returns an empty string via _git_dir_var.
|
||||
#
|
||||
# Example: Given a path C:/bla/foo/bar and assuming C:/bla/.git exists and
|
||||
# neither foo nor bar contain a file/directory .git. This will return
|
||||
# C:/bla/.git
|
||||
#
|
||||
function(_git_find_closest_git_dir _start_dir _git_dir_var)
|
||||
set(cur_dir "${_start_dir}")
|
||||
set(git_dir "${_start_dir}/.git")
|
||||
while(NOT EXISTS "${git_dir}")
|
||||
# .git dir not found, search parent directories
|
||||
set(git_previous_parent "${cur_dir}")
|
||||
get_filename_component(cur_dir "${cur_dir}" DIRECTORY)
|
||||
if(cur_dir STREQUAL git_previous_parent)
|
||||
# We have reached the root directory, we are not in git
|
||||
set(${_git_dir_var}
|
||||
""
|
||||
PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
set(git_dir "${cur_dir}/.git")
|
||||
endwhile()
|
||||
set(${_git_dir_var}
|
||||
"${git_dir}"
|
||||
PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(get_git_head_revision _refspecvar _hashvar)
|
||||
_git_find_closest_git_dir("${CMAKE_CURRENT_SOURCE_DIR}" GIT_DIR)
|
||||
|
||||
if("${ARGN}" STREQUAL "ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR")
|
||||
set(ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR TRUE)
|
||||
else()
|
||||
set(ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR FALSE)
|
||||
endif()
|
||||
if(NOT "${GIT_DIR}" STREQUAL "")
|
||||
file(RELATIVE_PATH _relative_to_source_dir "${CMAKE_SOURCE_DIR}"
|
||||
"${GIT_DIR}")
|
||||
if("${_relative_to_source_dir}" MATCHES "[.][.]" AND NOT ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR)
|
||||
# We've gone above the CMake root dir.
|
||||
set(GIT_DIR "")
|
||||
endif()
|
||||
endif()
|
||||
if("${GIT_DIR}" STREQUAL "")
|
||||
set(${_refspecvar}
|
||||
"GITDIR-NOTFOUND"
|
||||
PARENT_SCOPE)
|
||||
set(${_hashvar}
|
||||
"GITDIR-NOTFOUND"
|
||||
PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# Check if the current source dir is a git submodule or a worktree.
|
||||
# In both cases .git is a file instead of a directory.
|
||||
#
|
||||
if(NOT IS_DIRECTORY ${GIT_DIR})
|
||||
# The following git command will return a non empty string that
|
||||
# points to the super project working tree if the current
|
||||
# source dir is inside a git submodule.
|
||||
# Otherwise the command will return an empty string.
|
||||
#
|
||||
execute_process(
|
||||
COMMAND "${GIT_EXECUTABLE}" rev-parse
|
||||
--show-superproject-working-tree
|
||||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
OUTPUT_VARIABLE out
|
||||
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
if(NOT "${out}" STREQUAL "")
|
||||
# If out is empty, GIT_DIR/CMAKE_CURRENT_SOURCE_DIR is in a submodule
|
||||
file(READ ${GIT_DIR} submodule)
|
||||
string(REGEX REPLACE "gitdir: (.*)$" "\\1" GIT_DIR_RELATIVE
|
||||
${submodule})
|
||||
string(STRIP ${GIT_DIR_RELATIVE} GIT_DIR_RELATIVE)
|
||||
get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH)
|
||||
get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE}
|
||||
ABSOLUTE)
|
||||
set(HEAD_SOURCE_FILE "${GIT_DIR}/HEAD")
|
||||
else()
|
||||
# GIT_DIR/CMAKE_CURRENT_SOURCE_DIR is in a worktree
|
||||
file(READ ${GIT_DIR} worktree_ref)
|
||||
# The .git directory contains a path to the worktree information directory
|
||||
# inside the parent git repo of the worktree.
|
||||
#
|
||||
string(REGEX REPLACE "gitdir: (.*)$" "\\1" git_worktree_dir
|
||||
${worktree_ref})
|
||||
string(STRIP ${git_worktree_dir} git_worktree_dir)
|
||||
_git_find_closest_git_dir("${git_worktree_dir}" GIT_DIR)
|
||||
set(HEAD_SOURCE_FILE "${git_worktree_dir}/HEAD")
|
||||
endif()
|
||||
else()
|
||||
set(HEAD_SOURCE_FILE "${GIT_DIR}/HEAD")
|
||||
endif()
|
||||
set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data")
|
||||
if(NOT EXISTS "${GIT_DATA}")
|
||||
file(MAKE_DIRECTORY "${GIT_DATA}")
|
||||
endif()
|
||||
|
||||
if(NOT EXISTS "${HEAD_SOURCE_FILE}")
|
||||
return()
|
||||
endif()
|
||||
set(HEAD_FILE "${GIT_DATA}/HEAD")
|
||||
configure_file("${HEAD_SOURCE_FILE}" "${HEAD_FILE}" COPYONLY)
|
||||
|
||||
configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in"
|
||||
"${GIT_DATA}/grabRef.cmake" @ONLY)
|
||||
include("${GIT_DATA}/grabRef.cmake")
|
||||
|
||||
set(${_refspecvar}
|
||||
"${HEAD_REF}"
|
||||
PARENT_SCOPE)
|
||||
set(${_hashvar}
|
||||
"${HEAD_HASH}"
|
||||
PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(git_describe _var)
|
||||
if(NOT GIT_FOUND)
|
||||
find_package(Git QUIET)
|
||||
endif()
|
||||
get_git_head_revision(refspec hash)
|
||||
if(NOT GIT_FOUND)
|
||||
set(${_var}
|
||||
"GIT-NOTFOUND"
|
||||
PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
if(NOT hash)
|
||||
set(${_var}
|
||||
"HEAD-HASH-NOTFOUND"
|
||||
PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# TODO sanitize
|
||||
#if((${ARGN}" MATCHES "&&") OR
|
||||
# (ARGN MATCHES "||") OR
|
||||
# (ARGN MATCHES "\\;"))
|
||||
# message("Please report the following error to the project!")
|
||||
# message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}")
|
||||
#endif()
|
||||
|
||||
#message(STATUS "Arguments to execute_process: ${ARGN}")
|
||||
|
||||
execute_process(
|
||||
COMMAND "${GIT_EXECUTABLE}" describe --tags --always ${hash} ${ARGN}
|
||||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
RESULT_VARIABLE res
|
||||
OUTPUT_VARIABLE out
|
||||
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
if(NOT res EQUAL 0)
|
||||
set(out "${out}-${res}-NOTFOUND")
|
||||
endif()
|
||||
|
||||
set(${_var}
|
||||
"${out}"
|
||||
PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(git_describe_working_tree _var)
|
||||
if(NOT GIT_FOUND)
|
||||
find_package(Git QUIET)
|
||||
endif()
|
||||
if(NOT GIT_FOUND)
|
||||
set(${_var}
|
||||
"GIT-NOTFOUND"
|
||||
PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
COMMAND "${GIT_EXECUTABLE}" describe --dirty ${ARGN}
|
||||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
RESULT_VARIABLE res
|
||||
OUTPUT_VARIABLE out
|
||||
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
if(NOT res EQUAL 0)
|
||||
set(out "${out}-${res}-NOTFOUND")
|
||||
endif()
|
||||
|
||||
set(${_var}
|
||||
"${out}"
|
||||
PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(git_get_exact_tag _var)
|
||||
git_describe(out --exact-match ${ARGN})
|
||||
set(${_var}
|
||||
"${out}"
|
||||
PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(git_local_changes _var)
|
||||
if(NOT GIT_FOUND)
|
||||
find_package(Git QUIET)
|
||||
endif()
|
||||
get_git_head_revision(refspec hash)
|
||||
if(NOT GIT_FOUND)
|
||||
set(${_var}
|
||||
"GIT-NOTFOUND"
|
||||
PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
if(NOT hash)
|
||||
set(${_var}
|
||||
"HEAD-HASH-NOTFOUND"
|
||||
PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
COMMAND "${GIT_EXECUTABLE}" diff-index --quiet HEAD --
|
||||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
RESULT_VARIABLE res
|
||||
OUTPUT_VARIABLE out
|
||||
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
if(res EQUAL 0)
|
||||
set(${_var}
|
||||
"CLEAN"
|
||||
PARENT_SCOPE)
|
||||
else()
|
||||
set(${_var}
|
||||
"DIRTY"
|
||||
PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
43
cmake/GetGitRevisionDescription.cmake.in
Normal file
43
cmake/GetGitRevisionDescription.cmake.in
Normal file
@ -0,0 +1,43 @@
|
||||
#
|
||||
# Internal file for GetGitRevisionDescription.cmake
|
||||
#
|
||||
# Requires CMake 2.6 or newer (uses the 'function' command)
|
||||
#
|
||||
# Original Author:
|
||||
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
|
||||
# http://academic.cleardefinition.com
|
||||
# Iowa State University HCI Graduate Program/VRAC
|
||||
#
|
||||
# Copyright 2009-2012, Iowa State University
|
||||
# Copyright 2011-2015, Contributors
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
# SPDX-License-Identifier: BSL-1.0
|
||||
|
||||
set(HEAD_HASH)
|
||||
|
||||
file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024)
|
||||
|
||||
string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS)
|
||||
if(HEAD_CONTENTS MATCHES "ref")
|
||||
# named branch
|
||||
string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
|
||||
if(EXISTS "@GIT_DIR@/${HEAD_REF}")
|
||||
configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
|
||||
else()
|
||||
configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" COPYONLY)
|
||||
file(READ "@GIT_DATA@/packed-refs" PACKED_REFS)
|
||||
if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}")
|
||||
set(HEAD_HASH "${CMAKE_MATCH_1}")
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
# detached HEAD
|
||||
configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY)
|
||||
endif()
|
||||
|
||||
if(NOT HEAD_HASH)
|
||||
file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024)
|
||||
string(STRIP "${HEAD_HASH}" HEAD_HASH)
|
||||
endif()
|
39
cmake/PkgConfigHelper.cmake
Normal file
39
cmake/PkgConfigHelper.cmake
Normal file
@ -0,0 +1,39 @@
|
||||
# Helper for Find modules
|
||||
|
||||
function(get_flags_from_pkg_config _library _pc_prefix _out_prefix)
|
||||
if("${_library}" MATCHES "${CMAKE_STATIC_LIBRARY_SUFFIX}$")
|
||||
set(_include_dirs ${_pc_prefix}_STATIC_INCLUDE_DIRS)
|
||||
set(_cflags ${_pc_prefix}_STATIC_CFLAGS_OTHER)
|
||||
set(_link_libraries ${_pc_prefix}_STATIC_LIBRARIES)
|
||||
set(_link_options ${_pc_prefix}_STATIC_LDFLAGS_OTHER)
|
||||
set(_library_dirs ${_pc_prefix}_STATIC_LIBRARY_DIRS)
|
||||
else()
|
||||
set(_include_dirs ${_pc_prefix}_INCLUDE_DIRS)
|
||||
set(_cflags ${_pc_prefix}_CFLAGS_OTHER)
|
||||
set(_link_libraries ${_pc_prefix}_LIBRARIES)
|
||||
set(_link_options ${_pc_prefix}_LDFLAGS_OTHER)
|
||||
set(_library_dirs ${_pc_prefix}_LIBRARY_DIRS)
|
||||
endif()
|
||||
|
||||
# The *_LIBRARIES lists always start with the library itself
|
||||
list(POP_FRONT "${_link_libraries}")
|
||||
|
||||
# Work around CMake's flag deduplication when pc files use `-framework A` instead of `-Wl,-framework,A`
|
||||
string(REPLACE "-framework;" "-Wl,-framework," "_filtered_link_options" "${${_link_options}}")
|
||||
|
||||
set(${_out_prefix}_include_dirs
|
||||
"${${_include_dirs}}"
|
||||
PARENT_SCOPE)
|
||||
set(${_out_prefix}_compile_options
|
||||
"${${_cflags}}"
|
||||
PARENT_SCOPE)
|
||||
set(${_out_prefix}_link_libraries
|
||||
"${${_link_libraries}}"
|
||||
PARENT_SCOPE)
|
||||
set(${_out_prefix}_link_options
|
||||
"${_filtered_link_options}"
|
||||
PARENT_SCOPE)
|
||||
set(${_out_prefix}_link_directories
|
||||
"${${_library_dirs}}"
|
||||
PARENT_SCOPE)
|
||||
endfunction()
|
97
cmake/SDL3Config.cmake.in
Normal file
97
cmake/SDL3Config.cmake.in
Normal file
@ -0,0 +1,97 @@
|
||||
# SDL cmake project-config input for CMakeLists.txt script
|
||||
|
||||
include(FeatureSummary)
|
||||
set_package_properties(SDL3 PROPERTIES
|
||||
URL "https://www.libsdl.org/"
|
||||
DESCRIPTION "low level access to audio, keyboard, mouse, joystick, and graphics hardware"
|
||||
)
|
||||
|
||||
@PACKAGE_INIT@
|
||||
|
||||
set(SDL3_FOUND TRUE)
|
||||
set(_sdl3_framework @SDL_FRAMEWORK@)
|
||||
|
||||
# Find SDL3::Headers
|
||||
if(NOT TARGET SDL3::Headers)
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/SDL3headersTargets.cmake")
|
||||
endif()
|
||||
set(SDL3_Headers_FOUND TRUE)
|
||||
|
||||
# Find SDL3::SDL3-shared
|
||||
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL3sharedTargets.cmake")
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/SDL3sharedTargets.cmake")
|
||||
set(SDL3_SDL3-shared_FOUND TRUE)
|
||||
endif()
|
||||
|
||||
macro(find_sdl3_static_dependencies)
|
||||
@SDL_FIND_PKG_CONFIG_COMMANDS@
|
||||
endmacro()
|
||||
|
||||
# Find SDL3::SDL3-static
|
||||
if(_sdl3_framework)
|
||||
set(SDL3_SDL3-static_FOUND TRUE)
|
||||
find_sdl3_static_dependencies()
|
||||
find_package(SDL3-static CONFIG)
|
||||
if(SDL3_SDL3-static_FOUND AND SDL3-static_FOUND)
|
||||
set(SDL3_SDL3-static_FOUND TRUE)
|
||||
endif()
|
||||
else()
|
||||
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL3staticTargets.cmake")
|
||||
set(SDL3_SDL3-static_FOUND TRUE)
|
||||
find_sdl3_static_dependencies()
|
||||
if(SDL3_SDL3-static_FOUND)
|
||||
if(ANDROID OR HAIKU)
|
||||
enable_language(CXX)
|
||||
endif()
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/SDL3staticTargets.cmake")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(SDL3_SDL3-shared_FOUND OR SDL3_SDL3-static_FOUND)
|
||||
set(SDL3_SDL3_FOUND TRUE)
|
||||
endif()
|
||||
|
||||
# Find SDL3::SDL3_test
|
||||
if(_sdl3_framework)
|
||||
find_package(SDL3_test CONFIG)
|
||||
if(SDL3_test_FOUND)
|
||||
enable_language(OBJC)
|
||||
set(SDL3_SDL3_test_FOUND TRUE)
|
||||
endif()
|
||||
else()
|
||||
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL3testTargets.cmake")
|
||||
set(SDL3_SDL3_test_FOUND TRUE)
|
||||
@SDL_TEST_FIND_PKG_CONFIG_COMMANDS@
|
||||
if(SDL3_SDL3_test_FOUND)
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/SDL3testTargets.cmake")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
check_required_components(SDL3)
|
||||
|
||||
function(_sdl_create_target_alias_compat NEW_TARGET TARGET)
|
||||
if(CMAKE_VERSION VERSION_LESS "3.18")
|
||||
# Aliasing local targets is not supported on CMake < 3.18, so make it global.
|
||||
add_library(${NEW_TARGET} INTERFACE IMPORTED)
|
||||
set_target_properties(${NEW_TARGET} PROPERTIES INTERFACE_LINK_LIBRARIES "${TARGET}")
|
||||
else()
|
||||
add_library(${NEW_TARGET} ALIAS ${TARGET})
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# Make sure SDL3::SDL3 always exists
|
||||
if(NOT TARGET SDL3::SDL3)
|
||||
if(TARGET SDL3::SDL3-shared)
|
||||
_sdl_create_target_alias_compat(SDL3::SDL3 SDL3::SDL3-shared)
|
||||
else()
|
||||
_sdl_create_target_alias_compat(SDL3::SDL3 SDL3::SDL3-static)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(SDL3_LIBRARIES SDL3::SDL3)
|
||||
set(SDL3_STATIC_LIBRARIES SDL3::SDL3-static)
|
||||
set(SDL3_STATIC_PRIVATE_LIBS)
|
||||
|
||||
set(SDL3TEST_LIBRARY SDL3::SDL3_test)
|
103
cmake/android/FindSdlAndroid.cmake
Normal file
103
cmake/android/FindSdlAndroid.cmake
Normal file
@ -0,0 +1,103 @@
|
||||
#[=======================================================================[
|
||||
|
||||
FindSdlAndroid
|
||||
----------------------
|
||||
|
||||
Locate various executables that are essential to creating an Android APK archive.
|
||||
This find module uses the FindSdlAndroidBuildTools module to locate some Android utils.
|
||||
|
||||
|
||||
Imported targets
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
This module defines the following :prop_tgt:`IMPORTED` target(s):
|
||||
|
||||
`` SdlAndroid::aapt2 ``
|
||||
Imported executable for the "android package tool" v2
|
||||
|
||||
`` SdlAndroid::apksigner``
|
||||
Imported executable for the APK signer tool
|
||||
|
||||
`` SdlAndroid::d8 ``
|
||||
Imported executable for the dex compiler
|
||||
|
||||
`` SdlAndroid::zipalign ``
|
||||
Imported executable for the zipalign util
|
||||
|
||||
`` SdlAndroid::adb ``
|
||||
Imported executable for the "android debug bridge" tool
|
||||
|
||||
`` SdlAndroid::keytool ``
|
||||
Imported executable for the keytool, a key and certificate management utility
|
||||
|
||||
`` SdlAndroid::zip ``
|
||||
Imported executable for the zip, for packaging and compressing files
|
||||
|
||||
Result variables
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
This module will set the following variables in your project:
|
||||
|
||||
`` AAPT2_BIN ``
|
||||
Path of aapt2
|
||||
|
||||
`` APKSIGNER_BIN ``
|
||||
Path of apksigner
|
||||
|
||||
`` D8_BIN ``
|
||||
Path of d8
|
||||
|
||||
`` ZIPALIGN_BIN ``
|
||||
Path of zipalign
|
||||
|
||||
`` ADB_BIN ``
|
||||
Path of adb
|
||||
|
||||
`` KEYTOOL_BIN ``
|
||||
Path of keytool
|
||||
|
||||
`` ZIP_BIN ``
|
||||
Path of zip
|
||||
|
||||
#]=======================================================================]
|
||||
|
||||
cmake_minimum_required(VERSION 3.7)
|
||||
|
||||
if(NOT PROJECT_NAME MATCHES "^SDL.*")
|
||||
message(WARNING "This module is internal to SDL and is currently not supported.")
|
||||
endif()
|
||||
|
||||
find_package(SdlAndroidBuildTools MODULE)
|
||||
|
||||
function(_sdl_android_find_create_imported_executable NAME)
|
||||
string(TOUPPER "${NAME}" NAME_UPPER)
|
||||
set(varname "${NAME_UPPER}_BIN")
|
||||
find_program("${varname}" NAMES "${NAME}" PATHS ${SDL_ANDROID_BUILD_TOOLS_ROOT})
|
||||
if(EXISTS "${${varname}}" AND NOT TARGET SdlAndroid::${NAME})
|
||||
add_executable(SdlAndroid::${NAME} IMPORTED)
|
||||
set_property(TARGET SdlAndroid::${NAME} PROPERTY IMPORTED_LOCATION "${${varname}}")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
if(SdlAndroidBuildTools_FOUND)
|
||||
_sdl_android_find_create_imported_executable(aapt2)
|
||||
_sdl_android_find_create_imported_executable(apksigner)
|
||||
_sdl_android_find_create_imported_executable(d8)
|
||||
_sdl_android_find_create_imported_executable(zipalign)
|
||||
endif()
|
||||
|
||||
_sdl_android_find_create_imported_executable(adb)
|
||||
_sdl_android_find_create_imported_executable(keytool)
|
||||
_sdl_android_find_create_imported_executable(zip)
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
find_package_handle_standard_args(SdlAndroid
|
||||
VERSION_VAR
|
||||
REQUIRED_VARS
|
||||
AAPT2_BIN
|
||||
APKSIGNER_BIN
|
||||
D8_BIN
|
||||
ZIPALIGN_BIN
|
||||
KEYTOOL_BIN
|
||||
ZIP_BIN
|
||||
)
|
115
cmake/android/FindSdlAndroidBuildTools.cmake
Normal file
115
cmake/android/FindSdlAndroidBuildTools.cmake
Normal file
@ -0,0 +1,115 @@
|
||||
#[=======================================================================[
|
||||
|
||||
FindSdlAndroidBuildTools
|
||||
----------------------
|
||||
|
||||
Locate the Android build tools directory.
|
||||
|
||||
|
||||
Imported targets
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
This find module defines the following :prop_tgt:`IMPORTED` target(s):
|
||||
|
||||
<none>
|
||||
|
||||
Result variables
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
This module will set the following variables in your project:
|
||||
|
||||
`` SdlAndroidBuildTools_FOUND
|
||||
if false, no Android build tools have been found
|
||||
|
||||
`` SDL_ANDROID_BUILD_TOOLS_ROOT
|
||||
path of the Android build tools root directory if found
|
||||
|
||||
`` SDL_ANDROID_BUILD_TOOLS_VERSION
|
||||
the human-readable string containing the android build tools version if found
|
||||
|
||||
Cache variables
|
||||
^^^^^^^^^^^^^^^
|
||||
|
||||
These variables may optionally be set to help this module find the correct files:
|
||||
|
||||
``SDL_ANDROID_BUILD_TOOLS_ROOT``
|
||||
path of the Android build tools root directory
|
||||
|
||||
|
||||
Variables for locating Android platform
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
This module responds to the flags:
|
||||
|
||||
``SDL_ANDROID_HOME
|
||||
First, this module will look for platforms in this CMake variable.
|
||||
|
||||
``ANDROID_HOME
|
||||
If no platform was found in `SDL_ANDROID_HOME`, then try `ANDROID_HOME`.
|
||||
|
||||
``$ENV{ANDROID_HOME}
|
||||
If no platform was found in neither `SDL_ANDROID_HOME` or `ANDROID_HOME`, then try `ANDROID_HOME}`
|
||||
|
||||
#]=======================================================================]
|
||||
|
||||
cmake_minimum_required(VERSION 3.7)
|
||||
|
||||
if(NOT PROJECT_NAME MATCHES "^SDL.*")
|
||||
message(WARNING "This module is internal to SDL and is currently not supported.")
|
||||
endif()
|
||||
|
||||
function(_sdl_is_valid_android_build_tools_root RESULT VERSION BUILD_TOOLS_ROOT)
|
||||
set(result TRUE)
|
||||
set(version -1)
|
||||
|
||||
string(REGEX MATCH "/([0-9.]+)$" root_match "${BUILD_TOOLS_ROOT}")
|
||||
if(root_match
|
||||
AND EXISTS "${BUILD_TOOLS_ROOT}/aapt2"
|
||||
AND EXISTS "${BUILD_TOOLS_ROOT}/apksigner"
|
||||
AND EXISTS "${BUILD_TOOLS_ROOT}/d8"
|
||||
AND EXISTS "${BUILD_TOOLS_ROOT}/zipalign")
|
||||
set(result "${BUILD_TOOLS_ROOT}")
|
||||
set(version "${CMAKE_MATCH_1}")
|
||||
endif()
|
||||
|
||||
set(${RESULT} ${result} PARENT_SCOPE)
|
||||
set(${VERSION} ${version} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(_find_sdl_android_build_tools_root ROOT)
|
||||
cmake_parse_arguments(fsabtr "" "" "" ${ARGN})
|
||||
set(homes ${SDL_ANDROID_HOME} ${ANDROID_HOME} $ENV{ANDROID_HOME})
|
||||
set(root ${ROOT}-NOTFOUND)
|
||||
foreach(home IN LISTS homes)
|
||||
if(NOT IS_DIRECTORY "${home}")
|
||||
continue()
|
||||
endif()
|
||||
file(GLOB build_tools_roots LIST_DIRECTORIES true "${home}/build-tools/*")
|
||||
set(max_build_tools_version -1)
|
||||
set(max_build_tools_root "")
|
||||
foreach(build_tools_root IN LISTS build_tools_roots)
|
||||
_sdl_is_valid_android_build_tools_root(is_valid build_tools_version "${build_tools_root}")
|
||||
if(is_valid AND build_tools_version GREATER max_build_tools_version)
|
||||
set(max_build_tools_version "${build_tools_version}")
|
||||
set(max_build_tools_root "${build_tools_root}")
|
||||
endif()
|
||||
endforeach()
|
||||
if(max_build_tools_version GREATER -1)
|
||||
set(root ${max_build_tools_root})
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
set(${ROOT} ${root} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
if(NOT DEFINED SDL_ANDROID_BUILD_TOOLS_ROOT)
|
||||
_find_sdl_android_build_tools_root(SDL_ANDROID_BUILD_TOOLS_ROOT)
|
||||
set(SDL_ANDROID_BUILD_TOOLS_ROOT "${SDL_ANDROID_BUILD_TOOLS_ROOT}" CACHE PATH "Path of Android build tools")
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
find_package_handle_standard_args(SdlAndroidBuildTools
|
||||
VERSION_VAR SDL_ANDROID_BUILD_TOOLS_VERSION
|
||||
REQUIRED_VARS SDL_ANDROID_BUILD_TOOLS_ROOT
|
||||
)
|
123
cmake/android/FindSdlAndroidPlatform.cmake
Normal file
123
cmake/android/FindSdlAndroidPlatform.cmake
Normal file
@ -0,0 +1,123 @@
|
||||
#[=======================================================================[
|
||||
|
||||
FindSdlAndroidPlatform
|
||||
----------------------
|
||||
|
||||
Locate the Android SDK platform.
|
||||
|
||||
|
||||
Imported targets
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
This module defines the following :prop_tgt:`IMPORTED` target(s):
|
||||
|
||||
<none>
|
||||
|
||||
Result variables
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
This find module will set the following variables in your project:
|
||||
|
||||
`` SdlAndroidPlatform_FOUND
|
||||
if false, no Android platform has been found
|
||||
|
||||
`` SDL_ANDROID_PLATFORM_ROOT
|
||||
path of the Android SDK platform root directory if found
|
||||
|
||||
`` SDL_ANDROID_PLATFORM_ANDROID_JAR
|
||||
path of the Android SDK platform jar file if found
|
||||
|
||||
`` SDL_ANDROID_PLATFORM_VERSION
|
||||
the human-readable string containing the android platform version if found
|
||||
|
||||
Cache variables
|
||||
^^^^^^^^^^^^^^^
|
||||
|
||||
These variables may optionally be set to help this module find the correct files:
|
||||
|
||||
``SDL_ANDROID_PLATFORM_ROOT``
|
||||
path of the Android SDK platform root directory
|
||||
|
||||
|
||||
Variables for locating Android platform
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
This module responds to the flags:
|
||||
|
||||
``SDL_ANDROID_HOME
|
||||
First, this module will look for platforms in this CMake variable.
|
||||
|
||||
``ANDROID_HOME
|
||||
If no platform was found in `SDL_ANDROID_HOME`, then try `ANDROID_HOME`.
|
||||
|
||||
``$ENV{ANDROID_HOME}
|
||||
If no platform was found in neither `SDL_ANDROID_HOME` or `ANDROID_HOME`, then try `ANDROID_HOME}`
|
||||
|
||||
#]=======================================================================]
|
||||
|
||||
cmake_minimum_required(VERSION 3.7)
|
||||
|
||||
if(NOT PROJECT_NAME MATCHES "^SDL.*")
|
||||
message(WARNING "This module is internal to SDL and is currently not supported.")
|
||||
endif()
|
||||
|
||||
function(_sdl_is_valid_android_platform_root RESULT VERSION PLATFORM_ROOT)
|
||||
set(result FALSE)
|
||||
set(version -1)
|
||||
|
||||
string(REGEX MATCH "/android-([0-9]+)$" root_match "${PLATFORM_ROOT}")
|
||||
if(root_match AND EXISTS "${PLATFORM_ROOT}/android.jar")
|
||||
set(result TRUE)
|
||||
set(version "${CMAKE_MATCH_1}")
|
||||
endif()
|
||||
|
||||
set(${RESULT} ${result} PARENT_SCOPE)
|
||||
set(${VERSION} ${version} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(_sdl_find_android_platform_root ROOT)
|
||||
cmake_parse_arguments(sfapr "" "" "" ${ARGN})
|
||||
set(homes ${SDL_ANDROID_HOME} ${ANDROID_HOME} $ENV{ANDROID_HOME})
|
||||
set(root ${ROOT}-NOTFOUND)
|
||||
foreach(home IN LISTS homes)
|
||||
if(NOT IS_DIRECTORY "${home}")
|
||||
continue()
|
||||
endif()
|
||||
file(GLOB platform_roots LIST_DIRECTORIES true "${home}/platforms/*")
|
||||
set(max_platform_version -1)
|
||||
set(max_platform_root "")
|
||||
foreach(platform_root IN LISTS platform_roots)
|
||||
_sdl_is_valid_android_platform_root(is_valid platform_version "${platform_root}")
|
||||
if(is_valid AND platform_version GREATER max_platform_version)
|
||||
set(max_platform_version "${platform_version}")
|
||||
set(max_platform_root "${platform_root}")
|
||||
endif()
|
||||
endforeach()
|
||||
if(max_platform_version GREATER -1)
|
||||
set(root ${max_platform_root})
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
set(${ROOT} ${root} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
set(SDL_ANDROID_PLATFORM_ANDROID_JAR "SDL_ANDROID_PLATFORM_ANDROID_JAR-NOTFOUND")
|
||||
|
||||
if(NOT DEFINED SDL_ANDROID_PLATFORM_ROOT)
|
||||
_sdl_find_android_platform_root(SDL_ANDROID_PLATFORM_ROOT)
|
||||
set(SDL_ANDROID_PLATFORM_ROOT "${SDL_ANDROID_PLATFORM_ROOT}" CACHE PATH "Path of Android platform")
|
||||
endif()
|
||||
if(SDL_ANDROID_PLATFORM_ROOT)
|
||||
_sdl_is_valid_android_platform_root(_valid SDL_ANDROID_PLATFORM_VERSION "${SDL_ANDROID_PLATFORM_ROOT}")
|
||||
if(_valid)
|
||||
set(SDL_ANDROID_PLATFORM_ANDROID_JAR "${SDL_ANDROID_PLATFORM_ROOT}/android.jar")
|
||||
endif()
|
||||
unset(_valid)
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
find_package_handle_standard_args(SdlAndroidPlatform
|
||||
VERSION_VAR SDL_ANDROID_PLATFORM_VERSION
|
||||
REQUIRED_VARS SDL_ANDROID_PLATFORM_ROOT SDL_ANDROID_PLATFORM_ANDROID_JAR
|
||||
)
|
276
cmake/android/SdlAndroidFunctions.cmake
Normal file
276
cmake/android/SdlAndroidFunctions.cmake
Normal file
@ -0,0 +1,276 @@
|
||||
#[=======================================================================[
|
||||
|
||||
This CMake script contains functions to build an Android APK.
|
||||
It is (currently) limited to packaging binaries for a single architecture.
|
||||
|
||||
#]=======================================================================]
|
||||
|
||||
cmake_minimum_required(VERSION 3.7)
|
||||
|
||||
if(NOT PROJECT_NAME MATCHES "^SDL.*")
|
||||
message(WARNING "This module is internal to SDL and is currently not supported.")
|
||||
endif()
|
||||
|
||||
function(_sdl_create_outdir_for_target OUTDIRECTORY TARGET)
|
||||
set(outdir "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${TARGET}.dir")
|
||||
# Some CMake versions have a slow `cmake -E make_directory` implementation
|
||||
if(NOT IS_DIRECTORY "${outdir}")
|
||||
execute_process(COMMAND "${CMAKE_COMMAND}" -E make_directory "${outdir}")
|
||||
endif()
|
||||
set("${OUTDIRECTORY}" "${outdir}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(sdl_create_android_debug_keystore TARGET)
|
||||
set(output "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_debug.keystore")
|
||||
add_custom_command(OUTPUT ${output}
|
||||
COMMAND ${CMAKE_COMMAND} -E rm -f "${output}"
|
||||
COMMAND SdlAndroid::keytool -genkey -keystore "${output}" -storepass android -alias androiddebugkey -keypass android -keyalg RSA -keysize 2048 -validity 10000 -dname "C=US, O=Android, CN=Android Debug"
|
||||
)
|
||||
add_custom_target(${TARGET} DEPENDS "${output}")
|
||||
set_property(TARGET ${TARGET} PROPERTY OUTPUT "${output}")
|
||||
endfunction()
|
||||
|
||||
function(sdl_android_compile_resources TARGET)
|
||||
cmake_parse_arguments(arg "" "RESFOLDER" "RESOURCES" ${ARGN})
|
||||
|
||||
if(NOT arg_RESFOLDER AND NOT arg_RESOURCES)
|
||||
message(FATAL_ERROR "Missing RESFOLDER or RESOURCES argument (need one or both)")
|
||||
endif()
|
||||
_sdl_create_outdir_for_target(outdir "${TARGET}")
|
||||
set(out_files "")
|
||||
|
||||
set(res_files "")
|
||||
if(arg_RESFOLDER)
|
||||
get_filename_component(arg_RESFOLDER "${arg_RESFOLDER}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
file(GLOB_RECURSE res_folder_files "${arg_RESFOLDER}/*")
|
||||
list(APPEND res_files ${res_folder_files})
|
||||
|
||||
foreach(res_file IN LISTS res_files)
|
||||
file(RELATIVE_PATH rel_res_file "${arg_RESFOLDER}" "${res_file}")
|
||||
string(REPLACE "/" "_" rel_comp_path "${rel_res_file}")
|
||||
if(res_file MATCHES ".*res/values.*\\.xml$")
|
||||
string(REGEX REPLACE "\\.xml" ".arsc" rel_comp_path "${rel_comp_path}")
|
||||
endif()
|
||||
set(comp_path "${outdir}/${rel_comp_path}.flat")
|
||||
add_custom_command(
|
||||
OUTPUT "${comp_path}"
|
||||
COMMAND SdlAndroid::aapt2 compile -o "${outdir}" "${res_file}"
|
||||
DEPENDS ${res_file}
|
||||
)
|
||||
list(APPEND out_files "${comp_path}")
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
if(arg_RESOURCES)
|
||||
list(APPEND res_files ${arg_RESOURCES})
|
||||
foreach(res_file IN LISTS arg_RESOURCES)
|
||||
string(REGEX REPLACE ".*/res/" "" rel_res_file ${res_file})
|
||||
string(REPLACE "/" "_" rel_comp_path "${rel_res_file}")
|
||||
if(res_file MATCHES ".*res/values.*\\.xml$")
|
||||
string(REGEX REPLACE "\\.xml" ".arsc" rel_comp_path "${rel_comp_path}")
|
||||
endif()
|
||||
set(comp_path "${outdir}/${rel_comp_path}.flat")
|
||||
add_custom_command(
|
||||
OUTPUT "${comp_path}"
|
||||
COMMAND SdlAndroid::aapt2 compile -o "${outdir}" "${res_file}"
|
||||
DEPENDS ${res_file}
|
||||
)
|
||||
list(APPEND out_files "${comp_path}")
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
add_custom_target(${TARGET} DEPENDS ${out_files})
|
||||
set_property(TARGET "${TARGET}" PROPERTY OUTPUTS "${out_files}")
|
||||
set_property(TARGET "${TARGET}" PROPERTY SOURCES "${res_files}")
|
||||
endfunction()
|
||||
|
||||
function(sdl_android_link_resources TARGET)
|
||||
cmake_parse_arguments(arg "NO_DEBUG" "MIN_SDK_VERSION;TARGET_SDK_VERSION;ANDROID_JAR;OUTPUT_APK;MANIFEST;PACKAGE" "RES_TARGETS" ${ARGN})
|
||||
|
||||
if(arg_MANIFEST)
|
||||
get_filename_component(arg_MANIFEST "${arg_MANIFEST}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
else()
|
||||
message(FATAL_ERROR "sdl_add_android_link_resources_target requires a Android MANIFEST path (${arg_MANIFEST})")
|
||||
endif()
|
||||
if(NOT arg_PACKAGE)
|
||||
file(READ "${arg_MANIFEST}" manifest_contents)
|
||||
string(REGEX MATCH "package=\"([a-zA-Z0-9_.]+)\"" package_match "${manifest_contents}")
|
||||
if(NOT package_match)
|
||||
message(FATAL_ERROR "Could not extract package from Android manifest (${arg_MANIFEST})")
|
||||
endif()
|
||||
set(arg_PACKAGE "${CMAKE_MATCH_1}")
|
||||
endif()
|
||||
|
||||
set(depends "")
|
||||
|
||||
_sdl_create_outdir_for_target(outdir "${TARGET}")
|
||||
string(REPLACE "." "/" java_r_path "${arg_PACKAGE}")
|
||||
get_filename_component(java_r_path "${java_r_path}" ABSOLUTE BASE_DIR "${outdir}")
|
||||
set(java_r_path "${java_r_path}/R.java")
|
||||
|
||||
set(command SdlAndroid::aapt2 link)
|
||||
if(NOT arg_NO_DEBUG)
|
||||
list(APPEND command --debug-mode)
|
||||
endif()
|
||||
if(arg_MIN_SDK_VERSION)
|
||||
list(APPEND command --min-sdk-version ${arg_MIN_SDK_VERSION})
|
||||
endif()
|
||||
if(arg_TARGET_SDK_VERSION)
|
||||
list(APPEND command --target-sdk-version ${arg_TARGET_SDK_VERSION})
|
||||
endif()
|
||||
if(arg_ANDROID_JAR)
|
||||
list(APPEND command -I "${arg_ANDROID_JAR}")
|
||||
else()
|
||||
list(APPEND command -I "${SDL_ANDROID_PLATFORM_ANDROID_JAR}")
|
||||
endif()
|
||||
if(NOT arg_OUTPUT_APK)
|
||||
set(arg_OUTPUT_APK "${TARGET}.apk")
|
||||
endif()
|
||||
get_filename_component(arg_OUTPUT_APK "${arg_OUTPUT_APK}" ABSOLUTE BASE_DIR "${outdir}")
|
||||
list(APPEND command -o "${arg_OUTPUT_APK}")
|
||||
list(APPEND command --java "${outdir}")
|
||||
list(APPEND command --manifest "${arg_MANIFEST}")
|
||||
foreach(res_target IN LISTS arg_RES_TARGETS)
|
||||
list(APPEND command $<TARGET_PROPERTY:${res_target},OUTPUTS>)
|
||||
list(APPEND depends $<TARGET_PROPERTY:${res_target},OUTPUTS>)
|
||||
endforeach()
|
||||
add_custom_command(
|
||||
OUTPUT "${arg_OUTPUT_APK}" "${java_r_path}"
|
||||
COMMAND ${command}
|
||||
DEPENDS ${depends} ${arg_MANIFEST}
|
||||
COMMAND_EXPAND_LISTS
|
||||
VERBATIM
|
||||
)
|
||||
add_custom_target(${TARGET} DEPENDS "${arg_OUTPUT_APK}" "${java_r_path}")
|
||||
set_property(TARGET ${TARGET} PROPERTY OUTPUT "${arg_OUTPUT_APK}")
|
||||
set_property(TARGET ${TARGET} PROPERTY JAVA_R "${java_r_path}")
|
||||
set_property(TARGET ${TARGET} PROPERTY OUTPUTS "${${arg_OUTPUT_APK}};${java_r_path}")
|
||||
endfunction()
|
||||
|
||||
function(sdl_add_to_apk_unaligned TARGET)
|
||||
cmake_parse_arguments(arg "" "APK_IN;NAME;OUTDIR" "ASSETS;NATIVE_LIBS;DEX" ${ARGN})
|
||||
|
||||
if(NOT arg_APK_IN)
|
||||
message(FATAL_ERROR "Missing APK_IN argument")
|
||||
endif()
|
||||
|
||||
if(NOT TARGET ${arg_APK_IN})
|
||||
message(FATAL_ERROR "APK_IN (${arg_APK_IN}) must be a target providing an apk")
|
||||
endif()
|
||||
|
||||
_sdl_create_outdir_for_target(workdir ${TARGET})
|
||||
|
||||
if(NOT arg_OUTDIR)
|
||||
set(arg_OUTDIR "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
endif()
|
||||
|
||||
if(NOT arg_NAME)
|
||||
string(REGEX REPLACE "[:-]+" "." arg_NAME "${TARGET}")
|
||||
if(NOT arg_NAME MATCHES "\\.apk")
|
||||
set(arg_NAME "${arg_NAME}.apk")
|
||||
endif()
|
||||
endif()
|
||||
get_filename_component(apk_file "${arg_NAME}" ABSOLUTE BASE_DIR "${arg_OUTDIR}")
|
||||
|
||||
set(apk_libdir "lib/${ANDROID_ABI}")
|
||||
|
||||
set(depends "")
|
||||
|
||||
set(commands
|
||||
COMMAND "${CMAKE_COMMAND}" -E remove_directory -rf "${apk_libdir}" "assets"
|
||||
COMMAND "${CMAKE_COMMAND}" -E make_directory "${apk_libdir}" "assets"
|
||||
COMMAND "${CMAKE_COMMAND}" -E copy "$<TARGET_PROPERTY:${arg_APK_IN},OUTPUT>" "${apk_file}"
|
||||
)
|
||||
|
||||
set(dex_i "1")
|
||||
foreach(dex IN LISTS arg_DEX)
|
||||
set(suffix "${dex_i}")
|
||||
if(suffix STREQUAL "1")
|
||||
set(suffix "")
|
||||
endif()
|
||||
list(APPEND commands
|
||||
COMMAND "${CMAKE_COMMAND}" -E copy "$<TARGET_PROPERTY:${dex},OUTPUT>" "classes${suffix}.dex"
|
||||
COMMAND SdlAndroid::zip -u -q -j "${apk_file}" "classes${suffix}.dex"
|
||||
)
|
||||
math(EXPR dex_i "${dex_i}+1")
|
||||
list(APPEND depends "$<TARGET_PROPERTY:${dex},OUTPUT>")
|
||||
endforeach()
|
||||
|
||||
foreach(native_lib IN LISTS arg_NATIVE_LIBS)
|
||||
list(APPEND commands
|
||||
COMMAND "${CMAKE_COMMAND}" -E copy $<TARGET_FILE:${native_lib}> "${apk_libdir}/$<TARGET_FILE_NAME:${native_lib}>"
|
||||
COMMAND SdlAndroid::zip -u -q "${apk_file}" "${apk_libdir}/$<TARGET_FILE_NAME:${native_lib}>"
|
||||
)
|
||||
endforeach()
|
||||
if(arg_ASSETS)
|
||||
list(APPEND commands
|
||||
COMMAND "${CMAKE_COMMAND}" -E copy ${arg_ASSETS} "assets"
|
||||
COMMAND SdlAndroid::zip -u -r -q "${apk_file}" "assets"
|
||||
)
|
||||
endif()
|
||||
|
||||
add_custom_command(OUTPUT "${apk_file}"
|
||||
${commands}
|
||||
DEPENDS ${arg_NATIVE_LIBS} ${depends} "$<TARGET_PROPERTY:${arg_APK_IN},OUTPUT>"
|
||||
WORKING_DIRECTORY "${workdir}"
|
||||
)
|
||||
add_custom_target(${TARGET} DEPENDS "${apk_file}")
|
||||
set_property(TARGET ${TARGET} PROPERTY OUTPUT "${apk_file}")
|
||||
endfunction()
|
||||
|
||||
function(sdl_apk_align TARGET APK_IN)
|
||||
cmake_parse_arguments(arg "" "NAME;OUTDIR" "" ${ARGN})
|
||||
|
||||
if(NOT TARGET ${arg_APK_IN})
|
||||
message(FATAL_ERROR "APK_IN (${arg_APK_IN}) must be a target providing an apk")
|
||||
endif()
|
||||
|
||||
if(NOT arg_OUTDIR)
|
||||
set(arg_OUTDIR "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
endif()
|
||||
|
||||
if(NOT arg_NAME)
|
||||
string(REGEX REPLACE "[:-]+" "." arg_NAME "${TARGET}")
|
||||
if(NOT arg_NAME MATCHES "\\.apk")
|
||||
set(arg_NAME "${arg_NAME}.apk")
|
||||
endif()
|
||||
endif()
|
||||
get_filename_component(apk_file "${arg_NAME}" ABSOLUTE BASE_DIR "${arg_OUTDIR}")
|
||||
|
||||
add_custom_command(OUTPUT "${apk_file}"
|
||||
COMMAND SdlAndroid::zipalign -f 4 "$<TARGET_PROPERTY:${APK_IN},OUTPUT>" "${apk_file}"
|
||||
DEPENDS "$<TARGET_PROPERTY:${APK_IN},OUTPUT>"
|
||||
)
|
||||
add_custom_target(${TARGET} DEPENDS "${apk_file}")
|
||||
set_property(TARGET ${TARGET} PROPERTY OUTPUT "${apk_file}")
|
||||
endfunction()
|
||||
|
||||
function(sdl_apk_sign TARGET APK_IN)
|
||||
cmake_parse_arguments(arg "" "OUTPUT;KEYSTORE" "" ${ARGN})
|
||||
|
||||
if(NOT TARGET ${arg_APK_IN})
|
||||
message(FATAL_ERROR "APK_IN (${arg_APK_IN}) must be a target providing an apk")
|
||||
endif()
|
||||
|
||||
if(NOT TARGET ${arg_KEYSTORE})
|
||||
message(FATAL_ERROR "APK_KEYSTORE (${APK_KEYSTORE}) must be a target providing a keystore")
|
||||
endif()
|
||||
|
||||
if(NOT arg_OUTPUT)
|
||||
string(REGEX REPLACE "[:-]+" "." arg_OUTPUT "${TARGET}")
|
||||
if(NOT arg_OUTPUT MATCHES "\\.apk")
|
||||
set(arg_OUTPUT "${arg_OUTPUT}.apk")
|
||||
endif()
|
||||
endif()
|
||||
get_filename_component(apk_file "${arg_OUTPUT}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
||||
add_custom_command(OUTPUT "${apk_file}"
|
||||
COMMAND SdlAndroid::apksigner sign
|
||||
--ks "$<TARGET_PROPERTY:${arg_KEYSTORE},OUTPUT>"
|
||||
--ks-pass pass:android --in "$<TARGET_PROPERTY:${APK_IN},OUTPUT>" --out "${apk_file}"
|
||||
DEPENDS "$<TARGET_PROPERTY:${APK_IN},OUTPUT>" "$<TARGET_PROPERTY:${arg_KEYSTORE},OUTPUT>"
|
||||
BYPRODUCTS "${apk_file}.idsig"
|
||||
)
|
||||
add_custom_target(${TARGET} DEPENDS "${apk_file}")
|
||||
set_property(TARGET ${TARGET} PROPERTY OUTPUT "${apk_file}")
|
||||
endfunction()
|
74
cmake/android/SdlAndroidScript.cmake
Normal file
74
cmake/android/SdlAndroidScript.cmake
Normal file
@ -0,0 +1,74 @@
|
||||
#[=======================================================================[
|
||||
|
||||
This CMake script is meant to be used in CMake script mode (cmake -P).
|
||||
It wraps commands that communicate with an actual Android device.
|
||||
Because
|
||||
|
||||
#]=======================================================================]
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
if(NOT CMAKE_SCRIPT_MODE_FILE)
|
||||
message(FATAL_ERROR "This file can only be used in CMake script mode")
|
||||
endif()
|
||||
if(NOT ADB)
|
||||
set(ADB "adb")
|
||||
endif()
|
||||
|
||||
if(NOT ACTION)
|
||||
message(FATAL_ERROR "Missing ACTION argument")
|
||||
endif()
|
||||
|
||||
if(ACTION STREQUAL "uninstall")
|
||||
# The uninstall action attempts to uninstall all packages. All failures are ignored.
|
||||
foreach(package IN LISTS PACKAGES)
|
||||
message("Uninstalling ${package} ...")
|
||||
execute_process(
|
||||
COMMAND ${ADB} uninstall ${package}
|
||||
RESULT_VARIABLE res
|
||||
)
|
||||
message("... result=${res}")
|
||||
endforeach()
|
||||
elseif(ACTION STREQUAL "install")
|
||||
# The install actions attempts to install APK's to an Android device using adb. Failures are ignored.
|
||||
set(failed_apks "")
|
||||
foreach(apk IN LISTS APKS)
|
||||
message("Installing ${apk} ...")
|
||||
execute_process(
|
||||
COMMAND ${ADB} install -d -r --streaming ${apk}
|
||||
RESULT_VARIABLE res
|
||||
)
|
||||
message("... result=${res}")
|
||||
if(NOT res EQUAL 0)
|
||||
list(APPEND failed_apks ${apk})
|
||||
endif()
|
||||
endforeach()
|
||||
if(failed_apks)
|
||||
message(FATAL_ERROR "Failed to install ${failed_apks}")
|
||||
endif()
|
||||
elseif(ACTION STREQUAL "build-install-run")
|
||||
if(NOT EXECUTABLES)
|
||||
message(FATAL_ERROR "Missing EXECUTABLES (don't know what executables to build/install and start")
|
||||
endif()
|
||||
if(NOT BUILD_FOLDER)
|
||||
message(FATAL_ERROR "Missing BUILD_FOLDER (don't know where to build the APK's")
|
||||
endif()
|
||||
set(install_targets "")
|
||||
foreach(executable IN LISTS EXECUTABLES)
|
||||
list(APPEND install_targets "install-${executable}")
|
||||
endforeach()
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND} --build "${BUILD_FOLDER}" --target ${install_targets}
|
||||
RESULT_VARIABLE res
|
||||
)
|
||||
if(NOT res EQUAL 0)
|
||||
message(FATAL_ERROR "Failed to install APK(s) for ${EXECUTABLES}")
|
||||
endif()
|
||||
list(GET EXECUTABLES 0 start_executable)
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND} --build "${BUILD_FOLDER}" --target start-${start_executable}
|
||||
RESULT_VARIABLE res
|
||||
)
|
||||
else()
|
||||
message(FATAL_ERROR "Unknown ACTION=${ACTION}")
|
||||
endif()
|
17
cmake/cmake_uninstall.cmake.in
Normal file
17
cmake/cmake_uninstall.cmake.in
Normal file
@ -0,0 +1,17 @@
|
||||
if (NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
|
||||
message(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_BINARY_DIR@/install_manifest.txt\"")
|
||||
endif()
|
||||
|
||||
file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files)
|
||||
string(REGEX REPLACE "\n" ";" files "${files}")
|
||||
foreach(file ${files})
|
||||
message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"")
|
||||
execute_process(
|
||||
COMMAND @CMAKE_COMMAND@ -E remove "$ENV{DESTDIR}${file}"
|
||||
OUTPUT_VARIABLE rm_out
|
||||
RESULT_VARIABLE rm_retval
|
||||
)
|
||||
if(NOT ${rm_retval} EQUAL 0)
|
||||
message(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"")
|
||||
endif (NOT ${rm_retval} EQUAL 0)
|
||||
endforeach()
|
171
cmake/macros.cmake
Normal file
171
cmake/macros.cmake
Normal file
@ -0,0 +1,171 @@
|
||||
macro(add_to_alloptions _NEWNAME)
|
||||
list(APPEND ALLOPTIONS ${_NEWNAME})
|
||||
endmacro()
|
||||
|
||||
macro(set_option _NAME _DESC)
|
||||
add_to_alloptions(${_NAME})
|
||||
if(${ARGC} EQUAL 3)
|
||||
set(_DEFLT ${ARGV2})
|
||||
else()
|
||||
set(_DEFLT OFF)
|
||||
endif()
|
||||
option(${_NAME} ${_DESC} ${_DEFLT})
|
||||
endmacro()
|
||||
|
||||
macro(dep_option _NAME _DESC _DEFLT _DEPTEST _FAILDFLT)
|
||||
add_to_alloptions("${_NAME}")
|
||||
cmake_dependent_option("${_NAME}" "${_DESC}" "${_DEFLT}" "${_DEPTEST}" "${_FAILDFLT}")
|
||||
endmacro()
|
||||
|
||||
macro(option_string _NAME _DESC _VALUE)
|
||||
add_to_alloptions(${_NAME})
|
||||
set(${_NAME} ${_VALUE} CACHE STRING "${_DESC}")
|
||||
set(HAVE_${_NAME} ${_VALUE})
|
||||
ENDMACRO()
|
||||
|
||||
macro(message_bool_option _NAME _VALUE)
|
||||
set(_PAD "\t")
|
||||
if(${ARGC} EQUAL 3)
|
||||
set(_PAD ${ARGV2})
|
||||
endif()
|
||||
if(${_VALUE})
|
||||
message(STATUS " ${_NAME}:${_PAD}ON")
|
||||
else()
|
||||
message(STATUS " ${_NAME}:${_PAD}OFF")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
macro(message_tested_option _NAME)
|
||||
set(_REQVALUE ${${_NAME}})
|
||||
set(_PAD " ")
|
||||
if(${ARGC} EQUAL 2)
|
||||
set(_PAD ${ARGV1})
|
||||
endif()
|
||||
string(SUBSTRING "${_NAME}" 0 4 _NAMESTART)
|
||||
if(_NAMESTART STREQUAL "SDL_")
|
||||
string(SUBSTRING "${_NAME}" 4 -1 _STRIPPEDNAME)
|
||||
else()
|
||||
set(_STRIPPEDNAME "${_NAME}")
|
||||
endif()
|
||||
if(NOT HAVE_${_STRIPPEDNAME})
|
||||
set(HAVE_${_STRIPPEDNAME} OFF)
|
||||
elseif("${HAVE_${_STRIPPEDNAME}}" MATCHES "1|TRUE|YES|Y")
|
||||
set(HAVE_${_STRIPPEDNAME} ON)
|
||||
endif()
|
||||
message(STATUS " ${_NAME}${_PAD}(Wanted: ${_REQVALUE}): ${HAVE_${_STRIPPEDNAME}}")
|
||||
endmacro()
|
||||
|
||||
function(find_stringlength_longest_item inList outLength)
|
||||
set(maxLength 0)
|
||||
foreach(item IN LISTS ${inList})
|
||||
string(LENGTH "${item}" slen)
|
||||
if(slen GREATER maxLength)
|
||||
set(maxLength ${slen})
|
||||
endif()
|
||||
endforeach()
|
||||
set("${outLength}" ${maxLength} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(message_dictlist inList)
|
||||
find_stringlength_longest_item(${inList} maxLength)
|
||||
foreach(name IN LISTS ${inList})
|
||||
# Get the padding
|
||||
string(LENGTH ${name} nameLength)
|
||||
math(EXPR padLength "(${maxLength} + 1) - ${nameLength}")
|
||||
string(RANDOM LENGTH ${padLength} ALPHABET " " padding)
|
||||
message_tested_option(${name} ${padding})
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
if(APPLE)
|
||||
include(CheckOBJCSourceCompiles)
|
||||
enable_language(OBJC)
|
||||
endif()
|
||||
|
||||
if(CMAKE_VERSION VERSION_LESS 3.18)
|
||||
function(check_linker_flag LANG FLAG VAR)
|
||||
cmake_push_check_state()
|
||||
list(APPEND CMAKE_REQUIRED_LINK_OPTIONS ${FLAG} )
|
||||
if(LANG STREQUAL "C")
|
||||
include(CheckCSourceCompiles)
|
||||
check_c_source_compiles("int main(int argc,char*argv[]){(void)argc;(void)argv;return 0;}" ${VAR} FAIL_REGEX "warning")
|
||||
elseif(LANG STREQUAL "CXX")
|
||||
include(CheckCXXSourceCompiles)
|
||||
check_cxx_source_compiles("int main(int argc,char*argv[]){(void)argc;(void)argv;return 0;}" ${VAR} FAIL_REGEX "warning")
|
||||
else()
|
||||
message(FATAL_ERROR "Unsupported language: ${LANG}")
|
||||
endif()
|
||||
cmake_pop_check_state()
|
||||
endfunction()
|
||||
else()
|
||||
cmake_policy(SET CMP0057 NEW) # Support new if() IN_LIST operator. (used inside check_linker_flag, used in CMake 3.18)
|
||||
include(CheckLinkerFlag)
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
check_language(OBJC)
|
||||
if(NOT CMAKE_OBJC_COMPILER)
|
||||
message(WARNING "Cannot find working OBJC compiler.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
function(SDL_PrintSummary)
|
||||
##### Info output #####
|
||||
message(STATUS "")
|
||||
message(STATUS "SDL3 was configured with the following options:")
|
||||
message(STATUS "")
|
||||
message(STATUS "Platform: ${CMAKE_SYSTEM}")
|
||||
message(STATUS "64-bit: ${ARCH_64}")
|
||||
message(STATUS "Compiler: ${CMAKE_C_COMPILER}")
|
||||
message(STATUS "Revision: ${SDL_REVISION}")
|
||||
message(STATUS "Vendor: ${SDL_VENDOR_INFO}")
|
||||
message(STATUS "")
|
||||
message(STATUS "Subsystems:")
|
||||
|
||||
find_stringlength_longest_item(SDL_SUBSYSTEMS maxLength)
|
||||
foreach(_SUB IN LISTS SDL_SUBSYSTEMS)
|
||||
string(LENGTH ${_SUB} _SUBLEN)
|
||||
math(EXPR _PADLEN "(${maxLength} + 1) - ${_SUBLEN}")
|
||||
string(RANDOM LENGTH ${_PADLEN} ALPHABET " " _PADDING)
|
||||
string(TOUPPER ${_SUB} _OPT)
|
||||
message_bool_option(${_SUB} SDL_${_OPT} ${_PADDING})
|
||||
endforeach()
|
||||
message(STATUS "")
|
||||
message(STATUS "Options:")
|
||||
list(SORT ALLOPTIONS)
|
||||
message_dictlist(ALLOPTIONS)
|
||||
message(STATUS "")
|
||||
message(STATUS " Build Shared Library: ${SDL_SHARED}")
|
||||
message(STATUS " Build Static Library: ${SDL_STATIC}")
|
||||
if(SDL_STATIC)
|
||||
message(STATUS " Build Static Library with Position Independent Code: ${SDL_STATIC_PIC}")
|
||||
endif()
|
||||
if(APPLE)
|
||||
message(STATUS " Build libraries as Apple Framework: ${SDL_FRAMEWORK}")
|
||||
endif()
|
||||
message(STATUS "")
|
||||
if(UNIX)
|
||||
message(STATUS "If something was not detected, although the libraries")
|
||||
message(STATUS "were installed, then make sure you have set the")
|
||||
message(STATUS "CMAKE_C_FLAGS and CMAKE_PREFIX_PATH CMake variables correctly.")
|
||||
message(STATUS "")
|
||||
endif()
|
||||
|
||||
if(WARN_ABOUT_ARM_SIMD_ASM_MIT)
|
||||
message(STATUS "SDL is being built with ARM SIMD optimizations, which")
|
||||
message(STATUS "uses code licensed under the MIT license. If this is a")
|
||||
message(STATUS "problem, please disable that code by rerunning CMake with:")
|
||||
message(STATUS "")
|
||||
message(STATUS " -DSDL_ARMSIMD=OFF")
|
||||
message(STATUS "")
|
||||
endif()
|
||||
|
||||
if(WARN_ABOUT_ARM_NEON_ASM_MIT)
|
||||
message(STATUS "SDL is being built with ARM NEON optimizations, which")
|
||||
message(STATUS "uses code licensed under the MIT license. If this is a")
|
||||
message(STATUS "problem, please disable that code by rerunning CMake with:")
|
||||
message(STATUS "")
|
||||
message(STATUS " -DSDL_ARMNEON=OFF")
|
||||
message(STATUS "")
|
||||
endif()
|
||||
endfunction()
|
13
cmake/sdl3.pc.in
Normal file
13
cmake/sdl3.pc.in
Normal file
@ -0,0 +1,13 @@
|
||||
prefix=@SDL_PKGCONFIG_PREFIX@
|
||||
exec_prefix=${prefix}
|
||||
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
|
||||
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
|
||||
|
||||
Name: sdl3
|
||||
Description: Simple DirectMedia Layer is a cross-platform multimedia library designed to provide low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video framebuffer.
|
||||
URL: https://www.libsdl.org/
|
||||
Version: @PROJECT_VERSION@
|
||||
Requires.private: @SDL_PC_PRIVATE_REQUIRES@
|
||||
Conflicts:
|
||||
Libs: -L${libdir} @SDL_RLD_FLAGS@ @SDL_PC_LIBS@ @SDL_PC_SECTION_LIBS_PRIVATE@ @SDL_PC_STATIC_LIBS@
|
||||
Cflags: -I${includedir} -I${includedir}/SDL3 @SDL_PC_CFLAGS@
|
1217
cmake/sdlchecks.cmake
Normal file
1217
cmake/sdlchecks.cmake
Normal file
File diff suppressed because it is too large
Load Diff
128
cmake/sdlcompilers.cmake
Normal file
128
cmake/sdlcompilers.cmake
Normal file
@ -0,0 +1,128 @@
|
||||
macro(SDL_DetectCompiler)
|
||||
set(USE_CLANG FALSE)
|
||||
set(USE_GCC FALSE)
|
||||
set(USE_INTELCC FALSE)
|
||||
set(USE_QCC FALSE)
|
||||
if(CMAKE_C_COMPILER_ID MATCHES "Clang|IntelLLVM")
|
||||
set(USE_CLANG TRUE)
|
||||
# Visual Studio 2019 v16.2 added support for Clang/LLVM.
|
||||
# Check if a Visual Studio project is being generated with the Clang toolset.
|
||||
if(MSVC)
|
||||
set(MSVC_CLANG TRUE)
|
||||
endif()
|
||||
elseif(CMAKE_COMPILER_IS_GNUCC)
|
||||
set(USE_GCC TRUE)
|
||||
elseif(CMAKE_C_COMPILER_ID MATCHES "^Intel$")
|
||||
set(USE_INTELCC TRUE)
|
||||
elseif(CMAKE_C_COMPILER_ID MATCHES "QCC")
|
||||
set(USE_QCC TRUE)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
function(SDL_AddCommonCompilerFlags TARGET)
|
||||
option(SDL_WERROR "Enable -Werror" OFF)
|
||||
|
||||
if(USE_GCC OR USE_CLANG OR USE_INTELCC OR USE_QCC)
|
||||
if(MINGW)
|
||||
# See if GCC's -gdwarf-4 is supported
|
||||
# See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101377 for why this is needed on Windows
|
||||
cmake_push_check_state()
|
||||
check_c_compiler_flag("-gdwarf-4" HAVE_GDWARF_4)
|
||||
if(HAVE_GDWARF_4)
|
||||
target_compile_options(${TARGET} PRIVATE "-gdwarf-4")
|
||||
endif()
|
||||
cmake_pop_check_state()
|
||||
endif()
|
||||
|
||||
# Check for -Wall first, so later things can override pieces of it.
|
||||
# Note: clang-cl treats -Wall as -Weverything (which is very loud),
|
||||
# /W3 as -Wall, and /W4 as -Wall -Wextra. So: /W3 is enough.
|
||||
check_c_compiler_flag(-Wall HAVE_GCC_WALL)
|
||||
if(MSVC_CLANG)
|
||||
target_compile_options(${TARGET} PRIVATE "/W3")
|
||||
elseif(HAVE_GCC_WALL)
|
||||
target_compile_options(${TARGET} PRIVATE "-Wall")
|
||||
if(HAIKU)
|
||||
target_compile_options(${TARGET} PRIVATE "-Wno-multichar")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
check_c_compiler_flag(-Wundef HAVE_GCC_WUNDEF)
|
||||
if(HAVE_GCC_WUNDEF)
|
||||
target_compile_options(${TARGET} PRIVATE "-Wundef")
|
||||
endif()
|
||||
|
||||
check_c_compiler_flag(-fno-strict-aliasing HAVE_GCC_NO_STRICT_ALIASING)
|
||||
if(HAVE_GCC_NO_STRICT_ALIASING)
|
||||
target_compile_options(${TARGET} PRIVATE "-fno-strict-aliasing")
|
||||
endif()
|
||||
|
||||
check_c_compiler_flag(-Wdocumentation HAVE_GCC_WDOCUMENTATION)
|
||||
if(HAVE_GCC_WDOCUMENTATION)
|
||||
if(SDL_WERROR)
|
||||
check_c_compiler_flag(-Werror=documentation HAVE_GCC_WERROR_DOCUMENTATION)
|
||||
if(HAVE_GCC_WERROR_DOCUMENTATION)
|
||||
target_compile_options(${TARGET} PRIVATE "-Werror=documentation")
|
||||
endif()
|
||||
endif()
|
||||
target_compile_options(${TARGET} PRIVATE "-Wdocumentation")
|
||||
endif()
|
||||
|
||||
check_c_compiler_flag(-Wdocumentation-unknown-command HAVE_GCC_WDOCUMENTATION_UNKNOWN_COMMAND)
|
||||
if(HAVE_GCC_WDOCUMENTATION_UNKNOWN_COMMAND)
|
||||
if(SDL_WERROR)
|
||||
check_c_compiler_flag(-Werror=documentation-unknown-command HAVE_GCC_WERROR_DOCUMENTATION_UNKNOWN_COMMAND)
|
||||
if(HAVE_GCC_WERROR_DOCUMENTATION_UNKNOWN_COMMAND)
|
||||
target_compile_options(${TARGET} PRIVATE "-Werror=documentation-unknown-command")
|
||||
endif()
|
||||
endif()
|
||||
target_compile_options(${TARGET} PRIVATE "-Wdocumentation-unknown-command")
|
||||
endif()
|
||||
|
||||
check_c_compiler_flag(-fcomment-block-commands=threadsafety HAVE_GCC_COMMENT_BLOCK_COMMANDS)
|
||||
if(HAVE_GCC_COMMENT_BLOCK_COMMANDS)
|
||||
target_compile_options(${TARGET} PRIVATE "-fcomment-block-commands=threadsafety")
|
||||
else()
|
||||
check_c_compiler_flag(/clang:-fcomment-block-commands=threadsafety HAVE_CLANG_COMMENT_BLOCK_COMMANDS)
|
||||
if(HAVE_CLANG_COMMENT_BLOCK_COMMANDS)
|
||||
target_compile_options(${TARGET} PRIVATE "/clang:-fcomment-block-commands=threadsafety")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
check_c_compiler_flag(-Wshadow HAVE_GCC_WSHADOW)
|
||||
if(HAVE_GCC_WSHADOW)
|
||||
target_compile_options(${TARGET} PRIVATE "-Wshadow")
|
||||
endif()
|
||||
|
||||
check_c_compiler_flag(-Wunused-local-typedefs HAVE_GCC_WUNUSED_LOCAL_TYPEDEFS)
|
||||
if(HAVE_GCC_WUNUSED_LOCAL_TYPEDEFS)
|
||||
target_compile_options(${TARGET} PRIVATE "-Wno-unused-local-typedefs")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(SDL_WERROR)
|
||||
if(MSVC)
|
||||
check_c_compiler_flag(/WX HAVE_WX)
|
||||
if(HAVE_WX)
|
||||
target_compile_options(${TARGET} PRIVATE "/WX")
|
||||
endif()
|
||||
elseif(USE_GCC OR USE_CLANG OR USE_INTELCC OR USE_QNX)
|
||||
check_c_compiler_flag(-Werror HAVE_WERROR)
|
||||
if(HAVE_WERROR)
|
||||
target_compile_options(${TARGET} PRIVATE "-Werror")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(USE_CLANG)
|
||||
check_c_compiler_flag("-fcolor-diagnostics" COMPILER_SUPPORTS_FCOLOR_DIAGNOSTICS)
|
||||
if(COMPILER_SUPPORTS_FCOLOR_DIAGNOSTICS)
|
||||
target_compile_options(${TARGET} PRIVATE "-fcolor-diagnostics")
|
||||
endif()
|
||||
else()
|
||||
check_c_compiler_flag("-fdiagnostics-color=always" COMPILER_SUPPORTS_FDIAGNOSTICS_COLOR_ALWAYS)
|
||||
if(COMPILER_SUPPORTS_FDIAGNOSTICS_COLOR_ALWAYS)
|
||||
target_compile_options(${TARGET} PRIVATE "-fdiagnostics-color=always")
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
62
cmake/sdlmanpages.cmake
Normal file
62
cmake/sdlmanpages.cmake
Normal file
@ -0,0 +1,62 @@
|
||||
include(CMakeParseArguments)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
function(SDL_generate_manpages)
|
||||
cmake_parse_arguments(ARG "" "RESULT_VARIABLE;NAME;BUILD_DOCDIR;HEADERS_DIR;SOURCE_DIR;SYMBOL;OPTION_FILE;WIKIHEADERS_PL_PATH" "" ${ARGN})
|
||||
|
||||
if(NOT ARG_NAME)
|
||||
set(ARG_NAME "${PROJECT_NAME}")
|
||||
endif()
|
||||
|
||||
if(NOT ARG_SOURCE_DIR)
|
||||
set(ARG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
endif()
|
||||
|
||||
if(NOT ARG_OPTION_FILE)
|
||||
set(ARG_OPTION_FILE "${PROJECT_SOURCE_DIR}/.wikiheaders-options")
|
||||
endif()
|
||||
|
||||
if(NOT ARG_HEADERS_DIR)
|
||||
set(ARG_HEADERS_DIR "${PROJECT_SOURCE_DIR}/include/SDL3")
|
||||
endif()
|
||||
|
||||
# FIXME: get rid of SYMBOL and let the perl script figure out the dependencies
|
||||
if(NOT ARG_SYMBOL)
|
||||
message(FATAL_ERROR "Missing required SYMBOL argument")
|
||||
endif()
|
||||
|
||||
if(NOT ARG_BUILD_DOCDIR)
|
||||
set(ARG_BUILD_DOCDIR "${CMAKE_CURRENT_BINARY_DIR}/docs")
|
||||
endif()
|
||||
set(BUILD_WIKIDIR "${ARG_BUILD_DOCDIR}/wiki")
|
||||
set(BUILD_MANDIR "${ARG_BUILD_DOCDIR}/man")
|
||||
|
||||
find_package(Perl)
|
||||
file(GLOB HEADER_FILES "${ARG_HEADERS_DIR}/*.h")
|
||||
|
||||
set(result FALSE)
|
||||
|
||||
if(PERL_FOUND AND EXISTS "${ARG_WIKIHEADERS_PL_PATH}")
|
||||
add_custom_command(
|
||||
OUTPUT "${BUILD_WIKIDIR}/${ARG_SYMBOL}.md"
|
||||
COMMAND "${CMAKE_COMMAND}" -E make_directory "${BUILD_WIKIDIR}"
|
||||
COMMAND "${PERL_EXECUTABLE}" "${ARG_WIKIHEADERS_PL_PATH}" "${ARG_SOURCE_DIR}" "${BUILD_WIKIDIR}" "--options=${ARG_OPTION_FILE}" --copy-to-wiki
|
||||
DEPENDS ${HEADER_FILES} "${ARG_WIKIHEADERS_PL_PATH}" "${ARG_OPTION_FILE}"
|
||||
COMMENT "Generating ${ARG_NAME} wiki markdown files"
|
||||
)
|
||||
add_custom_command(
|
||||
OUTPUT "${BUILD_MANDIR}/man3/${ARG_SYMBOL}.3"
|
||||
COMMAND "${PERL_EXECUTABLE}" "${ARG_WIKIHEADERS_PL_PATH}" "${ARG_SOURCE_DIR}" "${BUILD_WIKIDIR}" "--options=${ARG_OPTION_FILE}" "--manpath=${BUILD_MANDIR}" --copy-to-manpages
|
||||
DEPENDS "${BUILD_WIKIDIR}/${ARG_SYMBOL}.md" "${ARG_WIKIHEADERS_PL_PATH}" "${ARG_OPTION_FILE}"
|
||||
COMMENT "Generating ${ARG_NAME} man pages"
|
||||
)
|
||||
add_custom_target(${ARG_NAME}-docs ALL DEPENDS "${BUILD_MANDIR}/man3/${ARG_SYMBOL}.3")
|
||||
|
||||
install(DIRECTORY "${BUILD_MANDIR}/" DESTINATION "${CMAKE_INSTALL_MANDIR}")
|
||||
set(result TRUE)
|
||||
endif()
|
||||
|
||||
if(ARG_RESULT_VARIABLE)
|
||||
set(${ARG_RESULT_VARIABLE} ${result} PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
106
cmake/sdlplatform.cmake
Normal file
106
cmake/sdlplatform.cmake
Normal file
@ -0,0 +1,106 @@
|
||||
macro(SDL_DetectCMakePlatform)
|
||||
set(SDL_CMAKE_PLATFORM )
|
||||
# Get the platform
|
||||
if(WIN32)
|
||||
set(SDL_CMAKE_PLATFORM Windows)
|
||||
elseif(PSP)
|
||||
set(SDL_CMAKE_PLATFORM psp)
|
||||
elseif(APPLE)
|
||||
if(CMAKE_SYSTEM_NAME MATCHES ".*Darwin.*")
|
||||
set(SDL_CMAKE_PLATFORM Darwin)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES ".*MacOS.*")
|
||||
set(SDL_CMAKE_PLATFORM MacosX)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES ".*tvOS.*")
|
||||
set(SDL_CMAKE_PLATFORM tvOS)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES ".*iOS.*")
|
||||
set(SDL_CMAKE_PLATFORM iOS)
|
||||
endif()
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "Haiku.*")
|
||||
set(SDL_CMAKE_PLATFORM Haiku)
|
||||
elseif(NINTENDO_3DS)
|
||||
set(SDL_CMAKE_PLATFORM n3ds)
|
||||
elseif(PS2)
|
||||
set(SDL_CMAKE_PLATFORM ps2)
|
||||
elseif(VITA)
|
||||
set(SDL_CMAKE_PLATFORM Vita)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES ".*Linux")
|
||||
set(SDL_CMAKE_PLATFORM Linux)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "kFreeBSD.*")
|
||||
set(SDL_CMAKE_PLATFORM FreeBSD)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "kNetBSD.*|NetBSD.*")
|
||||
set(SDL_CMAKE_PLATFORM NetBSD)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "kOpenBSD.*|OpenBSD.*")
|
||||
set(SDL_CMAKE_PLATFORM OpenBSD)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES ".*GNU.*")
|
||||
set(SDL_CMAKE_PLATFORM GNU)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES ".*BSDI.*")
|
||||
set(SDL_CMAKE_PLATFORM BSDi)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "DragonFly.*|FreeBSD")
|
||||
set(SDL_CMAKE_PLATFORM FreeBSD)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "SYSV5.*")
|
||||
set(SDL_CMAKE_PLATFORM SYSV5)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "Solaris.*|SunOS.*")
|
||||
set(SDL_CMAKE_PLATFORM Solaris)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "HP-UX.*")
|
||||
set(SDL_CMAKE_PLATFORM HPUX)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "AIX.*")
|
||||
set(SDL_CMAKE_PLATFORM AIX)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "Minix.*")
|
||||
set(SDL_CMAKE_PLATFORM Minix)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "Android.*")
|
||||
set(SDL_CMAKE_PLATFORM Android)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "Emscripten.*")
|
||||
set(SDL_CMAKE_PLATFORM Emscripten)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "QNX.*")
|
||||
set(SDL_CMAKE_PLATFORM QNX)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "BeOS.*")
|
||||
message(FATAL_ERROR "BeOS support has been removed as of SDL 2.0.2.")
|
||||
endif()
|
||||
|
||||
if(SDL_CMAKE_PLATFORM)
|
||||
string(TOUPPER "${SDL_CMAKE_PLATFORM}" _upper_platform)
|
||||
set(${_upper_platform} TRUE)
|
||||
else()
|
||||
set(SDL_CMAKE_PLATFORM} "unknown")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
function(SDL_DetectCPUArchitecture)
|
||||
set(sdl_cpu_names)
|
||||
if(APPLE AND CMAKE_OSX_ARCHITECTURES)
|
||||
foreach(osx_arch ${CMAKE_OSX_ARCHITECTURES})
|
||||
if(osx_arch STREQUAL "x86_64")
|
||||
list(APPEND sdl_cpu_names "x64")
|
||||
elseif(osx_arch STREQUAL "arm64")
|
||||
list(APPEND sdl_cpu_names "arm64")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
set(sdl_known_archs x64 x86 arm64 arm32 emscripten powerpc64 powerpc32 loongarch64)
|
||||
if(NOT sdl_cpu_names)
|
||||
set(found FALSE)
|
||||
foreach(sdl_known_arch ${sdl_known_archs})
|
||||
if(NOT found)
|
||||
string(TOUPPER "${sdl_known_arch}" sdl_known_arch_upper)
|
||||
set(var_name "SDL_CPU_${sdl_known_arch_upper}")
|
||||
check_cpu_architecture(${sdl_known_arch} ${var_name})
|
||||
if(${var_name})
|
||||
list(APPEND sdl_cpu_names ${sdl_known_arch})
|
||||
set(found TRUE)
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
foreach(sdl_known_arch ${sdl_known_archs})
|
||||
string(TOUPPER "${sdl_known_arch}" sdl_known_arch_upper)
|
||||
set(var_name "SDL_CPU_${sdl_known_arch_upper}")
|
||||
if(sdl_cpu_names MATCHES "(^|;)${sdl_known_arch}($|;)") # FIXME: use if(IN_LIST)
|
||||
set(${var_name} 1 PARENT_SCOPE)
|
||||
else()
|
||||
set(${var_name} 0 PARENT_SCOPE)
|
||||
endif()
|
||||
endforeach()
|
||||
set(SDL_CPU_NAMES ${sdl_cpu_names} PARENT_SCOPE)
|
||||
endfunction()
|
361
cmake/sdltargets.cmake
Normal file
361
cmake/sdltargets.cmake
Normal file
@ -0,0 +1,361 @@
|
||||
add_library(SDL3-collector INTERFACE)
|
||||
add_library(SDL3_test-collector INTERFACE)
|
||||
|
||||
# Use sdl_glob_sources to add glob sources to SDL3-shared, to SDL3-static, or to both.
|
||||
function(sdl_glob_sources)
|
||||
cmake_parse_arguments(ARGS "" "" "SHARED;STATIC" ${ARGN})
|
||||
file(GLOB shared_sources ${ARGS_SHARED})
|
||||
file(GLOB static_sources ${ARGS_STATIC})
|
||||
file(GLOB both_sources ${ARGS_UNPARSED_ARGUMENTS})
|
||||
if(TARGET SDL3-shared)
|
||||
target_sources(SDL3-shared PRIVATE ${shared_sources} ${both_sources})
|
||||
endif()
|
||||
if(TARGET SDL3-static)
|
||||
target_sources(SDL3-static PRIVATE ${static_sources} ${both_sources})
|
||||
endif()
|
||||
set_property(TARGET SDL3-collector APPEND PROPERTY INTERFACE_SOURCES ${shared_sources} ${static_sources} ${both_sources})
|
||||
endfunction()
|
||||
|
||||
# Use sdl_sources to add sources to SDL3-shared, to SDL3-static, or to both.
|
||||
function(sdl_sources)
|
||||
cmake_parse_arguments(ARGS "" "" "SHARED;STATIC" ${ARGN})
|
||||
if(TARGET SDL3-shared)
|
||||
target_sources(SDL3-shared PRIVATE ${ARGS_SHARED} ${ARGS_UNPARSED_ARGUMENTS})
|
||||
endif()
|
||||
if(TARGET SDL3-static)
|
||||
target_sources(SDL3-static PRIVATE ${ARGS_STATIC} ${ARGS_UNPARSED_ARGUMENTS})
|
||||
endif()
|
||||
set_property(TARGET SDL3-collector APPEND PROPERTY INTERFACE_SOURCES ${ARGS_SHARED} ${ARGS_STATIC} ${ARGS_UNPARSED_ARGUMENTS})
|
||||
endfunction()
|
||||
|
||||
# Use sdl_generic_link_dependency to describe a private depency of SDL3. All options are optional.
|
||||
# Users should use sdl_link_dependency and sdl_test_link_dependency instead
|
||||
# - SHARED_TARGETS: shared targets to add this dependency to
|
||||
# - STATIC_TARGETS: static targets to add this dependency to
|
||||
# - COLLECTOR: target that stores information, for pc and Config.cmake generation.
|
||||
# - INCLUDES: the include directories of the dependency
|
||||
# - PKG_CONFIG_PREFIX: name of the prefix, when using the functions of FindPkgConfig
|
||||
# - PKG_CONFIG_SPECS: pkg-config spec, used as argument for the functions of FindPkgConfig
|
||||
# - PKG_CONFIG_LIBS: libs that will only end up in the Libs.private of sdl3.pc
|
||||
# - CMAKE_MODULE: CMake module name of the dependency, used as argument of find_package
|
||||
# - LIBS: list of libraries to link to
|
||||
# - LINK_OPTIONS: list of link options
|
||||
function(sdl_generic_link_dependency ID)
|
||||
cmake_parse_arguments(ARGS "" "COLLECTOR" "SHARED_TARGETS;STATIC_TARGETS;INCLUDES;PKG_CONFIG_LIBS;PKG_CONFIG_PREFIX;PKG_CONFIG_SPECS;CMAKE_MODULE;LIBS;LINK_OPTIONS" ${ARGN})
|
||||
foreach(target IN LISTS ARGS_SHARED_TARGETS)
|
||||
if(TARGET ${target})
|
||||
target_include_directories(${target} SYSTEM PRIVATE ${ARGS_INCLUDES})
|
||||
target_link_libraries(${target} PRIVATE ${ARGS_LIBS})
|
||||
target_link_options(${target} PRIVATE ${ARGS_LINK_OPTIONS})
|
||||
endif()
|
||||
endforeach()
|
||||
foreach(target IN LISTS ARGS_STATIC_TARGETS)
|
||||
if(TARGET ${target})
|
||||
target_include_directories(${target} SYSTEM PRIVATE ${ARGS_INCLUDES})
|
||||
target_link_libraries(${target} PRIVATE ${ARGS_LIBS})
|
||||
target_link_options(${target} INTERFACE ${ARGS_LINK_OPTIONS})
|
||||
endif()
|
||||
endforeach()
|
||||
get_property(ids TARGET ${ARGS_COLLECTOR} PROPERTY INTERFACE_SDL_DEP_IDS)
|
||||
if(NOT ID IN_LIST ids)
|
||||
set_property(TARGET ${ARGS_COLLECTOR} APPEND PROPERTY INTERFACE_SDL_DEP_IDS ${ID})
|
||||
endif()
|
||||
set_property(TARGET ${ARGS_COLLECTOR} APPEND PROPERTY INTERFACE_SDL_DEP_${ID}_PKG_CONFIG_PREFIX ${ARGS_PKG_CONFIG_PREFIX})
|
||||
set_property(TARGET ${ARGS_COLLECTOR} APPEND PROPERTY INTERFACE_SDL_DEP_${ID}_PKG_CONFIG_SPECS ${ARGS_PKG_CONFIG_SPECS})
|
||||
set_property(TARGET ${ARGS_COLLECTOR} APPEND PROPERTY INTERFACE_SDL_DEP_${ID}_PKG_CONFIG_LIBS ${ARGS_PKG_CONFIG_LIBS})
|
||||
set_property(TARGET ${ARGS_COLLECTOR} APPEND PROPERTY INTERFACE_SDL_DEP_${ID}_LIBS ${ARGS_LIBS})
|
||||
set_property(TARGET ${ARGS_COLLECTOR} APPEND PROPERTY INTERFACE_SDL_DEP_${ID}_LINK_OPTIONS ${ARGS_LINK_OPTIONS})
|
||||
set_property(TARGET ${ARGS_COLLECTOR} APPEND PROPERTY INTERFACE_SDL_DEP_${ID}_CMAKE_MODULE ${ARGS_CMAKE_MODULE})
|
||||
set_property(TARGET ${ARGS_COLLECTOR} APPEND PROPERTY INTERFACE_SDL_DEP_${ID}_INCLUDES ${ARGS_INCLUDES})
|
||||
endfunction()
|
||||
|
||||
function(sdl_link_dependency )
|
||||
sdl_generic_link_dependency(${ARGN} COLLECTOR SDL3-collector SHARED_TARGETS SDL3-shared STATIC_TARGETS SDL3-static)
|
||||
endfunction()
|
||||
|
||||
function(sdl_test_link_dependency )
|
||||
sdl_generic_link_dependency(${ARGN} COLLECTOR SDL3_test-collector STATIC_TARGETS SDL3_test)
|
||||
endfunction()
|
||||
|
||||
macro(_get_ARGS_visibility)
|
||||
set(_conflict FALSE)
|
||||
set(visibility)
|
||||
if(ARGS_PRIVATE)
|
||||
set(visibility PRIVATE)
|
||||
elseif(ARGS_PUBLIC)
|
||||
if(visibility)
|
||||
set(_conflict TRUE)
|
||||
endif()
|
||||
set(visibility PUBLIC)
|
||||
elseif(ARGS_INTERFACE)
|
||||
if(visibility)
|
||||
set(_conflict TRUE)
|
||||
endif()
|
||||
set(visibility INTERFACE)
|
||||
endif()
|
||||
if(_conflict OR NOT visibility)
|
||||
message(FATAL_ERROR "PRIVATE/PUBLIC/INTERFACE must be used exactly once")
|
||||
endif()
|
||||
unset(_conflict)
|
||||
endmacro()
|
||||
|
||||
# Use sdl_link_dependency to add compile definitions to the SDL3 libraries.
|
||||
function(sdl_compile_definitions)
|
||||
cmake_parse_arguments(ARGS "PRIVATE;PUBLIC;INTERFACE;NO_EXPORT" "" "" ${ARGN})
|
||||
_get_ARGS_visibility()
|
||||
if(TARGET SDL3-shared)
|
||||
target_compile_definitions(SDL3-shared ${visibility} ${ARGS_UNPARSED_ARGUMENTS})
|
||||
endif()
|
||||
if(TARGET SDL3-static)
|
||||
target_compile_definitions(SDL3-static ${visibility} ${ARGS_UNPARSED_ARGUMENTS})
|
||||
endif()
|
||||
if(NOT ARGS_NO_EXPORT AND (ARGS_PUBLIC OR ARGS_INTERFACE))
|
||||
set_property(TARGET SDL3-collector APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS "${ARGS_UNPARSED_ARGUMENTS}")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# Use sdl_link_dependency to add compile options to the SDL3 libraries.
|
||||
function(sdl_compile_options)
|
||||
cmake_parse_arguments(ARGS "PRIVATE;PUBLIC;INTERFACE;NO_EXPORT" "" "" ${ARGN})
|
||||
_get_ARGS_visibility()
|
||||
set(escaped_opts ${ARGS_UNPARSED_ARGUMENTS})
|
||||
if(ARGS_NO_EXPORT)
|
||||
set(escaped_opts "$<BUILD_INTERFACE:${ARGS_UNPARSED_ARGUMENTS}>")
|
||||
endif()
|
||||
if(TARGET SDL3-shared)
|
||||
target_compile_options(SDL3-shared ${visibility} ${escaped_opts})
|
||||
endif()
|
||||
if(TARGET SDL3-static)
|
||||
target_compile_options(SDL3-static ${visibility} ${escaped_opts})
|
||||
endif()
|
||||
if(NOT ARGS_NO_EXPORT AND (ARGS_PUBLIC OR ARGS_INTERFACE))
|
||||
set_property(TARGET SDL3-collector APPEND PROPERTY INTERFACE_COMPILE_COMPILE_OPTIONS "${ARGS_UNPARSED_ARGUMENTS}")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# Use sdl_link_dependency to add incude directories to the SDL3 libraries.
|
||||
function(sdl_include_directories)
|
||||
cmake_parse_arguments(ARGS "SYSTEM;BEFORE;AFTER;PRIVATE;PUBLIC;INTERFACE;NO_EXPORT" "" "" ${ARGN})
|
||||
set(system "")
|
||||
if(ARGS_SYSTEM)
|
||||
set(system "SYSTEM")
|
||||
endif()
|
||||
set(before_after )
|
||||
if(ARGS_AFTER)
|
||||
set(before_after "AFTER")
|
||||
endif()
|
||||
if(ARGS_BEFORE)
|
||||
if(before_after)
|
||||
message(FATAL_ERROR "before and after are exclusive options")
|
||||
endif()
|
||||
set(before_after "BEFORE")
|
||||
endif()
|
||||
_get_ARGS_visibility()
|
||||
if(TARGET SDL3-shared)
|
||||
target_include_directories(SDL3-shared ${system} ${before_after} ${visibility} ${ARGS_UNPARSED_ARGUMENTS})
|
||||
endif()
|
||||
if(TARGET SDL3-static)
|
||||
target_include_directories(SDL3-static ${system} ${before_after} ${visibility} ${ARGS_UNPARSED_ARGUMENTS})
|
||||
endif()
|
||||
if(NOT NO_EXPORT AND (ARGS_PUBLIC OR ARGS_INTERFACE))
|
||||
set_property(TARGET SDL3-collector APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${ARGS_UNPARSED_ARGUMENTS}")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# Use sdl_link_dependency to add link directories to the SDL3 libraries.
|
||||
function(sdl_link_directories)
|
||||
if(TARGET SDL3-shared)
|
||||
target_link_directories(SDL3-shared PRIVATE ${ARGN})
|
||||
endif()
|
||||
if(TARGET SDL3-static)
|
||||
target_link_directories(SDL3-static INTERFACE ${ARGN})
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# Use sdl_pc_link_options to add a link option, only visible in sdl3.pc
|
||||
function(sdl_pc_link_options)
|
||||
set_property(TARGET SDL3-collector APPEND PROPERTY INTERFACE_SDL_PC_LINK_OPTIONS "${ARGN}")
|
||||
endfunction()
|
||||
|
||||
# Use sdl_pc_link_options to add a link option only to SDL3-shared
|
||||
function(sdl_shared_link_options)
|
||||
if(TARGET SDL3-shared)
|
||||
target_link_options(SDL3-shared PRIVATE ${ARGN})
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# Return minimum list of custom SDL CMake modules, used for finding dependencies of SDL.
|
||||
function(sdl_cmake_config_required_modules OUTPUT)
|
||||
set(cmake_modules)
|
||||
foreach(collector SDL3-collector SDL3_test-collector)
|
||||
get_property(ids TARGET ${collector} PROPERTY INTERFACE_SDL_DEP_IDS)
|
||||
foreach(ID IN LISTS ids)
|
||||
get_property(CMAKE_MODULE TARGET ${collector} PROPERTY INTERFACE_SDL_DEP_${ID}_CMAKE_MODULE)
|
||||
if(CMAKE_MODULE)
|
||||
if(EXISTS "${SDL3_SOURCE_DIR}/cmake/Find${CMAKE_MODULE}.cmake")
|
||||
list(APPEND cmake_modules "${SDL3_SOURCE_DIR}/cmake/Find${CMAKE_MODULE}.cmake")
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
if(cmake_modules)
|
||||
list(APPEND cmake_modules "${SDL3_SOURCE_DIR}/cmake/PkgConfigHelper.cmake")
|
||||
endif()
|
||||
endforeach()
|
||||
set(${OUTPUT} "${cmake_modules}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# Generate string for SDL3Config.cmake, finding all pkg-config dependencies of SDL3.
|
||||
function(sdl_cmake_config_find_pkg_config_commands OUTPUT)
|
||||
cmake_parse_arguments(ARGS "" "COLLECTOR;CONFIG_COMPONENT_FOUND_NAME" "" ${ARGN})
|
||||
if(NOT ARGS_COLLECTOR OR NOT ARGS_CONFIG_COMPONENT_FOUND_NAME)
|
||||
message(FATAL_ERROR "COLLECTOR AND CONFIG_COMPONENT_FOUND_NAME are required arguments")
|
||||
endif()
|
||||
get_property(ids TARGET ${ARGS_COLLECTOR} PROPERTY INTERFACE_SDL_DEP_IDS)
|
||||
|
||||
set(static_pkgconfig_deps_checks)
|
||||
set(static_module_deps_checks)
|
||||
set(cmake_modules_seen)
|
||||
|
||||
foreach(ID IN LISTS ids)
|
||||
get_property(PKG_CONFIG_PREFIX TARGET ${ARGS_COLLECTOR} PROPERTY INTERFACE_SDL_DEP_${ID}_PKG_CONFIG_PREFIX)
|
||||
get_property(PKG_CONFIG_SPECS TARGET ${ARGS_COLLECTOR} PROPERTY INTERFACE_SDL_DEP_${ID}_PKG_CONFIG_SPECS)
|
||||
get_property(CMAKE_MODULE TARGET ${ARGS_COLLECTOR} PROPERTY INTERFACE_SDL_DEP_${ID}_CMAKE_MODULE)
|
||||
if(CMAKE_MODULE AND NOT CMAKE_MODULE IN_LIST cmake_modules_seen)
|
||||
list(APPEND static_module_deps_checks
|
||||
"find_package(${CMAKE_MODULE})"
|
||||
"if(NOT ${CMAKE_MODULE}_FOUND)"
|
||||
" set(${ARGS_CONFIG_COMPONENT_FOUND_NAME} OFF)"
|
||||
"endif()"
|
||||
)
|
||||
list(APPEND cmake_modules_seen ${CMAKE_MODULE})
|
||||
endif()
|
||||
if(PKG_CONFIG_PREFIX AND PKG_CONFIG_SPECS)
|
||||
string(JOIN " " pkg_config_specs_str ${PKG_CONFIG_SPECS})
|
||||
list(APPEND static_pkgconfig_deps_checks
|
||||
" pkg_check_modules(${PKG_CONFIG_PREFIX} QUIET IMPORTED_TARGET ${pkg_config_specs_str})"
|
||||
" if(NOT ${PKG_CONFIG_PREFIX}_FOUND)"
|
||||
" set(${ARGS_CONFIG_COMPONENT_FOUND_NAME} OFF)"
|
||||
" endif()"
|
||||
)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
set(prefix " ")
|
||||
|
||||
set(static_module_deps_texts)
|
||||
if(static_module_deps_checks)
|
||||
set(static_module_deps_texts
|
||||
[[set(_original_module_path "${CMAKE_MODULE_PATH}")]]
|
||||
[[list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")]]
|
||||
${static_module_deps_checks}
|
||||
[[set(CMAKE_MODULE_PATH "${_original_module_path}")]]
|
||||
[[unset(_original_module_path)]]
|
||||
)
|
||||
endif()
|
||||
|
||||
set(static_pkgconfig_deps_texts)
|
||||
if(static_pkgconfig_deps_checks)
|
||||
string(JOIN "\n${prefix}" static_deps_texts_str ${static_deps_texts})
|
||||
list(APPEND static_pkgconfig_deps_texts
|
||||
"find_package(PkgConfig)"
|
||||
"if(PkgConfig_FOUND)"
|
||||
${static_pkgconfig_deps_checks}
|
||||
"else()"
|
||||
" set(${ARGS_CONFIG_COMPONENT_FOUND_NAME} OFF)"
|
||||
"endif()"
|
||||
)
|
||||
endif()
|
||||
|
||||
set(text)
|
||||
string(JOIN "\n${prefix}" text ${static_module_deps_texts} ${static_pkgconfig_deps_texts})
|
||||
if(text)
|
||||
set(text "${prefix}${text}")
|
||||
endif()
|
||||
|
||||
set(${OUTPUT} "${text}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# Create sdl3.pc.
|
||||
function(configure_sdl3_pc)
|
||||
# Clean up variables for sdl3.pc
|
||||
if(TARGET SDL3-shared)
|
||||
set(SDL_PC_SECTION_LIBS_PRIVATE "\nLibs.private:")
|
||||
else()
|
||||
set(SDL_PC_SECTION_LIBS_PRIVATE "")
|
||||
endif()
|
||||
|
||||
get_property(ids TARGET SDL3-collector PROPERTY SDL3-collector PROPERTY INTERFACE_SDL_DEP_IDS)
|
||||
|
||||
set(private_requires)
|
||||
set(private_libs)
|
||||
set(private_ldflags)
|
||||
|
||||
foreach(ID IN LISTS ids)
|
||||
get_property(CMAKE_MODULE TARGET SDL3-collector PROPERTY INTERFACE_SDL_DEP_${ID}_CMAKE_MODULE)
|
||||
get_property(PKG_CONFIG_SPECS TARGET SDL3-collector PROPERTY INTERFACE_SDL_DEP_${ID}_PKG_CONFIG_SPECS)
|
||||
get_property(PKG_CONFIG_LIBS TARGET SDL3-collector PROPERTY INTERFACE_SDL_DEP_${ID}_PKG_CONFIG_LIBS)
|
||||
get_property(LIBS TARGET SDL3-collector PROPERTY INTERFACE_SDL_DEP_${ID}_LIBS)
|
||||
get_property(LINK_OPTIONS TARGET SDL3-collector PROPERTY INTERFACE_SDL_DEP_${ID}_LINK_OPTIONS)
|
||||
|
||||
list(APPEND private_requires ${PKG_CONFIG_SPECS})
|
||||
list(APPEND private_libs ${PKG_CONFIG_LIBS})
|
||||
if(NOT PKG_CONFIG_SPECS AND NOT CMAKE_MODULE)
|
||||
list(APPEND private_libs ${LIBS})
|
||||
list(APPEND private_ldflags ${LINK_OPTIONS})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
list(TRANSFORM private_libs PREPEND "-l")
|
||||
set(SDL_PC_STATIC_LIBS ${private_ldflags} ${private_libs})
|
||||
list(REMOVE_DUPLICATES SDL_PC_STATIC_LIBS)
|
||||
string(JOIN " " SDL_PC_STATIC_LIBS ${SDL_PC_STATIC_LIBS})
|
||||
|
||||
string(JOIN " " SDL_PC_PRIVATE_REQUIRES ${private_requires})
|
||||
string(REGEX REPLACE "(>=|>|=|<|<=)" [[ \1 ]] SDL_PC_PRIVATE_REQUIRES "${SDL_PC_PRIVATE_REQUIRES}")
|
||||
|
||||
get_property(interface_defines TARGET SDL3-collector PROPERTY INTERFACE_COMPILE_DEFINITIONS)
|
||||
list(TRANSFORM interface_defines PREPEND "-D")
|
||||
get_property(interface_includes TARGET SDL3-collector PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
|
||||
list(TRANSFORM interface_includes PREPEND "-I")
|
||||
set(SDL_PC_CFLAGS ${interface_defines} ${interface_includes})
|
||||
string(JOIN " " SDL_PC_CFLAGS ${SDL_PC_CFLAGS})
|
||||
|
||||
get_property(SDL_PC_LIBS TARGET SDL3-collector PROPERTY INTERFACE_SDL_PC_LINK_OPTIONS)
|
||||
string(JOIN " " SDL_PC_LIBS ${SDL_PC_LIBS})
|
||||
|
||||
string(REGEX REPLACE "-lSDL3( |$)" "-l${sdl_static_libname} " SDL_PC_STATIC_LIBS "${SDL_PC_STATIC_LIBS}")
|
||||
if(NOT SDL_SHARED)
|
||||
string(REGEX REPLACE "-lSDL3( |$)" "-l${sdl_static_libname} " SDL_PC_LIBS "${SDL_PC_LIBS}")
|
||||
endif()
|
||||
if(TARGET SDL3-shared AND TARGET SDL3-static AND NOT sdl_static_libname STREQUAL "SDL3")
|
||||
message(STATUS "\"pkg-config --static --libs sdl3\" will return invalid information")
|
||||
endif()
|
||||
|
||||
# Calculate prefix relative to location of sdl3.pc
|
||||
file(RELATIVE_PATH SDL_PATH_PREFIX_RELATIVE_TO_PKGCONFIG "${CMAKE_INSTALL_PREFIX}/${SDL_PKGCONFIG_INSTALLDIR}" "${CMAKE_INSTALL_PREFIX}")
|
||||
string(REGEX REPLACE "[/]+$" "" SDL_PATH_PREFIX_RELATIVE_TO_PKGCONFIG "${SDL_PATH_PREFIX_RELATIVE_TO_PKGCONFIG}")
|
||||
set(SDL_PKGCONFIG_PREFIX "\${pcfiledir}/${SDL_PATH_PREFIX_RELATIVE_TO_PKGCONFIG}")
|
||||
|
||||
configure_file("${SDL3_SOURCE_DIR}/cmake/sdl3.pc.in" "${SDL3_BINARY_DIR}/sdl3.pc" @ONLY)
|
||||
endfunction()
|
||||
|
||||
# Write list of dependencies to output. Only visible when configuring with --log-level=DEBUG.
|
||||
function(debug_show_sdl_deps)
|
||||
get_property(ids TARGET SDL3-collector PROPERTY SDL3-collector PROPERTY INTERFACE_SDL_DEP_IDS)
|
||||
|
||||
foreach(ID IN LISTS ids)
|
||||
message(DEBUG "- id: ${ID}")
|
||||
get_property(INCLUDES TARGET SDL3-collector PROPERTY INTERFACE_SDL_DEP_${ID}_INCLUDES)
|
||||
get_property(CMAKE_MODULE TARGET SDL3-collector PROPERTY INTERFACE_SDL_DEP_${ID}_CMAKE_MODULE)
|
||||
get_property(PKG_CONFIG_PREFIX TARGET SDL3-collector PROPERTY INTERFACE_SDL_DEP_${ID}_PKG_CONFIG_PREFIX)
|
||||
get_property(PKG_CONFIG_SPECS TARGET SDL3-collector PROPERTY INTERFACE_SDL_DEP_${ID}_PKG_CONFIG_SPECS)
|
||||
get_property(LIBS TARGET SDL3-collector PROPERTY INTERFACE_SDL_DEP_${ID}_LIBS)
|
||||
get_property(LINK_OPTIONS TARGET SDL3-collector PROPERTY INTERFACE_SDL_DEP_${ID}_LINK_OPTIONS)
|
||||
message(DEBUG " INCLUDES: ${INCLUDES}")
|
||||
message(DEBUG " CMAKE_MODULE: ${CMAKE_MODULE}")
|
||||
message(DEBUG " PKG_CONFIG_PREFIX: ${PKG_CONFIG_PREFIX}")
|
||||
message(DEBUG " PKG_CONFIG_SPECS: ${PKG_CONFIG_SPECS}")
|
||||
message(DEBUG " LIBS: ${LIBS}")
|
||||
message(DEBUG " LINK_OPTIONS: ${LINK_OPTIONS}")
|
||||
endforeach()
|
||||
endfunction()
|
91
cmake/test/CMakeLists.txt
Normal file
91
cmake/test/CMakeLists.txt
Normal file
@ -0,0 +1,91 @@
|
||||
# This cmake build script is meant for verifying the various CMake configuration script.
|
||||
|
||||
cmake_minimum_required(VERSION 3.12)
|
||||
project(sdl_test LANGUAGES C)
|
||||
|
||||
include(GenerateExportHeader)
|
||||
|
||||
if(ANDROID)
|
||||
macro(add_executable NAME)
|
||||
set(args ${ARGN})
|
||||
list(REMOVE_ITEM args WIN32)
|
||||
add_library(${NAME} SHARED ${args})
|
||||
unset(args)
|
||||
endmacro()
|
||||
endif()
|
||||
|
||||
cmake_policy(SET CMP0074 NEW)
|
||||
|
||||
# Override CMAKE_FIND_ROOT_PATH_MODE to allow search for SDL3 outside of sysroot
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE NEVER)
|
||||
|
||||
include(FeatureSummary)
|
||||
|
||||
option(TEST_SHARED "Test linking to shared SDL3 library" ON)
|
||||
add_feature_info("TEST_SHARED" TEST_SHARED "Test linking with shared library")
|
||||
|
||||
option(TEST_STATIC "Test linking to static SDL3 library" ON)
|
||||
add_feature_info("TEST_STATIC" TEST_STATIC "Test linking with static library")
|
||||
|
||||
option(TEST_TEST "Test linking to SDL3_test library" ON)
|
||||
add_feature_info("TEST_TEST" TEST_STATIC "Test linking to SDL test library")
|
||||
|
||||
find_package(SDL3 REQUIRED CONFIG COMPONENTS Headers)
|
||||
add_library(headers_test OBJECT inc_sdl_slash.c inc_sdl_noslash.c)
|
||||
target_link_libraries(headers_test PRIVATE SDL3::Headers)
|
||||
|
||||
if(TEST_SHARED)
|
||||
find_package(SDL3 REQUIRED CONFIG COMPONENTS SDL3-shared)
|
||||
add_executable(gui-shared WIN32 main_gui.c)
|
||||
target_link_libraries(gui-shared PRIVATE SDL3::SDL3-shared)
|
||||
if(WIN32)
|
||||
add_custom_command(TARGET gui-shared POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:SDL3::SDL3-shared>" "$<TARGET_FILE_DIR:gui-shared>"
|
||||
)
|
||||
endif()
|
||||
|
||||
add_library(sharedlib-shared SHARED main_lib.c)
|
||||
target_link_libraries(sharedlib-shared PRIVATE SDL3::SDL3-shared)
|
||||
generate_export_header(sharedlib-shared EXPORT_MACRO_NAME MYLIBRARY_EXPORT)
|
||||
target_compile_definitions(sharedlib-shared PRIVATE "EXPORT_HEADER=\"${CMAKE_CURRENT_BINARY_DIR}/sharedlib-shared_export.h\"")
|
||||
set_target_properties(sharedlib-shared PROPERTIES C_VISIBILITY_PRESET "hidden")
|
||||
|
||||
add_executable(cli-shared main_cli.c)
|
||||
target_link_libraries(cli-shared PRIVATE SDL3::SDL3-shared)
|
||||
if(WIN32)
|
||||
add_custom_command(TARGET cli-shared POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:SDL3::SDL3-shared>" "$<TARGET_FILE_DIR:cli-shared>"
|
||||
)
|
||||
endif()
|
||||
|
||||
if(TEST_TEST)
|
||||
add_executable(sdltest-shared sdltest.c)
|
||||
target_link_libraries(sdltest-shared PRIVATE SDL3::SDL3_test SDL3::SDL3-shared)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(TEST_STATIC)
|
||||
find_package(SDL3 REQUIRED CONFIG COMPONENTS SDL3-static)
|
||||
add_executable(gui-static WIN32 main_gui.c)
|
||||
target_link_libraries(gui-static PRIVATE SDL3::SDL3-static)
|
||||
|
||||
option(SDL_STATIC_PIC "SDL static library has been built with PIC")
|
||||
if(SDL_STATIC_PIC OR WIN32)
|
||||
add_library(sharedlib-static SHARED main_lib.c)
|
||||
target_link_libraries(sharedlib-static PRIVATE SDL3::SDL3-static)
|
||||
generate_export_header(sharedlib-static EXPORT_MACRO_NAME MYLIBRARY_EXPORT)
|
||||
target_compile_definitions(sharedlib-static PRIVATE "EXPORT_HEADER=\"${CMAKE_CURRENT_BINARY_DIR}/sharedlib-static_export.h\"")
|
||||
set_target_properties(sharedlib-static PROPERTIES C_VISIBILITY_PRESET "hidden")
|
||||
endif()
|
||||
|
||||
if(TEST_TEST)
|
||||
add_executable(sdltest-static sdltest.c)
|
||||
target_link_libraries(sdltest-static PRIVATE SDL3::SDL3_test SDL3::SDL3-static)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
find_package(SDL3 REQUIRED CONFIG COMPONENTS SDL3)
|
||||
add_executable(gui-whatever WIN32 main_gui.c)
|
||||
target_link_libraries(gui-whatever PRIVATE SDL3::SDL3)
|
||||
|
||||
feature_summary(WHAT ALL)
|
8
cmake/test/inc_sdl_noslash.c
Normal file
8
cmake/test/inc_sdl_noslash.c
Normal file
@ -0,0 +1,8 @@
|
||||
#include "SDL.h"
|
||||
#include "SDL_main.h"
|
||||
|
||||
void inc_sdl_noslash(void) {
|
||||
SDL_SetMainReady();
|
||||
SDL_Init(SDL_INIT_EVERYTHING);
|
||||
SDL_Quit();
|
||||
}
|
8
cmake/test/inc_sdl_slash.c
Normal file
8
cmake/test/inc_sdl_slash.c
Normal file
@ -0,0 +1,8 @@
|
||||
#include "SDL3/SDL.h"
|
||||
#include "SDL3/SDL_main.h"
|
||||
|
||||
void inc_sdl_slash(void) {
|
||||
SDL_SetMainReady();
|
||||
SDL_Init(SDL_INIT_EVERYTHING);
|
||||
SDL_Quit();
|
||||
}
|
15
cmake/test/main_cli.c
Normal file
15
cmake/test/main_cli.c
Normal file
@ -0,0 +1,15 @@
|
||||
#define SDL_MAIN_HANDLED
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_main.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SDL_SetMainReady();
|
||||
if (SDL_Init(0) < 0) {
|
||||
SDL_Log("Could not initialize SDL: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
SDL_Delay(100);
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
24
cmake/test/main_gui.c
Normal file
24
cmake/test/main_gui.c
Normal file
@ -0,0 +1,24 @@
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_main.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Window *window = NULL;
|
||||
SDL_Surface *screenSurface = NULL;
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
SDL_Log("Could not initialize SDL: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
window = SDL_CreateWindow("Hello SDL", 640, 480, 0);
|
||||
if (window == NULL) {
|
||||
SDL_Log("could not create window: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
screenSurface = SDL_GetWindowSurface(window);
|
||||
SDL_FillSurfaceRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0xff, 0xff, 0xff));
|
||||
SDL_UpdateWindowSurface(window);
|
||||
SDL_Delay(100);
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
34
cmake/test/main_lib.c
Normal file
34
cmake/test/main_lib.c
Normal file
@ -0,0 +1,34 @@
|
||||
#include <SDL3/SDL.h>
|
||||
#define SDL_MAIN_HANDLED /* don't drag in header-only SDL_main implementation */
|
||||
#include <SDL3/SDL_main.h>
|
||||
|
||||
#include EXPORT_HEADER
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
int MYLIBRARY_EXPORT mylibrary_init(void);
|
||||
void MYLIBRARY_EXPORT mylibrary_quit(void);
|
||||
int MYLIBRARY_EXPORT mylibrary_work(void);
|
||||
|
||||
int mylibrary_init(void) {
|
||||
SDL_SetMainReady();
|
||||
if (SDL_Init(0) < 0) {
|
||||
SDL_Log("Could not initialize SDL: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mylibrary_quit(void) {
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
int mylibrary_work(void) {
|
||||
SDL_Delay(100);
|
||||
return 0;
|
||||
}
|
9
cmake/test/sdltest.c
Normal file
9
cmake/test/sdltest.c
Normal file
@ -0,0 +1,9 @@
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_test.h>
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
SDLTest_CommonState state;
|
||||
SDLTest_CommonDefaultArgs(&state, argc, argv);
|
||||
return 0;
|
||||
}
|
51
cmake/test/test_pkgconfig.sh
Executable file
51
cmake/test/test_pkgconfig.sh
Executable file
@ -0,0 +1,51 @@
|
||||
#!/bin/sh
|
||||
|
||||
if test "x$CC" = "x"; then
|
||||
CC=cc
|
||||
fi
|
||||
|
||||
machine="$($CC -dumpmachine)"
|
||||
case "$machine" in
|
||||
*mingw* )
|
||||
EXEPREFIX=""
|
||||
EXESUFFIX=".exe"
|
||||
;;
|
||||
*android* )
|
||||
EXEPREFIX="lib"
|
||||
EXESUFFIX=".so"
|
||||
LDFLAGS="$EXTRA_LDFLAGS -shared"
|
||||
;;
|
||||
* )
|
||||
EXEPREFIX=""
|
||||
EXESUFFIX=""
|
||||
;;
|
||||
esac
|
||||
|
||||
set -e
|
||||
|
||||
# Get the canonical path of the folder containing this script
|
||||
testdir=$(cd -P -- "$(dirname -- "$0")" && printf '%s\n' "$(pwd -P)")
|
||||
SDL_CFLAGS="$( pkg-config sdl3 --cflags )"
|
||||
SDL_LDFLAGS="$( pkg-config sdl3 --libs )"
|
||||
SDL_STATIC_LDFLAGS="$( pkg-config sdl3 --libs --static )"
|
||||
|
||||
compile_cmd="$CC -c "$testdir/main_gui.c" -o main_gui_pkgconfig.c.o $SDL_CFLAGS $CFLAGS"
|
||||
link_cmd="$CC main_gui_pkgconfig.c.o -o ${EXEPREFIX}main_gui_pkgconfig${EXESUFFIX} $SDL_LDFLAGS $LDFLAGS"
|
||||
static_link_cmd="$CC main_gui_pkgconfig.c.o -o ${EXEPREFIX}main_gui_pkgconfig_static${EXESUFFIX} $SDL_STATIC_LDFLAGS $LDFLAGS"
|
||||
|
||||
echo "-- CC: $CC"
|
||||
echo "-- CFLAGS: $CFLAGS"
|
||||
echo "-- LDFLASG: $LDFLAGS"
|
||||
echo "-- SDL_CFLAGS: $SDL_CFLAGS"
|
||||
echo "-- SDL_LDFLAGS: $SDL_LDFLAGS"
|
||||
echo "-- SDL_STATIC_LDFLAGS: $SDL_STATIC_LDFLAGS"
|
||||
|
||||
echo "-- COMPILE: $compile_cmd"
|
||||
echo "-- LINK: $link_cmd"
|
||||
echo "-- STATIC_LINK: $static_link_cmd"
|
||||
|
||||
set -x
|
||||
|
||||
$compile_cmd
|
||||
$link_cmd
|
||||
$static_link_cmd
|
37
cmake/xxd.py
Executable file
37
cmake/xxd.py
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import pathlib
|
||||
import re
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(allow_abbrev=False, description="Convert file into includable C header")
|
||||
parser.add_argument("--in", "-i", type=pathlib.Path, metavar="INPUT", dest="input", required=True, help="Input file")
|
||||
parser.add_argument("--out", "-o", type=pathlib.Path, metavar="OUTPUT", dest="output", required=True, help="Output header")
|
||||
parser.add_argument("--columns", type=int, default=12, help="Column count")
|
||||
args = parser.parse_args()
|
||||
|
||||
t = pathlib.Path()
|
||||
varname, _ = re.subn("[^a-zA-Z0-9]", "_", str(args.input.name))
|
||||
|
||||
binary_data = args.input.open("rb").read()
|
||||
|
||||
with open(args.output, "w") as fout:
|
||||
fout.write("unsigned char {}[] = {{\n".format(varname))
|
||||
bytes_written = 0
|
||||
while bytes_written < len(binary_data):
|
||||
col = bytes_written % args.columns
|
||||
if col == 0:
|
||||
fout.write(" ")
|
||||
column_data = binary_data[bytes_written:bytes_written+args.columns]
|
||||
fout.write(", ".join("0x{:02x}".format(d) for d in column_data))
|
||||
bytes_written += len(column_data)
|
||||
if bytes_written < len(binary_data):
|
||||
fout.write(",\n")
|
||||
else:
|
||||
fout.write("\n")
|
||||
fout.write("}};\nunsigned int {}_len = {:d};\n".format(varname, len(binary_data)))
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
Reference in New Issue
Block a user