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_BASE_LIBS_ALL xml net base)
set(STD_GUI_LIBS_ALL xrc html qa adv core) 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) 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 (wx${lib} IN_LIST wxLIB_TARGETS)
if (hasLib GREATER -1)
wx_string_append(BUILT_WX_LIBS "${lib} ") wx_string_append(BUILT_WX_LIBS "${lib} ")
list(FIND STD_BASE_LIBS_ALL ${lib} index) if (${lib} IN_LIST STD_BASE_LIBS_ALL)
if (index GREATER -1)
wx_string_append(STD_BASE_LIBS "${lib} ") wx_string_append(STD_BASE_LIBS "${lib} ")
endif() endif()
list(FIND STD_GUI_LIBS_ALL ${lib} index) if (${lib} IN_LIST STD_GUI_LIBS_ALL)
if (index GREATER -1)
wx_string_append(STD_GUI_LIBS "${lib} ") wx_string_append(STD_GUI_LIBS "${lib} ")
endif() endif()
endif() endif()

View file

@ -324,6 +324,11 @@ function(wx_set_target_properties target_name)
) )
endif() 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}) file(RELATIVE_PATH wxSETUP_HEADER_REL ${wxOUTPUT_DIR} ${wxSETUP_HEADER_PATH})
target_include_directories(${target_name} target_include_directories(${target_name}
BEFORE BEFORE
@ -565,6 +570,12 @@ function(wx_set_builtin_target_properties target_name)
) )
endif() 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}) target_include_directories(${target_name} BEFORE PRIVATE ${wxSETUP_HEADER_PATH})
set_target_properties(${target_name} PROPERTIES FOLDER "Third Party Libraries") set_target_properties(${target_name} PROPERTIES FOLDER "Third Party Libraries")
@ -583,6 +594,12 @@ endfunction()
function(wx_add_builtin_library name) function(wx_add_builtin_library name)
wx_list_add_prefix(src_list "${wxSOURCE_DIR}/" ${ARGN}) 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.*") if(${name} MATCHES "wx.*")
string(SUBSTRING ${name} 2 -1 name_short) string(SUBSTRING ${name} 2 -1 name_short)
else() else()

View file

