CMake: Drop support for CMake versions below 3.13

We are already using target_link_options, and while it's possible to keep supporting older versions, it doesn't sound worth it.  I can revert this out if someone gives me a really good reason to.
This commit is contained in:
rdb 2022-03-09 14:35:57 +01:00
parent e716dba8d4
commit 264747d213
6 changed files with 10 additions and 168 deletions

View File

@ -1,36 +1,14 @@
cmake_minimum_required(VERSION 3.0.2)
cmake_minimum_required(VERSION 3.13)
set(CMAKE_DISABLE_SOURCE_CHANGES ON) # Must go before project() below
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON) # Must go before project() below
if(CMAKE_VERSION VERSION_GREATER "3.11" OR POLICY CMP0072)
# Prefer GLVND over libGL when available; this will be enabled by default
# once the minimum CMake version is at least 3.11.
cmake_policy(SET CMP0072 NEW)
endif()
if(CMAKE_VERSION VERSION_GREATER "3.12" OR POLICY CMP0074)
# Needed for THIRDPARTY_DIRECTORY support; this will be enabled by default
# once the minimum CMake version is at least 3.12.
cmake_policy(SET CMP0074 NEW)
endif()
if(POLICY CMP0091)
# Needed for CMake to pass /MD flag properly with non-VC generators.
cmake_policy(SET CMP0091 NEW)
endif()
# Determine whether we are using a multi-config generator.
if(CMAKE_VERSION VERSION_GREATER "3.8")
get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
else()
message(WARNING "Multi-configuration builds may not work properly when using
a CMake < 3.9. Making a guess if this is a multi-config generator.")
if(DEFINED CMAKE_CONFIGURATION_TYPES)
set(IS_MULTICONFIG ON)
else()
set(IS_MULTICONFIG OFF)
endif()
endif()
get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
# Set the default CMAKE_BUILD_TYPE before calling project().
if(IS_MULTICONFIG)
@ -89,11 +67,9 @@ string(REPLACE "$(EFFECTIVE_PLATFORM_NAME)" "" PANDA_CFG_INTDIR "${CMAKE_CFG_INT
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/macros/")
if(CMAKE_VERSION VERSION_GREATER "3.8")
# When using the Xcode generator, don't append the platform name to the
# intermediate configuration directory.
set_property(GLOBAL PROPERTY XCODE_EMIT_EFFECTIVE_PLATFORM_NAME OFF)
endif()
# When using the Xcode generator, don't append the platform name to the
# intermediate configuration directory.
set_property(GLOBAL PROPERTY XCODE_EMIT_EFFECTIVE_PLATFORM_NAME OFF)
# Include modules builtin to CMake
include(GNUInstallDirs) # Defines CMAKE_INSTALL_<dir> variables

View File

@ -5,83 +5,6 @@
# instead just an agglomeration of the various component libraries that get
# linked into them. A library of libraries - a "metalibrary."
#
# Function: target_link_libraries(...)
#
# Overrides CMake's target_link_libraries() to support "linking" object
# libraries. This is a partial reimplementation of CMake commit dc38970f83,
# which is only available in CMake 3.12+
#
if(CMAKE_VERSION VERSION_LESS "3.12")
function(target_link_libraries target)
get_target_property(target_type "${target}" TYPE)
if(NOT target_type STREQUAL "OBJECT_LIBRARY")
_target_link_libraries("${target}" ${ARGN})
return()
endif()
foreach(library ${ARGN})
# This is a quick and dirty regex to tell targets apart from other stuff.
# It just checks if it's alphanumeric and starts with p3/panda.
if(library MATCHES "^(PKG::|p3|panda)[A-Za-z0-9]*$")
# We need to add "library"'s include directories to "target"
# (and transitively to INTERFACE_INCLUDE_DIRECTORIES so further
# dependencies will work)
set(include_directories "$<TARGET_PROPERTY:${library},INTERFACE_INCLUDE_DIRECTORIES>")
set_property(TARGET "${target}" APPEND PROPERTY INCLUDE_DIRECTORIES "${include_directories}")
set_property(TARGET "${target}" APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${include_directories}")
# SYSTEM include directories should still be reported as SYSTEM, so
# that warnings from those includes are suppressed
set(sys_include_directories
"$<TARGET_PROPERTY:${library},INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>")
target_include_directories("${target}" SYSTEM PUBLIC "${sys_include_directories}")
# And for INTERFACE_COMPILE_DEFINITIONS as well
set(compile_definitions "$<TARGET_PROPERTY:${library},INTERFACE_COMPILE_DEFINITIONS>")
set_property(TARGET "${target}" APPEND PROPERTY COMPILE_DEFINITIONS "${compile_definitions}")
set_property(TARGET "${target}" APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS "${compile_definitions}")
# Build up some generator expressions for determining whether `library`
# is a component library or not.
if(library MATCHES ".*::.*")
# "::" messes up CMake's genex parser; fortunately, a library whose
# name contains that is either an interface library or alias, and
# definitely not a component
set(is_component 0)
set(name_of_component "")
set(name_of_non_component "${library}")
else()
set(is_component "$<TARGET_PROPERTY:${library},IS_COMPONENT>")
# CMake complains if we lookup IS_COMPONENT on an INTERFACE library :(
set(is_object "$<STREQUAL:$<TARGET_PROPERTY:${library},TYPE>,OBJECT_LIBRARY>")
set(is_component "$<BOOL:$<${is_object}:${is_component}>>")
set(name_of_component "$<${is_component}:$<TARGET_NAME:${library}>>")
set(name_of_non_component "$<$<NOT:${is_component}>:$<TARGET_NAME:${library}>>")
endif()
# Libraries are only linked transitively if they aren't components.
set_property(TARGET "${target}" APPEND PROPERTY
INTERFACE_LINK_LIBRARIES "${name_of_non_component}")
else()
# This is a file path to an out-of-tree library - this needs to be
# recorded so that the metalib can link them. (They aren't needed at
# all for the object libraries themselves, so they don't have to work
# transitively.)
set_property(TARGET "${target}" APPEND PROPERTY INTERFACE_LINK_LIBRARIES "${library}")
endif()
endforeach(library)
endfunction(target_link_libraries)
endif()
#
# Function: add_component_library(target [SYMBOL building_symbol]
# [SOURCES] [[NOINIT]/[INIT func [header]]])

View File

@ -176,18 +176,6 @@ function(package_option name)
# Create the INTERFACE library used to depend on this package.
add_library(PKG::${name} INTERFACE IMPORTED GLOBAL)
# Explicitly record the package's include directories as system include
# directories. CMake does do this automatically for INTERFACE libraries, but
# it does it by discovering all transitive links first, then reading
# INTERFACE_INCLUDE_DIRECTORIES for those which are INTERFACE libraries. So,
# this would be broken for the metalib system (pre CMake 3.12) which doesn't
# "link" the object libraries.
if(CMAKE_VERSION VERSION_LESS "3.12")
set_target_properties(PKG::${name} PROPERTIES
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES
"$<TARGET_PROPERTY:PKG::${name},INTERFACE_INCLUDE_DIRECTORIES>")
endif()
# If the option actually is enabled, populate the INTERFACE library created above
if(HAVE_${name})
set(use_variables ON)
@ -412,9 +400,8 @@ function(export_packages filename)
endforeach(config)
endif()
elseif(CMAKE_VERSION VERSION_GREATER "3.8")
# This is an INTERFACE_LIBRARY, and CMake is new enough to support
# IMPORTED_IMPLIB
else()
# This is an INTERFACE_LIBRARY.
get_target_property(imported_libname "${head}" IMPORTED_LIBNAME)
if(imported_libname)
list(APPEND libraries ${imported_libname})

View File

@ -48,21 +48,9 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GCC")
endif()
# Panda3D is now a C++11 project. Newer versions of CMake support this out of
# the box; for older versions we take a shot in the dark:
if(CMAKE_VERSION VERSION_LESS "3.1")
check_cxx_compiler_flag("-std=gnu++11" COMPILER_SUPPORTS_CXX11)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
endif()
else()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()
# Panda3D is now a C++11 project.
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Set certain CMake flags we expect
set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON)
@ -110,21 +98,6 @@ if(APPLE)
set(CMAKE_SHARED_MODULE_SUFFIX ".dylib")
endif()
# We want the output structured like build/CONFIG/bin, not build/bin/CONFIG per
# the default for multi-configuration generators. In CMake 3.4+, it switches
# automatically if the *_OUTPUT_DIRECTORY property contains a generator
# expresssion, but as of this writing we support as early as CMake 3.0.2.
#
# So, let's just do this:
if(CMAKE_VERSION VERSION_LESS "3.4")
foreach(_type RUNTIME ARCHIVE LIBRARY)
foreach(_config ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER "${_config}" _config)
set(CMAKE_${_type}_OUTPUT_DIRECTORY_${_config} "${CMAKE_${_type}_OUTPUT_DIRECTORY}")
endforeach(_config)
endforeach(_type)
endif()
# Set warning levels
if(MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3")

View File

@ -211,19 +211,6 @@ if(Python_FOUND)
set(PYTHON_INCLUDE_DIRS ${Python_INCLUDE_DIRS})
set(PYTHON_LIBRARY_DIRS ${Python_LIBRARY_DIRS})
set(PYTHON_VERSION_STRING ${Python_VERSION})
elseif(CMAKE_VERSION VERSION_LESS "3.12")
find_package(PythonInterp ${WANT_PYTHON_VERSION} QUIET)
find_package(PythonLibs ${PYTHON_VERSION_STRING} QUIET)
if(PYTHONLIBS_FOUND)
set(PYTHON_FOUND ON)
if(NOT PYTHON_VERSION_STRING)
set(PYTHON_VERSION_STRING ${PYTHONLIBS_VERSION_STRING})
endif()
endif()
endif()
if(CMAKE_VERSION VERSION_LESS "3.15")

View File

@ -46,10 +46,6 @@ math(EXPR PANDA_NUMERIC_VERSION "${PROJECT_VERSION_MAJOR}*1000000 + ${PROJECT_VE
# If SOURCE_DATE_EPOCH is set, it affects PandaSystem::get_build_date()
if(DEFINED ENV{SOURCE_DATE_EPOCH})
if(CMAKE_VERSION VERSION_LESS "3.8")
message(FATAL_ERROR "CMake 3.8 is required to support SOURCE_DATE_EPOCH properly.")
endif()
string(TIMESTAMP _build_date "%b %d %Y %H:%M:%S" UTC)
# CMake doesn't support %e, replace leading zero in day with space