Miscellaneous CMake improvements:

- Add more configuration options for CMake installation.
- Only install the headers of the used platform/toolkit.
- Fix some bugs and warnings.

See #24792.
This commit is contained in:
Vadim Zeitlin
2025-01-08 02:51:04 +01:00
13 changed files with 133 additions and 23 deletions
+1 -3
View File
@@ -7,7 +7,7 @@
# Licence: wxWindows licence
#############################################################################
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.5...3.31)
if(NOT CMAKE_CONFIGURATION_TYPES)
get_property(HAVE_MULTI_CONFIG_GENERATOR GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
@@ -17,8 +17,6 @@ if(NOT CMAKE_CONFIGURATION_TYPES)
endif()
endif()
file(TO_CMAKE_PATH "${CMAKE_INSTALL_PREFIX}" CMAKE_INSTALL_PREFIX)
# https://blog.kitware.com/cmake-and-the-default-build-type/
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(default_build_type "Debug")
+46 -9
View File
@@ -21,6 +21,12 @@ else()
endif()
# List of libraries added via wx_add_library() to use for wx-config
# and headers added via wx_append_sources() to use for install.
set(wxLIB_TARGETS)
set(wxINSTALL_HEADERS)
# This function adds a list of headers to a variable while prepending
# include/ to the path
macro(wx_add_headers src_var)
@@ -52,6 +58,14 @@ macro(wx_append_sources src_var source_base_name)
endif()
if(DEFINED ${source_base_name}_HDR)
wx_add_headers(${src_var} ${${source_base_name}_HDR})
list(APPEND wxINSTALL_HEADERS ${${source_base_name}_HDR})
set(wxINSTALL_HEADERS ${wxINSTALL_HEADERS} PARENT_SCOPE)
endif()
if(DEFINED ${source_base_name}_RSC)
list(APPEND wxINSTALL_HEADERS ${${source_base_name}_RSC})
set(wxINSTALL_HEADERS ${wxINSTALL_HEADERS} PARENT_SCOPE)
endif()
endmacro()
@@ -421,8 +435,21 @@ function(wx_set_target_properties target_name)
wx_set_common_target_properties(${target_name})
endfunction()
# List of libraries added via wx_add_library() to use for wx-config
set(wxLIB_TARGETS)
macro(wx_get_install_dir artifact default)
string(TOUPPER ${artifact} artifact_upper)
if(wxBUILD_INSTALL_${artifact_upper}_DIR)
set(${artifact}_dir "${wxBUILD_INSTALL_${artifact_upper}_DIR}")
else()
set(${artifact}_dir ${default})
endif()
if(wxBUILD_INSTALL_PLATFORM_SUBDIR)
if(${artifact}_dir)
wx_string_append(${artifact}_dir ${GEN_EXPR_DIR})
endif()
wx_string_append(${artifact}_dir "${wxPLATFORM_LIB_DIR}")
endif()
endmacro()
# Add a wxWidgets library
# wx_add_library(<target_name> [IS_BASE;IS_PLUGIN;IS_MONO] <src_files>...)
@@ -466,17 +493,27 @@ macro(wx_add_library name)
# Setup install
if(MSYS OR CYGWIN)
# configure puts the .dll in the bin directory
set(runtime_dir "bin")
set(runtime_default_dir "bin")
else()
set(runtime_dir "lib")
set(runtime_default_dir "lib")
endif()
wx_get_install_dir(library "lib")
wx_get_install_dir(archive "lib")
wx_get_install_dir(runtime "${runtime_default_dir}")
wx_install(TARGETS ${name}
EXPORT wxWidgetsTargets
LIBRARY DESTINATION "lib${GEN_EXPR_DIR}${wxPLATFORM_LIB_DIR}"
ARCHIVE DESTINATION "lib${GEN_EXPR_DIR}${wxPLATFORM_LIB_DIR}"
RUNTIME DESTINATION "${runtime_dir}${GEN_EXPR_DIR}${wxPLATFORM_LIB_DIR}"
LIBRARY DESTINATION "${library_dir}"
ARCHIVE DESTINATION "${archive_dir}"
RUNTIME DESTINATION "${runtime_dir}"
BUNDLE DESTINATION Applications/wxWidgets
)
)
if(wxBUILD_SHARED AND MSVC AND wxBUILD_INSTALL_PDB)
wx_install(FILES $<TARGET_PDB_FILE:${name}> DESTINATION "${runtime_dir}")
endif()
wx_target_enable_precomp(${name} "${wxSOURCE_DIR}/include/wx/wxprec.h")
endif()
endmacro()
@@ -883,7 +920,7 @@ function(wx_add name group)
${wxOUTPUT_DIR}/${wxPLATFORM_LIB_DIR}/${data_dst})
endforeach()
add_custom_command(
TARGET ${target_name} ${cmds}
TARGET ${target_name} POST_BUILD ${cmds}
COMMENT "Copying ${target_name} data files...")
endif()
+19 -4
View File
@@ -12,13 +12,28 @@ if(NOT wxBUILD_INSTALL)
endif()
install(CODE "message(STATUS \"Installing: Headers...\")")
install(
DIRECTORY "${wxSOURCE_DIR}/include/wx"
DESTINATION "${wxINSTALL_INCLUDE_DIR}")
foreach(header ${wxINSTALL_HEADERS})
get_filename_component(path "${header}" PATH)
install(
FILES "${wxSOURCE_DIR}/include/${header}"
DESTINATION "${wxINSTALL_INCLUDE_DIR}/${path}"
)
endforeach()
if(MSVC)
install(
DIRECTORY "${wxSOURCE_DIR}/include/msvc"
DESTINATION "${wxINSTALL_INCLUDE_DIR}")
DESTINATION "${wxINSTALL_INCLUDE_DIR}"
)
install(
FILES "${wxSOURCE_DIR}/wxwidgets.props"
DESTINATION "."
)
install(
FILES "${wxSOURCE_DIR}/build/msw/wx_setup.props"
DESTINATION "build/msw"
)
endif()
# setup header and wx-config
+1
View File
@@ -110,3 +110,4 @@ endif()
# Propagate variable(s) to parent scope
set(wxLIB_TARGETS ${wxLIB_TARGETS} PARENT_SCOPE)
set(wxINSTALL_HEADERS ${wxINSTALL_HEADERS} PARENT_SCOPE)
+7 -3
View File
@@ -14,9 +14,13 @@ if(WIN32)
wx_append_sources(BASE_FILES BASE_WIN32)
wx_append_sources(BASE_FILES BASE_AND_GUI_WIN32)
elseif(APPLE)
wx_append_sources(BASE_FILES BASE_OSX_SHARED)
if(WXOSX_COCOA)
wx_append_sources(BASE_FILES BASE_AND_GUI_OSX_COCOA)
if(WXOSX_COCOA OR WXOSX_IPHONE)
wx_append_sources(BASE_FILES BASE_OSX_SHARED)
if(WXOSX_COCOA)
wx_append_sources(BASE_FILES BASE_AND_GUI_OSX_COCOA)
endif()
else()
wx_append_sources(BASE_FILES BASE_OSX_NOTWXMAC)
endif()
elseif(UNIX)
wx_append_sources(BASE_FILES BASE_UNIX)
+2
View File
@@ -28,6 +28,7 @@ if(WXMSW)
endif()
elseif(WXGTK)
if(WXGTK2)
set(GTK2_LOWLEVEL_HDR ${GTK_LOWLEVEL_HDR})
wx_append_sources(CORE_SRC GTK2_LOWLEVEL)
wx_append_sources(CORE_SRC GTK2)
else()
@@ -47,6 +48,7 @@ elseif(WXOSX_COCOA)
wx_append_sources(CORE_SRC OSX_COCOA)
elseif(WXOSX_IPHONE)
wx_append_sources(CORE_SRC OSX_LOWLEVEL)
wx_append_sources(CORE_SRC OSX_SHARED)
wx_append_sources(CORE_SRC OSX_IPHONE)
elseif(WXQT)
wx_append_sources(CORE_SRC QT)
+1 -1
View File
@@ -31,5 +31,5 @@ endif()
if (wxUSE_WEBREQUEST_CURL)
wx_lib_include_directories(wxnet ${CURL_INCLUDE_DIRS})
wx_lib_link_libraries(wxnet PRIVATE ${CURL_LIBRARIES})
wx_lib_link_libraries(wxnet PUBLIC ${CURL_LIBRARIES})
endif()
+36
View File
@@ -0,0 +1,36 @@
if(wxBUILD_LOCALES STREQUAL "AUTO")
find_package(Gettext QUIET)
elseif(wxBUILD_LOCALES)
find_package(Gettext REQUIRED)
endif()
mark_as_advanced(GETTEXT_MSGMERGE_EXECUTABLE)
mark_as_advanced(GETTEXT_MSGFMT_EXECUTABLE)
if(NOT GETTEXT_FOUND OR wxBUILD_LOCALES STREQUAL "OFF")
return()
endif()
# list and process the po files
file(GLOB _po_files "${wxSOURCE_DIR}/locale/*.po")
foreach(_po_file ${_po_files})
get_filename_component(name "${_po_file}" NAME)
string(REGEX REPLACE "\\.[^.]*$" "" lang ${name})
gettext_process_po_files(${lang} ALL PO_FILES "${_po_file}")
wx_install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${lang}.gmo"
DESTINATION "share/locale/${lang}/LC_MESSAGES"
RENAME "wxstd-${wxMAJOR_VERSION}.${wxMINOR_VERSION}.mo"
)
endforeach()
# put all pofiles targets in a group to not clutter visual studio
set(base_name "pofiles")
set(target_index 0)
set(target_name ${base_name})
while(TARGET ${target_name})
set_target_properties(${target_name} PROPERTIES FOLDER "Locales")
math(EXPR target_index "${target_index}+1")
set(target_name "${base_name}_${target_index}")
endwhile()
+3
View File
@@ -9,6 +9,8 @@
list(APPEND CMAKE_MODULE_PATH "${wxSOURCE_DIR}/build/cmake/modules")
file(TO_CMAKE_PATH "${CMAKE_INSTALL_PREFIX}" CMAKE_INSTALL_PREFIX)
include(build/cmake/files.cmake) # Files list
include(build/cmake/source_groups.cmake) # Source group definitions
include(build/cmake/functions.cmake) # wxWidgets functions
@@ -16,6 +18,7 @@ include(build/cmake/toolkit.cmake) # Platform/toolkit settings
include(build/cmake/options.cmake) # User options
include(build/cmake/init.cmake) # Init various global build vars
include(build/cmake/pch.cmake) # Precompiled header support
include(build/cmake/locale.cmake) # Locale files
add_subdirectory(build/cmake/lib libs)
add_subdirectory(build/cmake/utils utils)
+14
View File
@@ -16,6 +16,8 @@ wx_option(wxBUILD_TESTS "Build console tests (CONSOLE_ONLY) or ALL" OFF
STRINGS CONSOLE_ONLY ALL OFF)
wx_option(wxBUILD_DEMOS "Build demos" OFF)
wx_option(wxBUILD_BENCHMARKS "Build benchmarks" OFF)
wx_option(wxBUILD_LOCALES "Build locales" AUTO STRINGS ON OFF AUTO)
mark_as_advanced(wxBUILD_LOCALES)
wx_option(wxBUILD_PRECOMP "Use precompiled headers" ON STRINGS ON OFF COTIRE)
mark_as_advanced(wxBUILD_PRECOMP)
wx_option(wxBUILD_INSTALL "Create install/uninstall target for wxWidgets")
@@ -76,6 +78,18 @@ wx_option(wxBUILD_PIC "Enable position independent code (PIC)." ON)
mark_as_advanced(wxBUILD_PIC)
wx_option(wxUSE_NO_RTTI "disable RTTI support" OFF)
set(wxBUILD_INSTALL_RUNTIME_DIR "" CACHE PATH "override default sub-directory to install runtime files")
mark_as_advanced(wxBUILD_INSTALL_RUNTIME_DIR)
set(wxBUILD_INSTALL_LIBRARY_DIR "" CACHE PATH "override default sub-directory to install library files")
mark_as_advanced(wxBUILD_INSTALL_LIBRARY_DIR)
set(wxBUILD_INSTALL_ARCHIVE_DIR "" CACHE PATH "override default sub-directory to install archive files")
mark_as_advanced(wxBUILD_INSTALL_ARCHIVE_DIR)
wx_option(wxBUILD_INSTALL_PLATFORM_SUBDIR "platform specific sub-directory (MSVC-naming)" ON)
mark_as_advanced(wxBUILD_INSTALL_PLATFORM_SUBDIR)
wx_option(wxBUILD_INSTALL_PDB "install pdb files in the runtime direcotry (MSVC)" OFF)
mark_as_advanced(wxBUILD_INSTALL_PDB)
# STL options
wx_option(wxUSE_STD_IOSTREAM "use standard C++ streams" ON)
wx_option(wxUSE_STD_CONTAINERS "use standard C++ container classes" ON)
+1 -1
View File
@@ -392,7 +392,7 @@ if(UNIX)
check_symbol_exists(inet_addr arpa/inet.h HAVE_INET_ADDR)
endif(wxUSE_SOCKETS)
if(wxUSE_JOYSTICK AND NOT APPLE)
if(wxUSE_JOYSTICK AND WXGTK)
check_include_files("linux/joystick.h" HAVE_JOYSTICK_H)
if(NOT HAVE_JOYSTICK_H)
message(WARNING "wxJoystick is not available")
+1 -1
View File
@@ -143,7 +143,7 @@ if(WXQT)
endif()
endif()
if(APPLE)
if(wxBUILD_TOOLKIT MATCHES "osx_cocoa")
list(APPEND wxTOOLKIT_DEFINITIONS __WXMAC__ __WXOSX__)
endif()
+1 -1
View File
@@ -14,7 +14,7 @@
#
# Declare the minimum required CMake version
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.5...3.31)
if(APPLE AND NOT CMAKE_OSX_DEPLOYMENT_TARGET)
# If no deployment target has been set default to the minimum supported