@ -8,12 +8,7 @@
# Licence: wxWindows licence # Licence: wxWindows licence
############################################################################# #############################################################################
if(DEFINED wxBUILD_CXX_STANDARD AND NOT wxBUILD_CXX_STANDARD STREQUAL COMPILER_DEFAULT) function(checkCompilerDefaults)
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.
include(CheckCXXSourceCompiles) include(CheckCXXSourceCompiles)
check_cxx_source_compiles(" check_cxx_source_compiles("
#include <vector> #include <vector>
@ -24,8 +19,33 @@ else()
return v[0]; return v[0];
}" }"
wxHAVE_CXX11) 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 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 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif() endif()
@ -133,20 +153,12 @@ wx_string_append(wxBUILD_FILE_ID "${lib_flavour}")
set(wxPLATFORM_ARCH) set(wxPLATFORM_ARCH)
if(CMAKE_GENERATOR_PLATFORM) if(CMAKE_GENERATOR_PLATFORM)
if (CMAKE_GENERATOR_PLATFORM STREQUAL "x64") if(NOT CMAKE_GENERATOR_PLATFORM STREQUAL "Win32")
set(wxPLATFORM_ARCH "x64") string(TOLOWER ${CMAKE_GENERATOR_PLATFORM} wxPLATFORM_ARCH)
elseif(CMAKE_GENERATOR_PLATFORM STREQUAL "ARM")
set(wxPLATFORM_ARCH "arm")
elseif(CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64")
set(wxPLATFORM_ARCH "arm64")
endif() endif()
elseif(CMAKE_VS_PLATFORM_NAME) elseif(CMAKE_VS_PLATFORM_NAME)
if (CMAKE_VS_PLATFORM_NAME STREQUAL "x64") if(NOT CMAKE_VS_PLATFORM_NAME STREQUAL "Win32")
set(wxPLATFORM_ARCH "x64") string(TOLOWER ${CMAKE_VS_PLATFORM_NAME} wxPLATFORM_ARCH)
elseif(CMAKE_VS_PLATFORM_NAME STREQUAL "ARM")
set(wxPLATFORM_ARCH "arm")
elseif(CMAKE_VS_PLATFORM_NAME STREQUAL "ARM64")
set(wxPLATFORM_ARCH "arm64")
endif() endif()
else() else()
if(CMAKE_SIZEOF_VOID_P EQUAL 8) 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") message(WARNING "webkit or chromium not found or enabled, wxWebview won't be available")
wx_option_force_value(wxUSE_WEBVIEW OFF) wx_option_force_value(wxUSE_WEBVIEW OFF)
endif() 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) elseif(APPLE)
if(NOT wxUSE_WEBVIEW_WEBKIT AND NOT wxUSE_WEBVIEW_CHROMIUM) if(NOT wxUSE_WEBVIEW_WEBKIT AND NOT wxUSE_WEBVIEW_CHROMIUM)
message(WARNING "webkit and chromium not found or enabled, wxWebview won't be available") message(WARNING "webkit and chromium not found or enabled, wxWebview won't be available")
wx_option_force_value(wxUSE_WEBVIEW OFF) wx_option_force_value(wxUSE_WEBVIEW OFF)
endif() 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() endif()
if(wxUSE_WEBVIEW_CHROMIUM AND WIN32 AND NOT MSVC) if(wxUSE_WEBVIEW_CHROMIUM AND WIN32 AND NOT MSVC)
message(WARNING "WebviewChromium libcef_dll_wrapper can only be built with MSVC... disabled") message(FATAL_ERROR "WebviewChromium libcef_dll_wrapper can only be built with MSVC")
wx_option_force_value(wxUSE_WEBVIEW_CHROMIUM OFF)
endif() 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 # 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 # 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 # continue neither as libcef_dll_wrapper will fail to build
@ -553,6 +546,32 @@ if(wxUSE_GUI)
endif() endif()
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) if(wxUSE_PRIVATE_FONTS AND WXGTK)
find_package(FONTCONFIG) find_package(FONTCONFIG)
find_package(PANGOFT2) find_package(PANGOFT2)

View file

@ -56,18 +56,30 @@ endif()
set(USE_ATL OFF) # Disable usage of ATL in CEF set(USE_ATL OFF) # Disable usage of ATL in CEF
set(USE_SANDBOX OFF) # Disable usage of sandbox on windows 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) 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 set_target_properties(libcef_dll_wrapper PROPERTIES
FOLDER "Third Party Libraries" FOLDER "Third Party Libraries"
OUTPUT_NAME "libcef_dll_wrapper" OUTPUT_NAME "libcef_dll_wrapper"
) )
if(MSVC) if(NOT 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()
set_target_properties(libcef_dll_wrapper PROPERTIES COMPILE_OPTIONS "-Wno-extra") set_target_properties(libcef_dll_wrapper PROPERTIES COMPILE_OPTIONS "-Wno-extra")
endif() endif()
@ -100,5 +112,6 @@ mark_as_advanced(USE_ATL)
mark_as_advanced(USE_SANDBOX) mark_as_advanced(USE_SANDBOX)
mark_as_advanced(OPTION_USE_ARC) mark_as_advanced(OPTION_USE_ARC)
mark_as_advanced(CEF_ROOT) mark_as_advanced(CEF_ROOT)
mark_as_advanced(CEF_SHOW_RESULTS)
mark_as_advanced(CEF_DEBUG_INFO_FLAG) mark_as_advanced(CEF_DEBUG_INFO_FLAG)
mark_as_advanced(CEF_RUNTIME_LIBRARY_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}") set(wxTOOLKIT_DESC "with support for: ${wxTOOLKIT_DESC}")
endif() 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} Min OS Version required at runtime: ${wxREQUIRED_OS_DESC}
Which GUI toolkit should wxWidgets use? ${wxBUILD_TOOLKIT} ${wxTOOLKIT_VERSION} ${wxTOOLKIT_DESC} Which GUI toolkit should wxWidgets use? ${wxBUILD_TOOLKIT} ${wxTOOLKIT_VERSION} ${wxTOOLKIT_DESC}
Should wxWidgets be compiled into single library? ${wxBUILD_MONOLITHIC} Should wxWidgets be compiled into single library? ${wxBUILD_MONOLITHIC}

