1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051
|
#############################################################################
# Name: build/cmake/functions.cmake
# Purpose: Common CMake functions for wxWidgets
# Author: Tobias Taschner
# Created: 2016-09-20
# Copyright: (c) 2016 wxWidgets development team
# Licence: wxWindows licence
#############################################################################
include(CMakeDependentOption)
include(CMakeParseArguments) # For compatibility with CMake < 3.4
include(ExternalProject)
include(CMakePrintHelpers)
# Use the MSVC/makefile naming convention, or the configure naming convention,
# this is the same check as used in FindwxWidgets.
if(WIN32 AND NOT CYGWIN AND NOT MSYS)
set(WIN32_MSVC_NAMING 1)
else()
set(WIN32_MSVC_NAMING 0)
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)
set(headers)
foreach(header ${ARGN})
list(APPEND headers ${wxSOURCE_DIR}/include/${header})
if(header MATCHES "\\.cpp$")
# .cpp files in include directory should not be compiled
if (wxBUILD_MONOLITHIC)
# set_source_files_properties only works within the same CMakeLists.txt
list(APPEND wxMONO_NONCOMPILED_CPP_FILES ${wxSOURCE_DIR}/include/${header})
set(wxMONO_NONCOMPILED_CPP_FILES ${wxMONO_NONCOMPILED_CPP_FILES} PARENT_SCOPE)
else()
set_source_files_properties(${wxSOURCE_DIR}/include/${header}
PROPERTIES HEADER_FILE_ONLY TRUE)
endif()
endif()
endforeach()
list(APPEND ${src_var} ${headers})
endmacro()
# Add sources from a ..._SRC variable and headers from a ..._HDR
macro(wx_append_sources src_var source_base_name)
if(NOT DEFINED ${src_var})
set(${src_var} "")
endif()
if(DEFINED ${source_base_name}_SRC)
wx_list_add_prefix(${src_var} "${wxSOURCE_DIR}/" ${${source_base_name}_SRC})
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()
# Add prefix to list of items
# wx_list_add_prefix(<out_var> <pref> <items...>)
macro(wx_list_add_prefix out_var prefix)
foreach(item ${ARGN})
list(APPEND ${out_var} ${prefix}${item})
endforeach()
endmacro()
# Older cmake versions don't support string(APPEND ...) provide a workaround
macro(wx_string_append var str)
set(${var} ${${var}}${str})
endmacro()
# wx_install(...)
# Forward to install call if wxBUILD_INSTALL is enabled
macro(wx_install)
if(wxBUILD_INSTALL)
install(${ARGN})
endif()
endmacro()
# Get a valid flavour name with optional prefix
macro(wx_get_flavour flavour prefix)
if(wxBUILD_FLAVOUR)
set(flav ${wxBUILD_FLAVOUR})
string(REPLACE "-" "_" flav ${flav})
set(${flavour} "${prefix}${flav}")
else()
set(${flavour})
endif()
endmacro()
if(WIN32_MSVC_NAMING)
# Generator expression to not create different Debug and Release directories
set(GEN_EXPR_DIR "$<1:/>")
set(wxINSTALL_INCLUDE_DIR "include")
else()
set(GEN_EXPR_DIR "/")
wx_get_flavour(lib_flavour "-")
set(wxINSTALL_INCLUDE_DIR "include/wx-${wxMAJOR_VERSION}.${wxMINOR_VERSION}${lib_flavour}")
endif()
# Set properties common to builtin third party libraries and wx libs
function(wx_set_common_target_properties target_name)
cmake_parse_arguments(wxCOMMON_TARGET_PROPS "DEFAULT_WARNINGS" "" "" ${ARGN})
set_target_properties(${target_name} PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${wxOUTPUT_DIR}${GEN_EXPR_DIR}${wxPLATFORM_LIB_DIR}"
ARCHIVE_OUTPUT_DIRECTORY "${wxOUTPUT_DIR}${GEN_EXPR_DIR}${wxPLATFORM_LIB_DIR}"
RUNTIME_OUTPUT_DIRECTORY "${wxOUTPUT_DIR}${GEN_EXPR_DIR}${wxPLATFORM_LIB_DIR}"
)
if(wxBUILD_PIC)
set_target_properties(${target_name} PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
endif()
if(NOT WIN32 AND wxUSE_VISIBILITY)
set_target_properties(${target_name} PROPERTIES
C_VISIBILITY_PRESET hidden
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN TRUE
)
endif()
if(MSVC)
if(wxCOMMON_TARGET_PROPS_DEFAULT_WARNINGS)
set(MSVC_WARNING_LEVEL "/W3")
else()
set(MSVC_WARNING_LEVEL "/W4")
endif()
target_compile_options(${target_name} PRIVATE ${MSVC_WARNING_LEVEL})
if(CMAKE_VERSION GREATER_EQUAL "3.15")
set(msvc_runtime "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
if(wxBUILD_USE_STATIC_RUNTIME)
set(msvc_runtime "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
set_target_properties(${target_name} PROPERTIES MSVC_RUNTIME_LIBRARY ${msvc_runtime})
endif()
elseif(NOT wxCOMMON_TARGET_PROPS_DEFAULT_WARNINGS)
set(common_gcc_clang_compile_options
-Wall
-Wundef
-Wunused-parameter
)
set(common_gcc_clang_cpp_compile_options
-Wno-ctor-dtor-privacy
-Woverloaded-virtual
)
if(WXOSX_COCOA OR WXGTK3)
# when building using GTK+ 3 or Cocoa we currently get tons of deprecation
# warnings from the standard headers -- disable them as we already know
# that they're deprecated but we still have to use them to support older
# toolkit versions and leaving this warning enabled prevents seeing any
# other ones
list(APPEND common_gcc_clang_compile_options
-Wno-deprecated-declarations
)
endif()
if(APPLE)
# Xcode automatically adds -Wshorten-64-to-32 to C++ flags
# and it causes a lot of warnings in wx code
list(APPEND common_gcc_clang_compile_options
-Wno-shorten-64-to-32
)
endif()
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
list(APPEND common_gcc_clang_compile_options
-Wno-ignored-attributes
)
endif()
target_compile_options(${target_name} PRIVATE
${common_gcc_clang_compile_options}
$<$<COMPILE_LANGUAGE:CXX>:${common_gcc_clang_cpp_compile_options}>
)
endif()
if(wxUSE_NO_RTTI)
if(MSVC)
target_compile_options(${target_name} PRIVATE "/GR-")
elseif(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang"))
target_compile_options(${target_name} PRIVATE "-fno-rtti")
endif()
target_compile_definitions(${target_name} PRIVATE "-DwxNO_RTTI")
endif()
if(wxBUILD_LARGEFILE_SUPPORT)
target_compile_definitions(${target_name} PUBLIC "-D_FILE_OFFSET_BITS=64")
endif()
if(CMAKE_THREAD_LIBS_INIT)
target_compile_options(${target_name} PRIVATE ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(${target_name} PUBLIC ${CMAKE_THREAD_LIBS_INIT})
endif()
wx_set_source_groups()
endfunction()
# Set common properties on wx library target
function(wx_set_target_properties target_name)
cmake_parse_arguments(wxTARGET "IS_BASE;IS_PLUGIN;IS_MONO" "" "" ${ARGN})
if(${target_name} MATCHES "wx.*")
string(SUBSTRING ${target_name} 2 -1 target_name_short)
else()
set(target_name_short ${target_name})
endif()
# Set library name according to:
# docs/contributing/about-platform-toolkit-and-library-names.md
if(wxTARGET_IS_BASE)
set(lib_toolkit base)
else()
set(lib_toolkit ${wxBUILD_TOOLKIT}${wxBUILD_WIDGETSET})
endif()
if(WIN32_MSVC_NAMING)
set(lib_version ${wxMAJOR_VERSION}${wxMINOR_VERSION})
else()
set(lib_version ${wxMAJOR_VERSION}.${wxMINOR_VERSION})
endif()
set(dll_version ${wxMAJOR_VERSION}${wxMINOR_VERSION})
if(wxVERSION_IS_DEV)
wx_string_append(dll_version ${wxRELEASE_NUMBER})
endif()
set(lib_unicode)
if(wxUSE_UNICODE)
set(lib_unicode "u")
endif()
set(lib_rls)
set(lib_dbg)
set(lib_gen)
if(WIN32_MSVC_NAMING)
set(lib_dbg "d")
set(lib_gen "$<$<CONFIG:Debug>:${lib_dbg}>")
endif()
set(lib_suffix)
if(NOT target_name_short STREQUAL "base" AND NOT wxTARGET_IS_MONO)
# Do not append library name for base or mono library
set(lib_suffix "_${target_name_short}")
endif()
wx_get_flavour(lib_flavour "_")
set(lib_suffix "${lib_flavour}${lib_suffix}")
set(dll_suffix "${lib_suffix}")
if(wxCOMPILER_PREFIX)
wx_string_append(dll_suffix "_${wxCOMPILER_PREFIX}")
endif()
# For compatibility with MSVS project files and makefile.vc, use arch
# suffix for non-x86 (including x86_64) DLLs.
if(MSVC AND wxARCH_SUFFIX)
# This one already includes the leading underscore, so don't add another one.
wx_string_append(dll_suffix "${wxARCH_SUFFIX}")
endif()
if(wxBUILD_VENDOR)
wx_string_append(dll_suffix "_${wxBUILD_VENDOR}")
endif()
set(cross_target)
if (CMAKE_CROSSCOMPILING)
set(cross_target "-${CMAKE_SYSTEM_NAME}")
endif()
set(lib_prefix "lib")
if(MSVC OR (WIN32 AND wxBUILD_SHARED))
set(lib_prefix)
elseif (CYGWIN AND wxBUILD_SHARED)
set(lib_prefix "cyg")
endif()
# static (and import) library names
if(WIN32_MSVC_NAMING)
# match msvc/makefile output name
set(wxOUTPUT_NAME "wx${lib_toolkit}${lib_version}${lib_unicode}${lib_rls}${lib_suffix}")
set(wxOUTPUT_NAME_DEBUG "wx${lib_toolkit}${lib_version}${lib_unicode}${lib_dbg}${lib_suffix}")
else()
# match configure output name
set(wxOUTPUT_NAME "wx_${lib_toolkit}${lib_unicode}${lib_rls}${lib_suffix}-${lib_version}${cross_target}")
set(wxOUTPUT_NAME_DEBUG "wx_${lib_toolkit}${lib_unicode}${lib_dbg}${lib_suffix}-${lib_version}${cross_target}")
endif()
# shared library names
if(WIN32)
# msvc/makefile/configure use the same format on Windows
set(wxRUNTIME_OUTPUT_NAME "wx${lib_toolkit}${dll_version}${lib_unicode}${lib_rls}${dll_suffix}")
set(wxRUNTIME_OUTPUT_NAME_DEBUG "wx${lib_toolkit}${dll_version}${lib_unicode}${lib_dbg}${dll_suffix}")
set(wxDLLNAME "wx${lib_toolkit}${dll_version}${lib_unicode}${lib_gen}${dll_suffix}")
else()
# match configure on linux/mac
set(wxRUNTIME_OUTPUT_NAME "wx_${lib_toolkit}${lib_unicode}${lib_rls}${dll_suffix}-${lib_version}${cross_target}")
set(wxRUNTIME_OUTPUT_NAME_DEBUG "wx_${lib_toolkit}${lib_unicode}${lib_dbg}${dll_suffix}-${lib_version}${cross_target}")
set(wxDLLNAME "wx_${lib_toolkit}${lib_unicode}${lib_gen}${dll_suffix}-${lib_version}${cross_target}")
endif()
set_target_properties(${target_name} PROPERTIES
OUTPUT_NAME "${wxOUTPUT_NAME}"
OUTPUT_NAME_DEBUG "${wxOUTPUT_NAME_DEBUG}"
RUNTIME_OUTPUT_NAME "${wxRUNTIME_OUTPUT_NAME}"
RUNTIME_OUTPUT_NAME_DEBUG "${wxRUNTIME_OUTPUT_NAME_DEBUG}"
PREFIX "${lib_prefix}"
)
if(WIN32_MSVC_NAMING AND NOT MSVC)
# match makefile.gcc, use .a instead of .dll.a for import libraries
set_target_properties(${target_name} PROPERTIES IMPORT_SUFFIX ".a")
endif()
if(wxBUILD_SHARED)
target_compile_definitions(${target_name} PRIVATE "WXDLLNAME=${wxDLLNAME}")
endif()
if(CYGWIN)
target_link_libraries(${target_name} PUBLIC -L/usr/lib/w32api)
endif()
# Set common compile definitions
target_compile_definitions(${target_name} PRIVATE WXBUILDING)
if(wxTARGET_IS_MONO AND wxUSE_GUI)
target_compile_definitions(${target_name} PRIVATE wxUSE_GUI=1 wxUSE_BASE=1)
elseif(wxTARGET_IS_PLUGIN)
target_compile_definitions(${target_name} PRIVATE wxUSE_GUI=0 wxUSE_BASE=0)
elseif(wxTARGET_IS_BASE OR NOT wxUSE_GUI)
target_compile_definitions(${target_name} PRIVATE wxUSE_GUI=0 wxUSE_BASE=1)
else()
target_compile_definitions(${target_name} PRIVATE wxUSE_GUI=1 wxUSE_BASE=0)
endif()
if(wxUSE_UNICODE)
if(WIN32)
target_compile_definitions(${target_name} PUBLIC UNICODE)
endif()
target_compile_definitions(${target_name} PUBLIC _UNICODE)
endif()
if(WIN32 AND MSVC)
# Suppress deprecation warnings for standard library calls
target_compile_definitions(${target_name} PRIVATE
_CRT_SECURE_NO_DEPRECATE=1
_CRT_NON_CONFORMING_SWPRINTFS=1
_SCL_SECURE_NO_WARNINGS=1
_WINSOCK_DEPRECATED_NO_WARNINGS=1
)
endif()
file(RELATIVE_PATH wxSETUP_HEADER_REL ${wxOUTPUT_DIR} ${wxSETUP_HEADER_PATH})
target_include_directories(${target_name}
BEFORE
PUBLIC
$<BUILD_INTERFACE:${wxSETUP_HEADER_PATH}>
$<BUILD_INTERFACE:${wxSOURCE_DIR}/include>
$<INSTALL_INTERFACE:lib/${wxSETUP_HEADER_REL}>
$<INSTALL_INTERFACE:${wxINSTALL_INCLUDE_DIR}>
)
if(wxTOOLKIT_INCLUDE_DIRS AND NOT wxTARGET_IS_BASE)
target_include_directories(${target_name}
PRIVATE ${wxTOOLKIT_INCLUDE_DIRS})
endif()
if (WIN32)
set(WIN32_LIBRARIES
kernel32
user32
gdi32
comdlg32
winspool
winmm
shell32
shlwapi
comctl32
ole32
oleaut32
uuid
rpcrt4
advapi32
version
ws2_32
wininet
oleacc
uxtheme
)
target_link_libraries(${target_name}
PUBLIC ${WIN32_LIBRARIES})
endif()
if(wxTOOLKIT_LIBRARIES AND NOT wxTARGET_IS_BASE)
target_link_libraries(${target_name}
PUBLIC ${wxTOOLKIT_LIBRARIES})
endif()
target_compile_definitions(${target_name}
PUBLIC ${wxTOOLKIT_DEFINITIONS})
if(wxBUILD_SHARED)
string(TOUPPER ${target_name_short} target_name_upper)
if(wxTARGET_IS_MONO)
target_compile_definitions(${target_name} PRIVATE WXMAKINGDLL)
elseif(NOT wxTARGET_IS_PLUGIN)
target_compile_definitions(${target_name} PRIVATE WXMAKINGDLL_${target_name_upper})
endif()
target_compile_definitions(${target_name} INTERFACE WXUSINGDLL)
endif()
if(wxTARGET_IS_PLUGIN OR (wxBUILD_SHARED AND NOT target_name_short STREQUAL "base"))
target_compile_definitions(${target_name} PRIVATE WXUSINGDLL)
endif()
# Link common libraries
if(NOT wxTARGET_IS_MONO AND NOT wxTARGET_IS_PLUGIN)
if(NOT target_name_short STREQUAL "base")
# All libraries except base need the base library
target_link_libraries(${target_name} PUBLIC wxbase)
endif()
if(NOT wxTARGET_IS_BASE AND NOT target_name_short STREQUAL "core")
# All non base libraries except core need core
target_link_libraries(${target_name} PUBLIC wxcore)
endif()
endif()
set_target_properties(${target_name} PROPERTIES FOLDER Libraries)
set_target_properties(${target_name} PROPERTIES
SOVERSION ${wxSOVERSION_MAJOR}
VERSION ${wxSOVERSION}
)
wx_set_common_target_properties(${target_name})
endfunction()
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>...)
# first parameter is the name of the library
# the second parameter is the type of library, empty for a UI library
# all additional parameters are source files for the library
macro(wx_add_library name)
cmake_parse_arguments(wxADD_LIBRARY "IS_BASE;IS_PLUGIN;IS_MONO" "" "" ${ARGN})
set(src_files ${wxADD_LIBRARY_UNPARSED_ARGUMENTS})
list(APPEND wxLIB_TARGETS ${name})
set(wxLIB_TARGETS ${wxLIB_TARGETS} PARENT_SCOPE)
if(wxBUILD_MONOLITHIC AND NOT wxADD_LIBRARY_IS_MONO)
# collect all source files for mono library
set(wxMONO_SRC_FILES ${wxMONO_SRC_FILES} ${src_files} PARENT_SCOPE)
else()
list(APPEND src_files ${wxSETUP_HEADER_FILE})
if(wxBUILD_SHARED)
set(wxBUILD_LIB_TYPE SHARED)
if(WIN32)
# Add WIN32 version information
list(APPEND src_files "${wxSOURCE_DIR}/src/msw/version.rc" "${wxSOURCE_DIR}/include/wx/msw/genrcdefs.h")
endif()
else()
set(wxBUILD_LIB_TYPE STATIC)
endif()
if(${name} MATCHES "wx.*")
string(SUBSTRING ${name} 2 -1 name_short)
else()
set(name_short ${name})
endif()
add_library(${name} ${wxBUILD_LIB_TYPE} ${src_files})
add_library(wx::${name_short} ALIAS ${name})
wx_set_target_properties(${name} ${ARGN})
set_target_properties(${name} PROPERTIES PROJECT_LABEL ${name_short})
# Setup install
if(MSYS OR CYGWIN)
# configure puts the .dll in the bin directory
set(runtime_default_dir "bin")
else()
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 "${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()
# wx_lib_link_libraries(name [])
# Forwards everything to target_link_libraries() except for monolithic
# build where it collects all libraries for linking with the mono lib
macro(wx_lib_link_libraries name)
if(wxBUILD_MONOLITHIC)
cmake_parse_arguments(_LIB_LINK "" "" "PUBLIC;PRIVATE" ${ARGN})
list(APPEND wxMONO_LIBS_PUBLIC ${_LIB_LINK_PUBLIC})
list(APPEND wxMONO_LIBS_PRIVATE ${_LIB_LINK_PRIVATE})
set(wxMONO_LIBS_PUBLIC ${wxMONO_LIBS_PUBLIC} PARENT_SCOPE)
set(wxMONO_LIBS_PRIVATE ${wxMONO_LIBS_PRIVATE} PARENT_SCOPE)
else()
target_link_libraries(${name};${ARGN})
endif()
endmacro()
# wx_exe_link_libraries(target libs...)
# Link wx libraries to executable
macro(wx_exe_link_libraries name)
if(TARGET ${name})
if(wxBUILD_MONOLITHIC)
target_link_libraries(${name} PUBLIC wxmono)
else()
target_link_libraries(${name};PRIVATE;${ARGN})
endif()
endif()
endmacro()
# wx_lib_include_directories(name files)
# Forwards everything to target_include_directories() except for monolithic
# build where it collects all include paths for linking with the mono lib
macro(wx_lib_include_directories name)
if(wxBUILD_MONOLITHIC)
list(APPEND wxMONO_INCLUDE_DIRS ${ARGN})
set(wxMONO_INCLUDE_DIRS ${wxMONO_INCLUDE_DIRS} PARENT_SCOPE)
else()
target_include_directories(${name} BEFORE PRIVATE ${ARGN})
endif()
endmacro()
# wx_lib_compile_definitions(name defs)
# Forwards everything to target_compile_definitions() except for monolithic
# build where it collects all definitions for linking with the mono lib
macro(wx_lib_compile_definitions name)
if(wxBUILD_MONOLITHIC)
list(APPEND wxMONO_DEFINITIONS ${ARGN})
set(wxMONO_DEFINITIONS ${wxMONO_DEFINITIONS} PARENT_SCOPE)
else()
target_compile_definitions(${name} PRIVATE ${ARGN})
endif()
endmacro()
# wx_add_dependencies(name dep)
# Forwards everything to add_dependencies() except for monolithic
# build where it collects all dependencies for linking with the mono lib
macro(wx_add_dependencies name)
if(wxBUILD_MONOLITHIC)
list(APPEND wxMONO_DEPENDENCIES ${ARGN})
set(wxMONO_DEPENDENCIES ${wxMONO_DEPENDENCIES} PARENT_SCOPE)
else()
add_dependencies(${name} ${ARGN})
endif()
endmacro()
# Set common properties for a builtin third party library
function(wx_set_builtin_target_properties target_name)
set(lib_unicode)
if(wxUSE_UNICODE AND target_name STREQUAL "wxregex")
set(lib_unicode "u")
endif()
set(lib_rls)
set(lib_dbg)
if(WIN32_MSVC_NAMING)
set(lib_dbg "d")
endif()
wx_get_flavour(lib_flavour "_")
set(lib_version)
if(NOT WIN32_MSVC_NAMING)
set(lib_version "-${wxMAJOR_VERSION}.${wxMINOR_VERSION}")
endif()
set_target_properties(${target_name} PROPERTIES
OUTPUT_NAME "${target_name}${lib_unicode}${lib_rls}${lib_flavour}${lib_version}"
OUTPUT_NAME_DEBUG "${target_name}${lib_unicode}${lib_dbg}${lib_flavour}${lib_version}"
)
if(wxUSE_UNICODE)
if(WIN32)
target_compile_definitions(${target_name} PUBLIC UNICODE)
endif()
target_compile_definitions(${target_name} PUBLIC _UNICODE)
endif()
if(MSVC)
# we're not interested in deprecation warnings about the use of
# standard C functions in the 3rd party libraries (these warnings
# are only given by VC8+ but it's simpler to just always define
# this symbol which disables them, even for previous VC versions)
target_compile_definitions(${target_name} PRIVATE
_CRT_SECURE_NO_DEPRECATE=1
_SCL_SECURE_NO_WARNINGS=1
)
endif()
target_include_directories(${target_name} BEFORE PRIVATE ${wxSETUP_HEADER_PATH})
set_target_properties(${target_name} PROPERTIES FOLDER "Third Party Libraries")
if(wxBUILD_SHARED OR wxBUILD_PIC)
set_target_properties(${target_name} PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
endif()
wx_set_common_target_properties(${target_name} DEFAULT_WARNINGS)
if(NOT wxBUILD_SHARED)
wx_install(TARGETS ${name} EXPORT wxWidgetsTargets ARCHIVE DESTINATION "lib${GEN_EXPR_DIR}${wxPLATFORM_LIB_DIR}")
endif()
endfunction()
# Add a third party builtin library
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()
set(name_short ${name})
endif()
add_library(${name} STATIC ${src_list})
add_library(wx::${name_short} ALIAS ${name})
wx_set_builtin_target_properties(${name})
set_target_properties(${name} PROPERTIES PROJECT_LABEL ${name_short})
endfunction()
# List of third party libraries added via wx_add_thirdparty_library()
# to display in configuration summary
set(wxTHIRD_PARTY_LIBRARIES)
# Add third party library
function(wx_add_thirdparty_library var_name lib_name help_str)
cmake_parse_arguments(THIRDPARTY "" "DEFAULT;DEFAULT_APPLE;DEFAULT_WIN32" "" ${ARGN})
if(THIRDPARTY_DEFAULT)
set(thirdparty_lib_default ${THIRDPARTY_DEFAULT})
elseif(THIRDPARTY_DEFAULT_APPLE AND APPLE)
set(thirdparty_lib_default ${THIRDPARTY_DEFAULT_APPLE})
elseif(THIRDPARTY_DEFAULT_WIN32 AND WIN32)
set(thirdparty_lib_default ${THIRDPARTY_DEFAULT_WIN32})
elseif(UNIX AND NOT APPLE)
# Try sys libraries for MSYS and CYGWIN
set(thirdparty_lib_default sys)
elseif(WIN32 OR APPLE)
# On Windows or apple platforms prefer using the builtin libraries
set(thirdparty_lib_default builtin)
else()
set(thirdparty_lib_default sys)
endif()
wx_option(${var_name} ${help_str} ${thirdparty_lib_default}
STRINGS builtin sys OFF)
if(${var_name} STREQUAL "sys")
# If the sys library can not be found use builtin
find_package(${lib_name})
if(NOT ${lib_name}_FOUND)
wx_option_force_value(${var_name} builtin)
endif()
endif()
set(wxTHIRD_PARTY_LIBRARIES ${wxTHIRD_PARTY_LIBRARIES} ${var_name} "${help_str}" PARENT_SCOPE)
endfunction()
function(wx_print_thirdparty_library_summary)
set(nameLength 0)
set(nameValLength 0)
set(var_name)
foreach(entry IN LISTS wxTHIRD_PARTY_LIBRARIES)
if(NOT var_name)
set(var_name ${entry})
else()
string(LENGTH ${var_name} len)
if(len GREATER nameLength)
set(nameLength ${len})
endif()
string(LENGTH ${${var_name}} len)
if(len GREATER nameValLength)
set(nameValLength ${len})
endif()
set(var_name)
endif()
endforeach()
math(EXPR nameLength "${nameLength}+1") # account for :
set(message "Which libraries should wxWidgets use?\n")
foreach(entry IN LISTS wxTHIRD_PARTY_LIBRARIES)
if(NOT var_name)
set(var_name ${entry})
else()
set(namestr "${var_name}: ")
set(nameval "${${var_name}} ")
string(SUBSTRING ${namestr} 0 ${nameLength} namestr)
string(SUBSTRING ${nameval} 0 ${nameValLength} nameval)
wx_string_append(message " ${namestr} ${nameval} (${entry})\n")
set(var_name)
endif()
endforeach()
message(STATUS ${message})
endfunction()
# Add sample, test, demo or benchmark
# wx_add(<name> <group> [CONSOLE|CONSOLE_GUI|DLL] [IMPORTANT] [SRC_FILES...]
# [LIBRARIES ...] [NAME target_name] [FOLDER folder]
# [DATA ...] [DEFINITIONS ...] [RES ...] [PLIST ...)
# name default target name
# group can be Samples, Tests, Demos or Benchmarks
# first parameter may be CONSOLE to indicate a console application or DLL to indicate a shared library
# or CONSOLE_GUI to indicate a console application that uses gui libraries
# all following parameters are src files for the executable
#
# Optionally:
# IMPORTANT (samples only) does not require wxBUILD_SAMPLES=ALL
# LIBRARIES followed by required libraries
# NAME alternative target_name
# FOLDER subfolder in IDE
# DATA followed by required data files. Use a colon to separate different source and dest paths
# DEFINITIONS list of definitions for the target
# RES followed by WIN32 .rc files
# PLIST followed by macOS Info.plist.in file
#
# Additionally the following variables may be set before calling wx_add_sample:
# wxSAMPLE_SUBDIR subdirectory in the samples/ folder to use as base
# wxSAMPLE_FOLDER IDE sub folder to be used for the samples
function(wx_add_sample name)
wx_add(${name} "Samples" ${ARGN})
endfunction()
function(wx_add_test name)
wx_add(${name} "Tests" ${ARGN})
endfunction()
function(wx_add_demo name)
wx_add(${name} "Demos" ${ARGN})
endfunction()
function(wx_add_benchmark name)
wx_add(${name} "Benchmarks" ${ARGN})
endfunction()
function(wx_add name group)
cmake_parse_arguments(APP
"CONSOLE;CONSOLE_GUI;DLL;IMPORTANT"
"NAME;FOLDER"
"DATA;DEFINITIONS;DEPENDS;LIBRARIES;RES;PLIST"
${ARGN}
)
if(APP_NAME)
set(target_name ${APP_NAME})
else()
set(target_name ${name})
endif()
if(group STREQUAL Samples)
if(NOT APP_IMPORTANT AND NOT wxBUILD_SAMPLES STREQUAL "ALL")
return()
endif()
set(SUB_DIR "samples/${wxSAMPLE_SUBDIR}${name}")
set(DEFAULT_RC_FILE "samples/sample.rc")
elseif(group STREQUAL Tests)
if(NOT APP_CONSOLE AND NOT wxBUILD_TESTS STREQUAL "ALL")
return()
endif()
set(SUB_DIR "tests")
set(DEFAULT_RC_FILE "samples/sample.rc")
elseif(group STREQUAL Demos)
set(SUB_DIR "demos/${name}")
set(DEFAULT_RC_FILE "demos/${name}/${target_name}.rc")
elseif(group STREQUAL Benchmarks)
set(SUB_DIR "tests/benchmarks")
set(DEFAULT_RC_FILE "samples/sample.rc")
else()
message(WARNING "Unknown group \"${group}\"")
return()
endif()
foreach(depend ${APP_DEPENDS})
if(NOT ${depend})
return()
endif()
endforeach()
# Only build GUI applications with wxUSE_GUI=1
if(NOT wxUSE_GUI AND NOT APP_CONSOLE)
return()
endif()
if(APP_UNPARSED_ARGUMENTS)
wx_list_add_prefix(src_files
"${wxSOURCE_DIR}/${SUB_DIR}/"
${APP_UNPARSED_ARGUMENTS})
else()
# If no source files have been specified use default src name
set(src_files ${wxSOURCE_DIR}/${SUB_DIR}/${name}.cpp)
endif()
if(WIN32)
if(APP_RES)
foreach(res ${APP_RES})
list(APPEND src_files ${wxSOURCE_DIR}/${SUB_DIR}/${res})
endforeach()
else()
# Include default resource file
list(APPEND src_files ${wxSOURCE_DIR}/${DEFAULT_RC_FILE})
endif()
elseif(APPLE AND NOT IPHONE)
list(APPEND src_files ${wxSOURCE_DIR}/src/osx/carbon/wxmac.icns)
endif()
if(APP_DLL)
add_library(${target_name} SHARED ${src_files})
else()
if(APP_CONSOLE OR APP_CONSOLE_GUI)
set(exe_type)
else()
set(exe_type WIN32 MACOSX_BUNDLE)
endif()
if (WXMSW AND DEFINED wxUSE_DPI_AWARE_MANIFEST)
set(wxUSE_DPI_AWARE_MANIFEST_VALUE 0)
if (${wxUSE_DPI_AWARE_MANIFEST} MATCHES "system")
set(wxUSE_DPI_AWARE_MANIFEST_VALUE 1)
list(APPEND src_files "${wxSOURCE_DIR}/include/wx/msw/wx_dpi_aware.manifest")
elseif(${wxUSE_DPI_AWARE_MANIFEST} MATCHES "per-monitor")
set(wxUSE_DPI_AWARE_MANIFEST_VALUE 2)
list(APPEND src_files "${wxSOURCE_DIR}/include/wx/msw/wx_dpi_aware_pmv2.manifest")
endif()
endif()
add_executable(${target_name} ${exe_type} ${src_files})
if (DEFINED wxUSE_DPI_AWARE_MANIFEST_VALUE)
target_compile_definitions(${target_name} PRIVATE wxUSE_DPI_AWARE_MANIFEST=${wxUSE_DPI_AWARE_MANIFEST_VALUE})
endif()
endif()
# All applications use at least the base library other libraries
# will have to be added with wx_link_sample_libraries()
wx_exe_link_libraries(${target_name} wxbase)
if(NOT APP_CONSOLE)
# UI applications always require core
wx_exe_link_libraries(${target_name} wxcore)
else()
target_compile_definitions(${target_name} PRIVATE wxUSE_GUI=0 wxUSE_BASE=1)
endif()
if(APP_LIBRARIES)
wx_exe_link_libraries(${target_name} ${APP_LIBRARIES})
endif()
if(APP_DEFINITIONS)
target_compile_definitions(${target_name} PRIVATE ${APP_DEFINITIONS})
endif()
if(group STREQUAL Samples)
target_include_directories(${target_name} PRIVATE ${wxSOURCE_DIR}/samples)
elseif(group STREQUAL Tests)
target_include_directories(${target_name} PRIVATE ${wxSOURCE_DIR}/tests)
target_include_directories(${target_name} PRIVATE ${wxSOURCE_DIR}/3rdparty/catch/include)
target_include_directories(${target_name} PRIVATE ${wxTOOLKIT_INCLUDE_DIRS})
endif()
if(APP_DATA)
# TODO: handle data files differently for OS X bundles
# Copy data files to output directory
foreach(data_src ${APP_DATA})
string(FIND ${data_src} ":" HAS_COLON)
if(${HAS_COLON} GREATER -1)
MATH(EXPR DEST_INDEX "${HAS_COLON}+1")
string(SUBSTRING ${data_src} ${DEST_INDEX} -1 data_dst)
string(SUBSTRING ${data_src} 0 ${HAS_COLON} data_src)
else()
set(data_dst ${data_src})
endif()
list(APPEND cmds COMMAND ${CMAKE_COMMAND}
-E copy ${wxSOURCE_DIR}/${SUB_DIR}/${data_src}
${wxOUTPUT_DIR}/${wxPLATFORM_LIB_DIR}/${data_dst})
endforeach()
add_custom_command(
TARGET ${target_name} POST_BUILD ${cmds}
COMMENT "Copying ${target_name} data files...")
endif()
if(APPLE)
if(NOT IPHONE)
set(PLIST_FILE "${wxSOURCE_DIR}/src/osx/carbon/Info.plist.in")
if(APP_PLIST)
set(PLIST_FILE "${wxSOURCE_DIR}/${SUB_DIR}/${APP_PLIST}")
endif()
set_target_properties(${target_name} PROPERTIES
MACOSX_BUNDLE_INFO_PLIST "${PLIST_FILE}"
RESOURCE "${wxSOURCE_DIR}/src/osx/carbon/wxmac.icns")
endif()
set_target_properties(${target_name} PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER "org.wxwidgets.${target_name}"
MACOSX_BUNDLE_EXECUTABLE_NAME "${target_name}"
MACOSX_BUNDLE_BUNDLE_NAME "${target_name}"
MACOSX_BUNDLE_COPYRIGHT "Copyright ${wxCOPYRIGHT}"
MACOSX_BUNDLE_BUNDLE_VERSION "${wxVERSION}"
MACOSX_BUNDLE_INFO_STRING "${target_name} version ${wxVERSION}, (c) ${wxCOPYRIGHT}"
MACOSX_BUNDLE_LONG_VERSION_STRING "${wxVERSION}, (c) ${wxCOPYRIGHT}"
MACOSX_BUNDLE_SHORT_VERSION_STRING "${wxMAJOR_VERSION}.${wxMINOR_VERSION}"
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "org.wxwidgets.${target_name}"
)
endif()
if(APP_FOLDER)
set(APP_FOLDER ${group}/${APP_FOLDER})
elseif(wxSAMPLE_FOLDER)
set(APP_FOLDER ${group}/${wxSAMPLE_FOLDER})
else()
set(APP_FOLDER ${group})
endif()
wx_set_common_target_properties(${target_name})
wx_target_enable_precomp(${target_name} "${wxSOURCE_DIR}/include/wx/wxprec.h")
set_target_properties(${target_name} PROPERTIES
FOLDER ${APP_FOLDER}
)
set_target_properties(${target_name} PROPERTIES
VS_DEBUGGER_WORKING_DIRECTORY "${wxOUTPUT_DIR}/${wxPLATFORM_LIB_DIR}"
)
if(group STREQUAL Tests)
add_test(NAME ${target_name}
COMMAND ${target_name}
WORKING_DIRECTORY "${wxOUTPUT_DIR}/${wxPLATFORM_LIB_DIR}")
endif()
endfunction()
# Link libraries to a sample
function(wx_link_sample_libraries name)
if(TARGET ${name})
target_link_libraries(${name} PUBLIC ${ARGN})
endif()
endfunction()
# Add a option and mark is as advanced if it starts with wxUSE_
# wx_option(<name> <desc> [default] [STRINGS strings])
# The default is ON if not third parameter is specified
function(wx_option name desc)
cmake_parse_arguments(OPTION "" "" "STRINGS" ${ARGN})
if(ARGC EQUAL 2)
set(default ON)
else()
set(default ${OPTION_UNPARSED_ARGUMENTS})
endif()
if(OPTION_STRINGS)
set(cache_type STRING)
else()
set(cache_type BOOL)
endif()
set(${name} "${default}" CACHE ${cache_type} "${desc}")
string(SUBSTRING ${name} 0 6 prefix)
if(prefix STREQUAL "wxUSE_")
mark_as_advanced(${name})
endif()
if(OPTION_STRINGS)
set_property(CACHE ${name} PROPERTY STRINGS ${OPTION_STRINGS})
# Check valid value
set(value_is_valid FALSE)
set(avail_values)
foreach(opt ${OPTION_STRINGS})
if(${name} STREQUAL opt)
set(value_is_valid TRUE)
break()
endif()
wx_string_append(avail_values " ${opt}")
endforeach()
if(NOT value_is_valid)
message(FATAL_ERROR "Invalid value \"${${name}}\" for option ${name}. Valid values are: ${avail_values}")
endif()
endif()
endfunction()
# Force a new value for an option created with wx_option
function(wx_option_force_value name value)
get_property(helpstring CACHE ${name} PROPERTY HELPSTRING)
get_property(type CACHE ${name} PROPERTY TYPE)
set(${name} ${value} CACHE ${type} ${helpstring} FORCE)
endfunction()
macro(wx_dependent_option option doc default depends force)
if(${option}_ISSET MATCHES "^${option}_ISSET$")
set(${option}_AVAILABLE 1)
foreach(d ${depends})
string(REGEX REPLACE " +" ";" CMAKE_DEPENDENT_OPTION_DEP "${d}")
if(${CMAKE_DEPENDENT_OPTION_DEP})
else()
set(${option}_AVAILABLE 0)
endif()
endforeach()
if(${option}_AVAILABLE)
wx_option(${option} "${doc}" "${default}")
set(${option} "${${option}}" CACHE BOOL "${doc}" FORCE)
else()
if(${option} MATCHES "^${option}$")
else()
set(${option} "${${option}}" CACHE INTERNAL "${doc}")
endif()
set(${option} ${force})
endif()
else()
set(${option} "${${option}_ISSET}")
endif()
endmacro()
|