Spaces:
Running
Running
File size: 34,431 Bytes
1380717 |
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 |
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# Common path suffixes to be searched by find_library or find_path.
# Windows artifacts may be found under "<root>/Library", so
# search there as well.
set(ARROW_LIBRARY_PATH_SUFFIXES
"${CMAKE_LIBRARY_ARCHITECTURE}"
"lib/${CMAKE_LIBRARY_ARCHITECTURE}"
"lib64"
"lib32"
"lib"
"bin"
"Library"
"Library/lib"
"Library/bin")
set(ARROW_INCLUDE_PATH_SUFFIXES "include" "Library" "Library/include")
function(add_thirdparty_lib LIB_NAME LIB_TYPE LIB)
set(options)
set(one_value_args)
set(multi_value_args DEPS INCLUDE_DIRECTORIES)
cmake_parse_arguments(ARG
"${options}"
"${one_value_args}"
"${multi_value_args}"
${ARGN})
if(ARG_UNPARSED_ARGUMENTS)
message(SEND_ERROR "Error: unrecognized arguments: ${ARG_UNPARSED_ARGUMENTS}")
endif()
add_library(${LIB_NAME} ${LIB_TYPE} IMPORTED)
if(${LIB_TYPE} STREQUAL "STATIC")
set_target_properties(${LIB_NAME} PROPERTIES IMPORTED_LOCATION "${LIB}")
message(STATUS "Added static library dependency ${LIB_NAME}: ${LIB}")
else()
if(WIN32)
# Mark the ".lib" location as part of a Windows DLL
set_target_properties(${LIB_NAME} PROPERTIES IMPORTED_IMPLIB "${LIB}")
else()
set_target_properties(${LIB_NAME} PROPERTIES IMPORTED_LOCATION "${LIB}")
endif()
message(STATUS "Added shared library dependency ${LIB_NAME}: ${LIB}")
endif()
if(ARG_DEPS)
set_target_properties(${LIB_NAME} PROPERTIES INTERFACE_LINK_LIBRARIES "${ARG_DEPS}")
endif()
if(ARG_INCLUDE_DIRECTORIES)
set_target_properties(${LIB_NAME} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
"${ARG_INCLUDE_DIRECTORIES}")
endif()
endfunction()
function(REUSE_PRECOMPILED_HEADER_LIB TARGET_NAME LIB_NAME)
if(ARROW_USE_PRECOMPILED_HEADERS)
target_precompile_headers(${TARGET_NAME} REUSE_FROM ${LIB_NAME})
endif()
endfunction()
# Based on MIT-licensed
# https://gist.github.com/cristianadam/ef920342939a89fae3e8a85ca9459b49
function(arrow_create_merged_static_lib output_target)
set(options)
set(one_value_args NAME ROOT)
set(multi_value_args TO_MERGE)
cmake_parse_arguments(ARG
"${options}"
"${one_value_args}"
"${multi_value_args}"
${ARGN})
if(ARG_UNPARSED_ARGUMENTS)
message(SEND_ERROR "Error: unrecognized arguments: ${ARG_UNPARSED_ARGUMENTS}")
endif()
file(MAKE_DIRECTORY ${BUILD_OUTPUT_ROOT_DIRECTORY})
set(output_lib_path
${BUILD_OUTPUT_ROOT_DIRECTORY}${CMAKE_STATIC_LIBRARY_PREFIX}${ARG_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}
)
set(all_library_paths $<TARGET_FILE:${ARG_ROOT}>)
foreach(lib ${ARG_TO_MERGE})
list(APPEND all_library_paths $<TARGET_FILE:${lib}>)
endforeach()
if(APPLE)
# The apple-distributed libtool is what we want for bundling, but there is
# a GNU libtool that has a namecollision (and happens to be bundled with R, too).
# We are not compatible with GNU libtool, so we need to avoid it.
# check in the obvious places first to find Apple's libtool
# HINTS is used before system paths and before PATHS, so we use that
# even though hard coded paths should go in PATHS
# TODO: use a VALIDATOR when we require cmake >= 3.25
find_program(LIBTOOL_MACOS libtool HINTS /usr/bin
/Library/Developer/CommandLineTools/usr/bin)
# confirm that the libtool we found is not GNU libtool
execute_process(COMMAND ${LIBTOOL_MACOS} -V
OUTPUT_VARIABLE LIBTOOL_V_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT "${LIBTOOL_V_OUTPUT}" MATCHES ".*cctools-([0-9.]+).*")
message(FATAL_ERROR "libtool found appears to be the incompatible GNU libtool: ${LIBTOOL_MACOS}"
)
endif()
set(BUNDLE_COMMAND ${LIBTOOL_MACOS} "-no_warning_for_no_symbols" "-static" "-o"
${output_lib_path} ${all_library_paths})
elseif(CMAKE_CXX_COMPILER_ID MATCHES "^(Clang|GNU|Intel|IntelLLVM)$")
set(ar_script_path ${CMAKE_BINARY_DIR}/${ARG_NAME}.ar)
file(WRITE ${ar_script_path}.in "CREATE ${output_lib_path}\n")
file(APPEND ${ar_script_path}.in "ADDLIB $<TARGET_FILE:${ARG_ROOT}>\n")
foreach(lib ${ARG_TO_MERGE})
file(APPEND ${ar_script_path}.in "ADDLIB $<TARGET_FILE:${lib}>\n")
endforeach()
file(APPEND ${ar_script_path}.in "SAVE\nEND\n")
file(GENERATE
OUTPUT ${ar_script_path}
INPUT ${ar_script_path}.in)
set(ar_tool ${CMAKE_AR})
if(CMAKE_INTERPROCEDURAL_OPTIMIZATION)
set(ar_tool ${CMAKE_CXX_COMPILER_AR})
endif()
set(BUNDLE_COMMAND ${ar_tool} -M < ${ar_script_path})
elseif(MSVC)
if(CMAKE_LIBTOOL)
set(BUNDLE_TOOL ${CMAKE_LIBTOOL})
else()
find_program(BUNDLE_TOOL lib HINTS "${CMAKE_CXX_COMPILER}/..")
if(NOT BUNDLE_TOOL)
message(FATAL_ERROR "Cannot locate lib.exe to bundle libraries")
endif()
endif()
set(BUNDLE_COMMAND ${BUNDLE_TOOL} /NOLOGO /OUT:${output_lib_path}
${all_library_paths})
else()
message(FATAL_ERROR "Unknown bundle scenario!")
endif()
add_custom_target(${output_target}_merge ALL
${BUNDLE_COMMAND}
DEPENDS ${ARG_ROOT} ${ARG_TO_MERGE}
BYPRODUCTS ${output_lib_path}
COMMENT "Bundling ${output_lib_path}"
VERBATIM)
message(STATUS "Creating bundled static library target ${output_target} at ${output_lib_path}"
)
add_library(${output_target} STATIC IMPORTED)
set_target_properties(${output_target} PROPERTIES IMPORTED_LOCATION ${output_lib_path})
add_dependencies(${output_target} ${output_target}_merge)
endfunction()
function(arrow_install_cmake_package PACKAGE_NAME EXPORT_NAME)
set(CONFIG_CMAKE "${PACKAGE_NAME}Config.cmake")
set(BUILT_CONFIG_CMAKE "${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_CMAKE}")
configure_package_config_file("${CONFIG_CMAKE}.in" "${BUILT_CONFIG_CMAKE}"
INSTALL_DESTINATION "${ARROW_CMAKE_DIR}/${PACKAGE_NAME}")
set(CONFIG_VERSION_CMAKE "${PACKAGE_NAME}ConfigVersion.cmake")
set(BUILT_CONFIG_VERSION_CMAKE "${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_VERSION_CMAKE}")
write_basic_package_version_file("${BUILT_CONFIG_VERSION_CMAKE}"
COMPATIBILITY SameMajorVersion)
install(FILES "${BUILT_CONFIG_CMAKE}" "${BUILT_CONFIG_VERSION_CMAKE}"
DESTINATION "${ARROW_CMAKE_DIR}/${PACKAGE_NAME}")
set(TARGETS_CMAKE "${PACKAGE_NAME}Targets.cmake")
install(EXPORT ${EXPORT_NAME}
DESTINATION "${ARROW_CMAKE_DIR}/${PACKAGE_NAME}"
NAMESPACE "${PACKAGE_NAME}::"
FILE "${TARGETS_CMAKE}")
endfunction()
# \arg OUTPUTS list to append built targets to
function(ADD_ARROW_LIB LIB_NAME)
set(options)
set(one_value_args
BUILD_SHARED
BUILD_STATIC
CMAKE_PACKAGE_NAME
INSTALL_ARCHIVE_DIR
INSTALL_LIBRARY_DIR
INSTALL_RUNTIME_DIR
PKG_CONFIG_NAME
PRECOMPILED_HEADER_LIB
SHARED_LINK_FLAGS)
set(multi_value_args
SOURCES
PRECOMPILED_HEADERS
OUTPUTS
STATIC_LINK_LIBS
SHARED_LINK_LIBS
SHARED_PRIVATE_LINK_LIBS
EXTRA_INCLUDES
PRIVATE_INCLUDES
DEPENDENCIES
DEFINITIONS
SHARED_INSTALL_INTERFACE_LIBS
STATIC_INSTALL_INTERFACE_LIBS
OUTPUT_PATH)
cmake_parse_arguments(ARG
"${options}"
"${one_value_args}"
"${multi_value_args}"
${ARGN})
if(ARG_UNPARSED_ARGUMENTS)
message(SEND_ERROR "Error: unrecognized arguments: ${ARG_UNPARSED_ARGUMENTS}")
endif()
if(ARG_OUTPUTS)
set(${ARG_OUTPUTS})
endif()
# Allow overriding ARROW_BUILD_SHARED and ARROW_BUILD_STATIC
if(DEFINED ARG_BUILD_SHARED)
set(BUILD_SHARED ${ARG_BUILD_SHARED})
else()
set(BUILD_SHARED ${ARROW_BUILD_SHARED})
endif()
if(DEFINED ARG_BUILD_STATIC)
set(BUILD_STATIC ${ARG_BUILD_STATIC})
else()
set(BUILD_STATIC ${ARROW_BUILD_STATIC})
endif()
if(ARG_OUTPUT_PATH)
set(OUTPUT_PATH ${ARG_OUTPUT_PATH})
else()
set(OUTPUT_PATH ${BUILD_OUTPUT_ROOT_DIRECTORY})
endif()
if(WIN32
OR CMAKE_GENERATOR STREQUAL Xcode
OR NOT ARROW_POSITION_INDEPENDENT_CODE)
# We need to compile C++ separately for each library kind (shared and static)
# because of dllexport declarations on Windows.
# The Xcode generator doesn't reliably work with Xcode as target names are not
# guessed correctly.
set(USE_OBJLIB OFF)
else()
set(USE_OBJLIB ON)
endif()
if(USE_OBJLIB)
# Generate a single "objlib" from all C++ modules and link
# that "objlib" into each library kind, to avoid compiling twice
add_library(${LIB_NAME}_objlib OBJECT ${ARG_SOURCES})
# Necessary to make static linking into other shared libraries work properly
set_property(TARGET ${LIB_NAME}_objlib PROPERTY POSITION_INDEPENDENT_CODE ON)
if(ARG_DEPENDENCIES)
add_dependencies(${LIB_NAME}_objlib ${ARG_DEPENDENCIES})
endif()
if(ARG_DEFINITIONS)
target_compile_definitions(${LIB_NAME}_objlib PRIVATE ${ARG_DEFINITIONS})
endif()
if(ARG_PRECOMPILED_HEADER_LIB)
reuse_precompiled_header_lib(${LIB_NAME}_objlib ${ARG_PRECOMPILED_HEADER_LIB})
endif()
if(ARG_PRECOMPILED_HEADERS AND ARROW_USE_PRECOMPILED_HEADERS)
target_precompile_headers(${LIB_NAME}_objlib PRIVATE ${ARG_PRECOMPILED_HEADERS})
endif()
set(LIB_DEPS $<TARGET_OBJECTS:${LIB_NAME}_objlib>)
set(EXTRA_DEPS)
if(ARG_OUTPUTS)
list(APPEND ${ARG_OUTPUTS} ${LIB_NAME}_objlib)
endif()
if(ARG_EXTRA_INCLUDES)
target_include_directories(${LIB_NAME}_objlib SYSTEM PUBLIC ${ARG_EXTRA_INCLUDES})
endif()
if(ARG_PRIVATE_INCLUDES)
target_include_directories(${LIB_NAME}_objlib PRIVATE ${ARG_PRIVATE_INCLUDES})
endif()
if(BUILD_SHARED)
if(ARG_SHARED_LINK_LIBS)
target_link_libraries(${LIB_NAME}_objlib PRIVATE ${ARG_SHARED_LINK_LIBS})
endif()
if(ARG_SHARED_PRIVATE_LINK_LIBS)
target_link_libraries(${LIB_NAME}_objlib PRIVATE ${ARG_SHARED_PRIVATE_LINK_LIBS})
endif()
endif()
if(BUILD_STATIC AND ARG_STATIC_LINK_LIBS)
target_link_libraries(${LIB_NAME}_objlib PRIVATE ${ARG_STATIC_LINK_LIBS})
endif()
else()
# Prepare arguments for separate compilation of static and shared libs below
# TODO: add PCH directives
set(LIB_DEPS ${ARG_SOURCES})
set(EXTRA_DEPS ${ARG_DEPENDENCIES})
endif()
if(ARG_EXTRA_INCLUDES)
set(LIB_INCLUDES ${ARG_EXTRA_INCLUDES})
else()
set(LIB_INCLUDES "")
endif()
if(ARG_INSTALL_ARCHIVE_DIR)
set(INSTALL_ARCHIVE_DIR ${ARG_INSTALL_ARCHIVE_DIR})
else()
set(INSTALL_ARCHIVE_DIR ${CMAKE_INSTALL_LIBDIR})
endif()
if(ARG_INSTALL_LIBRARY_DIR)
set(INSTALL_LIBRARY_DIR ${ARG_INSTALL_LIBRARY_DIR})
else()
set(INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR})
endif()
if(ARG_INSTALL_RUNTIME_DIR)
set(INSTALL_RUNTIME_DIR ${ARG_INSTALL_RUNTIME_DIR})
else()
set(INSTALL_RUNTIME_DIR bin)
endif()
if(BUILD_SHARED)
add_library(${LIB_NAME}_shared SHARED ${LIB_DEPS})
if(EXTRA_DEPS)
add_dependencies(${LIB_NAME}_shared ${EXTRA_DEPS})
endif()
if(ARG_DEFINITIONS)
target_compile_definitions(${LIB_NAME}_shared PRIVATE ${ARG_DEFINITIONS})
endif()
if(ARG_PRECOMPILED_HEADER_LIB)
reuse_precompiled_header_lib(${LIB_NAME}_shared ${ARG_PRECOMPILED_HEADER_LIB})
endif()
if(ARG_OUTPUTS)
list(APPEND ${ARG_OUTPUTS} ${LIB_NAME}_shared)
endif()
if(LIB_INCLUDES)
target_include_directories(${LIB_NAME}_shared SYSTEM PUBLIC ${ARG_EXTRA_INCLUDES})
endif()
if(ARG_PRIVATE_INCLUDES)
target_include_directories(${LIB_NAME}_shared PRIVATE ${ARG_PRIVATE_INCLUDES})
endif()
# On iOS, specifying -undefined conflicts with enabling bitcode
if(APPLE
AND NOT IOS
AND NOT DEFINED ENV{EMSCRIPTEN})
# On OS X, you can avoid linking at library load time and instead
# expecting that the symbols have been loaded separately. This happens
# with libpython* where there can be conflicts between system Python and
# the Python from a thirdparty distribution
#
# When running with the Emscripten Compiler, we need not worry about
# python, and the Emscripten Compiler does not support this option.
set(ARG_SHARED_LINK_FLAGS "-undefined dynamic_lookup ${ARG_SHARED_LINK_FLAGS}")
endif()
set_target_properties(${LIB_NAME}_shared
PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${OUTPUT_PATH}"
RUNTIME_OUTPUT_DIRECTORY "${OUTPUT_PATH}"
PDB_OUTPUT_DIRECTORY "${OUTPUT_PATH}"
LINK_FLAGS "${ARG_SHARED_LINK_FLAGS}"
OUTPUT_NAME ${LIB_NAME}
VERSION "${ARROW_FULL_SO_VERSION}"
SOVERSION "${ARROW_SO_VERSION}")
target_link_libraries(${LIB_NAME}_shared
PUBLIC "$<BUILD_INTERFACE:${ARG_SHARED_LINK_LIBS}>"
"$<INSTALL_INTERFACE:${ARG_SHARED_INSTALL_INTERFACE_LIBS}>"
PRIVATE ${ARG_SHARED_PRIVATE_LINK_LIBS})
if(USE_OBJLIB)
# Ensure that dependencies are built before compilation of objects in
# object library, rather than only before the final link step
foreach(SHARED_LINK_LIB ${ARG_SHARED_LINK_LIBS})
if(TARGET ${SHARED_LINK_LIB})
add_dependencies(${LIB_NAME}_objlib ${SHARED_LINK_LIB})
endif()
endforeach()
endif()
if(ARROW_RPATH_ORIGIN)
if(APPLE)
set(_lib_install_rpath "@loader_path")
else()
set(_lib_install_rpath "\$ORIGIN")
endif()
set_target_properties(${LIB_NAME}_shared PROPERTIES INSTALL_RPATH
${_lib_install_rpath})
endif()
if(APPLE)
if(ARROW_INSTALL_NAME_RPATH)
set(_lib_install_name "@rpath")
else()
set(_lib_install_name "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
endif()
set_target_properties(${LIB_NAME}_shared
PROPERTIES BUILD_WITH_INSTALL_RPATH ON INSTALL_NAME_DIR
"${_lib_install_name}")
endif()
install(TARGETS ${LIB_NAME}_shared ${INSTALL_IS_OPTIONAL}
EXPORT ${LIB_NAME}_targets
ARCHIVE DESTINATION ${INSTALL_ARCHIVE_DIR}
LIBRARY DESTINATION ${INSTALL_LIBRARY_DIR}
RUNTIME DESTINATION ${INSTALL_RUNTIME_DIR}
INCLUDES
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()
if(BUILD_STATIC)
add_library(${LIB_NAME}_static STATIC ${LIB_DEPS})
if(EXTRA_DEPS)
add_dependencies(${LIB_NAME}_static ${EXTRA_DEPS})
endif()
if(ARG_DEFINITIONS)
target_compile_definitions(${LIB_NAME}_static PRIVATE ${ARG_DEFINITIONS})
endif()
if(ARG_PRECOMPILED_HEADER_LIB)
reuse_precompiled_header_lib(${LIB_NAME}_static ${ARG_PRECOMPILED_HEADER_LIB})
endif()
if(ARG_OUTPUTS)
list(APPEND ${ARG_OUTPUTS} ${LIB_NAME}_static)
endif()
if(LIB_INCLUDES)
target_include_directories(${LIB_NAME}_static SYSTEM PUBLIC ${ARG_EXTRA_INCLUDES})
endif()
if(ARG_PRIVATE_INCLUDES)
target_include_directories(${LIB_NAME}_static PRIVATE ${ARG_PRIVATE_INCLUDES})
endif()
if(MSVC_TOOLCHAIN)
set(LIB_NAME_STATIC ${LIB_NAME}_static)
else()
set(LIB_NAME_STATIC ${LIB_NAME})
endif()
if(WIN32)
target_compile_definitions(${LIB_NAME}_static PUBLIC ARROW_STATIC)
target_compile_definitions(${LIB_NAME}_static PUBLIC ARROW_FLIGHT_STATIC)
target_compile_definitions(${LIB_NAME}_static PUBLIC ARROW_FLIGHT_SQL_STATIC)
endif()
set_target_properties(${LIB_NAME}_static
PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${OUTPUT_PATH}"
OUTPUT_NAME ${LIB_NAME_STATIC})
if(ARG_STATIC_INSTALL_INTERFACE_LIBS)
target_link_libraries(${LIB_NAME}_static
INTERFACE "$<INSTALL_INTERFACE:${ARG_STATIC_INSTALL_INTERFACE_LIBS}>"
)
endif()
if(ARG_STATIC_LINK_LIBS)
target_link_libraries(${LIB_NAME}_static
PUBLIC "$<BUILD_INTERFACE:${ARG_STATIC_LINK_LIBS}>")
if(USE_OBJLIB)
# Ensure that dependencies are built before compilation of objects in
# object library, rather than only before the final link step
foreach(STATIC_LINK_LIB ${ARG_STATIC_LINK_LIBS})
if(TARGET ${STATIC_LINK_LIB})
add_dependencies(${LIB_NAME}_objlib ${STATIC_LINK_LIB})
endif()
endforeach()
endif()
endif()
install(TARGETS ${LIB_NAME}_static ${INSTALL_IS_OPTIONAL}
EXPORT ${LIB_NAME}_targets
ARCHIVE DESTINATION ${INSTALL_ARCHIVE_DIR}
LIBRARY DESTINATION ${INSTALL_LIBRARY_DIR}
RUNTIME DESTINATION ${INSTALL_RUNTIME_DIR}
INCLUDES
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()
if(ARG_CMAKE_PACKAGE_NAME)
arrow_install_cmake_package(${ARG_CMAKE_PACKAGE_NAME} ${LIB_NAME}_targets)
endif()
if(ARG_PKG_CONFIG_NAME)
arrow_add_pkg_config("${ARG_PKG_CONFIG_NAME}")
endif()
# Modify variable in calling scope
if(ARG_OUTPUTS)
set(${ARG_OUTPUTS}
${${ARG_OUTPUTS}}
PARENT_SCOPE)
endif()
endfunction()
#
# Benchmarking
#
# Add a new micro benchmark, with or without an executable that should be built.
# If benchmarks are enabled then they will be run along side unit tests with ctest.
# 'make benchmark' and 'make unittest' to build/run only benchmark or unittests,
# respectively.
#
# REL_BENCHMARK_NAME is the name of the benchmark app. It may be a single component
# (e.g. monotime-benchmark) or contain additional components (e.g.
# net/net_util-benchmark). Either way, the last component must be a globally
# unique name.
# The benchmark will registered as unit test with ctest with a label
# of 'benchmark'.
#
# Arguments after the test name will be passed to set_tests_properties().
#
# \arg PREFIX a string to append to the name of the benchmark executable. For
# example, if you have src/arrow/foo/bar-benchmark.cc, then PREFIX "foo" will
# create test executable foo-bar-benchmark
# \arg LABELS the benchmark label or labels to assign the unit tests to. By
# default, benchmarks will go in the "benchmark" group. Custom targets for the
# group names must exist
function(ADD_BENCHMARK REL_BENCHMARK_NAME)
set(options)
set(one_value_args)
set(multi_value_args
EXTRA_LINK_LIBS
STATIC_LINK_LIBS
DEPENDENCIES
SOURCES
PREFIX
LABELS)
cmake_parse_arguments(ARG
"${options}"
"${one_value_args}"
"${multi_value_args}"
${ARGN})
if(ARG_UNPARSED_ARGUMENTS)
message(SEND_ERROR "Error: unrecognized arguments: ${ARG_UNPARSED_ARGUMENTS}")
endif()
if(NO_BENCHMARKS)
return()
endif()
get_filename_component(BENCHMARK_NAME ${REL_BENCHMARK_NAME} NAME_WE)
if(ARG_PREFIX)
set(BENCHMARK_NAME "${ARG_PREFIX}-${BENCHMARK_NAME}")
endif()
if(ARG_SOURCES)
set(SOURCES ${ARG_SOURCES})
else()
set(SOURCES "${REL_BENCHMARK_NAME}.cc")
endif()
# Make sure the executable name contains only hyphens, not underscores
string(REPLACE "_" "-" BENCHMARK_NAME ${BENCHMARK_NAME})
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${REL_BENCHMARK_NAME}.cc)
# This benchmark has a corresponding .cc file, set it up as an executable.
set(BENCHMARK_PATH "${EXECUTABLE_OUTPUT_PATH}/${BENCHMARK_NAME}")
add_executable(${BENCHMARK_NAME} ${SOURCES})
if(ARG_STATIC_LINK_LIBS)
# Customize link libraries
target_link_libraries(${BENCHMARK_NAME} PRIVATE ${ARG_STATIC_LINK_LIBS})
else()
target_link_libraries(${BENCHMARK_NAME} PRIVATE ${ARROW_BENCHMARK_LINK_LIBS})
endif()
add_dependencies(benchmark ${BENCHMARK_NAME})
if(ARG_EXTRA_LINK_LIBS)
target_link_libraries(${BENCHMARK_NAME} PRIVATE ${ARG_EXTRA_LINK_LIBS})
endif()
else()
# No executable, just invoke the benchmark (probably a script) directly.
set(BENCHMARK_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${REL_BENCHMARK_NAME})
endif()
# With OSX and conda, we need to set the correct RPATH so that dependencies
# are found. The installed libraries with conda have an RPATH that matches
# for executables and libraries lying in $ENV{CONDA_PREFIX}/bin or
# $ENV{CONDA_PREFIX}/lib but our test libraries and executables are not
# installed there.
if(NOT "$ENV{CONDA_PREFIX}" STREQUAL "" AND APPLE)
set_target_properties(${BENCHMARK_NAME}
PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE
INSTALL_RPATH_USE_LINK_PATH TRUE
INSTALL_RPATH
"$ENV{CONDA_PREFIX}/lib;${EXECUTABLE_OUTPUT_PATH}")
endif()
# Add test as dependency of relevant label targets
add_dependencies(all-benchmarks ${BENCHMARK_NAME})
foreach(TARGET ${ARG_LABELS})
add_dependencies(${TARGET} ${BENCHMARK_NAME})
endforeach()
if(ARG_DEPENDENCIES)
add_dependencies(${BENCHMARK_NAME} ${ARG_DEPENDENCIES})
endif()
if(ARG_LABELS)
set(ARG_LABELS "benchmark;${ARG_LABELS}")
else()
set(ARG_LABELS benchmark)
endif()
if(ARROW_BUILD_DETAILED_BENCHMARKS)
target_compile_definitions(${BENCHMARK_NAME} PRIVATE ARROW_BUILD_DETAILED_BENCHMARKS)
endif()
add_test(${BENCHMARK_NAME}
${BUILD_SUPPORT_DIR}/run-test.sh
${CMAKE_BINARY_DIR}
benchmark
${BENCHMARK_PATH})
set_property(TEST ${BENCHMARK_NAME}
APPEND
PROPERTY LABELS ${ARG_LABELS})
endfunction()
#
# Testing
#
# Add a new test case, with or without an executable that should be built.
#
# REL_TEST_NAME is the name of the test. It may be a single component
# (e.g. monotime-test) or contain additional components (e.g.
# net/net_util-test). Either way, the last component must be a globally
# unique name.
#
# If given, SOURCES is the list of C++ source files to compile into the test
# executable. Otherwise, "REL_TEST_NAME.cc" is used.
#
# The unit test is added with a label of "unittest" to support filtering with
# ctest.
#
# Arguments after the test name will be passed to set_tests_properties().
#
# \arg ENABLED if passed, add this unit test even if ARROW_BUILD_TESTS is off
# \arg PREFIX a string to append to the name of the test executable. For
# example, if you have src/arrow/foo/bar-test.cc, then PREFIX "foo" will create
# test executable foo-bar-test
# \arg LABELS the unit test label or labels to assign the unit tests
# to. By default, unit tests will go in the "unittest" group, but if we have
# multiple unit tests in some subgroup, you can assign a test to multiple
# groups use the syntax unittest;GROUP2;GROUP3. Custom targets for the group
# names must exist
function(ADD_TEST_CASE REL_TEST_NAME)
set(options NO_VALGRIND ENABLED)
set(one_value_args PRECOMPILED_HEADER_LIB)
set(multi_value_args
SOURCES
PRECOMPILED_HEADERS
STATIC_LINK_LIBS
EXTRA_LINK_LIBS
EXTRA_INCLUDES
EXTRA_DEPENDENCIES
LABELS
EXTRA_LABELS
TEST_ARGUMENTS
PREFIX
DEFINITIONS)
cmake_parse_arguments(ARG
"${options}"
"${one_value_args}"
"${multi_value_args}"
${ARGN})
if(ARG_UNPARSED_ARGUMENTS)
message(SEND_ERROR "Error: unrecognized arguments: ${ARG_UNPARSED_ARGUMENTS}")
endif()
if(NO_TESTS AND NOT ARG_ENABLED)
return()
endif()
get_filename_component(TEST_NAME ${REL_TEST_NAME} NAME_WE)
if(ARG_PREFIX)
set(TEST_NAME "${ARG_PREFIX}-${TEST_NAME}")
endif()
if(ARG_SOURCES)
set(SOURCES ${ARG_SOURCES})
else()
set(SOURCES "${REL_TEST_NAME}.cc")
endif()
# Make sure the executable name contains only hyphens, not underscores
string(REPLACE "_" "-" TEST_NAME ${TEST_NAME})
set(TEST_PATH "${EXECUTABLE_OUTPUT_PATH}/${TEST_NAME}")
add_executable(${TEST_NAME} ${SOURCES})
# With OSX and conda, we need to set the correct RPATH so that dependencies
# are found. The installed libraries with conda have an RPATH that matches
# for executables and libraries lying in $ENV{CONDA_PREFIX}/bin or
# $ENV{CONDA_PREFIX}/lib but our test libraries and executables are not
# installed there.
if(NOT "$ENV{CONDA_PREFIX}" STREQUAL "" AND APPLE)
set_target_properties(${TEST_NAME}
PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE
INSTALL_RPATH_USE_LINK_PATH TRUE
INSTALL_RPATH
"${EXECUTABLE_OUTPUT_PATH};$ENV{CONDA_PREFIX}/lib")
endif()
if(ARG_STATIC_LINK_LIBS)
# Customize link libraries
target_link_libraries(${TEST_NAME} PRIVATE ${ARG_STATIC_LINK_LIBS})
else()
target_link_libraries(${TEST_NAME} PRIVATE ${ARROW_TEST_LINK_LIBS})
endif()
if(ARG_PRECOMPILED_HEADER_LIB)
reuse_precompiled_header_lib(${TEST_NAME} ${ARG_PRECOMPILED_HEADER_LIB})
endif()
if(ARG_PRECOMPILED_HEADERS AND ARROW_USE_PRECOMPILED_HEADERS)
target_precompile_headers(${TEST_NAME} PRIVATE ${ARG_PRECOMPILED_HEADERS})
endif()
if(ARG_EXTRA_LINK_LIBS)
target_link_libraries(${TEST_NAME} PRIVATE ${ARG_EXTRA_LINK_LIBS})
endif()
if(ARG_EXTRA_INCLUDES)
target_include_directories(${TEST_NAME} SYSTEM PUBLIC ${ARG_EXTRA_INCLUDES})
endif()
if(ARG_EXTRA_DEPENDENCIES)
add_dependencies(${TEST_NAME} ${ARG_EXTRA_DEPENDENCIES})
endif()
if(ARG_DEFINITIONS)
target_compile_definitions(${TEST_NAME} PRIVATE ${ARG_DEFINITIONS})
endif()
if(ARROW_TEST_MEMCHECK AND NOT ARG_NO_VALGRIND)
add_test(${TEST_NAME}
bash
-c
"cd '${CMAKE_SOURCE_DIR}'; \
valgrind --suppressions=valgrind.supp --tool=memcheck --gen-suppressions=all \
--num-callers=500 --leak-check=full --leak-check-heuristics=stdstring \
--error-exitcode=1 ${TEST_PATH} ${ARG_TEST_ARGUMENTS}")
elseif(WIN32 OR CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME} ${ARG_TEST_ARGUMENTS})
else()
add_test(${TEST_NAME}
${BUILD_SUPPORT_DIR}/run-test.sh
${CMAKE_BINARY_DIR}
test
${TEST_PATH}
${ARG_TEST_ARGUMENTS})
endif()
# Add test as dependency of relevant targets
add_dependencies(all-tests ${TEST_NAME})
foreach(TARGET ${ARG_LABELS})
add_dependencies(${TARGET} ${TEST_NAME})
endforeach()
set(LABELS)
list(APPEND LABELS "unittest")
if(ARG_LABELS)
list(APPEND LABELS ${ARG_LABELS})
endif()
# EXTRA_LABELS don't create their own dependencies, they are only used
# to ease running certain test categories.
if(ARG_EXTRA_LABELS)
list(APPEND LABELS ${ARG_EXTRA_LABELS})
endif()
foreach(LABEL ${ARG_LABELS})
# ensure there is a cmake target which exercises tests with this LABEL
set(LABEL_TEST_NAME "test-${LABEL}")
if(NOT TARGET ${LABEL_TEST_NAME})
add_custom_target(${LABEL_TEST_NAME}
ctest -L "${LABEL}" --output-on-failure
USES_TERMINAL)
endif()
# ensure the test is (re)built before the LABEL test runs
add_dependencies(${LABEL_TEST_NAME} ${TEST_NAME})
endforeach()
set_property(TEST ${TEST_NAME}
APPEND
PROPERTY LABELS ${LABELS})
endfunction()
#
# Examples
#
# Add a new example, with or without an executable that should be built.
# If examples are enabled then they will be run along side unit tests with ctest.
# 'make runexample' to build/run only examples.
#
# REL_EXAMPLE_NAME is the name of the example app. It may be a single component
# (e.g. monotime-example) or contain additional components (e.g.
# net/net_util-example). Either way, the last component must be a globally
# unique name.
# The example will registered as unit test with ctest with a label
# of 'example'.
#
# Arguments after the test name will be passed to set_tests_properties().
#
# \arg PREFIX a string to append to the name of the example executable. For
# example, if you have src/arrow/foo/bar-example.cc, then PREFIX "foo" will
# create test executable foo-bar-example
function(ADD_ARROW_EXAMPLE REL_EXAMPLE_NAME)
set(options)
set(one_value_args)
set(multi_value_args
EXTRA_INCLUDES
EXTRA_LINK_LIBS
EXTRA_SOURCES
DEPENDENCIES
PREFIX)
cmake_parse_arguments(ARG
"${options}"
"${one_value_args}"
"${multi_value_args}"
${ARGN})
if(ARG_UNPARSED_ARGUMENTS)
message(SEND_ERROR "Error: unrecognized arguments: ${ARG_UNPARSED_ARGUMENTS}")
endif()
if(NO_EXAMPLES)
return()
endif()
get_filename_component(EXAMPLE_NAME ${REL_EXAMPLE_NAME} NAME_WE)
if(ARG_PREFIX)
set(EXAMPLE_NAME "${ARG_PREFIX}-${EXAMPLE_NAME}")
endif()
# Make sure the executable name contains only hyphens, not underscores
string(REPLACE "_" "-" EXAMPLE_NAME ${EXAMPLE_NAME})
if(EXISTS ${CMAKE_SOURCE_DIR}/examples/arrow/${REL_EXAMPLE_NAME}.cc)
# This example has a corresponding .cc file, set it up as an executable.
set(EXAMPLE_PATH "${EXECUTABLE_OUTPUT_PATH}/${EXAMPLE_NAME}")
add_executable(${EXAMPLE_NAME} "${REL_EXAMPLE_NAME}.cc" ${ARG_EXTRA_SOURCES})
target_link_libraries(${EXAMPLE_NAME} ${ARROW_EXAMPLE_LINK_LIBS})
add_dependencies(runexample ${EXAMPLE_NAME})
if(ARG_EXTRA_LINK_LIBS)
target_link_libraries(${EXAMPLE_NAME} ${ARG_EXTRA_LINK_LIBS})
endif()
endif()
if(ARG_DEPENDENCIES)
add_dependencies(${EXAMPLE_NAME} ${ARG_DEPENDENCIES})
endif()
if(ARG_EXTRA_INCLUDES)
target_include_directories(${EXAMPLE_NAME} SYSTEM PUBLIC ${ARG_EXTRA_INCLUDES})
endif()
add_test(${EXAMPLE_NAME} ${EXAMPLE_PATH})
set_tests_properties(${EXAMPLE_NAME} PROPERTIES LABELS "example")
endfunction()
#
# Fuzzing
#
# Add new fuzz target executable.
#
# The single source file must define a function:
# extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
#
# No main function must be present within the source file!
#
function(ADD_FUZZ_TARGET REL_FUZZING_NAME)
set(options)
set(one_value_args PREFIX)
set(multi_value_args LINK_LIBS)
cmake_parse_arguments(ARG
"${options}"
"${one_value_args}"
"${multi_value_args}"
${ARGN})
if(ARG_UNPARSED_ARGUMENTS)
message(SEND_ERROR "Error: unrecognized arguments: ${ARG_UNPARSED_ARGUMENTS}")
endif()
if(NOT ARROW_FUZZING)
return()
endif()
get_filename_component(FUZZING_NAME ${REL_FUZZING_NAME} NAME_WE)
# Make sure the executable name contains only hyphens, not underscores
string(REPLACE "_" "-" FUZZING_NAME ${FUZZING_NAME})
if(ARG_PREFIX)
set(FUZZING_NAME "${ARG_PREFIX}-${FUZZING_NAME}")
endif()
# For OSS-Fuzz
# (https://google.github.io/oss-fuzz/advanced-topics/ideal-integration/)
if(DEFINED ENV{LIB_FUZZING_ENGINE})
set(FUZZ_LDFLAGS $ENV{LIB_FUZZING_ENGINE})
else()
set(FUZZ_LDFLAGS "-fsanitize=fuzzer")
endif()
add_executable(${FUZZING_NAME} "${REL_FUZZING_NAME}.cc")
target_link_libraries(${FUZZING_NAME} ${LINK_LIBS})
target_compile_options(${FUZZING_NAME} PRIVATE ${FUZZ_LDFLAGS})
set_target_properties(${FUZZING_NAME} PROPERTIES LINK_FLAGS ${FUZZ_LDFLAGS} LABELS
"fuzzing")
endfunction()
function(ARROW_INSTALL_ALL_HEADERS PATH)
set(options)
set(one_value_args)
set(multi_value_args PATTERN)
cmake_parse_arguments(ARG
"${options}"
"${one_value_args}"
"${multi_value_args}"
${ARGN})
if(NOT ARG_PATTERN)
# The .hpp extension is used by some vendored libraries
set(ARG_PATTERN "*.h" "*.hpp")
endif()
file(GLOB CURRENT_DIRECTORY_HEADERS ${ARG_PATTERN})
set(PUBLIC_HEADERS)
foreach(HEADER ${CURRENT_DIRECTORY_HEADERS})
get_filename_component(HEADER_BASENAME ${HEADER} NAME)
if(HEADER_BASENAME MATCHES "internal")
continue()
endif()
list(APPEND PUBLIC_HEADERS ${HEADER})
endforeach()
install(FILES ${PUBLIC_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PATH}")
endfunction()
function(ARROW_ADD_PKG_CONFIG MODULE)
configure_file(${MODULE}.pc.in "${CMAKE_CURRENT_BINARY_DIR}/${MODULE}.pc.generate.in"
@ONLY)
file(GENERATE
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${MODULE}.pc"
INPUT "${CMAKE_CURRENT_BINARY_DIR}/${MODULE}.pc.generate.in")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${MODULE}.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/")
endfunction()
# Implementations of lisp "car" and "cdr" functions
macro(ARROW_CAR var)
set(${var} ${ARGV1})
endmacro()
macro(ARROW_CDR var rest)
set(${var} ${ARGN})
endmacro()
|