Miscellaneous CMake improvements.

Note that the new required CMake version is 3.5 now.

See #24263.
This commit is contained in:
Vadim Zeitlin 2024-02-09 17:12:18 +01:00
commit a401106da0
9 changed files with 173 additions and 95 deletions

View file

@ -137,15 +137,12 @@ function(wx_write_config)
set(STD_BASE_LIBS_ALL xml net base)
set(STD_GUI_LIBS_ALL xrc html qa adv core)
foreach(lib IN ITEMS xrc webview stc richtext ribbon propgrid aui gl media html qa adv core xml net base)
list(FIND wxLIB_TARGETS wx${lib} hasLib)
if (hasLib GREATER -1)
if (wx${lib} IN_LIST wxLIB_TARGETS)
wx_string_append(BUILT_WX_LIBS "${lib} ")
list(FIND STD_BASE_LIBS_ALL ${lib} index)
if (index GREATER -1)
if (${lib} IN_LIST STD_BASE_LIBS_ALL)
wx_string_append(STD_BASE_LIBS "${lib} ")
endif()
list(FIND STD_GUI_LIBS_ALL ${lib} index)
if (index GREATER -1)
if (${lib} IN_LIST STD_GUI_LIBS_ALL)
wx_string_append(STD_GUI_LIBS "${lib} ")
endif()
endif()

View file

@ -324,6 +324,11 @@ function(wx_set_target_properties target_name)
)
endif()
if(WIN32)
target_compile_definitions(${target_name} PUBLIC UNICODE)
endif()
target_compile_definitions(${target_name} PUBLIC _UNICODE)
file(RELATIVE_PATH wxSETUP_HEADER_REL ${wxOUTPUT_DIR} ${wxSETUP_HEADER_PATH})
target_include_directories(${target_name}
BEFORE
@ -565,6 +570,12 @@ function(wx_set_builtin_target_properties target_name)
)
endif()
if(WIN32)
# not needed for wxWidgets anymore (it is always built with unicode)
# but keep it here so applications linking to wxWidgets will inherit it
target_compile_definitions(${target_name} PUBLIC UNICODE _UNICODE)
endif()
target_include_directories(${target_name} BEFORE PRIVATE ${wxSETUP_HEADER_PATH})
set_target_properties(${target_name} PROPERTIES FOLDER "Third Party Libraries")
@ -583,6 +594,12 @@ endfunction()
function(wx_add_builtin_library name)
wx_list_add_prefix(src_list "${wxSOURCE_DIR}/" ${ARGN})
list(GET src_list 0 src_file)
if(NOT EXISTS "${src_file}")
message(FATAL_ERROR "${name} file does not exist: \"${src_file}\".\
Make sure you checkout the git submodules.")
endif()
if(${name} MATCHES "wx.*")
string(SUBSTRING ${name} 2 -1 name_short)
else()

View file

