From 20e98390b3dd016c4e1665b84f83725ed7a81c22 Mon Sep 17 00:00:00 2001 From: KWSys Upstream Date: Wed, 29 Nov 2023 07:53:40 -0500 Subject: [PATCH] KWSys 2023-11-29 (433f3d23) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Code extracted from: https://gitlab.kitware.com/utils/kwsys.git at commit 433f3d23ffa37f8fa6dd42468933f36c28a9e7fa (master). Upstream Shortlog ----------------- Ben Boeckel (2): 46f47034 SharedForward: Drop this component of KWSys 72e677e9 kwsysPrivate.h: Remove unused build-tree copy Brad King (8): 5df8c0a1 RegularExpression: Extend max paren groups from 10 to 32 bfa688b5 SystemTools: Drop optional FindProgramPath arguments 093d6e45 DynamicLoader: Update test to avoid using CMAKE_INTDIR c3201073 String.hxx: Drop this component of KWSys b4492d09 cmake: Drop use of legacy "Dart" module 51272e80 SystemTools: Avoid macOS copyfile semantic differences as root 199aa713 RegularExpression: Tell clang-analyzer that program memory is initialized 9f9ff427 SystemTools: Teach RemoveADirectory to handle non-readable directories Clemens Wasser (1): dd7d92d6 SystemTools: Implement GetEnv via GetEnvironmentVariableW on Win32 Timo Röhling (1): 9119f1a1 SystemInformation: Tolerate empty /proc/cpuinfo scivision (7): e76a8438 Remove try_compile logging in favor of CMake>=3.26 configure log 12825be6 lint: use foreach(... IN {ITEMS,LISTS} ...) f10cb6ad lint: use modern add_test(NAME ... COMMAND ...) ebb95153 lint: set_property(TEST f26b1b39 SystemInformation: use std::cerr like rest of KWSys 3c403fa9 SystemInformation: Replace C-style cast with reinterpret_cast 7f4459d5 Comeau: Remove undocumented support for this compiler --- CMakeLists.txt | 70 ++-- CommandLineArguments.cxx | 13 +- RegularExpression.cxx | 56 ++- RegularExpression.hxx.in | 2 +- SharedForward.h.in | 873 --------------------------------------- String.hxx.in | 57 --- SystemInformation.cxx | 18 +- SystemTools.cxx | 69 +--- SystemTools.hxx.in | 5 +- kwsysPlatformTests.cmake | 63 +-- testDynamicLoader.cxx | 4 +- testSharedForward.c.in | 31 -- 12 files changed, 157 insertions(+), 1104 deletions(-) delete mode 100644 SharedForward.h.in delete mode 100644 String.hxx.in delete mode 100644 testSharedForward.c.in diff --git a/CMakeLists.txt b/CMakeLists.txt index af02f7fb80f..562d5e607d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -201,11 +201,7 @@ endif() # Enable testing if building standalone. if(KWSYS_STANDALONE) - include(Dart) - mark_as_advanced(BUILD_TESTING DART_ROOT TCL_TCLSH) - if(BUILD_TESTING) - enable_testing() - endif() + include(CTest) endif() # Choose default shared/static build if not specified. @@ -302,14 +298,6 @@ endif() set(KWSYS_HEADER_INSTALL_DIR) set(KWSYS_LIBRARY_INSTALL_DIR) -# Generated source files will need this header. -string(COMPARE EQUAL "${PROJECT_SOURCE_DIR}" "${PROJECT_BINARY_DIR}" - KWSYS_IN_SOURCE_BUILD) -if(NOT KWSYS_IN_SOURCE_BUILD) - configure_file(${PROJECT_SOURCE_DIR}/kwsysPrivate.h - ${PROJECT_BINARY_DIR}/kwsysPrivate.h COPYONLY IMMEDIATE) -endif() - # Select plugin module file name convention. if(NOT KWSYS_DynamicLoader_PREFIX) set(KWSYS_DynamicLoader_PREFIX ${CMAKE_SHARED_MODULE_PREFIX}) @@ -630,15 +618,15 @@ endif() # Build a list of classes and headers we need to implement the # selected components. Initialize with required components. set(KWSYS_CLASSES) -set(KWSYS_H_FILES Configure SharedForward) -set(KWSYS_HXX_FILES Configure String) +set(KWSYS_H_FILES Configure) +set(KWSYS_HXX_FILES Configure) # Add selected C++ classes. set(cppclasses Directory DynamicLoader Encoding Glob RegularExpression SystemTools CommandLineArguments FStream SystemInformation ConsoleBuf Status ) -foreach(cpp ${cppclasses}) +foreach(cpp IN LISTS cppclasses) if(KWSYS_USE_${cpp}) # Use the corresponding class. set(KWSYS_CLASSES ${KWSYS_CLASSES} ${cpp}) @@ -651,7 +639,7 @@ foreach(cpp ${cppclasses}) endforeach() # Add selected C components. -foreach(c +foreach(c IN ITEMS Process Base64 Encoding MD5 Terminal System String ) if(KWSYS_USE_${c}) @@ -683,7 +671,7 @@ if(KWSYS_USE_Process) endif() # Add selected C sources. -foreach(c Base64 Encoding MD5 Terminal System String) +foreach(c IN ITEMS Base64 Encoding MD5 Terminal System String) if(KWSYS_USE_${c}) if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${c}C.c) list(APPEND KWSYS_C_SRCS ${c}C.c) @@ -694,7 +682,7 @@ foreach(c Base64 Encoding MD5 Terminal System String) endforeach() # Configure headers of C++ classes and construct the list of sources. -foreach(c ${KWSYS_CLASSES}) +foreach(c IN LISTS KWSYS_CLASSES) # Add this source to the list of source files for the library. if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${c}CXX.cxx) list(APPEND KWSYS_CXX_SRCS ${c}CXX.cxx) @@ -716,7 +704,7 @@ foreach(c ${KWSYS_CLASSES}) endforeach() # Configure C headers. -foreach(h ${KWSYS_H_FILES}) +foreach(h IN LISTS KWSYS_H_FILES) # Configure the header into the given directory. configure_file(${PROJECT_SOURCE_DIR}/${h}.h.in ${KWSYS_HEADER_DIR}/${h}.h @ONLY IMMEDIATE) @@ -731,7 +719,7 @@ foreach(h ${KWSYS_H_FILES}) endforeach() # Configure other C++ headers. -foreach(h ${KWSYS_HXX_FILES}) +foreach(h IN LISTS KWSYS_HXX_FILES) # Configure the header into the given directory. configure_file(${PROJECT_SOURCE_DIR}/${h}.hxx.in ${KWSYS_HEADER_DIR}/${h}.hxx @ONLY IMMEDIATE) @@ -960,9 +948,11 @@ if(KWSYS_STANDALONE OR CMake_SOURCE_DIR) add_executable(${KWSYS_NAMESPACE}TestsC ${KWSYS_C_TEST_SRCS}) set_property(TARGET ${KWSYS_NAMESPACE}TestsC PROPERTY LABELS ${KWSYS_LABELS_EXE}) target_link_libraries(${KWSYS_NAMESPACE}TestsC ${KWSYS_TARGET_C_LINK}) - foreach(testfile ${KWSYS_C_TESTS}) + foreach(testfile IN LISTS KWSYS_C_TESTS) get_filename_component(test "${testfile}" NAME_WE) - add_test(kwsys.${test} ${EXEC_DIR}/${KWSYS_NAMESPACE}TestsC ${test} ${KWSYS_TEST_ARGS_${test}}) + add_test(NAME kwsys.${test} + COMMAND ${EXEC_DIR}/${KWSYS_NAMESPACE}TestsC ${test} ${KWSYS_TEST_ARGS_${test}} + ) set_property(TEST kwsys.${test} PROPERTY LABELS ${KWSYS_LABELS_TEST}) endforeach() @@ -1038,6 +1028,10 @@ if(KWSYS_STANDALONE OR CMake_SOURCE_DIR) set_property(TARGET ${KWSYS_NAMESPACE}TestsCxx PROPERTY CXX_INCLUDE_WHAT_YOU_USE "") set_property(TARGET ${KWSYS_NAMESPACE}TestsCxx PROPERTY LABELS ${KWSYS_LABELS_EXE}) target_link_libraries(${KWSYS_NAMESPACE}TestsCxx ${KWSYS_TARGET_LINK}) + get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + if(_isMultiConfig) + set_property(TARGET ${KWSYS_NAMESPACE}TestsCxx APPEND PROPERTY COMPILE_DEFINITIONS BUILD_CONFIG="$") + endif() set(TEST_SYSTEMTOOLS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") set(TEST_SYSTEMTOOLS_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}") @@ -1080,9 +1074,11 @@ if(KWSYS_STANDALONE OR CMake_SOURCE_DIR) -p some junk at the end ) - foreach(testfile ${KWSYS_CXX_TESTS}) + foreach(testfile IN LISTS KWSYS_CXX_TESTS) get_filename_component(test "${testfile}" NAME_WE) - add_test(kwsys.${test} ${EXEC_DIR}/${KWSYS_NAMESPACE}TestsCxx ${test} ${KWSYS_TEST_ARGS_${test}}) + add_test(NAME kwsys.${test} + COMMAND ${EXEC_DIR}/${KWSYS_NAMESPACE}TestsCxx ${test} ${KWSYS_TEST_ARGS_${test}} + ) set_property(TEST kwsys.${test} PROPERTY LABELS ${KWSYS_LABELS_TEST}) endforeach() @@ -1091,10 +1087,12 @@ if(KWSYS_STANDALONE OR CMake_SOURCE_DIR) set_property(TARGET ${KWSYS_NAMESPACE}TestProcess PROPERTY LABELS ${KWSYS_LABELS_EXE}) target_link_libraries(${KWSYS_NAMESPACE}TestProcess ${KWSYS_TARGET_C_LINK}) #set(KWSYS_TEST_PROCESS_7 7) # uncomment to run timing-sensitive test locally - foreach(n 1 2 3 4 5 6 ${KWSYS_TEST_PROCESS_7} 9 10) - add_test(kwsys.testProcess-${n} ${EXEC_DIR}/${KWSYS_NAMESPACE}TestProcess ${n}) + foreach(n IN ITEMS 1 2 3 4 5 6 ${KWSYS_TEST_PROCESS_7} 9 10) + add_test(NAME kwsys.testProcess-${n} + COMMAND ${EXEC_DIR}/${KWSYS_NAMESPACE}TestProcess ${n} + ) set_property(TEST kwsys.testProcess-${n} PROPERTY LABELS ${KWSYS_LABELS_TEST}) - set_tests_properties(kwsys.testProcess-${n} PROPERTIES TIMEOUT 120) + set_property(TEST kwsys.testProcess-${n} PROPERTY TIMEOUT 120) endforeach() set(testProcess_COMPILE_FLAGS "") @@ -1118,22 +1116,12 @@ if(KWSYS_STANDALONE OR CMake_SOURCE_DIR) endif() set_property(SOURCE testProcess.c PROPERTY COMPILE_FLAGS "${testProcess_COMPILE_FLAGS}") - # Test SharedForward - configure_file(${PROJECT_SOURCE_DIR}/testSharedForward.c.in - ${PROJECT_BINARY_DIR}/testSharedForward.c @ONLY IMMEDIATE) - add_executable(${KWSYS_NAMESPACE}TestSharedForward - ${PROJECT_BINARY_DIR}/testSharedForward.c) - set_property(TARGET ${KWSYS_NAMESPACE}TestSharedForward PROPERTY LABELS ${KWSYS_LABELS_EXE}) - add_dependencies(${KWSYS_NAMESPACE}TestSharedForward ${KWSYS_TARGET_C_LINK}) - add_test(kwsys.testSharedForward ${EXEC_DIR}/${KWSYS_NAMESPACE}TestSharedForward 1) - set_property(TEST kwsys.testSharedForward PROPERTY LABELS ${KWSYS_LABELS_TEST}) - # Configure some test properties. if(KWSYS_STANDALONE) # We expect test to fail - set_tests_properties(kwsys.testFail PROPERTIES WILL_FAIL ON) + set_property(TEST kwsys.testFail PROPERTY WILL_FAIL ON) get_test_property(kwsys.testFail WILL_FAIL wfv) - set_tests_properties(kwsys.testFail PROPERTIES MEASUREMENT "Some Key=Some Value") + set_property(TEST kwsys.testFail PROPERTY MEASUREMENT "Some Key=Some Value") message(STATUS "GET_TEST_PROPERTY returned: ${wfv}") endif() @@ -1143,7 +1131,7 @@ if(KWSYS_STANDALONE OR CMake_SOURCE_DIR) # Suppress known consistent failures on buggy systems. if(KWSYS_TEST_BOGUS_FAILURES) - set_tests_properties(${KWSYS_TEST_BOGUS_FAILURES} PROPERTIES WILL_FAIL ON) + set_property(TEST ${KWSYS_TEST_BOGUS_FAILURES} PROPERTY WILL_FAIL ON) endif() endif() diff --git a/CommandLineArguments.cxx b/CommandLineArguments.cxx index ccd5f6dccf6..50171dd3c60 100644 --- a/CommandLineArguments.cxx +++ b/CommandLineArguments.cxx @@ -4,20 +4,19 @@ #include KWSYS_HEADER(CommandLineArguments.hxx) #include KWSYS_HEADER(Configure.hxx) -#include KWSYS_HEADER(String.hxx) // Work-around CMake dependency scanning limitation. This must // duplicate the above list of headers. #if 0 # include "CommandLineArguments.hxx.in" # include "Configure.hxx.in" -# include "String.hxx.in" #endif #include #include #include #include +#include #include #include @@ -52,14 +51,14 @@ struct CommandLineArgumentsCallbackStructure const char* Help; }; -class CommandLineArgumentsVectorOfStrings : public std::vector +class CommandLineArgumentsVectorOfStrings : public std::vector { }; -class CommandLineArgumentsSetOfStrings : public std::set +class CommandLineArgumentsSetOfStrings : public std::set { }; class CommandLineArgumentsMapOfStrucs - : public std::map + : public std::map { }; @@ -70,7 +69,7 @@ class CommandLineArgumentsInternal using VectorOfStrings = CommandLineArgumentsVectorOfStrings; using CallbacksMap = CommandLineArgumentsMapOfStrucs; - using String = kwsys::String; + using String = std::string; using SetOfStrings = CommandLineArgumentsSetOfStrings; VectorOfStrings Argv; @@ -306,7 +305,7 @@ void CommandLineArguments::GetUnusedArguments(int* argc, char*** argv) // Copy everything after the LastArgument, since that was not parsed. for (cc = 0; cc < this->Internals->UnusedArguments.size(); cc++) { - kwsys::String& str = this->Internals->UnusedArguments[cc]; + std::string& str = this->Internals->UnusedArguments[cc]; args[cnt] = new char[str.size() + 1]; strcpy(args[cnt], str.c_str()); cnt++; diff --git a/RegularExpression.cxx b/RegularExpression.cxx index c96a96d4d22..b51e16d8ae0 100644 --- a/RegularExpression.cxx +++ b/RegularExpression.cxx @@ -218,7 +218,7 @@ bool RegularExpression::deep_equal(const RegularExpression& rxp) const 20 // no Mark this point in input as start of // #n. // OPEN+1 is number 1, etc. -#define CLOSE 30 // no Analogous to OPEN. +#define CLOSE 52 // no Analogous to OPEN. /* * Opcode notes: @@ -378,6 +378,10 @@ bool RegularExpression::compile(const char* exp) return false; } +#ifdef __clang_analyzer__ /* Convince it that the program is initialized. */ + memset(this->program, 0, comp.regsize); +#endif + // Second pass: emit code. comp.regparse = exp; comp.regnpar = 1; @@ -1018,7 +1022,30 @@ int RegExpFind::regmatch(const char* prog) case OPEN + 6: case OPEN + 7: case OPEN + 8: - case OPEN + 9: { + case OPEN + 9: + case OPEN + 10: + case OPEN + 11: + case OPEN + 12: + case OPEN + 13: + case OPEN + 14: + case OPEN + 15: + case OPEN + 16: + case OPEN + 17: + case OPEN + 18: + case OPEN + 19: + case OPEN + 20: + case OPEN + 21: + case OPEN + 22: + case OPEN + 23: + case OPEN + 24: + case OPEN + 25: + case OPEN + 26: + case OPEN + 27: + case OPEN + 28: + case OPEN + 29: + case OPEN + 30: + case OPEN + 31: + case OPEN + 32: { int no; const char* save; @@ -1046,7 +1073,30 @@ int RegExpFind::regmatch(const char* prog) case CLOSE + 6: case CLOSE + 7: case CLOSE + 8: - case CLOSE + 9: { + case CLOSE + 9: + case CLOSE + 10: + case CLOSE + 11: + case CLOSE + 12: + case CLOSE + 13: + case CLOSE + 14: + case CLOSE + 15: + case CLOSE + 16: + case CLOSE + 17: + case CLOSE + 18: + case CLOSE + 19: + case CLOSE + 20: + case CLOSE + 21: + case CLOSE + 22: + case CLOSE + 23: + case CLOSE + 24: + case CLOSE + 25: + case CLOSE + 26: + case CLOSE + 27: + case CLOSE + 28: + case CLOSE + 29: + case CLOSE + 30: + case CLOSE + 31: + case CLOSE + 32: { int no; const char* save; diff --git a/RegularExpression.hxx.in b/RegularExpression.hxx.in index 2cb7f5e1cf9..1dc1dfa2089 100644 --- a/RegularExpression.hxx.in +++ b/RegularExpression.hxx.in @@ -50,7 +50,7 @@ public: enum { - NSUBEXP = 10 + NSUBEXP = 32 }; private: diff --git a/SharedForward.h.in b/SharedForward.h.in deleted file mode 100644 index d6ae75c47b5..00000000000 --- a/SharedForward.h.in +++ /dev/null @@ -1,873 +0,0 @@ -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing#kwsys for details. */ -#ifndef @KWSYS_NAMESPACE@_SharedForward_h -# define @KWSYS_NAMESPACE@_SharedForward_h - -/* - This header is used to create a forwarding executable sets up the - shared library search path and replaces itself with a real - executable. This is useful when creating installations on UNIX with - shared libraries that will run from any install directory. Typical - usage: - - #if defined(CMAKE_INTDIR) - # define CONFIG_DIR_PRE CMAKE_INTDIR "/" - # define CONFIG_DIR_POST "/" CMAKE_INTDIR - #else - # define CONFIG_DIR_PRE "" - # define CONFIG_DIR_POST "" - #endif - #define @KWSYS_NAMESPACE@_SHARED_FORWARD_DIR_BUILD "/path/to/foo-build/bin" - #define @KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_BUILD "." CONFIG_DIR_POST - #define @KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_INSTALL "../lib/foo-1.2" - #define @KWSYS_NAMESPACE@_SHARED_FORWARD_EXE_BUILD CONFIG_DIR_PRE "foo-real" - #define @KWSYS_NAMESPACE@_SHARED_FORWARD_EXE_INSTALL - "../lib/foo-1.2/foo-real" - #define @KWSYS_NAMESPACE@_SHARED_FORWARD_OPTION_COMMAND "--command" - #define @KWSYS_NAMESPACE@_SHARED_FORWARD_OPTION_PRINT "--print" - #define @KWSYS_NAMESPACE@_SHARED_FORWARD_OPTION_LDD "--ldd" - #if defined(CMAKE_INTDIR) - # define @KWSYS_NAMESPACE@_SHARED_FORWARD_CONFIG_NAME CMAKE_INTDIR - #endif - #include <@KWSYS_NAMESPACE@/SharedForward.h> - int main(int argc, char** argv) - { - return @KWSYS_NAMESPACE@_shared_forward_to_real(argc, argv); - } - - Specify search and executable paths relative to the forwarding - executable location or as full paths. Include no trailing slash. - In the case of a multi-configuration build, when CMAKE_INTDIR is - defined, the DIR_BUILD setting should point at the directory above - the executable (the one containing the per-configuration - subdirectory specified by CMAKE_INTDIR). Then PATH_BUILD entries - and EXE_BUILD should be specified relative to this location and use - CMAKE_INTDIR as necessary. In the above example imagine appending - the PATH_BUILD or EXE_BUILD setting to the DIR_BUILD setting. The - result should form a valid path with per-configuration subdirectory. - - Additional paths may be specified in the PATH_BUILD and PATH_INSTALL - variables by using comma-separated strings. For example: - - #define @KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_BUILD \ - "." CONFIG_DIR_POST, "/path/to/bar-build" CONFIG_DIR_POST - #define @KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_INSTALL \ - "../lib/foo-1.2", "../lib/bar-4.5" - - See the comments below for specific explanations of each macro. -*/ - -/* Disable -Wcast-qual warnings since they are too hard to fix in a - cross-platform way. */ -# if defined(__clang__) && defined(__has_warning) -# if __has_warning("-Wcast-qual") -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wcast-qual" -# endif -# endif - -/* Full path to the directory in which this executable is built. Do - not include a trailing slash. */ -# if !defined(@KWSYS_NAMESPACE@_SHARED_FORWARD_DIR_BUILD) -# error "Must define @KWSYS_NAMESPACE@_SHARED_FORWARD_DIR_BUILD" -# endif -# if !defined(KWSYS_SHARED_FORWARD_DIR_BUILD) -# define KWSYS_SHARED_FORWARD_DIR_BUILD \ - @KWSYS_NAMESPACE@_SHARED_FORWARD_DIR_BUILD -# endif - -/* Library search path for build tree. */ -# if !defined(@KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_BUILD) -# error "Must define @KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_BUILD" -# endif -# if !defined(KWSYS_SHARED_FORWARD_PATH_BUILD) -# define KWSYS_SHARED_FORWARD_PATH_BUILD \ - @KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_BUILD -# endif - -/* Library search path for install tree. */ -# if !defined(@KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_INSTALL) -# error "Must define @KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_INSTALL" -# endif -# if !defined(KWSYS_SHARED_FORWARD_PATH_INSTALL) -# define KWSYS_SHARED_FORWARD_PATH_INSTALL \ - @KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_INSTALL -# endif - -/* The real executable to which to forward in the build tree. */ -# if !defined(@KWSYS_NAMESPACE@_SHARED_FORWARD_EXE_BUILD) -# error "Must define @KWSYS_NAMESPACE@_SHARED_FORWARD_EXE_BUILD" -# endif -# if !defined(KWSYS_SHARED_FORWARD_EXE_BUILD) -# define KWSYS_SHARED_FORWARD_EXE_BUILD \ - @KWSYS_NAMESPACE@_SHARED_FORWARD_EXE_BUILD -# endif - -/* The real executable to which to forward in the install tree. */ -# if !defined(@KWSYS_NAMESPACE@_SHARED_FORWARD_EXE_INSTALL) -# error "Must define @KWSYS_NAMESPACE@_SHARED_FORWARD_EXE_INSTALL" -# endif -# if !defined(KWSYS_SHARED_FORWARD_EXE_INSTALL) -# define KWSYS_SHARED_FORWARD_EXE_INSTALL \ - @KWSYS_NAMESPACE@_SHARED_FORWARD_EXE_INSTALL -# endif - -/* The configuration name with which this executable was built (Debug/Release). - */ -# if defined(@KWSYS_NAMESPACE@_SHARED_FORWARD_CONFIG_NAME) -# define KWSYS_SHARED_FORWARD_CONFIG_NAME \ - @KWSYS_NAMESPACE@_SHARED_FORWARD_CONFIG_NAME -# else -# undef KWSYS_SHARED_FORWARD_CONFIG_NAME -# endif - -/* Create command line option to replace executable. */ -# if defined(@KWSYS_NAMESPACE@_SHARED_FORWARD_OPTION_COMMAND) -# if !defined(KWSYS_SHARED_FORWARD_OPTION_COMMAND) -# define KWSYS_SHARED_FORWARD_OPTION_COMMAND \ - @KWSYS_NAMESPACE@_SHARED_FORWARD_OPTION_COMMAND -# endif -# else -# undef KWSYS_SHARED_FORWARD_OPTION_COMMAND -# endif - -/* Create command line option to print environment setting and exit. */ -# if defined(@KWSYS_NAMESPACE@_SHARED_FORWARD_OPTION_PRINT) -# if !defined(KWSYS_SHARED_FORWARD_OPTION_PRINT) -# define KWSYS_SHARED_FORWARD_OPTION_PRINT \ - @KWSYS_NAMESPACE@_SHARED_FORWARD_OPTION_PRINT -# endif -# else -# undef KWSYS_SHARED_FORWARD_OPTION_PRINT -# endif - -/* Create command line option to run ldd or equivalent. */ -# if defined(@KWSYS_NAMESPACE@_SHARED_FORWARD_OPTION_LDD) -# if !defined(KWSYS_SHARED_FORWARD_OPTION_LDD) -# define KWSYS_SHARED_FORWARD_OPTION_LDD \ - @KWSYS_NAMESPACE@_SHARED_FORWARD_OPTION_LDD -# endif -# else -# undef KWSYS_SHARED_FORWARD_OPTION_LDD -# endif - -/* Include needed system headers. */ - -# include -# include -# include /* size_t */ -# include -# include -# include - -# if defined(_WIN32) && !defined(__CYGWIN__) -# include - -# include -# include -# define KWSYS_SHARED_FORWARD_ESCAPE_ARGV /* re-escape argv for execvp */ -# else -# include -# include -# endif - -/* Configuration for this platform. */ - -/* The path separator for this platform. */ -# if defined(_WIN32) && !defined(__CYGWIN__) -# define KWSYS_SHARED_FORWARD_PATH_SEP ';' -# define KWSYS_SHARED_FORWARD_PATH_SLASH '\\' -# else -# define KWSYS_SHARED_FORWARD_PATH_SEP ':' -# define KWSYS_SHARED_FORWARD_PATH_SLASH '/' -# endif -static const char kwsys_shared_forward_path_sep[2] = { - KWSYS_SHARED_FORWARD_PATH_SEP, 0 -}; -static const char kwsys_shared_forward_path_slash[2] = { - KWSYS_SHARED_FORWARD_PATH_SLASH, 0 -}; - -/* The maximum length of a file name. */ -# if defined(PATH_MAX) -# define KWSYS_SHARED_FORWARD_MAXPATH PATH_MAX -# elif defined(MAXPATHLEN) -# define KWSYS_SHARED_FORWARD_MAXPATH MAXPATHLEN -# else -# define KWSYS_SHARED_FORWARD_MAXPATH 16384 -# endif - -/* Select the environment variable holding the shared library runtime - search path for this platform and build configuration. Also select - ldd command equivalent. */ - -/* Linux */ -# if defined(__linux) -# define KWSYS_SHARED_FORWARD_LDD "ldd" -# define KWSYS_SHARED_FORWARD_LDD_N 1 -# define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY_PATH" - -/* FreeBSD */ -# elif defined(__FreeBSD__) -# define KWSYS_SHARED_FORWARD_LDD "ldd" -# define KWSYS_SHARED_FORWARD_LDD_N 1 -# define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY_PATH" - -/* OpenBSD */ -# elif defined(__OpenBSD__) -# define KWSYS_SHARED_FORWARD_LDD "ldd" -# define KWSYS_SHARED_FORWARD_LDD_N 1 -# define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY_PATH" - -/* OS X */ -# elif defined(__APPLE__) -# define KWSYS_SHARED_FORWARD_LDD "otool", "-L" -# define KWSYS_SHARED_FORWARD_LDD_N 2 -# define KWSYS_SHARED_FORWARD_LDPATH "DYLD_LIBRARY_PATH" - -/* AIX */ -# elif defined(_AIX) -# define KWSYS_SHARED_FORWARD_LDD "dump", "-H" -# define KWSYS_SHARED_FORWARD_LDD_N 2 -# define KWSYS_SHARED_FORWARD_LDPATH "LIBPATH" - -/* SUN */ -# elif defined(__sun) -# define KWSYS_SHARED_FORWARD_LDD "ldd" -# define KWSYS_SHARED_FORWARD_LDD_N 1 -# include -# if defined(_ILP32) -# define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY_PATH" -# elif defined(_LP64) -# define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY_PATH_64" -# endif - -/* HP-UX */ -# elif defined(__hpux) -# define KWSYS_SHARED_FORWARD_LDD "chatr" -# define KWSYS_SHARED_FORWARD_LDD_N 1 -# if defined(__LP64__) -# define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY_PATH" -# else -# define KWSYS_SHARED_FORWARD_LDPATH "SHLIB_PATH" -# endif - -/* SGI MIPS */ -# elif defined(__sgi) && defined(_MIPS_SIM) -# define KWSYS_SHARED_FORWARD_LDD "ldd" -# define KWSYS_SHARED_FORWARD_LDD_N 1 -# if _MIPS_SIM == _ABIO32 -# define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY_PATH" -# elif _MIPS_SIM == _ABIN32 -# define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARYN32_PATH" -# elif _MIPS_SIM == _ABI64 -# define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY64_PATH" -# endif - -/* Cygwin */ -# elif defined(__CYGWIN__) -# define KWSYS_SHARED_FORWARD_LDD \ - "cygcheck" /* TODO: cygwin 1.7 has ldd \ - */ -# define KWSYS_SHARED_FORWARD_LDD_N 1 -# define KWSYS_SHARED_FORWARD_LDPATH "PATH" - -/* Windows */ -# elif defined(_WIN32) -# define KWSYS_SHARED_FORWARD_LDPATH "PATH" - -/* Guess on this unknown system. */ -# else -# define KWSYS_SHARED_FORWARD_LDD "ldd" -# define KWSYS_SHARED_FORWARD_LDD_N 1 -# define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY_PATH" -# endif - -# ifdef KWSYS_SHARED_FORWARD_ESCAPE_ARGV -typedef struct kwsys_sf_arg_info_s -{ - const char* arg; - int size; - int quote; -} kwsys_sf_arg_info; - -static kwsys_sf_arg_info kwsys_sf_get_arg_info(const char* in) -{ - /* Initialize information. */ - kwsys_sf_arg_info info; - - /* String iterator. */ - const char* c; - - /* Keep track of how many backslashes have been encountered in a row. */ - int windows_backslashes = 0; - - /* Start with the length of the original argument, plus one for - either a terminating null or a separating space. */ - info.arg = in; - info.size = (int)strlen(in) + 1; - info.quote = 0; - - /* Scan the string for characters that require escaping or quoting. */ - for (c = in; *c; ++c) { - /* Check whether this character needs quotes. */ - if (strchr(" \t?'#&<>|^", *c)) { - info.quote = 1; - } - - /* On Windows only backslashes and double-quotes need escaping. */ - if (*c == '\\') { - /* Found a backslash. It may need to be escaped later. */ - ++windows_backslashes; - } else if (*c == '"') { - /* Found a double-quote. We need to escape it and all - immediately preceding backslashes. */ - info.size += windows_backslashes + 1; - windows_backslashes = 0; - } else { - /* Found another character. This eliminates the possibility - that any immediately preceding backslashes will be - escaped. */ - windows_backslashes = 0; - } - } - - /* Check whether the argument needs surrounding quotes. */ - if (info.quote) { - /* Surrounding quotes are needed. Allocate space for them. */ - info.size += 2; - - /* We must escape all ending backslashes when quoting on windows. */ - info.size += windows_backslashes; - } - - return info; -} - -static char* kwsys_sf_get_arg(kwsys_sf_arg_info info, char* out) -{ - /* String iterator. */ - const char* c; - - /* Keep track of how many backslashes have been encountered in a row. */ - int windows_backslashes = 0; - - /* Whether the argument must be quoted. */ - if (info.quote) { - /* Add the opening quote for this argument. */ - *out++ = '"'; - } - - /* Scan the string for characters that require escaping or quoting. */ - for (c = info.arg; *c; ++c) { - /* On Windows only backslashes and double-quotes need escaping. */ - if (*c == '\\') { - /* Found a backslash. It may need to be escaped later. */ - ++windows_backslashes; - } else if (*c == '"') { - /* Found a double-quote. Escape all immediately preceding - backslashes. */ - while (windows_backslashes > 0) { - --windows_backslashes; - *out++ = '\\'; - } - - /* Add the backslash to escape the double-quote. */ - *out++ = '\\'; - } else { - /* We encountered a normal character. This eliminates any - escaping needed for preceding backslashes. */ - windows_backslashes = 0; - } - - /* Store this character. */ - *out++ = *c; - } - - if (info.quote) { - /* Add enough backslashes to escape any trailing ones. */ - while (windows_backslashes > 0) { - --windows_backslashes; - *out++ = '\\'; - } - - /* Add the closing quote for this argument. */ - *out++ = '"'; - } - - /* Store a terminating null without incrementing. */ - *out = 0; - - return out; -} -# endif - -/* Function to convert a logical or relative path to a physical full path. */ -static int kwsys_shared_forward_realpath(const char* in_path, char* out_path) -{ -# if defined(_WIN32) && !defined(__CYGWIN__) - /* Implementation for Windows. */ - DWORD n = - GetFullPathNameA(in_path, KWSYS_SHARED_FORWARD_MAXPATH, out_path, 0); - return n > 0 && n <= KWSYS_SHARED_FORWARD_MAXPATH; -# else - /* Implementation for UNIX. */ - return realpath(in_path, out_path) != 0; -# endif -} - -static int kwsys_shared_forward_samepath(const char* file1, const char* file2) -{ -# if defined(_WIN32) - int result = 0; - HANDLE h1 = CreateFileA(file1, GENERIC_READ, FILE_SHARE_READ, NULL, - OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); - HANDLE h2 = CreateFileA(file2, GENERIC_READ, FILE_SHARE_READ, NULL, - OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); - if (h1 != INVALID_HANDLE_VALUE && h2 != INVALID_HANDLE_VALUE) { - BY_HANDLE_FILE_INFORMATION fi1; - BY_HANDLE_FILE_INFORMATION fi2; - GetFileInformationByHandle(h1, &fi1); - GetFileInformationByHandle(h2, &fi2); - result = (fi1.dwVolumeSerialNumber == fi2.dwVolumeSerialNumber && - fi1.nFileIndexHigh == fi2.nFileIndexHigh && - fi1.nFileIndexLow == fi2.nFileIndexLow); - } - CloseHandle(h1); - CloseHandle(h2); - return result; -# else - struct stat fs1, fs2; - return (stat(file1, &fs1) == 0 && stat(file2, &fs2) == 0 && - memcmp(&fs2.st_dev, &fs1.st_dev, sizeof(fs1.st_dev)) == 0 && - memcmp(&fs2.st_ino, &fs1.st_ino, sizeof(fs1.st_ino)) == 0 && - fs2.st_size == fs1.st_size); -# endif -} - -/* Function to report a system error message. */ -static void kwsys_shared_forward_strerror(char* message) -{ -# if defined(_WIN32) && !defined(__CYGWIN__) - /* Implementation for Windows. */ - DWORD original = GetLastError(); - DWORD length = - FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - 0, original, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - message, KWSYS_SHARED_FORWARD_MAXPATH, 0); - if (length < 1 || length > KWSYS_SHARED_FORWARD_MAXPATH) { - /* FormatMessage failed. Use a default message. */ - snprintf(message, KWSYS_SHARED_FORWARD_MAXPATH, - "Error 0x%lX (FormatMessage failed with error 0x%lX)", original, - GetLastError()); - } -# else - /* Implementation for UNIX. */ - strcpy(message, strerror(errno)); -# endif -} - -/* Functions to execute a child process. */ -static void kwsys_shared_forward_execvp(const char* cmd, - char const* const* argv) -{ -# ifdef KWSYS_SHARED_FORWARD_ESCAPE_ARGV - /* Count the number of arguments. */ - int argc = 0; - { - char const* const* argvc; - for (argvc = argv; *argvc; ++argvc, ++argc) { - } - } - - /* Create the escaped arguments. */ - { - char** nargv = (char**)malloc((argc + 1) * sizeof(char*)); - int i; - for (i = 0; i < argc; ++i) { - kwsys_sf_arg_info info = kwsys_sf_get_arg_info(argv[i]); - nargv[i] = (char*)malloc(info.size); - kwsys_sf_get_arg(info, nargv[i]); - } - nargv[argc] = 0; - - /* Replace the command line to be used. */ - argv = (char const* const*)nargv; - } -# endif - -/* Invoke the child process. */ -# if defined(_MSC_VER) - _execvp(cmd, argv); -# elif defined(__MINGW32__) && !defined(__MINGW64__) - execvp(cmd, argv); -# else - execvp(cmd, (char* const*)argv); -# endif -} - -/* Function to get the directory containing the given file or directory. */ -static void kwsys_shared_forward_dirname(const char* begin, char* result) -{ - /* Find the location of the last slash. */ - int last_slash_index = -1; - const char* end = begin + strlen(begin); - for (; begin <= end && last_slash_index < 0; --end) { - if (*end == '/' || *end == '\\') { - last_slash_index = (int)(end - begin); - } - } - - /* Handle each case of the index of the last slash. */ - if (last_slash_index < 0) { - /* No slashes. */ - strcpy(result, "."); - } else if (last_slash_index == 0) { - /* Only one leading slash. */ - strcpy(result, kwsys_shared_forward_path_slash); - } -# if defined(_WIN32) - else if (last_slash_index == 2 && begin[1] == ':') { - /* Only one leading drive letter and slash. */ - strncpy(result, begin, (size_t)last_slash_index); - result[last_slash_index] = KWSYS_SHARED_FORWARD_PATH_SLASH; - result[last_slash_index + 1] = 0; - } -# endif - else { - /* A non-leading slash. */ - strncpy(result, begin, (size_t)last_slash_index); - result[last_slash_index] = 0; - } -} - -/* Function to check if a file exists and is executable. */ -static int kwsys_shared_forward_is_executable(const char* f) -{ -# if defined(_MSC_VER) -# define KWSYS_SHARED_FORWARD_ACCESS _access -# else -# define KWSYS_SHARED_FORWARD_ACCESS access -# endif -# if defined(X_OK) -# define KWSYS_SHARED_FORWARD_ACCESS_OK X_OK -# else -# define KWSYS_SHARED_FORWARD_ACCESS_OK 04 -# endif - if (KWSYS_SHARED_FORWARD_ACCESS(f, KWSYS_SHARED_FORWARD_ACCESS_OK) == 0) { - return 1; - } else { - return 0; - } -} - -/* Function to locate the executable currently running. */ -static int kwsys_shared_forward_self_path(const char* argv0, char* result) -{ - /* Check whether argv0 has a slash. */ - int has_slash = 0; - const char* p = argv0; - for (; *p && !has_slash; ++p) { - if (*p == '/' || *p == '\\') { - has_slash = 1; - } - } - - if (has_slash) { - /* There is a slash. Use the dirname of the given location. */ - kwsys_shared_forward_dirname(argv0, result); - return 1; - } else { - /* There is no slash. Search the PATH for the executable. */ - const char* path = getenv("PATH"); - const char* begin = path; - const char* end = begin + (begin ? strlen(begin) : 0); - const char* first = begin; - while (first != end) { - /* Store the end of this path entry. */ - const char* last; - - /* Skip all path separators. */ - for (; *first && *first == KWSYS_SHARED_FORWARD_PATH_SEP; ++first) - ; - - /* Find the next separator. */ - for (last = first; *last && *last != KWSYS_SHARED_FORWARD_PATH_SEP; - ++last) - ; - - /* If we got a non-empty directory, look for the executable there. */ - if (first < last) { - /* Determine the length without trailing slash. */ - size_t length = (size_t)(last - first); - if (*(last - 1) == '/' || *(last - 1) == '\\') { - --length; - } - - /* Construct the name of the executable in this location. */ - strncpy(result, first, length); - result[length] = KWSYS_SHARED_FORWARD_PATH_SLASH; - strcpy(result + (length) + 1, argv0); - - /* Check if it exists and is executable. */ - if (kwsys_shared_forward_is_executable(result)) { - /* Found it. */ - result[length] = 0; - return 1; - } - } - - /* Move to the next directory in the path. */ - first = last; - } - } - - /* We could not find the executable. */ - return 0; -} - -/* Function to convert a specified path to a full path. If it is not - already full, it is taken relative to the self path. */ -static int kwsys_shared_forward_fullpath(const char* self_path, - const char* in_path, char* result, - const char* desc) -{ - /* Check the specified path type. */ - if (in_path[0] == '/') { - /* Already a full path. */ - strcpy(result, in_path); - } -# if defined(_WIN32) - else if (in_path[0] && in_path[1] == ':') { - /* Already a full path. */ - strcpy(result, in_path); - } -# endif - else { - /* Relative to self path. */ - char temp_path[KWSYS_SHARED_FORWARD_MAXPATH]; - strcpy(temp_path, self_path); - strcat(temp_path, kwsys_shared_forward_path_slash); - strcat(temp_path, in_path); - if (!kwsys_shared_forward_realpath(temp_path, result)) { - if (desc) { - char msgbuf[KWSYS_SHARED_FORWARD_MAXPATH]; - kwsys_shared_forward_strerror(msgbuf); - fprintf(stderr, "Error converting %s \"%s\" to real path: %s\n", desc, - temp_path, msgbuf); - } - return 0; - } - } - return 1; -} - -/* Function to compute the library search path and executable name - based on the self path. */ -static int kwsys_shared_forward_get_settings(const char* self_path, - char* ldpath, char* exe) -{ - /* Possible search paths. */ - static const char* search_path_build[] = { KWSYS_SHARED_FORWARD_PATH_BUILD, - 0 }; - static const char* search_path_install[] = { - KWSYS_SHARED_FORWARD_PATH_INSTALL, 0 - }; - - /* Chosen paths. */ - const char** search_path; - const char* exe_path; - -/* Get the real name of the build and self paths. */ -# if defined(KWSYS_SHARED_FORWARD_CONFIG_NAME) - char build_path[] = - KWSYS_SHARED_FORWARD_DIR_BUILD "/" KWSYS_SHARED_FORWARD_CONFIG_NAME; - char self_path_logical[KWSYS_SHARED_FORWARD_MAXPATH]; -# else - char build_path[] = KWSYS_SHARED_FORWARD_DIR_BUILD; - const char* self_path_logical = self_path; -# endif - char build_path_real[KWSYS_SHARED_FORWARD_MAXPATH]; - char self_path_real[KWSYS_SHARED_FORWARD_MAXPATH]; - if (!kwsys_shared_forward_realpath(self_path, self_path_real)) { - char msgbuf[KWSYS_SHARED_FORWARD_MAXPATH]; - kwsys_shared_forward_strerror(msgbuf); - fprintf(stderr, "Error converting self path \"%s\" to real path: %s\n", - self_path, msgbuf); - return 0; - } - - /* Check whether we are running in the build tree or an install tree. */ - if (kwsys_shared_forward_realpath(build_path, build_path_real) && - kwsys_shared_forward_samepath(self_path_real, build_path_real)) { - /* Running in build tree. Use the build path and exe. */ - search_path = search_path_build; -# if defined(_WIN32) - exe_path = KWSYS_SHARED_FORWARD_EXE_BUILD ".exe"; -# else - exe_path = KWSYS_SHARED_FORWARD_EXE_BUILD; -# endif - -# if defined(KWSYS_SHARED_FORWARD_CONFIG_NAME) - /* Remove the configuration directory from self_path. */ - kwsys_shared_forward_dirname(self_path, self_path_logical); -# endif - } else { - /* Running in install tree. Use the install path and exe. */ - search_path = search_path_install; -# if defined(_WIN32) - exe_path = KWSYS_SHARED_FORWARD_EXE_INSTALL ".exe"; -# else - exe_path = KWSYS_SHARED_FORWARD_EXE_INSTALL; -# endif - -# if defined(KWSYS_SHARED_FORWARD_CONFIG_NAME) - /* Use the original self path directory. */ - strcpy(self_path_logical, self_path); -# endif - } - - /* Construct the runtime search path. */ - { - const char** dir; - for (dir = search_path; *dir; ++dir) { - /* Add separator between path components. */ - if (dir != search_path) { - strcat(ldpath, kwsys_shared_forward_path_sep); - } - - /* Add this path component. */ - if (!kwsys_shared_forward_fullpath(self_path_logical, *dir, - ldpath + strlen(ldpath), - "runtime path entry")) { - return 0; - } - } - } - - /* Construct the executable location. */ - if (!kwsys_shared_forward_fullpath(self_path_logical, exe_path, exe, - "executable file")) { - return 0; - } - return 1; -} - -/* Function to print why execution of a command line failed. */ -static void kwsys_shared_forward_print_failure(char const* const* argv) -{ - char msg[KWSYS_SHARED_FORWARD_MAXPATH]; - char const* const* arg = argv; - kwsys_shared_forward_strerror(msg); - fprintf(stderr, "Error running"); - for (; *arg; ++arg) { - fprintf(stderr, " \"%s\"", *arg); - } - fprintf(stderr, ": %s\n", msg); -} - -/* Static storage space to store the updated environment variable. */ -static char kwsys_shared_forward_ldpath[65535] = - KWSYS_SHARED_FORWARD_LDPATH "="; - -/* Main driver function to be called from main. */ -static int @KWSYS_NAMESPACE@_shared_forward_to_real(int argc, char** argv_in) -{ - char const** argv = (char const**)argv_in; - /* Get the directory containing this executable. */ - char self_path[KWSYS_SHARED_FORWARD_MAXPATH]; - if (kwsys_shared_forward_self_path(argv[0], self_path)) { - /* Found this executable. Use it to get the library directory. */ - char exe[KWSYS_SHARED_FORWARD_MAXPATH]; - if (kwsys_shared_forward_get_settings(self_path, - kwsys_shared_forward_ldpath, exe)) { - /* Append the old runtime search path. */ - const char* old_ldpath = getenv(KWSYS_SHARED_FORWARD_LDPATH); - if (old_ldpath) { - strcat(kwsys_shared_forward_ldpath, kwsys_shared_forward_path_sep); - strcat(kwsys_shared_forward_ldpath, old_ldpath); - } - - /* Store the environment variable. */ - putenv(kwsys_shared_forward_ldpath); - -# if defined(KWSYS_SHARED_FORWARD_OPTION_COMMAND) - /* Look for the command line replacement option. */ - if (argc > 1 && - strcmp(argv[1], KWSYS_SHARED_FORWARD_OPTION_COMMAND) == 0) { - if (argc > 2) { - /* Use the command line given. */ - strcpy(exe, argv[2]); - argv += 2; - argc -= 2; - } else { - /* The option was not given an executable. */ - fprintf(stderr, - "Option " KWSYS_SHARED_FORWARD_OPTION_COMMAND - " must be followed by a command line.\n"); - return 1; - } - } -# endif - -# if defined(KWSYS_SHARED_FORWARD_OPTION_PRINT) - /* Look for the print command line option. */ - if (argc > 1 && - strcmp(argv[1], KWSYS_SHARED_FORWARD_OPTION_PRINT) == 0) { - fprintf(stdout, "%s\n", kwsys_shared_forward_ldpath); - fprintf(stdout, "%s\n", exe); - return 0; - } -# endif - -# if defined(KWSYS_SHARED_FORWARD_OPTION_LDD) - /* Look for the ldd command line option. */ - if (argc > 1 && strcmp(argv[1], KWSYS_SHARED_FORWARD_OPTION_LDD) == 0) { -# if defined(KWSYS_SHARED_FORWARD_LDD) - /* Use the named ldd-like executable and arguments. */ - char const* ldd_argv[] = { KWSYS_SHARED_FORWARD_LDD, 0, 0 }; - ldd_argv[KWSYS_SHARED_FORWARD_LDD_N] = exe; - kwsys_shared_forward_execvp(ldd_argv[0], ldd_argv); - - /* Report why execution failed. */ - kwsys_shared_forward_print_failure(ldd_argv); - return 1; -# else - /* We have no ldd-like executable available on this platform. */ - fprintf(stderr, "No ldd-like tool is known to this executable.\n"); - return 1; -# endif - } -# endif - - /* Replace this process with the real executable. */ - argv[0] = exe; - kwsys_shared_forward_execvp(argv[0], argv); - - /* Report why execution failed. */ - kwsys_shared_forward_print_failure(argv); - } else { - /* Could not convert self path to the library directory. */ - } - } else { - /* Could not find this executable. */ - fprintf(stderr, "Error locating executable \"%s\".\n", argv[0]); - } - - /* Avoid unused argument warning. */ - (void)argc; - - /* Exit with failure. */ - return 1; -} - -/* Restore warning stack. */ -# if defined(__clang__) && defined(__has_warning) -# if __has_warning("-Wcast-qual") -# pragma clang diagnostic pop -# endif -# endif - -#else -# error "@KWSYS_NAMESPACE@/SharedForward.h should be included only once." -#endif diff --git a/String.hxx.in b/String.hxx.in deleted file mode 100644 index c36f4ce4a99..00000000000 --- a/String.hxx.in +++ /dev/null @@ -1,57 +0,0 @@ -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing#kwsys for details. */ -#ifndef @KWSYS_NAMESPACE@_String_hxx -#define @KWSYS_NAMESPACE@_String_hxx - -#include - -namespace @KWSYS_NAMESPACE@ { - -/** \class String - * \brief Short-name version of the STL basic_string class template. - * - * The standard library "string" type is actually a typedef for - * "basic_string<..long argument list..>". This string class is - * simply a subclass of this type with the same interface so that the - * name is shorter in debugging symbols and error messages. - */ -class String : public std::string -{ - /** The original string type. */ - typedef std::string stl_string; - -public: - /** String member types. */ - typedef stl_string::value_type value_type; - typedef stl_string::pointer pointer; - typedef stl_string::reference reference; - typedef stl_string::const_reference const_reference; - typedef stl_string::size_type size_type; - typedef stl_string::difference_type difference_type; - typedef stl_string::iterator iterator; - typedef stl_string::const_iterator const_iterator; - typedef stl_string::reverse_iterator reverse_iterator; - typedef stl_string::const_reverse_iterator const_reverse_iterator; - - /** String constructors. */ - String() - : stl_string() - { - } - String(const value_type* s) - : stl_string(s) - { - } - String(const value_type* s, size_type n) - : stl_string(s, n) - { - } - String(const stl_string& s, size_type pos = 0, size_type n = npos) - : stl_string(s, pos, n) - { - } -}; // End Class: String - -} // namespace @KWSYS_NAMESPACE@ - -#endif diff --git a/SystemInformation.cxx b/SystemInformation.cxx index 20e2edbffc0..369ff9af338 100644 --- a/SystemInformation.cxx +++ b/SystemInformation.cxx @@ -3443,7 +3443,7 @@ bool SystemInformationImplementation::RetrieveInformationFromCpuInfoFile() FILE* fd = fopen("/proc/cpuinfo", "r"); if (!fd) { - std::cout << "Problem opening /proc/cpuinfo" << std::endl; + std::cerr << "Problem opening /proc/cpuinfo\n"; return false; } @@ -3453,6 +3453,10 @@ bool SystemInformationImplementation::RetrieveInformationFromCpuInfoFile() fileSize++; } fclose(fd); + if (fileSize < 2) { + std::cerr << "No data in /proc/cpuinfo\n"; + return false; + } buffer.resize(fileSize - 2); // Number of logical CPUs (combination of multiple processors, multi-core // and SMT) @@ -4158,7 +4162,7 @@ bool SystemInformationImplementation::QueryLinuxMemory() struct utsname unameInfo; int errorFlag = uname(&unameInfo); if (errorFlag != 0) { - std::cout << "Problem calling uname(): " << strerror(errno) << std::endl; + std::cerr << "Problem calling uname(): " << strerror(errno) << "\n"; return false; } @@ -4178,7 +4182,7 @@ bool SystemInformationImplementation::QueryLinuxMemory() FILE* fd = fopen("/proc/meminfo", "r"); if (!fd) { - std::cout << "Problem opening /proc/meminfo" << std::endl; + std::cerr << "Problem opening /proc/meminfo\n"; return false; } @@ -4217,7 +4221,7 @@ bool SystemInformationImplementation::QueryLinuxMemory() this->TotalVirtualMemory = value[mSwapTotal] / 1024; this->AvailableVirtualMemory = value[mSwapFree] / 1024; } else { - std::cout << "Problem parsing /proc/meminfo" << std::endl; + std::cerr << "Problem parsing /proc/meminfo\n"; fclose(fd); return false; } @@ -4244,7 +4248,7 @@ bool SystemInformationImplementation::QueryLinuxMemory() this->AvailablePhysicalMemory = (ap + buffersMem + cachedMem) >> 10 >> 10; } else { - std::cout << "Problem parsing /proc/meminfo" << std::endl; + std::cerr << "Problem parsing /proc/meminfo\n"; fclose(fd); return false; } @@ -4468,8 +4472,8 @@ void SystemInformationImplementation::CPUCountWindows() typedef BOOL(WINAPI * GetLogicalProcessorInformationType)( PSYSTEM_LOGICAL_PROCESSOR_INFORMATION, PDWORD); static GetLogicalProcessorInformationType pGetLogicalProcessorInformation = - (GetLogicalProcessorInformationType)GetProcAddress( - GetModuleHandleW(L"kernel32"), "GetLogicalProcessorInformation"); + reinterpret_cast(GetProcAddress( + GetModuleHandleW(L"kernel32"), "GetLogicalProcessorInformation")); if (!pGetLogicalProcessorInformation) { // Fallback to approximate implementation on ancient Windows versions. diff --git a/SystemTools.cxx b/SystemTools.cxx index a3ab51a7221..53b55f6aef9 100644 --- a/SystemTools.cxx +++ b/SystemTools.cxx @@ -412,18 +412,6 @@ inline void Realpath(const std::string& path, std::string& resolved_path, } #endif -#if !defined(_WIN32) && defined(__COMO__) -// Hack for como strict mode to avoid defining _SVID_SOURCE or _BSD_SOURCE. -extern "C" { -extern FILE* popen(__const char* __command, __const char* __modes) __THROW; -extern int pclose(FILE* __stream) __THROW; -extern char* realpath(__const char* __restrict __name, - char* __restrict __resolved) __THROW; -extern char* strdup(__const char* __s) __THROW; -extern int putenv(char* __string) __THROW; -} -#endif - namespace KWSYS_NAMESPACE { double SystemTools::GetTime() @@ -777,12 +765,16 @@ const char* SystemTools::GetEnv(const std::string& key) bool SystemTools::GetEnv(const char* key, std::string& result) { #if defined(_WIN32) - const std::wstring wkey = Encoding::ToWide(key); - const wchar_t* wv = _wgetenv(wkey.c_str()); - if (wv) { - result = Encoding::ToNarrow(wv); - return true; + auto wide_key = Encoding::ToWide(key); + auto result_size = GetEnvironmentVariableW(wide_key.data(), nullptr, 0); + if (result_size <= 0) { + return false; } + std::wstring wide_result; + wide_result.resize(result_size - 1); + GetEnvironmentVariableW(wide_key.data(), &wide_result[0], result_size); + result = Encoding::ToNarrow(wide_result); + return true; #else const char* v = getenv(key); if (v) { @@ -2528,6 +2520,12 @@ SystemTools::CopyStatus SystemTools::CloneFileContent( return status; #elif defined(__APPLE__) && \ defined(KWSYS_SYSTEMTOOLS_HAVE_MACOS_COPYFILE_CLONE) + // When running as root, copyfile() copies more metadata than we + // want, such as ownership. Pretend it is not available. + if (getuid() == 0) { + return CopyStatus{ Status::POSIX(ENOSYS), CopyStatus::NoPath }; + } + // NOTE: we cannot use `clonefile` as the {a,c,m}time for the file needs to // be updated by `copy_file_if_different` and `copy_file`. if (copyfile(source.c_str(), destination.c_str(), nullptr, @@ -2796,14 +2794,14 @@ Status SystemTools::RemoveFile(std::string const& source) Status SystemTools::RemoveADirectory(std::string const& source) { - // Add write permission to the directory so we can modify its - // content to remove files and directories from it. + // Add read and write permission to the directory so we can read + // and modify its content to remove files and directories from it. mode_t mode = 0; if (SystemTools::GetPermissions(source, mode)) { #if defined(_WIN32) && !defined(__CYGWIN__) - mode |= S_IWRITE; + mode |= S_IREAD | S_IWRITE; #else - mode |= S_IWUSR; + mode |= S_IRUSR | S_IWUSR; #endif SystemTools::SetPermissions(source, mode); } @@ -3418,44 +3416,17 @@ bool SystemTools::SplitProgramPath(const std::string& in_name, } bool SystemTools::FindProgramPath(const char* argv0, std::string& pathOut, - std::string& errorMsg, const char* exeName, - const char* buildDir, - const char* installPrefix) + std::string& errorMsg) { std::vector failures; std::string self = argv0 ? argv0 : ""; failures.push_back(self); SystemTools::ConvertToUnixSlashes(self); self = SystemTools::FindProgram(self); - if (!SystemTools::FileIsExecutable(self)) { - if (buildDir) { - std::string intdir = "."; -#ifdef CMAKE_INTDIR - intdir = CMAKE_INTDIR; -#endif - self = buildDir; - self += "/bin/"; - self += intdir; - self += "/"; - self += exeName; - self += SystemTools::GetExecutableExtension(); - } - } - if (installPrefix) { - if (!SystemTools::FileIsExecutable(self)) { - failures.push_back(self); - self = installPrefix; - self += "/bin/"; - self += exeName; - } - } if (!SystemTools::FileIsExecutable(self)) { failures.push_back(self); std::ostringstream msg; msg << "Can not find the command line program "; - if (exeName) { - msg << exeName; - } msg << "\n"; if (argv0) { msg << " argv[0] = \"" << argv0 << "\"\n"; diff --git a/SystemTools.hxx.in b/SystemTools.hxx.in index 56b65fd2012..729928e6f3a 100644 --- a/SystemTools.hxx.in +++ b/SystemTools.hxx.in @@ -395,10 +395,7 @@ public: * installPrefix is a possibly null pointer to the install directory. */ static bool FindProgramPath(const char* argv0, std::string& pathOut, - std::string& errorMsg, - const char* exeName = nullptr, - const char* buildDir = nullptr, - const char* installPrefix = nullptr); + std::string& errorMsg); /** * Given a path to a file or directory, convert it to a full path. diff --git a/kwsysPlatformTests.cmake b/kwsysPlatformTests.cmake index 89be4b8853d..6c006bcd1ab 100644 --- a/kwsysPlatformTests.cmake +++ b/kwsysPlatformTests.cmake @@ -8,9 +8,6 @@ macro(KWSYS_PLATFORM_TEST lang var description invert) if(NOT DEFINED ${var}_COMPILED) message(STATUS "${description}") set(maybe_cxx_standard "") - if(CMAKE_VERSION VERSION_LESS 3.8 AND CMAKE_CXX_STANDARD) - set(maybe_cxx_standard "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}") - endif() try_compile(${var}_COMPILED ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${KWSYS_PLATFORM_TEST_FILE_${lang}} @@ -18,14 +15,16 @@ macro(KWSYS_PLATFORM_TEST lang var description invert) CMAKE_FLAGS "-DLINK_LIBRARIES:STRING=${KWSYS_PLATFORM_TEST_LINK_LIBRARIES}" ${maybe_cxx_standard} OUTPUT_VARIABLE OUTPUT) - if(${var}_COMPILED) - file(APPEND - ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log - "${description} compiled with the following output:\n${OUTPUT}\n\n") - else() - file(APPEND - ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "${description} failed to compile with the following output:\n${OUTPUT}\n\n") + if(CMAKE_VERSION VERSION_LESS 3.26) + if(${var}_COMPILED) + file(APPEND + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "${description} compiled with the following output:\n${OUTPUT}\n\n") + else() + file(APPEND + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "${description} failed to compile with the following output:\n${OUTPUT}\n\n") + endif() endif() if(${invert} MATCHES INVERT) if(${var}_COMPILED) @@ -67,19 +66,23 @@ macro(KWSYS_PLATFORM_TEST_RUN lang var description invert) # Note that ${var} will be a 0 return value on success. if(${var}_COMPILED) - if(${var}) + if(CMAKE_VERSION VERSION_LESS 3.26) + if(${var}) + file(APPEND + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "${description} compiled but failed to run with the following output:\n${OUTPUT}\n\n") + else() + file(APPEND + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "${description} compiled and ran with the following output:\n${OUTPUT}\n\n") + endif() + endif() + else() + if(CMAKE_VERSION VERSION_LESS 3.26) file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "${description} compiled but failed to run with the following output:\n${OUTPUT}\n\n") - else() - file(APPEND - ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log - "${description} compiled and ran with the following output:\n${OUTPUT}\n\n") + "${description} failed to compile with the following output:\n${OUTPUT}\n\n") endif() - else() - file(APPEND - ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "${description} failed to compile with the following output:\n${OUTPUT}\n\n") set(${var} -1 CACHE INTERNAL "${description} failed to compile.") endif() @@ -188,14 +191,16 @@ macro(KWSYS_PLATFORM_INFO_TEST lang var description) OUTPUT_VARIABLE OUTPUT COPY_FILE ${KWSYS_PLATFORM_INFO_FILE} ) - if(${var}_COMPILED) - file(APPEND - ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log - "${description} compiled with the following output:\n${OUTPUT}\n\n") - else() - file(APPEND - ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "${description} failed to compile with the following output:\n${OUTPUT}\n\n") + if(CMAKE_VERSION VERSION_LESS 3.26) + if(${var}_COMPILED) + file(APPEND + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "${description} compiled with the following output:\n${OUTPUT}\n\n") + else() + file(APPEND + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "${description} failed to compile with the following output:\n${OUTPUT}\n\n") + endif() endif() if(${var}_COMPILED) message(STATUS "${description} - compiled") diff --git a/testDynamicLoader.cxx b/testDynamicLoader.cxx index 806c01a0cf4..a5095a5fc7b 100644 --- a/testDynamicLoader.cxx +++ b/testDynamicLoader.cxx @@ -53,9 +53,9 @@ static std::string GetLibName(const char* lname, const char* subdir = nullptr) slname += "/"; slname += subdir; } -#ifdef CMAKE_INTDIR +#ifdef BUILD_CONFIG slname += "/"; - slname += CMAKE_INTDIR; + slname += BUILD_CONFIG; #endif slname += "/"; slname += kwsys::DynamicLoader::LibPrefix(); diff --git a/testSharedForward.c.in b/testSharedForward.c.in deleted file mode 100644 index e909458823b..00000000000 --- a/testSharedForward.c.in +++ /dev/null @@ -1,31 +0,0 @@ -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing#kwsys for details. */ -#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__OpenBSD__) -/* NOLINTNEXTLINE(bugprone-reserved-identifier) */ -# define _XOPEN_SOURCE 600 -#endif -#if defined(CMAKE_INTDIR) -# define CONFIG_DIR_PRE CMAKE_INTDIR "/" -# define CONFIG_DIR_POST "/" CMAKE_INTDIR -#else -# define CONFIG_DIR_PRE "" -# define CONFIG_DIR_POST "" -#endif -#define @KWSYS_NAMESPACE@_SHARED_FORWARD_DIR_BUILD "@EXEC_DIR@" -#define @KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_BUILD "." CONFIG_DIR_POST -#define @KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_INSTALL 0 -#define @KWSYS_NAMESPACE@_SHARED_FORWARD_EXE_BUILD \ - CONFIG_DIR_PRE "@KWSYS_NAMESPACE@TestProcess" -#define @KWSYS_NAMESPACE@_SHARED_FORWARD_EXE_INSTALL \ - "@KWSYS_NAMESPACE@TestProcess" -#define @KWSYS_NAMESPACE@_SHARED_FORWARD_OPTION_COMMAND "--command" -#define @KWSYS_NAMESPACE@_SHARED_FORWARD_OPTION_PRINT "--print" -#define @KWSYS_NAMESPACE@_SHARED_FORWARD_OPTION_LDD "--ldd" -#if defined(CMAKE_INTDIR) -# define @KWSYS_NAMESPACE@_SHARED_FORWARD_CONFIG_NAME CMAKE_INTDIR -#endif -#include <@KWSYS_NAMESPACE@/SharedForward.h> -int main(int argc, char** argv) -{ - return @KWSYS_NAMESPACE@_shared_forward_to_real(argc, argv); -}