From cd7e6308cdb29c3f40f32ac36351c75bdb6b159e Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sun, 28 Jan 2024 13:59:36 +0100 Subject: [PATCH 01/17] CMake: Generalize determining platform name It is the same as CMAKE_VS_PLATFORM_NAME. Except for win32, which uses an empty name. --- build/cmake/init.cmake | 16 ++++------------ build/cmake/wxWidgetsConfig.cmake.in | 12 ++++-------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/build/cmake/init.cmake b/build/cmake/init.cmake index 7f572ee2b6..494a5938cc 100644 --- a/build/cmake/init.cmake +++ b/build/cmake/init.cmake @@ -133,20 +133,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) diff --git a/build/cmake/wxWidgetsConfig.cmake.in b/build/cmake/wxWidgetsConfig.cmake.in index 9983bc90dd..6726963238 100644 --- a/build/cmake/wxWidgetsConfig.cmake.in +++ b/build/cmake/wxWidgetsConfig.cmake.in @@ -12,16 +12,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) From c39d2243a07e73028badb5e0a811c0bc6ec334bc Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sun, 28 Jan 2024 14:01:11 +0100 Subject: [PATCH 02/17] CMake: Use CEF_RUNTIME_LIBRARY_FLAG Instead of manually modifying the build flags. Because libcef_dll_wrapper uses a cached variable, we have to force a cache change. --- build/cmake/lib/webview_chromium/CMakeLists.txt | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/build/cmake/lib/webview_chromium/CMakeLists.txt b/build/cmake/lib/webview_chromium/CMakeLists.txt index 31a5374d97..df615746d8 100644 --- a/build/cmake/lib/webview_chromium/CMakeLists.txt +++ b/build/cmake/lib/webview_chromium/CMakeLists.txt @@ -56,18 +56,21 @@ 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() + add_subdirectory(${CEF_ROOT} ${CEF_BUILD_DIR} EXCLUDE_FROM_ALL) 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() From de6a117fdaaee29cd405f09c8f52ab679475efdb Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sun, 28 Jan 2024 14:01:45 +0100 Subject: [PATCH 03/17] CMake: Silence the CEF configuration summary And any other warnings that libcef_dll_wrapper might show, like missing doxygen package. For debug purposes, add an option CEF_SHOW_RESULTS to keep showing it. --- build/cmake/lib/webview_chromium/CMakeLists.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/build/cmake/lib/webview_chromium/CMakeLists.txt b/build/cmake/lib/webview_chromium/CMakeLists.txt index df615746d8..25a1915899 100644 --- a/build/cmake/lib/webview_chromium/CMakeLists.txt +++ b/build/cmake/lib/webview_chromium/CMakeLists.txt @@ -64,7 +64,16 @@ if(MSVC) 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" @@ -103,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) From db7f144c1b3ed629613d59c39f60e053dce5fb90 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sun, 28 Jan 2024 14:02:12 +0100 Subject: [PATCH 04/17] CMake: Use simplified system name in configuration summary There is no need to show the full system name, which included for example the Windows build number. --- build/cmake/main.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/cmake/main.cmake b/build/cmake/main.cmake index 6cdffd2bbe..f6b0ec553e 100644 --- a/build/cmake/main.cmake +++ b/build/cmake/main.cmake @@ -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} From 590e033344292421abf8a2f02b6092815e7876a2 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sun, 28 Jan 2024 14:03:07 +0100 Subject: [PATCH 05/17] CMake: Keep UNICODE defines So these defines are exported and used by libraries importing wxWidgets. And also Visual Studio will show the actual character set that is being used. --- build/cmake/functions.cmake | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/build/cmake/functions.cmake b/build/cmake/functions.cmake index a74e8b64b2..d85541509e 100644 --- a/build/cmake/functions.cmake +++ b/build/cmake/functions.cmake @@ -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,11 @@ function(wx_set_builtin_target_properties target_name) ) endif() + if(WIN32) + target_compile_definitions(${target_name} PUBLIC UNICODE) + endif() + target_compile_definitions(${target_name} PUBLIC _UNICODE) + target_include_directories(${target_name} BEFORE PRIVATE ${wxSETUP_HEADER_PATH}) set_target_properties(${target_name} PROPERTIES FOLDER "Third Party Libraries") From 966c39802ee65ac0732d23c92535fbaaddd8a58e Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sun, 28 Jan 2024 14:04:29 +0100 Subject: [PATCH 06/17] CMake: Throw a more descriptive error when submodule files do not exist Instead of having a long list of files that cannot be found, create an error message that mentions that the git submodule should be checked out. --- build/cmake/functions.cmake | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build/cmake/functions.cmake b/build/cmake/functions.cmake index d85541509e..50da094963 100644 --- a/build/cmake/functions.cmake +++ b/build/cmake/functions.cmake @@ -593,6 +593,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() From a63ba1cc04059c9bf0349ea91e5fef553538ae74 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sun, 28 Jan 2024 14:05:38 +0100 Subject: [PATCH 07/17] CMake: Create wxWidgets::wxWidgets imported target Use the same name as the target from the official FindwxWidgets module, so it can be used interchangeable. --- build/cmake/wxWidgetsConfig.cmake.in | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/build/cmake/wxWidgetsConfig.cmake.in b/build/cmake/wxWidgetsConfig.cmake.in index 6726963238..a6c64a9d1e 100644 --- a/build/cmake/wxWidgetsConfig.cmake.in +++ b/build/cmake/wxWidgetsConfig.cmake.in @@ -59,6 +59,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@) @@ -113,6 +120,9 @@ foreach(libname @wxLIB_TARGETS@) list(FIND @PROJECT_NAME@_FIND_COMPONENTS ${name} idx) if(NOT @PROJECT_NAME@_FIND_COMPONENTS OR idx GREATER -1) list(APPEND wxWidgets_LIBRARIES wx::${name}) + if(CREATE_WX_TARGET) + target_link_libraries(wxWidgets::wxWidgets INTERFACE wx::${name}) + endif() endif() endif() endforeach() From 302ad5f7cd220913d219135f1a9abd62e0872a45 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sun, 28 Jan 2024 14:06:11 +0100 Subject: [PATCH 08/17] CMake: Check for OpenGL in imported target The gl target uses OpenGL libraries, so these must be defined. Previously, the user has to do this before importing the wxWidget target. --- build/cmake/wxWidgetsConfig.cmake.in | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build/cmake/wxWidgetsConfig.cmake.in b/build/cmake/wxWidgetsConfig.cmake.in index a6c64a9d1e..a67ad494bc 100644 --- a/build/cmake/wxWidgetsConfig.cmake.in +++ b/build/cmake/wxWidgetsConfig.cmake.in @@ -127,6 +127,12 @@ foreach(libname @wxLIB_TARGETS@) 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}) From cf04523ecea12e13d4fe6464de37538a10641f81 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sun, 28 Jan 2024 14:08:37 +0100 Subject: [PATCH 09/17] CMake: Show wxWebview overview in configuration summary Show a list of all the back-ends that are available, similar to what configure does. Make sure to disable wxUSE_WEBVIEW_WEBKIT when it is not used. --- build/cmake/init.cmake | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/build/cmake/init.cmake b/build/cmake/init.cmake index 494a5938cc..bb6602c295 100644 --- a/build/cmake/init.cmake +++ b/build/cmake/init.cmake @@ -486,16 +486,18 @@ 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) @@ -545,6 +547,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) From 8aad6ba37aa758bbdac3ba4c0faa75033129ca4f Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sun, 28 Jan 2024 14:09:40 +0100 Subject: [PATCH 10/17] CMake: Abort if Chromium is enabled on Windows with unsupported compiler The user has explicitly enabled chromium, so we shouldn't continue without it. --- build/cmake/init.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/cmake/init.cmake b/build/cmake/init.cmake index bb6602c295..b466a6bdf2 100644 --- a/build/cmake/init.cmake +++ b/build/cmake/init.cmake @@ -501,9 +501,9 @@ if(wxUSE_GUI) 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 From 57ed33978d0923ae6d025c8ce820633156e91ce3 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sun, 28 Jan 2024 14:17:19 +0100 Subject: [PATCH 11/17] CMake: Group compiler-default checks into a function --- build/cmake/init.cmake | 56 ++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/build/cmake/init.cmake b/build/cmake/init.cmake index b466a6bdf2..be8fdd5d04 100644 --- a/build/cmake/init.cmake +++ b/build/cmake/init.cmake @@ -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 @@ -24,6 +19,28 @@ 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 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. + checkCompilerDefaults() if(NOT wxHAVE_CXX11) # If not, request it explicitly and let CMake check if it's supported. set(CMAKE_CXX_STANDARD 11) @@ -505,30 +522,9 @@ if(wxUSE_GUI) 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) + # 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 From 395a61fc9ab1fe15f5fccb488f4b697ffa6dbae0 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sun, 28 Jan 2024 14:19:57 +0100 Subject: [PATCH 12/17] CMake: Use user-provided CMAKE_CXX_STANDARD wxBUILD_CXX_STANDARD is initialized with CMAKE_CXX_STANDARD. But if the user changes the value of CMAKE_CXX_STANDARD, it would keep using the old wxBUILD_CXX_STANDARD value. --- build/cmake/init.cmake | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/build/cmake/init.cmake b/build/cmake/init.cmake index be8fdd5d04..47376caf59 100644 --- a/build/cmake/init.cmake +++ b/build/cmake/init.cmake @@ -34,15 +34,18 @@ function(checkCompilerDefaults) wxHAVE_CXX17) endfunction() -if(DEFINED wxBUILD_CXX_STANDARD AND NOT wxBUILD_CXX_STANDARD STREQUAL COMPILER_DEFAULT) +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() - # If the standard is not set explicitly, check whether we can use C++11 - # without any special options. + # 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() From e2302a834e1bc7fdd8a8f99bc3c91c1e3001241c Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sun, 28 Jan 2024 17:09:55 +0100 Subject: [PATCH 13/17] CMake: Use IN_LIST operator instead of list(FIND ) --- build/cmake/config.cmake | 9 +++------ build/cmake/wxWidgetsConfig.cmake.in | 22 ++++++++++------------ 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/build/cmake/config.cmake b/build/cmake/config.cmake index 6fdef5ca44..eb9890b476 100644 --- a/build/cmake/config.cmake +++ b/build/cmake/config.cmake @@ -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() diff --git a/build/cmake/wxWidgetsConfig.cmake.in b/build/cmake/wxWidgetsConfig.cmake.in index a67ad494bc..85e3e004bd 100644 --- a/build/cmake/wxWidgetsConfig.cmake.in +++ b/build/cmake/wxWidgetsConfig.cmake.in @@ -81,17 +81,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() @@ -117,8 +116,7 @@ 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}) From 17b0033fc9dd172e3cbac0d4a5955600c5507cad Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sun, 28 Jan 2024 18:37:42 +0100 Subject: [PATCH 14/17] CMake: Update script for minimal sample Update the minimum CMake version, to get rid of deprecation warning. Remove wxWidgets_USE_FILE, this is not defined in CONFIG mode. Link with the wxWidgets::wxWidgets target. Use the manifest from wx.rc instead of the default MSVC manifest. --- samples/minimal/CMakeLists.txt | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/samples/minimal/CMakeLists.txt b/samples/minimal/CMakeLists.txt index a68272f763..6a917ef5ab 100644 --- a/samples/minimal/CMakeLists.txt +++ b/samples/minimal/CMakeLists.txt @@ -14,7 +14,7 @@ # # Declare the minimum required CMake version -cmake_minimum_required(VERSION 2.8.12) +cmake_minimum_required(VERSION 3.5) if(APPLE AND NOT CMAKE_OSX_DEPLOYMENT_TARGET) # If no deployment target has been set default to the minimum supported @@ -35,15 +35,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) # Request the required wxWidgets libs find_package(wxWidgets 3.3 COMPONENTS core base REQUIRED CONFIG) -# Include the wxWidgets use file to initialize various settings -if(wxWidgets_USE_FILE) - include(${wxWidgets_USE_FILE}) -endif() - # Define a variable containing a list of source files for the project set(SRC_FILES minimal.cpp - ) +) if(WIN32) # Include a RC file for windows @@ -55,14 +50,20 @@ endif() # Define the build target for the executable add_executable(${PROJECT_NAME} WIN32 MACOSX_BUNDLE ${SRC_FILES}) -# Link required libraries to the executable -target_link_libraries(${PROJECT_NAME} ${wxWidgets_LIBRARIES}) +# Link executable to the wxWidgets target +target_link_libraries(${PROJECT_NAME} wxWidgets::wxWidgets) -if(APPLE) +if(MSVC) + # Use manifest from wx.rc + set_target_properties(${PROJECT_NAME} PROPERTIES + COMPILE_FLAGS "/DwxUSE_RC_MANIFEST" + LINK_FLAGS "/MANIFEST:NO" + ) +elseif(APPLE) set_target_properties(${PROJECT_NAME} PROPERTIES RESOURCE "../../src/osx/carbon/wxmac.icns" MACOSX_BUNDLE_ICON_FILE wxmac.icns MACOSX_BUNDLE_COPYRIGHT "Copyright wxWidgets" MACOSX_BUNDLE_GUI_IDENTIFIER "org.wxwidgets.minimal" - ) + ) endif() From f0d2d0e748bfc65c8d8ce134c0bd055b19415c7a Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sun, 4 Feb 2024 18:01:36 +0100 Subject: [PATCH 15/17] CMake: Prevent possible policy warnings --- build/cmake/policies.cmake | 5 +++++ build/cmake/wxWidgetsConfig.cmake.in | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/build/cmake/policies.cmake b/build/cmake/policies.cmake index 9ea1d995c0..997a0b3350 100644 --- a/build/cmake/policies.cmake +++ b/build/cmake/policies.cmake @@ -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) diff --git a/build/cmake/wxWidgetsConfig.cmake.in b/build/cmake/wxWidgetsConfig.cmake.in index 85e3e004bd..a174bfd9b5 100644 --- a/build/cmake/wxWidgetsConfig.cmake.in +++ b/build/cmake/wxWidgetsConfig.cmake.in @@ -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) @@ -137,3 +151,5 @@ if(NOT @PROJECT_NAME@_FIND_COMPONENTS) endif() check_required_components("@PROJECT_NAME@") + +cmake_policy(POP) From f0061b3c04a3be9e6e519c584ec925747c556c8b Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sun, 4 Feb 2024 18:03:06 +0100 Subject: [PATCH 16/17] CMake: Only keep unicode definitions on Windows --- build/cmake/functions.cmake | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build/cmake/functions.cmake b/build/cmake/functions.cmake index 50da094963..7e676a7cc7 100644 --- a/build/cmake/functions.cmake +++ b/build/cmake/functions.cmake @@ -571,9 +571,10 @@ function(wx_set_builtin_target_properties target_name) endif() if(WIN32) - target_compile_definitions(${target_name} PUBLIC UNICODE) + # 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_compile_definitions(${target_name} PUBLIC _UNICODE) target_include_directories(${target_name} BEFORE PRIVATE ${wxSETUP_HEADER_PATH}) From e41fd2052c8b132648126da1e625139e36b5b8a9 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sun, 4 Feb 2024 18:11:10 +0100 Subject: [PATCH 17/17] CMake: Mention that CMake 3.5 is the minimum version Generating project files has been confirmed to work with this version. --- docs/doxygen/overviews/cmake.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/doxygen/overviews/cmake.md b/docs/doxygen/overviews/cmake.md index dc887fd059..99596277d7 100644 --- a/docs/doxygen/overviews/cmake.md +++ b/docs/doxygen/overviews/cmake.md @@ -84,7 +84,7 @@ in CMake the following generators are recommended: * macOS: Xcode * Linux: Ninja or Makefiles -CMake 3.10 or newer is recommended. The minimum version required is 2.8.12. +CMake 3.10 or newer is recommended. The minimum tested version is 3.5. Using CMake with your applications {#cmake_apps} ==================================