View file

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

View file

@ -1,5 +1,19 @@
@PACKAGE_INIT@ @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 # determine target from compiler, platform and library type
if(WIN32 AND NOT CYGWIN AND NOT MSYS) if(WIN32 AND NOT CYGWIN AND NOT MSYS)
if(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC) if(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
@ -12,16 +26,12 @@ if(WIN32 AND NOT CYGWIN AND NOT MSYS)
set(wxPLATFORM_ARCH) set(wxPLATFORM_ARCH)
if(CMAKE_GENERATOR_PLATFORM) if(CMAKE_GENERATOR_PLATFORM)
if (CMAKE_GENERATOR_PLATFORM STREQUAL "x64") if(NOT CMAKE_GENERATOR_PLATFORM STREQUAL "Win32")
set(wxPLATFORM_ARCH "x64") string(TOLOWER ${CMAKE_GENERATOR_PLATFORM} wxPLATFORM_ARCH)
elseif(CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64")
set(wxPLATFORM_ARCH "arm64")
endif() endif()
elseif(CMAKE_VS_PLATFORM_NAME) elseif(CMAKE_VS_PLATFORM_NAME)
if (CMAKE_VS_PLATFORM_NAME STREQUAL "x64") if(NOT CMAKE_VS_PLATFORM_NAME STREQUAL "Win32")
set(wxPLATFORM_ARCH "x64") string(TOLOWER ${CMAKE_VS_PLATFORM_NAME} wxPLATFORM_ARCH)
elseif(CMAKE_VS_PLATFORM_NAME STREQUAL "ARM64")
set(wxPLATFORM_ARCH "arm64")
endif() endif()
else() else()
if(CMAKE_SIZEOF_VOID_P EQUAL 8) if(CMAKE_SIZEOF_VOID_P EQUAL 8)
@ -63,6 +73,13 @@ endmacro()
# for compatibility with FindwxWidgets # for compatibility with FindwxWidgets
set(wxWidgets_LIBRARIES) 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 # list all available components
set(@PROJECT_NAME@_COMPONENTS) set(@PROJECT_NAME@_COMPONENTS)
foreach(libname @wxLIB_TARGETS@) foreach(libname @wxLIB_TARGETS@)
@ -78,17 +95,16 @@ foreach(libname @wxLIB_TARGETS@)
# use the Release configuration for MinSizeRel and RelWithDebInfo configurations # use the Release configuration for MinSizeRel and RelWithDebInfo configurations
# only when Release target exists, and MinSizeRel/RelWithDebInfo doesn't exist # only when Release target exists, and MinSizeRel/RelWithDebInfo doesn't exist
get_target_property(configs wx::${libname} IMPORTED_CONFIGURATIONS) get_target_property(configs wx::${libname} IMPORTED_CONFIGURATIONS)
list(FIND configs "RELEASE" idxSrc) if("RELEASE" IN_LIST configs)
if(idxSrc GREATER -1) if(NOT "MINSIZEREL" IN_LIST configs)
list(FIND configs "MINSIZEREL" idxSrc) if("MinSizeRel" IN_LIST CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
list(FIND CMAKE_CONFIGURATION_TYPES "MinSizeRel" idxDst) set_target_properties(wx::${libname} PROPERTIES MAP_IMPORTED_CONFIG_MINSIZEREL "Release")
if(idxSrc EQUAL -1 AND (idxDst GREATER -1 OR CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")) endif()
set_target_properties(wx::${libname} PROPERTIES MAP_IMPORTED_CONFIG_MINSIZEREL "Release")
endif() endif()
list(FIND configs "RELWITHDEBINFO" idxSrc) if(NOT "RELWITHDEBINFO" IN_LIST configs)
list(FIND CMAKE_CONFIGURATION_TYPES "RelWithDebInfo" idxDst) if("RelWithDebInfo" IN_LIST CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
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")
set_target_properties(wx::${libname} PROPERTIES MAP_IMPORTED_CONFIG_RELWITHDEBINFO "Release") endif()
endif() endif()
endif() endif()
@ -114,16 +130,26 @@ foreach(libname @wxLIB_TARGETS@)
endif() endif()
# add to FindwxWidgets variable # add to FindwxWidgets variable
list(FIND @PROJECT_NAME@_FIND_COMPONENTS ${name} idx) if(NOT @PROJECT_NAME@_FIND_COMPONENTS OR ${name} IN_LIST @PROJECT_NAME@_FIND_COMPONENTS)
if(NOT @PROJECT_NAME@_FIND_COMPONENTS OR idx GREATER -1)
list(APPEND wxWidgets_LIBRARIES wx::${name}) list(APPEND wxWidgets_LIBRARIES wx::${name})
if(CREATE_WX_TARGET)
target_link_libraries(wxWidgets::wxWidgets INTERFACE wx::${name})
endif()
endif() endif()
endif() endif()
endforeach() 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 no components are specified in find_package, check all of them
if(NOT @PROJECT_NAME@_FIND_COMPONENTS) if(NOT @PROJECT_NAME@_FIND_COMPONENTS)
set(@PROJECT_NAME@_FIND_COMPONENTS ${@PROJECT_NAME@_COMPONENTS}) set(@PROJECT_NAME@_FIND_COMPONENTS ${@PROJECT_NAME@_COMPONENTS})
endif() endif()
check_required_components("@PROJECT_NAME@") check_required_components("@PROJECT_NAME@")
cmake_policy(POP)

View file

@ -84,7 +84,7 @@ in CMake the following generators are recommended:
* macOS: Xcode * macOS: Xcode
* Linux: Ninja or Makefiles * 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} Using CMake with your applications {#cmake_apps}
================================== ==================================

View file

@ -14,7 +14,7 @@
# #
# Declare the minimum required CMake version # 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(APPLE AND NOT CMAKE_OSX_DEPLOYMENT_TARGET)
# If no deployment target has been set default to the minimum supported # 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 # Request the required wxWidgets libs
find_package(wxWidgets 3.3 COMPONENTS core base REQUIRED CONFIG) 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 # Define a variable containing a list of source files for the project
set(SRC_FILES set(SRC_FILES
minimal.cpp minimal.cpp
) )
if(WIN32) if(WIN32)
# Include a RC file for windows # Include a RC file for windows
@ -55,14 +50,20 @@ endif()
# Define the build target for the executable # Define the build target for the executable
add_executable(${PROJECT_NAME} WIN32 MACOSX_BUNDLE ${SRC_FILES}) add_executable(${PROJECT_NAME} WIN32 MACOSX_BUNDLE ${SRC_FILES})
# Link required libraries to the executable # Link executable to the wxWidgets target
target_link_libraries(${PROJECT_NAME} ${wxWidgets_LIBRARIES}) 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 set_target_properties(${PROJECT_NAME} PROPERTIES
RESOURCE "../../src/osx/carbon/wxmac.icns" RESOURCE "../../src/osx/carbon/wxmac.icns"
MACOSX_BUNDLE_ICON_FILE wxmac.icns MACOSX_BUNDLE_ICON_FILE wxmac.icns
MACOSX_BUNDLE_COPYRIGHT "Copyright wxWidgets" MACOSX_BUNDLE_COPYRIGHT "Copyright wxWidgets"
MACOSX_BUNDLE_GUI_IDENTIFIER "org.wxwidgets.minimal" MACOSX_BUNDLE_GUI_IDENTIFIER "org.wxwidgets.minimal"
) )
endif() endif()