@ -8,12 +8,7 @@
# Licence: wxWindows licence
#############################################################################
if(DEFINED wxBUILD_CXX_STANDARD AND NOT wxBUILD_CXX_STANDARD STREQUAL COMPILER_DEFAULT)
set(CMAKE_CXX_STANDARD ${wxBUILD_CXX_STANDARD})
set(CMAKE_CXX_STANDARD_REQUIRED ON)
else()
# If the standard is not set explicitly, check whether we can use C++11
# without any special options.
function(checkCompilerDefaults)
include(CheckCXXSourceCompiles)
check_cxx_source_compiles("
#include <vector>
@ -24,8 +19,33 @@ else()
return v[0];
}"
wxHAVE_CXX11)
check_cxx_source_compiles("
#if defined(_MSVC_LANG)
#if _MSVC_LANG < 201703L
#error C++17 support is required
#endif
#elif __cplusplus < 201703L
#error C++17 support is required
#endif
int main() {
[[maybe_unused]] auto unused = 17;
}"
wxHAVE_CXX17)
endfunction()
if(DEFINED CMAKE_CXX_STANDARD)
# User has explicitly set a CMAKE_CXX_STANDARD.
elseif(DEFINED wxBUILD_CXX_STANDARD AND NOT wxBUILD_CXX_STANDARD STREQUAL COMPILER_DEFAULT)
# Standard is set using wxBUILD_CXX_STANDARD.
set(CMAKE_CXX_STANDARD ${wxBUILD_CXX_STANDARD})
set(CMAKE_CXX_STANDARD_REQUIRED ON)
else()
# CMAKE_CXX_STANDARD not defined.
checkCompilerDefaults()
if(NOT wxHAVE_CXX11)
# If not, request it explicitly and let CMake check if it's supported.
# If the standard is not set explicitly, and the default compiler settings
# do not support c++11, request it explicitly.
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()
@ -133,20 +153,12 @@ wx_string_append(wxBUILD_FILE_ID "${lib_flavour}")
set(wxPLATFORM_ARCH)
if(CMAKE_GENERATOR_PLATFORM)
if (CMAKE_GENERATOR_PLATFORM STREQUAL "x64")
set(wxPLATFORM_ARCH "x64")
elseif(CMAKE_GENERATOR_PLATFORM STREQUAL "ARM")
set(wxPLATFORM_ARCH "arm")
elseif(CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64")
set(wxPLATFORM_ARCH "arm64")
if(NOT CMAKE_GENERATOR_PLATFORM STREQUAL "Win32")
string(TOLOWER ${CMAKE_GENERATOR_PLATFORM} wxPLATFORM_ARCH)
endif()
elseif(CMAKE_VS_PLATFORM_NAME)
if (CMAKE_VS_PLATFORM_NAME STREQUAL "x64")
set(wxPLATFORM_ARCH "x64")
elseif(CMAKE_VS_PLATFORM_NAME STREQUAL "ARM")
set(wxPLATFORM_ARCH "arm")
elseif(CMAKE_VS_PLATFORM_NAME STREQUAL "ARM64")
set(wxPLATFORM_ARCH "arm64")
if(NOT CMAKE_VS_PLATFORM_NAME STREQUAL "Win32")
string(TOLOWER ${CMAKE_VS_PLATFORM_NAME} wxPLATFORM_ARCH)
endif()
else()
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
@ -494,47 +506,28 @@ if(wxUSE_GUI)
message(WARNING "webkit or chromium not found or enabled, wxWebview won't be available")
wx_option_force_value(wxUSE_WEBVIEW OFF)
endif()
elseif(WXMSW)
if(NOT wxUSE_WEBVIEW_IE AND NOT wxUSE_WEBVIEW_EDGE AND NOT wxUSE_WEBVIEW_CHROMIUM)
message(WARNING "WebviewIE and WebviewEdge and WebviewChromium not found or enabled, wxWebview won't be available")
wx_option_force_value(wxUSE_WEBVIEW OFF)
endif()
elseif(APPLE)
if(NOT wxUSE_WEBVIEW_WEBKIT AND NOT wxUSE_WEBVIEW_CHROMIUM)
message(WARNING "webkit and chromium not found or enabled, wxWebview won't be available")
wx_option_force_value(wxUSE_WEBVIEW OFF)
endif()
else()
set(wxUSE_WEBVIEW_WEBKIT OFF)
endif()
if(WXMSW AND NOT wxUSE_WEBVIEW_IE AND NOT wxUSE_WEBVIEW_EDGE AND NOT wxUSE_WEBVIEW_CHROMIUM)
message(WARNING "WebviewIE and WebviewEdge and WebviewChromium not found or enabled, wxWebview won't be available")
wx_option_force_value(wxUSE_WEBVIEW OFF)
endif()
if(wxUSE_WEBVIEW_CHROMIUM AND WIN32 AND NOT MSVC)
message(WARNING "WebviewChromium libcef_dll_wrapper can only be built with MSVC... disabled")
wx_option_force_value(wxUSE_WEBVIEW_CHROMIUM OFF)
message(FATAL_ERROR "WebviewChromium libcef_dll_wrapper can only be built with MSVC")
endif()
if(wxUSE_WEBVIEW_CHROMIUM)
# Check for C++17 support as it's required by CEF: we trust
# CMAKE_CXX_STANDARD if it is defined, but we need to compile a
# test program if it is not because the compiler could be
# supporting C++17 anyway.
if (DEFINED CMAKE_CXX_STANDARD)
if (CMAKE_CXX_STANDARD GREATER_EQUAL 17)
set(wxHAVE_CXX17 ON)
endif()
else()
check_cxx_source_compiles("
#if defined(_MSVC_LANG)
#if _MSVC_LANG < 201703L
#error C++17 support is required
#endif
#elif __cplusplus < 201703L
#error C++17 support is required
#endif
int main() {
[[maybe_unused]] auto unused = 17;
}"
wxHAVE_CXX17)
endif()
if (NOT wxHAVE_CXX17)
if(wxUSE_WEBVIEW_CHROMIUM)
# CEF requires C++17: we trust CMAKE_CXX_STANDARD if it is defined,
# or the previously tested wxHAVE_CXX17 if the compiler supports C++17 anyway.
if(NOT (CMAKE_CXX_STANDARD GREATER_EQUAL 17 OR wxHAVE_CXX17))
# We shouldn't disable this option as it's disabled by default and
# if it is on, it means that CEF is meant to be used, but we can't
# continue neither as libcef_dll_wrapper will fail to build
@ -553,6 +546,32 @@ if(wxUSE_GUI)
endif()
endif()
set(wxWebviewInfo "enable wxWebview")
if(wxUSE_WEBVIEW)
if(wxUSE_WEBVIEW_WEBKIT)
list(APPEND webviewBackends "WebKit")
endif()
if(wxUSE_WEBVIEW_WEBKIT2)
list(APPEND webviewBackends "WebKit2")
endif()
if(wxUSE_WEBVIEW_EDGE)
if(wxUSE_WEBVIEW_EDGE_STATIC)
list(APPEND webviewBackends "Edge (static)")
else()
list(APPEND webviewBackends "Edge")
endif()
endif()
if(wxUSE_WEBVIEW_IE)
list(APPEND webviewBackends "IE")
endif()
if(wxUSE_WEBVIEW_CHROMIUM)
list(APPEND webviewBackends "Chromium")
endif()
string(REPLACE ";" ", " webviewBackends "${webviewBackends}")
set(wxWebviewInfo "${wxWebviewInfo} with ${webviewBackends}")
endif()
set(wxTHIRD_PARTY_LIBRARIES ${wxTHIRD_PARTY_LIBRARIES} wxUSE_WEBVIEW ${wxWebviewInfo})
if(wxUSE_PRIVATE_FONTS AND WXGTK)
find_package(FONTCONFIG)
find_package(PANGOFT2)

View file

@ -56,18 +56,30 @@ endif()
set(USE_ATL OFF) # Disable usage of ATL in CEF
set(USE_SANDBOX OFF) # Disable usage of sandbox on windows
if(MSVC)
if(wxBUILD_USE_STATIC_RUNTIME)
set(CEF_RUNTIME_LIBRARY_FLAG "/MT" CACHE STRING "" FORCE)
else()
set(CEF_RUNTIME_LIBRARY_FLAG "/MD" CACHE STRING "" FORCE)
endif()
endif()
set(_saved_CMAKE_MESSAGE_LOG_LEVEL ${CMAKE_MESSAGE_LOG_LEVEL})
set(CEF_SHOW_RESULTS FALSE CACHE BOOL "Show CEF configuration results")
if(NOT CEF_SHOW_RESULTS)
set(CMAKE_MESSAGE_LOG_LEVEL ERROR)
endif()
add_subdirectory(${CEF_ROOT} ${CEF_BUILD_DIR} EXCLUDE_FROM_ALL)
set(CMAKE_MESSAGE_LOG_LEVEL ${_saved_CMAKE_MESSAGE_LOG_LEVEL})
set_target_properties(libcef_dll_wrapper PROPERTIES
FOLDER "Third Party Libraries"
OUTPUT_NAME "libcef_dll_wrapper"
)
if(MSVC)
# Modify CEF compiler options to match VC runtime
get_target_property(cef_compile_options libcef_dll_wrapper COMPILE_OPTIONS)
string(REGEX REPLACE "/MTd?;" "" cef_compile_options "${cef_compile_options}")
set_target_properties(libcef_dll_wrapper PROPERTIES COMPILE_OPTIONS "${cef_compile_options}")
else()
if(NOT MSVC)
set_target_properties(libcef_dll_wrapper PROPERTIES COMPILE_OPTIONS "-Wno-extra")
endif()
@ -100,5 +112,6 @@ mark_as_advanced(USE_ATL)
mark_as_advanced(USE_SANDBOX)
mark_as_advanced(OPTION_USE_ARC)
mark_as_advanced(CEF_ROOT)
mark_as_advanced(CEF_SHOW_RESULTS)
mark_as_advanced(CEF_DEBUG_INFO_FLAG)
mark_as_advanced(CEF_RUNTIME_LIBRARY_FLAG)

View file

@ -75,7 +75,7 @@ if(wxTOOLKIT_EXTRA)
set(wxTOOLKIT_DESC "with support for: ${wxTOOLKIT_DESC}")
endif()
message(STATUS "Configured wxWidgets ${wxVERSION} for ${CMAKE_SYSTEM}
message(STATUS "Configured wxWidgets ${wxVERSION} for ${CMAKE_SYSTEM_NAME}
Min OS Version required at runtime: ${wxREQUIRED_OS_DESC}
Which GUI toolkit should wxWidgets use? ${wxBUILD_TOOLKIT} ${wxTOOLKIT_VERSION} ${wxTOOLKIT_DESC}
Should wxWidgets be compiled into single library? ${wxBUILD_MONOLITHIC}

View file

@ -59,6 +59,11 @@ if(POLICY CMP0054)
cmake_policy(SET CMP0054 NEW)
endif()
if(POLICY CMP0057)
# Support new if() IN_LIST operator.
cmake_policy(SET CMP0057 NEW)
endif()
if(POLICY CMP0060)
# Link libraries by full path even in implicit directories.
cmake_policy(SET CMP0060 NEW)

View file

@ -1,5 +1,19 @@
@PACKAGE_INIT@
cmake_policy(PUSH)
# Set policies to prevent warnings
if(POLICY CMP0057)
# Support new if() IN_LIST operator.
cmake_policy(SET CMP0057 NEW)
endif()
if(POLICY CMP0072)
# FindOpenGL prefers GLVND by default when available.
cmake_policy(GET CMP0072 _OpenGL_GL_POLICY)
if (_OpenGL_GL_POLICY STREQUAL "")
cmake_policy(SET CMP0072 NEW)
endif()
endif()
# determine target from compiler, platform and library type
if(WIN32 AND NOT CYGWIN AND NOT MSYS)
if(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
@ -12,16 +26,12 @@ if(WIN32 AND NOT CYGWIN AND NOT MSYS)
set(wxPLATFORM_ARCH)
if(CMAKE_GENERATOR_PLATFORM)
if (CMAKE_GENERATOR_PLATFORM STREQUAL "x64")
set(wxPLATFORM_ARCH "x64")
elseif(CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64")
set(wxPLATFORM_ARCH "arm64")
if(NOT CMAKE_GENERATOR_PLATFORM STREQUAL "Win32")
string(TOLOWER ${CMAKE_GENERATOR_PLATFORM} wxPLATFORM_ARCH)
endif()
elseif(CMAKE_VS_PLATFORM_NAME)
if (CMAKE_VS_PLATFORM_NAME STREQUAL "x64")
set(wxPLATFORM_ARCH "x64")
elseif(CMAKE_VS_PLATFORM_NAME STREQUAL "ARM64")
set(wxPLATFORM_ARCH "arm64")
if(NOT CMAKE_VS_PLATFORM_NAME STREQUAL "Win32")
string(TOLOWER ${CMAKE_VS_PLATFORM_NAME} wxPLATFORM_ARCH)
endif()
else()
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
@ -63,6 +73,13 @@ endmacro()
# for compatibility with FindwxWidgets
set(wxWidgets_LIBRARIES)
# create one target with all libraries, same as FindwxWidgets
set(CREATE_WX_TARGET OFF)
if(NOT TARGET wxWidgets::wxWidgets)
add_library(wxWidgets::wxWidgets INTERFACE IMPORTED)
set(CREATE_WX_TARGET ON)
endif()
# list all available components
set(@PROJECT_NAME@_COMPONENTS)
foreach(libname @wxLIB_TARGETS@)
@ -78,17 +95,16 @@ foreach(libname @wxLIB_TARGETS@)
# use the Release configuration for MinSizeRel and RelWithDebInfo configurations
# only when Release target exists, and MinSizeRel/RelWithDebInfo doesn't exist
get_target_property(configs wx::${libname} IMPORTED_CONFIGURATIONS)
list(FIND configs "RELEASE" idxSrc)
if(idxSrc GREATER -1)
list(FIND configs "MINSIZEREL" idxSrc)
list(FIND CMAKE_CONFIGURATION_TYPES "MinSizeRel" idxDst)
if(idxSrc EQUAL -1 AND (idxDst GREATER -1 OR CMAKE_BUILD_TYPE STREQUAL "MinSizeRel"))
set_target_properties(wx::${libname} PROPERTIES MAP_IMPORTED_CONFIG_MINSIZEREL "Release")
if("RELEASE" IN_LIST configs)
if(NOT "MINSIZEREL" IN_LIST configs)
if("MinSizeRel" IN_LIST CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
set_target_properties(wx::${libname} PROPERTIES MAP_IMPORTED_CONFIG_MINSIZEREL "Release")
endif()
endif()
list(FIND configs "RELWITHDEBINFO" idxSrc)
list(FIND CMAKE_CONFIGURATION_TYPES "RelWithDebInfo" idxDst)
if(idxSrc EQUAL -1 AND (idxDst GREATER -1 OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo"))
set_target_properties(wx::${libname} PROPERTIES MAP_IMPORTED_CONFIG_RELWITHDEBINFO "Release")
if(NOT "RELWITHDEBINFO" IN_LIST configs)
if("RelWithDebInfo" IN_LIST CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
set_target_properties(wx::${libname} PROPERTIES MAP_IMPORTED_CONFIG_RELWITHDEBINFO "Release")
endif()
endif()
endif()
@ -114,16 +130,26 @@ foreach(libname @wxLIB_TARGETS@)
endif()
# add to FindwxWidgets variable
list(FIND @PROJECT_NAME@_FIND_COMPONENTS ${name} idx)
if(NOT @PROJECT_NAME@_FIND_COMPONENTS OR idx GREATER -1)
if(NOT @PROJECT_NAME@_FIND_COMPONENTS OR ${name} IN_LIST @PROJECT_NAME@_FIND_COMPONENTS)
list(APPEND wxWidgets_LIBRARIES wx::${name})
if(CREATE_WX_TARGET)
target_link_libraries(wxWidgets::wxWidgets INTERFACE wx::${name})
endif()
endif()
endif()
endforeach()
if(TARGET wx::wxgl)
# make sure OpenGL targets are available:
# The link interface of target "wx::wxgl" contains: OpenGL::GLU
find_package(OpenGL QUIET)
endif()
# if no components are specified in find_package, check all of them
if(NOT @PROJECT_NAME@_FIND_COMPONENTS)
set(@PROJECT_NAME@_FIND_COMPONENTS ${@PROJECT_NAME@_COMPONENTS})
endif()
check_required_components("@PROJECT_NAME@")
cmake_policy(POP)