diff options
32 files changed, 281 insertions, 63 deletions
diff --git a/.gitlab/ci/configure_debian12_ninja_common.cmake b/.gitlab/ci/configure_debian12_ninja_common.cmake index af260ee..b3a97f6 100644 --- a/.gitlab/ci/configure_debian12_ninja_common.cmake +++ b/.gitlab/ci/configure_debian12_ninja_common.cmake @@ -11,6 +11,7 @@ if (NOT "$ENV{CMAKE_CI_NIGHTLY}" STREQUAL "") endif() set(CMake_TEST_FindALSA "ON" CACHE BOOL "") +set(CMake_TEST_FindBacktrace "ON" CACHE BOOL "") set(CMake_TEST_FindBLAS "All;static=1;Generic" CACHE STRING "") set(CMake_TEST_FindBoost "ON" CACHE BOOL "") set(CMake_TEST_FindBoost_Python "ON" CACHE BOOL "") diff --git a/.gitlab/ci/configure_fedora39_makefiles.cmake b/.gitlab/ci/configure_fedora39_makefiles.cmake index 4e18c83..90d8343 100644 --- a/.gitlab/ci/configure_fedora39_makefiles.cmake +++ b/.gitlab/ci/configure_fedora39_makefiles.cmake @@ -11,6 +11,7 @@ endif() set(CMake_TEST_ASM_NASM "ON" CACHE BOOL "") set(CMake_TEST_FindALSA "ON" CACHE BOOL "") +set(CMake_TEST_FindBacktrace "ON" CACHE BOOL "") set(CMake_TEST_FindBLAS "All;static=1;Generic" CACHE STRING "") set(CMake_TEST_FindBoost "ON" CACHE BOOL "") set(CMake_TEST_FindBoost_Python "ON" CACHE BOOL "") diff --git a/Help/release/dev/FindBacktrace-imported-library.rst b/Help/release/dev/FindBacktrace-imported-library.rst new file mode 100644 index 0000000..ffb8d66 --- /dev/null +++ b/Help/release/dev/FindBacktrace-imported-library.rst @@ -0,0 +1,4 @@ +FindBacktrace-imported-library +------------------------------ + +* The :module:`FindBacktrace` module now provides an imported target. diff --git a/Modules/CMakeSwiftInformation.cmake b/Modules/CMakeSwiftInformation.cmake index 34ae751..60df6a2 100644 --- a/Modules/CMakeSwiftInformation.cmake +++ b/Modules/CMakeSwiftInformation.cmake @@ -138,7 +138,7 @@ if(CMAKE_Swift_COMPILATION_MODE_DEFAULT) endif() if(NOT CMAKE_Swift_CREATE_SHARED_MODULE) - set(CMAKE_Swift_CREATE_SHARED_MODULE ${CMAKE_Swift_CREATE_SHARED_LIBRARY}) + set(CMAKE_Swift_CREATE_SHARED_MODULE "${CMAKE_Swift_CREATE_SHARED_LIBRARY} <CMAKE_SHARED_MODULE_CREATE_Swift_FLAGS>") endif() if(NOT CMAKE_Swift_LINK_EXECUTABLE) @@ -162,7 +162,7 @@ else() endif() if(NOT CMAKE_Swift_CREATE_SHARED_MODULE) - set(CMAKE_Swift_CREATE_SHARED_MODULE ${CMAKE_Swift_CREATE_SHARED_LIBRARY}) + set(CMAKE_Swift_CREATE_SHARED_MODULE "${CMAKE_Swift_CREATE_SHARED_LIBRARY} <CMAKE_SHARED_MODULE_CREATE_Swift_FLAGS>") endif() if(NOT CMAKE_Swift_LINK_EXECUTABLE) diff --git a/Modules/Compiler/NAG-Fortran.cmake b/Modules/Compiler/NAG-Fortran.cmake index b946cfd..a6636c4 100644 --- a/Modules/Compiler/NAG-Fortran.cmake +++ b/Modules/Compiler/NAG-Fortran.cmake @@ -28,6 +28,13 @@ if(NOT CMAKE_Fortran_COMPILER_WORKS AND NOT CMAKE_Fortran_COMPILER_FORCED) endif() endif() +# Initial configuration flags. +string(APPEND CMAKE_Fortran_FLAGS_INIT " ") +string(APPEND CMAKE_Fortran_FLAGS_DEBUG_INIT " -g") +string(APPEND CMAKE_Fortran_FLAGS_MINSIZEREL_INIT " -O2 -DNDEBUG") +string(APPEND CMAKE_Fortran_FLAGS_RELEASE_INIT " -O4 -DNDEBUG") +string(APPEND CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT " -O2 -g -DNDEBUG") + set(CMAKE_Fortran_SUBMODULE_SEP ".") set(CMAKE_Fortran_SUBMODULE_EXT ".sub") set(CMAKE_Fortran_MODDIR_FLAG "-mdir ") @@ -39,3 +46,6 @@ set(CMAKE_Fortran_COMPILE_OPTIONS_PIC "-PIC") set(CMAKE_Fortran_COMPILE_OPTIONS_PIE "-PIC") set(CMAKE_Fortran_RESPONSE_FILE_LINK_FLAG "-Wl,@") set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_ON "-fpp") + +set(CMAKE_Fortran_PREPROCESS_SOURCE + "<CMAKE_Fortran_COMPILER> -fpp <DEFINES> <INCLUDES> <FLAGS> -F <SOURCE> -o <PREPROCESSED_SOURCE>") diff --git a/Modules/FindBacktrace.cmake b/Modules/FindBacktrace.cmake index 46b62d2..4d3186c 100644 --- a/Modules/FindBacktrace.cmake +++ b/Modules/FindBacktrace.cmake @@ -36,6 +36,17 @@ with the contents like the following:: #endif And then reference that generated header file in actual source. + +Imported Targets +^^^^^^^^^^^^^^^^ + +.. versionadded:: 3.30 + +This module defines the following :prop_tgt:`IMPORTED` targets: + +``Backtrace::Backtrace`` + An interface library providing usage requirements for the found components. + #]=======================================================================] include(CMakePushCheckState) @@ -89,3 +100,14 @@ set(Backtrace_HEADER "${_Backtrace_HEADER_TRY}" CACHE STRING "Header providing b find_package_handle_standard_args(Backtrace FOUND_VAR Backtrace_FOUND REQUIRED_VARS ${_Backtrace_STD_ARGS}) mark_as_advanced(Backtrace_HEADER Backtrace_INCLUDE_DIR Backtrace_LIBRARY) + +if(Backtrace_FOUND AND NOT TARGET Backtrace::Backtrace) + if(Backtrace_LIBRARY) + add_library(Backtrace::Backtrace UNKNOWN IMPORTED) + set_property(TARGET Backtrace::Backtrace PROPERTY IMPORTED_LOCATION "${Backtrace_LIBRARY}") + else() + add_library(Backtrace::Backtrace INTERFACE IMPORTED) + target_link_libraries(Backtrace::Backtrace INTERFACE ${Backtrace_LIBRARIES}) + endif() + target_include_directories(Backtrace::Backtrace INTERFACE ${Backtrace_INCLUDE_DIRS}) +endif() diff --git a/Modules/FindGTK2.cmake b/Modules/FindGTK2.cmake index 41f192b..f91d2fd 100644 --- a/Modules/FindGTK2.cmake +++ b/Modules/FindGTK2.cmake @@ -306,6 +306,10 @@ function(_GTK2_FIND_INCLUDE_DIR _var _hdr) endif() find_path(GTK2_${_var}_INCLUDE_DIR ${_hdr} PATHS + ${PC_GLIB2_INCLUDEDIR} + ${PC_GLIB2_LIBDIR} + ${PC_GTK2_INCLUDEDIR} + ${PC_GTK2_LIBDIR} ${_gtk2_arch_dir} /usr/local/libx32 /usr/local/lib64 @@ -616,6 +620,23 @@ if(NOT GTK2_FIND_COMPONENTS) set(GTK2_FIND_COMPONENTS gtk) endif() +# Retrieve LIBDIR from the GTK2 and GLIB2 pkg-config files, which are +# used to compute the arch-specific include prefixes. While at it, +# also retrieve their INCLUDEDIR, to accommodate non-standard layouts. +find_package(PkgConfig QUIET) +if(PKG_CONFIG_FOUND) + pkg_check_modules(PC_GTK2 QUIET gtk+-2.0) + if(PC_GTK2_FOUND) + pkg_get_variable(PC_GTK2_INCLUDEDIR gtk+-2.0 includedir) + pkg_get_variable(PC_GTK2_LIBDIR gtk+-2.0 libdir) + endif() + pkg_check_modules(PC_GLIB2 QUIET glib-2.0) + if(PC_GLIB2_FOUND) + pkg_get_variable(PC_GLIB2_INCLUDEDIR glib-2.0 includedir) + pkg_get_variable(PC_GLIB2_LIBDIR glib-2.0 libdir) + endif() +endif() + # # If specified, enforce version number # diff --git a/Modules/Platform/Apple-Apple-Swift.cmake b/Modules/Platform/Apple-Apple-Swift.cmake index 237f6e4..9f27efa 100644 --- a/Modules/Platform/Apple-Apple-Swift.cmake +++ b/Modules/Platform/Apple-Apple-Swift.cmake @@ -7,8 +7,11 @@ if("${CMAKE_GENERATOR}" STREQUAL Xcode) set(CMAKE_Swift_USING_LINKER_APPLE_CLASSIC "-fuse-ld=ld" "LINKER:-ld_classic") set(CMAKE_Swift_USING_LINKER_LLD "-fuse-ld=lld") set(CMAKE_Swift_USING_LINKER_SYSTEM "-fuse-ld=ld") + set(CMAKE_SHARED_MODULE_LOADER_Swift_FLAG "-Wl,-bundle_loader,") else() set(CMAKE_Swift_USING_LINKER_APPLE_CLASSIC "-use-ld=ld" "LINKER:-ld_classic") set(CMAKE_Swift_USING_LINKER_LLD "-use-ld=lld") set(CMAKE_Swift_USING_LINKER_SYSTEM "-use-ld=ld") + set(CMAKE_SHARED_MODULE_LOADER_Swift_FLAG "-Xclang-linker -Wl,-bundle_loader,") + set(CMAKE_SHARED_MODULE_CREATE_Swift_FLAGS "-Xlinker -bundle") endif() diff --git a/Modules/Platform/Apple-NAG-Fortran.cmake b/Modules/Platform/Apple-NAG-Fortran.cmake index 8d3e741..828d7ab 100644 --- a/Modules/Platform/Apple-NAG-Fortran.cmake +++ b/Modules/Platform/Apple-NAG-Fortran.cmake @@ -3,12 +3,17 @@ set(CMAKE_Fortran_VERBOSE_FLAG "-Wl,-v") # Runs gcc under the hood. -# Need -fpp explicitly on case-insensitive filesystem. -set(CMAKE_Fortran_COMPILE_OBJECT - "<CMAKE_Fortran_COMPILER> -fpp -o <OBJECT> <DEFINES> <INCLUDES> <FLAGS> -c <SOURCE>") +# FIXME(#25900): We need -fpp explicitly on case-insensitive filesystems, +# but this does not work with the Ninja generator's separate preprocessing +# and compilation steps. +if(NOT CMAKE_GENERATOR MATCHES "^Ninja") + set(CMAKE_Fortran_COMPILE_OBJECT + "<CMAKE_Fortran_COMPILER> -fpp -o <OBJECT> <DEFINES> <INCLUDES> <FLAGS> -c <SOURCE>") +endif() set(CMAKE_Fortran_OSX_COMPATIBILITY_VERSION_FLAG "-Wl,-compatibility_version -Wl,") set(CMAKE_Fortran_OSX_CURRENT_VERSION_FLAG "-Wl,-current_version -Wl,") +set(CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS "-Wl,-bundle") set(CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS "-Wl,-shared") set(CMAKE_SHARED_LIBRARY_SONAME_Fortran_FLAG "-Wl,-install_name -Wl,") set(CMAKE_Fortran_CREATE_SHARED_LIBRARY diff --git a/Modules/Platform/Linux-Apple-Swift.cmake b/Modules/Platform/Linux-Apple-Swift.cmake index 22f0554..248d2de 100644 --- a/Modules/Platform/Linux-Apple-Swift.cmake +++ b/Modules/Platform/Linux-Apple-Swift.cmake @@ -1,3 +1,5 @@ +set(CMAKE_EXE_EXPORTS_Swift_FLAG "-Xclang-linker -Wl,--export-dynamic") + # Linker Selection # BFD is known to mislink Swift objects resulting in missing type info set(CMAKE_Swift_USING_LINKER_SYSTEM "") diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 284c7a1..226f3a0 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,7 +1,7 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 29) -set(CMake_VERSION_PATCH 20240415) +set(CMake_VERSION_PATCH 20240416) #set(CMake_VERSION_RC 0) set(CMake_VERSION_IS_DIRTY 0) diff --git a/Source/Checks/cm_cxx_features.cmake b/Source/Checks/cm_cxx_features.cmake index 0262746..02ebaa6 100644 --- a/Source/Checks/cm_cxx_features.cmake +++ b/Source/Checks/cm_cxx_features.cmake @@ -43,7 +43,7 @@ function(cm_check_cxx_feature name) # Filter out MSVC output that looks like a command-line warning. string(REGEX REPLACE "[^\n]*warning D[0-9][0-9][0-9][0-9][^\n]*" "" check_output "${check_output}") # Filter out warnings caused by user flags. - string(REGEX REPLACE "[^\n]*warning:[^\n]*-Winvalid-command-line-argument[^\n]*" "" check_output "${check_output}") + string(REGEX REPLACE "[^\n]*warning:[^\n]*-W(invalid|unused)-command-line-argument[^\n]*" "" check_output "${check_output}") # Filter out warnings caused by local configuration. string(REGEX REPLACE "[^\n]*warning:[^\n]*directory not found for option[^\n]*" "" check_output "${check_output}") string(REGEX REPLACE "[^\n]*warning:[^\n]*object file compiled with -mlong-branch which is no longer needed[^\n]*" "" check_output "${check_output}") diff --git a/Source/cmArgumentParserTypes.h b/Source/cmArgumentParserTypes.h index 7daae09..3e0fae4 100644 --- a/Source/cmArgumentParserTypes.h +++ b/Source/cmArgumentParserTypes.h @@ -4,7 +4,7 @@ #include "cmConfigure.h" // IWYU pragma: keep -#if defined(__SUNPRO_CC) +#if defined(__SUNPRO_CC) || defined(__EDG__) # include <string> # include <vector> diff --git a/Source/cmBinUtilsMacOSMachOLinker.cxx b/Source/cmBinUtilsMacOSMachOLinker.cxx index 90e0891..7db7cb0 100644 --- a/Source/cmBinUtilsMacOSMachOLinker.cxx +++ b/Source/cmBinUtilsMacOSMachOLinker.cxx @@ -126,10 +126,16 @@ bool cmBinUtilsMacOSMachOLinker::GetFileDependencies( this->Archive->AddResolvedPath(filename, path, unique, dep_file_info->rpaths); - if (unique && - !this->ScanDependencies(path, dep_file_info->libs, - dep_file_info->rpaths, executablePath)) { - return false; + if (unique) { + std::vector<std::string> combinedParentRpaths = + dep_file_info->rpaths; + combinedParentRpaths.insert(combinedParentRpaths.end(), + rpaths.begin(), rpaths.end()); + if (!this->ScanDependencies(path, dep_file_info->libs, + combinedParentRpaths, + executablePath)) { + return false; + } } } } else { diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index d8f56d1..c943591 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1478,7 +1478,7 @@ void cmLocalGenerator::GetTargetFlags( CM_FALLTHROUGH; case cmStateEnums::SHARED_LIBRARY: { std::string sharedLibFlags; - if (linkLanguage != "Swift") { + if (this->IsSplitSwiftBuild() || linkLanguage != "Swift") { sharedLibFlags = cmStrCat( this->Makefile->GetSafeDefinition(libraryLinkVariable), ' '); if (!configUpper.empty()) { @@ -1521,6 +1521,13 @@ void cmLocalGenerator::GetTargetFlags( } break; case cmStateEnums::EXECUTABLE: { std::string exeFlags; + if (linkLanguage.empty()) { + cmSystemTools::Error( + "CMake can not determine linker language for target: " + + target->GetName()); + return; + } + if (linkLanguage != "Swift") { exeFlags = this->Makefile->GetSafeDefinition("CMAKE_EXE_LINKER_FLAGS"); exeFlags += " "; @@ -1529,28 +1536,22 @@ void cmLocalGenerator::GetTargetFlags( cmStrCat("CMAKE_EXE_LINKER_FLAGS_", configUpper)); exeFlags += " "; } - if (linkLanguage.empty()) { - cmSystemTools::Error( - "CMake can not determine linker language for target: " + - target->GetName()); - return; - } + } - if (target->IsWin32Executable(config)) { - exeFlags += this->Makefile->GetSafeDefinition( - cmStrCat("CMAKE_", linkLanguage, "_CREATE_WIN32_EXE")); - exeFlags += " "; - } else { - exeFlags += this->Makefile->GetSafeDefinition( - cmStrCat("CMAKE_", linkLanguage, "_CREATE_CONSOLE_EXE")); - exeFlags += " "; - } + if (target->IsWin32Executable(config)) { + exeFlags += this->Makefile->GetSafeDefinition( + cmStrCat("CMAKE_", linkLanguage, "_CREATE_WIN32_EXE")); + exeFlags += " "; + } else { + exeFlags += this->Makefile->GetSafeDefinition( + cmStrCat("CMAKE_", linkLanguage, "_CREATE_CONSOLE_EXE")); + exeFlags += " "; + } - if (target->IsExecutableWithExports()) { - exeFlags += this->Makefile->GetSafeDefinition( - cmStrCat("CMAKE_EXE_EXPORTS_", linkLanguage, "_FLAG")); - exeFlags += " "; - } + if (target->IsExecutableWithExports()) { + exeFlags += this->Makefile->GetSafeDefinition( + cmStrCat("CMAKE_EXE_EXPORTS_", linkLanguage, "_FLAG")); + exeFlags += " "; } this->AddLanguageFlagsForLinking(flags, target, linkLanguage, config); diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index bcf9254..fa388e0 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1455,6 +1455,7 @@ if(BUILD_TESTING) _mod IN ITEMS ALSA + Backtrace BLAS Boost BZip2 diff --git a/Tests/FindBacktrace/CMakeLists.txt b/Tests/FindBacktrace/CMakeLists.txt new file mode 100644 index 0000000..8ee2a4d --- /dev/null +++ b/Tests/FindBacktrace/CMakeLists.txt @@ -0,0 +1,10 @@ +add_test(NAME FindBacktrace.Test COMMAND + ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindBacktrace/Test" + "${CMake_BINARY_DIR}/Tests/FindBacktrace/Test" + ${build_generator_args} + --build-project TestFindBacktrace + --build-options ${build_options} + --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> + ) diff --git a/Tests/FindBacktrace/Test/CMakeLists.txt b/Tests/FindBacktrace/Test/CMakeLists.txt new file mode 100644 index 0000000..7f5d8ec --- /dev/null +++ b/Tests/FindBacktrace/Test/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.29) +project(TestFindBLAS C) +include(CTest) + +find_package(Backtrace REQUIRED) + +add_executable(test_tgt backtrace.c) +target_link_libraries(test_tgt Backtrace::Backtrace) +target_compile_options(test_tgt PUBLIC -rdynamic -fno-omit-frame-pointer) +target_link_options(test_tgt PUBLIC -rdynamic -fno-omit-frame-pointer) +add_test(NAME test_tgt COMMAND test_tgt) diff --git a/Tests/FindBacktrace/Test/backtrace.c b/Tests/FindBacktrace/Test/backtrace.c new file mode 100644 index 0000000..1a60b14 --- /dev/null +++ b/Tests/FindBacktrace/Test/backtrace.c @@ -0,0 +1,53 @@ +/* This is the code from `man backtrace_symbols`, reformatted, and without + * requiring a command-line argument */ + +#include <execinfo.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#define BT_BUF_SIZE 100 + +void myfunc3(void) +{ + int nptrs; + void* buffer[BT_BUF_SIZE]; + char** strings; + + nptrs = backtrace(buffer, BT_BUF_SIZE); + printf("backtrace() returned %d addresses\n", nptrs); + + /* The call backtrace_symbols_fd(buffer, nptrs, STDOUT_FILENO) + would produce similar output to the following: */ + + strings = backtrace_symbols(buffer, nptrs); + if (strings == NULL) { + perror("backtrace_symbols"); + exit(EXIT_FAILURE); + } + + for (size_t j = 0; j < nptrs; j++) + printf("%s\n", strings[j]); + + free(strings); +} + +static void /* "static" means don't export the symbol... */ +myfunc2(void) +{ + myfunc3(); +} + +void myfunc(int ncalls) +{ + if (ncalls > 1) + myfunc(ncalls - 1); + else + myfunc2(); +} + +int main(int argc, char* argv[]) +{ + myfunc(5); + exit(EXIT_SUCCESS); +} diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index a82c79f..9e85179 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -1087,11 +1087,22 @@ if(CMAKE_SYSTEM_PROCESSOR STREQUAL "e2k" AND NOT DEFINED CMake_TEST_E2K_BROKEN_L DEB.CUSTOM_NAMES DEB.DEB_PACKAGE_VERSION_BACK_COMPATIBILITY DEB.PROJECT_META DEB.DEPENDENCIES + DEB.EXTRA + DEB.GENERATE_SHLIBS_LDCONFIG + DEB.LONG_FILENAMES + DEB.MD5SUMS + DEB.EMPTY_DIR + DEB.DEFAULT_PERMISSIONS + DEB.VERSION + DEB.TIMESTAMPS RPM.PARTIALLY_RELOCATABLE_WARNING RPM.PER_COMPONENT_FIELDS RPM.USER_FILELIST RPM.DIST RPM.AUTO_SUFFIXES + 7Z + TXZ + TBZ2 TGZ ZIP STGZ diff --git a/Tests/RunCMake/file-GET_RUNTIME_DEPENDENCIES/RunCMakeTest.cmake b/Tests/RunCMake/file-GET_RUNTIME_DEPENDENCIES/RunCMakeTest.cmake index a68607e..f7ede51 100644 --- a/Tests/RunCMake/file-GET_RUNTIME_DEPENDENCIES/RunCMakeTest.cmake +++ b/Tests/RunCMake/file-GET_RUNTIME_DEPENDENCIES/RunCMakeTest.cmake @@ -42,6 +42,7 @@ if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") run_install_test(macos-unresolved) run_install_test(macos-conflict) run_install_test(macos-notfile) + run_install_test(macos-parent-rpath-propagation) run_install_test(file-filter) endif() run_cmake(project) diff --git a/Tests/RunCMake/file-GET_RUNTIME_DEPENDENCIES/macos-parent-rpath-propagation.cmake b/Tests/RunCMake/file-GET_RUNTIME_DEPENDENCIES/macos-parent-rpath-propagation.cmake new file mode 100644 index 0000000..43df621 --- /dev/null +++ b/Tests/RunCMake/file-GET_RUNTIME_DEPENDENCIES/macos-parent-rpath-propagation.cmake @@ -0,0 +1,44 @@ +enable_language(C) + +# bin/exe (RPATH = "lib1:lib2:lib3") +# ^ +# | +# lib1/libone.dylib (RPATH erased) +# ^ +# | +# lib2/libtwo.dylib (RPATH erased) +# ^ +# | +# lib3/libthree.dylib (RPATH erased) +# GET_RUNTIME_DEPENDENCIES(bin/exe) should resolve all three libraries + +set(TEST_SOURCE_DIR "macos/parent-rpath-propagation") + +add_library(three SHARED "${TEST_SOURCE_DIR}/three.c") + +add_library(two SHARED "${TEST_SOURCE_DIR}/two.c") +target_link_libraries(two PRIVATE three) + +add_library(one SHARED "${TEST_SOURCE_DIR}/one.c") +target_link_libraries(one PRIVATE two) + +add_executable(exe "${TEST_SOURCE_DIR}/main.c") +target_link_libraries(exe PUBLIC one) + +set_property(TARGET exe PROPERTY INSTALL_RPATH + @loader_path/../lib1 + @loader_path/../lib2 + @loader_path/../lib3 +) + +install(TARGETS exe DESTINATION bin) +install(TARGETS one DESTINATION lib1) +install(TARGETS two DESTINATION lib2) +install(TARGETS three DESTINATION lib3) + +install(CODE [[ + file(GET_RUNTIME_DEPENDENCIES + EXECUTABLES + "${CMAKE_INSTALL_PREFIX}/bin/$<TARGET_FILE_NAME:exe>" + ) + ]]) diff --git a/Tests/RunCMake/file-GET_RUNTIME_DEPENDENCIES/macos/parent-rpath-propagation/main.c b/Tests/RunCMake/file-GET_RUNTIME_DEPENDENCIES/macos/parent-rpath-propagation/main.c new file mode 100644 index 0000000..fc02afa --- /dev/null +++ b/Tests/RunCMake/file-GET_RUNTIME_DEPENDENCIES/macos/parent-rpath-propagation/main.c @@ -0,0 +1,8 @@ +extern void one(void); + +int main(void) +{ + one(); + + return 0; +} diff --git a/Tests/RunCMake/file-GET_RUNTIME_DEPENDENCIES/macos/parent-rpath-propagation/one.c b/Tests/RunCMake/file-GET_RUNTIME_DEPENDENCIES/macos/parent-rpath-propagation/one.c new file mode 100644 index 0000000..0c480cc --- /dev/null +++ b/Tests/RunCMake/file-GET_RUNTIME_DEPENDENCIES/macos/parent-rpath-propagation/one.c @@ -0,0 +1,6 @@ +extern void two(void); + +void one(void) +{ + two(); +} diff --git a/Tests/RunCMake/file-GET_RUNTIME_DEPENDENCIES/macos/parent-rpath-propagation/three.c b/Tests/RunCMake/file-GET_RUNTIME_DEPENDENCIES/macos/parent-rpath-propagation/three.c new file mode 100644 index 0000000..0be5f47 --- /dev/null +++ b/Tests/RunCMake/file-GET_RUNTIME_DEPENDENCIES/macos/parent-rpath-propagation/three.c @@ -0,0 +1,3 @@ +void three(void) +{ +} diff --git a/Tests/RunCMake/file-GET_RUNTIME_DEPENDENCIES/macos/parent-rpath-propagation/two.c b/Tests/RunCMake/file-GET_RUNTIME_DEPENDENCIES/macos/parent-rpath-propagation/two.c new file mode 100644 index 0000000..370baf7 --- /dev/null +++ b/Tests/RunCMake/file-GET_RUNTIME_DEPENDENCIES/macos/parent-rpath-propagation/two.c @@ -0,0 +1,6 @@ +extern void three(void); + +void two(void) +{ + three(); +} diff --git a/Tests/RunCMake/separate_arguments/ProgramCommand.cmake b/Tests/RunCMake/separate_arguments/ProgramCommand.cmake index bdf5810..cbd44bf 100644 --- a/Tests/RunCMake/separate_arguments/ProgramCommand.cmake +++ b/Tests/RunCMake/separate_arguments/ProgramCommand.cmake @@ -4,12 +4,11 @@ if (out) message (SEND_ERROR "unexpected result with nonexistent program") endif() -set (TEST_EXE_DIR "${CMAKE_CURRENT_BINARY_DIR}/TestExe") -file(MAKE_DIRECTORY "${TEST_EXE_DIR}") -file(COPY "${CMAKE_COMMAND}" DESTINATION "${TEST_EXE_DIR}") -cmake_path (GET CMAKE_COMMAND FILENAME cmake_exe) +get_filename_component(cmake_command "${CMAKE_COMMAND}" ABSOLUTE) +cmake_path (GET cmake_command FILENAME cmake_exe) +cmake_path (GET cmake_command PARENT_PATH cmake_dir) -set (ENV{PATH} "${TEST_EXE_DIR}") +set (ENV{PATH} "${cmake_dir}") separate_arguments (out UNIX_COMMAND PROGRAM "${cmake_exe}") @@ -22,8 +21,8 @@ if (NOT length EQUAL 2) endif() list(GET out 0 cmake) list(GET out 1 args) -if (NOT cmake STREQUAL "${TEST_EXE_DIR}/${cmake_exe}") - message (SEND_ERROR "bad path for program: '${cmake}' instead of '${TEST_EXE_DIR}/${cmake_exe}'") +if (NOT cmake STREQUAL "${cmake_dir}/${cmake_exe}") + message (SEND_ERROR "bad path for program: '${cmake}' instead of '${cmake_dir}/${cmake_exe}'") endif() if (NOT args STREQUAL "") message (SEND_ERROR "bad value for args: '${args}' instead of ''") @@ -40,8 +39,8 @@ if (NOT length EQUAL 2) endif() list(GET out 0 cmake) list(GET out 1 args) -if (NOT cmake STREQUAL "${TEST_EXE_DIR}/${cmake_exe}") - message (SEND_ERROR "bad path for program: '${cmake}' instead of '${TEST_EXE_DIR}/${cmake_exe}'") +if (NOT cmake STREQUAL "${cmake_dir}/${cmake_exe}") + message (SEND_ERROR "bad path for program: '${cmake}' instead of '${cmake_dir}/${cmake_exe}'") endif() if (NOT args STREQUAL " a b c") message (SEND_ERROR "bad value for args: '${args}' instead of ' a b c'") diff --git a/Tests/RunCMake/separate_arguments/ProgramCommandWithSeparateArgs.cmake b/Tests/RunCMake/separate_arguments/ProgramCommandWithSeparateArgs.cmake index 2826cc9..b93b42c 100644 --- a/Tests/RunCMake/separate_arguments/ProgramCommandWithSeparateArgs.cmake +++ b/Tests/RunCMake/separate_arguments/ProgramCommandWithSeparateArgs.cmake @@ -4,12 +4,11 @@ if (out) message (SEND_ERROR "unexpected result with nonexistent program") endif() -set (TEST_EXE_DIR "${CMAKE_CURRENT_BINARY_DIR}/TestExe") -file(MAKE_DIRECTORY "${TEST_EXE_DIR}") -file(COPY "${CMAKE_COMMAND}" DESTINATION "${TEST_EXE_DIR}") -cmake_path (GET CMAKE_COMMAND FILENAME cmake_exe) +get_filename_component(cmake_command "${CMAKE_COMMAND}" ABSOLUTE) +cmake_path (GET cmake_command FILENAME cmake_exe) +cmake_path (GET cmake_command PARENT_PATH cmake_dir) -set (ENV{PATH} "${TEST_EXE_DIR}") +set (ENV{PATH} "${cmake_dir}") separate_arguments (out UNIX_COMMAND PROGRAM SEPARATE_ARGS "${cmake_exe} a b c") list (LENGTH out length) @@ -20,8 +19,8 @@ if (NOT length EQUAL 4) message(FATAL_ERROR "unexpected arguments") endif() list(POP_FRONT out cmake) -if (NOT cmake STREQUAL "${TEST_EXE_DIR}/${cmake_exe}") - message (SEND_ERROR "bad path for program: '${cmake}' instead of '${TEST_EXE_DIR}/${cmake_exe}'") +if (NOT cmake STREQUAL "${cmake_dir}/${cmake_exe}") + message (SEND_ERROR "bad path for program: '${cmake}' instead of '${cmake_dir}/${cmake_exe}'") endif() if (NOT out STREQUAL "a;b;c") message (SEND_ERROR "bad path for args: '${out}' instead of 'a;b;c'") diff --git a/Tests/SwiftOnly/CMakeLists.txt b/Tests/SwiftOnly/CMakeLists.txt index db7caf9..de4c82f 100644 --- a/Tests/SwiftOnly/CMakeLists.txt +++ b/Tests/SwiftOnly/CMakeLists.txt @@ -57,16 +57,7 @@ add_dependencies(P SwiftOnly) add_library(SwiftIface INTERFACE) target_link_libraries(SwiftOnly PRIVATE SwiftIface) -# @_alwaysEmitIntoClient ensures that the function body is inserted into the -# swiftmodule instead of as a symbol in the binary itself. I'm doing this to -# avoid having to link the executable. There are some flags required in order to -# link an executable into a library that I didn't see CMake emitting for Swift -# on macOS. AEIC is the easiest workaround that still tests this functionality. -# Unfortunately, AEIC was only added recently (~Swift 5.2), so we need to check -# that it is available before using it. -if(CMAKE_Swift_COMPILER_VERSION VERSION_GREATER_EQUAL 5.2) - add_subdirectory("SwiftPlugin") -endif() +add_subdirectory("SwiftPlugin") function(test_cmp0157_default mode) if(POLICY CMP0157) diff --git a/Tests/SwiftOnly/SwiftPlugin/CMakeLists.txt b/Tests/SwiftOnly/SwiftPlugin/CMakeLists.txt index 4069f16..2bfbc8a 100644 --- a/Tests/SwiftOnly/SwiftPlugin/CMakeLists.txt +++ b/Tests/SwiftOnly/SwiftPlugin/CMakeLists.txt @@ -1,5 +1,5 @@ add_executable(main main.swift) set_target_properties(main PROPERTIES ENABLE_EXPORTS TRUE) -add_library(plugin plugin.swift) +add_library(plugin MODULE plugin.swift) target_link_libraries(plugin PRIVATE main) diff --git a/Tests/SwiftOnly/SwiftPlugin/main.swift b/Tests/SwiftOnly/SwiftPlugin/main.swift index f5aac51..caba1fb 100644 --- a/Tests/SwiftOnly/SwiftPlugin/main.swift +++ b/Tests/SwiftOnly/SwiftPlugin/main.swift @@ -1,4 +1,3 @@ -@_alwaysEmitIntoClient -public func exported() -> Int { 32 } +public func exported() -> Int { return 32 } print(exported()) diff --git a/Tests/SwiftOnly/SwiftPlugin/plugin.swift b/Tests/SwiftOnly/SwiftPlugin/plugin.swift index e84f248..d00ca33 100644 --- a/Tests/SwiftOnly/SwiftPlugin/plugin.swift +++ b/Tests/SwiftOnly/SwiftPlugin/plugin.swift @@ -1,3 +1,3 @@ import main -public func importing() -> Int { main.exported() + 1 } +public func importing() -> Int { return main.exported() + 1 } |