diff options
675 files changed, 15014 insertions, 5979 deletions
diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..d934bf9 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,7 @@ +Thanks for your interest in contributing to CMake! The GitHub repository +is a mirror provided for convenience, but CMake does not use GitHub pull +requests for contribution. Please see + + https://gitlab.kitware.com/cmake/cmake/tree/master/CONTRIBUTING.rst + +for contribution instructions. GitHub OAuth may be used to sign in. diff --git a/Auxiliary/vim/syntax/cmake.vim b/Auxiliary/vim/syntax/cmake.vim index a191c18..b06fa42 100644 --- a/Auxiliary/vim/syntax/cmake.vim +++ b/Auxiliary/vim/syntax/cmake.vim @@ -31,12 +31,11 @@ syn region cmakeEnvironment start="$ENV{" end="}" contained oneline contains=cma syn region cmakeArguments start="(" end=")" contains=ALLBUT,cmakeArguments,cmakeTodo syn case match - syn keyword cmakeProperty contained - \ ABSTRACT ADDITIONAL_MAKE_CLEAN_FILES ADVANCED ALIASED_TARGET ALLOW_DUPLICATE_CUSTOM_TARGETS ANDROID_ANT_ADDITIONAL_OPTIONS ANDROID_API ANDROID_API_MIN ANDROID_ARCH ANDROID_ASSETS_DIRECTORIES ANDROID_GUI ANDROID_JAR_DEPENDENCIES ANDROID_JAR_DIRECTORIES ANDROID_JAVA_SOURCE_DIR ANDROID_NATIVE_LIB_DEPENDENCIES ANDROID_NATIVE_LIB_DIRECTORIES ANDROID_PROCESS_MAX ANDROID_PROGUARD ANDROID_PROGUARD_CONFIG_PATH ANDROID_SECURE_PROPS_PATH ANDROID_SKIP_ANT_STEP ANDROID_STL_TYPE ARCHIVE_OUTPUT_DIRECTORY ARCHIVE_OUTPUT_DIRECTORY_DEBUG ARCHIVE_OUTPUT_DIRECTORY_RELEASE ARCHIVE_OUTPUT_NAME ARCHIVE_OUTPUT_NAME_DEBUG ARCHIVE_OUTPUT_NAME_RELEASE ATTACHED_FILES ATTACHED_FILES_ON_FAIL AUTOGEN_TARGETS_FOLDER AUTOGEN_TARGET_DEPENDS AUTOMOC AUTOMOC_MOC_OPTIONS AUTOMOC_TARGETS_FOLDER AUTORCC AUTORCC_OPTIONS AUTOUIC AUTOUIC_OPTIONS BINARY_DIR BUILD_WITH_INSTALL_RPATH BUNDLE BUNDLE_EXTENSION CACHE_VARIABLES CLEAN_NO_CUSTOM CMAKE_CONFIGURE_DEPENDS CMAKE_CXX_KNOWN_FEATURES CMAKE_C_KNOWN_FEATURES COMPATIBLE_INTERFACE_BOOL COMPATIBLE_INTERFACE_NUMBER_MAX COMPATIBLE_INTERFACE_NUMBER_MIN COMPATIBLE_INTERFACE_STRING COMPILE_DEFINITIONS COMPILE_DEFINITIONS_DEBUG COMPILE_DEFINITIONS_RELEASE COMPILE_FEATURES COMPILE_FLAGS COMPILE_OPTIONS COMPILE_PDB_NAME COMPILE_PDB_NAME_DEBUG COMPILE_PDB_NAME_RELEASE COMPILE_PDB_OUTPUT_DIRECTORY COMPILE_PDB_OUTPUT_DIRECTORY_DEBUG COMPILE_PDB_OUTPUT_DIRECTORY_RELEASE COST CPACK_DESKTOP_SHORTCUTS CPACK_NEVER_OVERWRITE CPACK_PERMANENT CPACK_STARTUP_SHORTCUTS CPACK_START_MENU_SHORTCUTS CPACK_WIX_ACL CROSSCOMPILING_EMULATOR CXX_EXTENSIONS CXX_STANDARD CXX_STANDARD_REQUIRED C_EXTENSIONS C_STANDARD C_STANDARD_REQUIRED DEBUG_CONFIGURATIONS DEBUG_POSTFIX DEFINE_SYMBOL DEFINITIONS DEPENDS DISABLED_FEATURES ECLIPSE_EXTRA_NATURES ENABLED_FEATURES ENABLED_LANGUAGES ENABLE_EXPORTS ENVIRONMENT EXCLUDE_FROM_ALL EXCLUDE_FROM_DEFAULT_BUILD EXCLUDE_FROM_DEFAULT_BUILD_DEBUG EXCLUDE_FROM_DEFAULT_BUILD_RELEASE EXPORT_NAME EXTERNAL_OBJECT EchoString FAIL_REGULAR_EXPRESSION FIND_LIBRARY_USE_LIB64_PATHS FIND_LIBRARY_USE_OPENBSD_VERSIONING FOLDER FRAMEWORK FRAMEWORK_VERSION Fortran_FORMAT Fortran_MODULE_DIRECTORY GENERATED GENERATOR_FILE_NAME GLOBAL_DEPENDS_DEBUG_MODE GLOBAL_DEPENDS_NO_CYCLES GNUtoMS HAS_CXX HEADER_FILE_ONLY HELPSTRING IMPLICIT_DEPENDS_INCLUDE_TRANSFORM IMPORTED IMPORTED_CONFIGURATIONS IMPORTED_IMPLIB IMPORTED_IMPLIB_DEBUG IMPORTED_IMPLIB_RELEASE IMPORTED_LINK_DEPENDENT_LIBRARIES IMPORTED_LINK_DEPENDENT_LIBRARIES_DEBUG IMPORTED_LINK_DEPENDENT_LIBRARIES_RELEASE IMPORTED_LINK_INTERFACE_LANGUAGES IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE IMPORTED_LINK_INTERFACE_LIBRARIES IMPORTED_LINK_INTERFACE_LIBRARIES_DEBUG IMPORTED_LINK_INTERFACE_LIBRARIES_RELEASE IMPORTED_LINK_INTERFACE_MULTIPLICITY IMPORTED_LINK_INTERFACE_MULTIPLICITY_DEBUG IMPORTED_LINK_INTERFACE_MULTIPLICITY_RELEASE IMPORTED_LOCATION IMPORTED_LOCATION_DEBUG IMPORTED_LOCATION_RELEASE IMPORTED_NO_SONAME IMPORTED_NO_SONAME_DEBUG IMPORTED_NO_SONAME_RELEASE IMPORTED_SONAME IMPORTED_SONAME_DEBUG IMPORTED_SONAME_RELEASE IMPORT_PREFIX IMPORT_SUFFIX INCLUDE_DIRECTORIES INCLUDE_REGULAR_EXPRESSION INSTALL_NAME_DIR INSTALL_RPATH INSTALL_RPATH_USE_LINK_PATH INTERFACE_AUTOUIC_OPTIONS INTERFACE_COMPILE_DEFINITIONS INTERFACE_COMPILE_FEATURES INTERFACE_COMPILE_OPTIONS INTERFACE_INCLUDE_DIRECTORIES INTERFACE_LINK_LIBRARIES INTERFACE_POSITION_INDEPENDENT_CODE INTERFACE_SOURCES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES INTERPROCEDURAL_OPTIMIZATION INTERPROCEDURAL_OPTIMIZATION_DEBUG INTERPROCEDURAL_OPTIMIZATION_RELEASE IN_TRY_COMPILE JOB_POOLS JOB_POOL_COMPILE JOB_POOL_LINK KEEP_EXTENSION LABELS LANGUAGE LIBRARY_OUTPUT_DIRECTORY LIBRARY_OUTPUT_DIRECTORY_DEBUG LIBRARY_OUTPUT_DIRECTORY_RELEASE LIBRARY_OUTPUT_NAME LIBRARY_OUTPUT_NAME_DEBUG LIBRARY_OUTPUT_NAME_RELEASE LINKER_LANGUAGE LINK_DEPENDS LINK_DEPENDS_NO_SHARED LINK_DIRECTORIES LINK_FLAGS LINK_FLAGS_DEBUG LINK_FLAGS_RELEASE LINK_INTERFACE_LIBRARIES LINK_INTERFACE_LIBRARIES_DEBUG LINK_INTERFACE_LIBRARIES_RELEASE LINK_INTERFACE_MULTIPLICITY LINK_INTERFACE_MULTIPLICITY_DEBUG LINK_INTERFACE_MULTIPLICITY_RELEASE LINK_LIBRARIES LINK_SEARCH_END_STATIC LINK_SEARCH_START_STATIC LISTFILE_STACK LOCATION LOCATION_DEBUG LOCATION_RELEASE MACOSX_BUNDLE MACOSX_BUNDLE_INFO_PLIST MACOSX_FRAMEWORK_INFO_PLIST MACOSX_PACKAGE_LOCATION MACOSX_RPATH MACROS MAP_IMPORTED_CONFIG_DEBUG MAP_IMPORTED_CONFIG_RELEASE MEASUREMENT MODIFIED NAME NO_SONAME NO_SYSTEM_FROM_IMPORTED OBJECT_DEPENDS OBJECT_OUTPUTS OSX_ARCHITECTURES OSX_ARCHITECTURES_DEBUG OSX_ARCHITECTURES_RELEASE OUTPUT_NAME OUTPUT_NAME_DEBUG OUTPUT_NAME_RELEASE PACKAGES_FOUND PACKAGES_NOT_FOUND PARENT_DIRECTORY PASS_REGULAR_EXPRESSION PDB_NAME PDB_NAME_DEBUG PDB_NAME_RELEASE PDB_OUTPUT_DIRECTORY PDB_OUTPUT_DIRECTORY_DEBUG PDB_OUTPUT_DIRECTORY_RELEASE POSITION_INDEPENDENT_CODE POST_INSTALL_SCRIPT PREDEFINED_TARGETS_FOLDER PREFIX PRE_INSTALL_SCRIPT PRIVATE_HEADER PROCESSORS PROJECT_LABEL PUBLIC_HEADER REPORT_UNDEFINED_PROPERTIES REQUIRED_FILES RESOURCE RESOURCE_LOCK RULE_LAUNCH_COMPILE RULE_LAUNCH_CUSTOM RULE_LAUNCH_LINK RULE_MESSAGES RUNTIME_OUTPUT_DIRECTORY RUNTIME_OUTPUT_DIRECTORY_DEBUG RUNTIME_OUTPUT_DIRECTORY_RELEASE RUNTIME_OUTPUT_NAME RUNTIME_OUTPUT_NAME_DEBUG RUNTIME_OUTPUT_NAME_RELEASE RUN_SERIAL SKIP_BUILD_RPATH SKIP_RETURN_CODE SOURCES SOURCE_DIR SOVERSION STATIC_LIBRARY_FLAGS STATIC_LIBRARY_FLAGS_DEBUG STATIC_LIBRARY_FLAGS_RELEASE STRINGS SUFFIX SYMBOLIC TARGET_ARCHIVES_MAY_BE_SHARED_LIBS TARGET_MESSAGES TARGET_SUPPORTS_SHARED_LIBS TEST_INCLUDE_FILE TIMEOUT TYPE USE_FOLDERS VALUE VARIABLES VERSION VISIBILITY_INLINES_HIDDEN VS_DEPLOYMENT_CONTENT VS_DEPLOYMENT_LOCATION VS_DESKTOP_EXTENSIONS_VERSION VS_DOTNET_REFERENCES VS_DOTNET_TARGET_FRAMEWORK_VERSION VS_GLOBAL_KEYWORD VS_GLOBAL_PROJECT_TYPES VS_GLOBAL_ROOTNAMESPACE VS_IOT_EXTENSIONS_VERSION VS_IOT_STARTUP_TASK VS_KEYWORD VS_MOBILE_EXTENSIONS_VERSION VS_SCC_AUXPATH VS_SCC_LOCALPATH VS_SCC_PROJECTNAME VS_SCC_PROVIDER VS_SHADER_ENTRYPOINT VS_SHADER_FLAGS VS_SHADER_MODEL VS_SHADER_TYPE VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION VS_WINRT_COMPONENT VS_WINRT_EXTENSIONS VS_WINRT_REFERENCES VS_XAML_TYPE WILL_FAIL WIN32_EXECUTABLE WINDOWS_EXPORT_ALL_SYMBOLS WORKING_DIRECTORY WRAP_EXCLUDE XCODE_EXPLICIT_FILE_TYPE XCODE_LAST_KNOWN_FILE_TYPE XCTEST + \ ABSTRACT ADDITIONAL_MAKE_CLEAN_FILES ADVANCED ALIASED_TARGET ALLOW_DUPLICATE_CUSTOM_TARGETS ANDROID_ANT_ADDITIONAL_OPTIONS ANDROID_API ANDROID_API_MIN ANDROID_ARCH ANDROID_ASSETS_DIRECTORIES ANDROID_GUI ANDROID_JAR_DEPENDENCIES ANDROID_JAR_DIRECTORIES ANDROID_JAVA_SOURCE_DIR ANDROID_NATIVE_LIB_DEPENDENCIES ANDROID_NATIVE_LIB_DIRECTORIES ANDROID_PROCESS_MAX ANDROID_PROGUARD ANDROID_PROGUARD_CONFIG_PATH ANDROID_SECURE_PROPS_PATH ANDROID_SKIP_ANT_STEP ANDROID_STL_TYPE ARCHIVE_OUTPUT_DIRECTORY ARCHIVE_OUTPUT_DIRECTORY_DEBUG ARCHIVE_OUTPUT_DIRECTORY_RELEASE ARCHIVE_OUTPUT_NAME ARCHIVE_OUTPUT_NAME_DEBUG ARCHIVE_OUTPUT_NAME_RELEASE ATTACHED_FILES ATTACHED_FILES_ON_FAIL AUTOGEN_TARGETS_FOLDER AUTOGEN_TARGET_DEPENDS AUTOMOC AUTOMOC_MOC_OPTIONS AUTOMOC_TARGETS_FOLDER AUTORCC AUTORCC_OPTIONS AUTOUIC AUTOUIC_OPTIONS BINARY_DIR BUILD_WITH_INSTALL_RPATH BUNDLE BUNDLE_EXTENSION CACHE_VARIABLES CLEAN_NO_CUSTOM CMAKE_CONFIGURE_DEPENDS CMAKE_CXX_KNOWN_FEATURES CMAKE_C_KNOWN_FEATURES CMAKE_DIRECTORY_LABELS COMPATIBLE_INTERFACE_BOOL COMPATIBLE_INTERFACE_NUMBER_MAX COMPATIBLE_INTERFACE_NUMBER_MIN COMPATIBLE_INTERFACE_STRING COMPILE_DEFINITIONS COMPILE_DEFINITIONS_DEBUG COMPILE_DEFINITIONS_RELEASE COMPILE_FEATURES COMPILE_FLAGS COMPILE_OPTIONS COMPILE_PDB_NAME COMPILE_PDB_NAME_DEBUG COMPILE_PDB_NAME_RELEASE COMPILE_PDB_OUTPUT_DIRECTORY COMPILE_PDB_OUTPUT_DIRECTORY_DEBUG COMPILE_PDB_OUTPUT_DIRECTORY_RELEASE COST CPACK_DESKTOP_SHORTCUTS CPACK_NEVER_OVERWRITE CPACK_PERMANENT CPACK_STARTUP_SHORTCUTS CPACK_START_MENU_SHORTCUTS CPACK_WIX_ACL CROSSCOMPILING_EMULATOR CXX_EXTENSIONS CXX_STANDARD CXX_STANDARD_REQUIRED C_EXTENSIONS C_STANDARD C_STANDARD_REQUIRED DEBUG_CONFIGURATIONS DEBUG_POSTFIX DEFINE_SYMBOL DEFINITIONS DEPENDS DISABLED_FEATURES ECLIPSE_EXTRA_NATURES ENABLED_FEATURES ENABLED_LANGUAGES ENABLE_EXPORTS ENVIRONMENT EXCLUDE_FROM_ALL EXCLUDE_FROM_DEFAULT_BUILD EXCLUDE_FROM_DEFAULT_BUILD_DEBUG EXCLUDE_FROM_DEFAULT_BUILD_RELEASE EXPORT_NAME EXTERNAL_OBJECT EchoString FAIL_REGULAR_EXPRESSION FIND_LIBRARY_USE_LIB64_PATHS FIND_LIBRARY_USE_OPENBSD_VERSIONING FOLDER FRAMEWORK FRAMEWORK_VERSION Fortran_FORMAT Fortran_MODULE_DIRECTORY GENERATED GENERATOR_FILE_NAME GLOBAL_DEPENDS_DEBUG_MODE GLOBAL_DEPENDS_NO_CYCLES GNUtoMS HAS_CXX HEADER_FILE_ONLY HELPSTRING IMPLICIT_DEPENDS_INCLUDE_TRANSFORM IMPORTED IMPORTED_CONFIGURATIONS IMPORTED_IMPLIB IMPORTED_IMPLIB_DEBUG IMPORTED_IMPLIB_RELEASE IMPORTED_LINK_DEPENDENT_LIBRARIES IMPORTED_LINK_DEPENDENT_LIBRARIES_DEBUG IMPORTED_LINK_DEPENDENT_LIBRARIES_RELEASE IMPORTED_LINK_INTERFACE_LANGUAGES IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE IMPORTED_LINK_INTERFACE_LIBRARIES IMPORTED_LINK_INTERFACE_LIBRARIES_DEBUG IMPORTED_LINK_INTERFACE_LIBRARIES_RELEASE IMPORTED_LINK_INTERFACE_MULTIPLICITY IMPORTED_LINK_INTERFACE_MULTIPLICITY_DEBUG IMPORTED_LINK_INTERFACE_MULTIPLICITY_RELEASE IMPORTED_LOCATION IMPORTED_LOCATION_DEBUG IMPORTED_LOCATION_RELEASE IMPORTED_NO_SONAME IMPORTED_NO_SONAME_DEBUG IMPORTED_NO_SONAME_RELEASE IMPORTED_SONAME IMPORTED_SONAME_DEBUG IMPORTED_SONAME_RELEASE IMPORT_PREFIX IMPORT_SUFFIX INCLUDE_DIRECTORIES INCLUDE_REGULAR_EXPRESSION INSTALL_NAME_DIR INSTALL_RPATH INSTALL_RPATH_USE_LINK_PATH INTERFACE_AUTOUIC_OPTIONS INTERFACE_COMPILE_DEFINITIONS INTERFACE_COMPILE_FEATURES INTERFACE_COMPILE_OPTIONS INTERFACE_INCLUDE_DIRECTORIES INTERFACE_LINK_LIBRARIES INTERFACE_POSITION_INDEPENDENT_CODE INTERFACE_SOURCES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES INTERPROCEDURAL_OPTIMIZATION INTERPROCEDURAL_OPTIMIZATION_DEBUG INTERPROCEDURAL_OPTIMIZATION_RELEASE IN_TRY_COMPILE JOB_POOLS JOB_POOL_COMPILE JOB_POOL_LINK KEEP_EXTENSION LABELS LANGUAGE LIBRARY_OUTPUT_DIRECTORY LIBRARY_OUTPUT_DIRECTORY_DEBUG LIBRARY_OUTPUT_DIRECTORY_RELEASE LIBRARY_OUTPUT_NAME LIBRARY_OUTPUT_NAME_DEBUG LIBRARY_OUTPUT_NAME_RELEASE LINKER_LANGUAGE LINK_DEPENDS LINK_DEPENDS_NO_SHARED LINK_DIRECTORIES LINK_FLAGS LINK_FLAGS_DEBUG LINK_FLAGS_RELEASE LINK_INTERFACE_LIBRARIES LINK_INTERFACE_LIBRARIES_DEBUG LINK_INTERFACE_LIBRARIES_RELEASE LINK_INTERFACE_MULTIPLICITY LINK_INTERFACE_MULTIPLICITY_DEBUG LINK_INTERFACE_MULTIPLICITY_RELEASE LINK_LIBRARIES LINK_SEARCH_END_STATIC LINK_SEARCH_START_STATIC LISTFILE_STACK LOCATION LOCATION_DEBUG LOCATION_RELEASE MACOSX_BUNDLE MACOSX_BUNDLE_INFO_PLIST MACOSX_FRAMEWORK_INFO_PLIST MACOSX_PACKAGE_LOCATION MACOSX_RPATH MACROS MAP_IMPORTED_CONFIG_DEBUG MAP_IMPORTED_CONFIG_RELEASE MEASUREMENT MODIFIED NAME NO_SONAME NO_SYSTEM_FROM_IMPORTED OBJECT_DEPENDS OBJECT_OUTPUTS OSX_ARCHITECTURES OSX_ARCHITECTURES_DEBUG OSX_ARCHITECTURES_RELEASE OUTPUT_NAME OUTPUT_NAME_DEBUG OUTPUT_NAME_RELEASE PACKAGES_FOUND PACKAGES_NOT_FOUND PARENT_DIRECTORY PASS_REGULAR_EXPRESSION PDB_NAME PDB_NAME_DEBUG PDB_NAME_RELEASE PDB_OUTPUT_DIRECTORY PDB_OUTPUT_DIRECTORY_DEBUG PDB_OUTPUT_DIRECTORY_RELEASE POSITION_INDEPENDENT_CODE POST_INSTALL_SCRIPT PREDEFINED_TARGETS_FOLDER PREFIX PRE_INSTALL_SCRIPT PRIVATE_HEADER PROCESSORS PROJECT_LABEL PUBLIC_HEADER REPORT_UNDEFINED_PROPERTIES REQUIRED_FILES RESOURCE RESOURCE_LOCK RULE_LAUNCH_COMPILE RULE_LAUNCH_CUSTOM RULE_LAUNCH_LINK RULE_MESSAGES RUNTIME_OUTPUT_DIRECTORY RUNTIME_OUTPUT_DIRECTORY_DEBUG RUNTIME_OUTPUT_DIRECTORY_RELEASE RUNTIME_OUTPUT_NAME RUNTIME_OUTPUT_NAME_DEBUG RUNTIME_OUTPUT_NAME_RELEASE RUN_SERIAL SKIP_BUILD_RPATH SKIP_RETURN_CODE SOURCES SOURCE_DIR SOVERSION STATIC_LIBRARY_FLAGS STATIC_LIBRARY_FLAGS_DEBUG STATIC_LIBRARY_FLAGS_RELEASE STRINGS SUFFIX SYMBOLIC TARGET_ARCHIVES_MAY_BE_SHARED_LIBS TARGET_MESSAGES TARGET_SUPPORTS_SHARED_LIBS TEST_INCLUDE_FILE TIMEOUT TYPE USE_FOLDERS VALUE VARIABLES VERSION VISIBILITY_INLINES_HIDDEN VS_DEPLOYMENT_CONTENT VS_DEPLOYMENT_LOCATION VS_DESKTOP_EXTENSIONS_VERSION VS_DOTNET_REFERENCES VS_DOTNET_TARGET_FRAMEWORK_VERSION VS_GLOBAL_KEYWORD VS_GLOBAL_PROJECT_TYPES VS_GLOBAL_ROOTNAMESPACE VS_IOT_EXTENSIONS_VERSION VS_IOT_STARTUP_TASK VS_KEYWORD VS_MOBILE_EXTENSIONS_VERSION VS_SCC_AUXPATH VS_SCC_LOCALPATH VS_SCC_PROJECTNAME VS_SCC_PROVIDER VS_SHADER_ENTRYPOINT VS_SHADER_FLAGS VS_SHADER_MODEL VS_SHADER_TYPE VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION VS_WINRT_COMPONENT VS_WINRT_EXTENSIONS VS_WINRT_REFERENCES VS_XAML_TYPE WILL_FAIL WIN32_EXECUTABLE WINDOWS_EXPORT_ALL_SYMBOLS WORKING_DIRECTORY WRAP_EXCLUDE XCODE_EXPLICIT_FILE_TYPE XCODE_LAST_KNOWN_FILE_TYPE XCTEST syn keyword cmakeVariable contained - \ ANDROID APPLE BORLAND BUILD_SHARED_LIBS CMAKE_ABSOLUTE_DESTINATION_FILES CMAKE_ANDROID_ANT_ADDITIONAL_OPTIONS CMAKE_ANDROID_API CMAKE_ANDROID_API_MIN CMAKE_ANDROID_ARCH CMAKE_ANDROID_ARCH_ABI CMAKE_ANDROID_ARM_MODE CMAKE_ANDROID_ARM_NEON CMAKE_ANDROID_ASSETS_DIRECTORIES CMAKE_ANDROID_GUI CMAKE_ANDROID_JAR_DEPENDENCIES CMAKE_ANDROID_JAR_DIRECTORIES CMAKE_ANDROID_JAVA_SOURCE_DIR CMAKE_ANDROID_NATIVE_LIB_DEPENDENCIES CMAKE_ANDROID_NATIVE_LIB_DIRECTORIES CMAKE_ANDROID_NDK CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION CMAKE_ANDROID_PROCESS_MAX CMAKE_ANDROID_PROGUARD CMAKE_ANDROID_PROGUARD_CONFIG_PATH CMAKE_ANDROID_SECURE_PROPS_PATH CMAKE_ANDROID_SKIP_ANT_STEP CMAKE_ANDROID_STANDALONE_TOOLCHAIN CMAKE_ANDROID_STL_TYPE CMAKE_APPBUNDLE_PATH CMAKE_AR CMAKE_ARCHIVE_OUTPUT_DIRECTORY CMAKE_ARGC CMAKE_ARGV0 CMAKE_AUTOMOC CMAKE_AUTOMOC_DEPEND_FILTERS CMAKE_AUTOMOC_MOC_OPTIONS CMAKE_AUTOMOC_RELAXED_MODE CMAKE_AUTORCC CMAKE_AUTORCC_OPTIONS CMAKE_AUTOUIC CMAKE_AUTOUIC_OPTIONS CMAKE_AUTOUIC_SEARCH_PATHS CMAKE_BACKWARDS_COMPATIBILITY CMAKE_BINARY_DIR CMAKE_BUILD_RPATH CMAKE_BUILD_TOOL CMAKE_BUILD_TYPE CMAKE_BUILD_WITH_INSTALL_NAME_DIR CMAKE_BUILD_WITH_INSTALL_RPATH CMAKE_CACHEFILE_DIR CMAKE_CACHE_MAJOR_VERSION CMAKE_CACHE_MINOR_VERSION CMAKE_CACHE_PATCH_VERSION CMAKE_CFG_INTDIR CMAKE_CL_64 CMAKE_CODELITE_USE_TARGETS CMAKE_COLOR_MAKEFILE CMAKE_COMMAND CMAKE_COMPILER_2005 CMAKE_COMPILER_IS_GNUCC CMAKE_COMPILER_IS_GNUCXX CMAKE_COMPILER_IS_GNUG77 CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY CMAKE_CONFIGURATION_TYPES CMAKE_CROSSCOMPILING CMAKE_CROSSCOMPILING_EMULATOR CMAKE_CTEST_COMMAND CMAKE_CUDA_EXTENSIONS CMAKE_CUDA_STANDARD CMAKE_CUDA_STANDARD_REQUIRED CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES CMAKE_CURRENT_BINARY_DIR CMAKE_CURRENT_LIST_DIR CMAKE_CURRENT_LIST_FILE CMAKE_CURRENT_LIST_LINE CMAKE_CURRENT_SOURCE_DIR CMAKE_CXX_COMPILE_FEATURES CMAKE_CXX_EXTENSIONS CMAKE_CXX_STANDARD CMAKE_CXX_STANDARD_REQUIRED CMAKE_C_COMPILE_FEATURES CMAKE_C_EXTENSIONS CMAKE_C_STANDARD CMAKE_C_STANDARD_REQUIRED CMAKE_DEBUG_POSTFIX CMAKE_DEBUG_TARGET_PROPERTIES CMAKE_DEPENDS_IN_PROJECT_ONLY CMAKE_DL_LIBS CMAKE_ECLIPSE_GENERATE_LINKED_RESOURCES CMAKE_ECLIPSE_GENERATE_SOURCE_PROJECT CMAKE_ECLIPSE_MAKE_ARGUMENTS CMAKE_ECLIPSE_VERSION CMAKE_EDIT_COMMAND CMAKE_ENABLE_EXPORTS CMAKE_ERROR_DEPRECATED CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION CMAKE_EXECUTABLE_SUFFIX CMAKE_EXE_LINKER_FLAGS CMAKE_EXE_LINKER_FLAGS_INIT CMAKE_EXPORT_COMPILE_COMMANDS CMAKE_EXPORT_NO_PACKAGE_REGISTRY CMAKE_EXTRA_GENERATOR CMAKE_EXTRA_SHARED_LIBRARY_SUFFIXES CMAKE_FIND_APPBUNDLE CMAKE_FIND_FRAMEWORK CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX CMAKE_FIND_LIBRARY_PREFIXES CMAKE_FIND_LIBRARY_SUFFIXES CMAKE_FIND_NO_INSTALL_PREFIX CMAKE_FIND_PACKAGE_NAME CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY CMAKE_FIND_PACKAGE_SORT_DIRECTION CMAKE_FIND_PACKAGE_SORT_ORDER CMAKE_FIND_PACKAGE_WARN_NO_MODULE CMAKE_FIND_ROOT_PATH CMAKE_FIND_ROOT_PATH_MODE_INCLUDE CMAKE_FIND_ROOT_PATH_MODE_LIBRARY CMAKE_FIND_ROOT_PATH_MODE_PACKAGE CMAKE_FIND_ROOT_PATH_MODE_PROGRAM CMAKE_FRAMEWORK_PATH CMAKE_Fortran_FORMAT CMAKE_Fortran_MODDIR_DEFAULT CMAKE_Fortran_MODDIR_FLAG CMAKE_Fortran_MODOUT_FLAG CMAKE_Fortran_MODULE_DIRECTORY CMAKE_GENERATOR CMAKE_GENERATOR_PLATFORM CMAKE_GENERATOR_TOOLSET CMAKE_GNUtoMS CMAKE_HOME_DIRECTORY CMAKE_HOST_APPLE CMAKE_HOST_SOLARIS CMAKE_HOST_SYSTEM CMAKE_HOST_SYSTEM_NAME CMAKE_HOST_SYSTEM_PROCESSOR CMAKE_HOST_SYSTEM_VERSION CMAKE_HOST_UNIX CMAKE_HOST_WIN32 CMAKE_IGNORE_PATH CMAKE_IMPORT_LIBRARY_PREFIX CMAKE_IMPORT_LIBRARY_SUFFIX CMAKE_INCLUDE_CURRENT_DIR CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE CMAKE_INCLUDE_DIRECTORIES_BEFORE CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE CMAKE_INCLUDE_PATH CMAKE_INSTALL_DEFAULT_COMPONENT_NAME CMAKE_INSTALL_MESSAGE CMAKE_INSTALL_NAME_DIR CMAKE_INSTALL_PREFIX CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT CMAKE_INSTALL_RPATH CMAKE_INSTALL_RPATH_USE_LINK_PATH CMAKE_INTERNAL_PLATFORM_ABI CMAKE_INTERPROCEDURAL_OPTIMIZATION CMAKE_IOS_INSTALL_COMBINED CMAKE_JOB_POOL_COMPILE CMAKE_JOB_POOL_LINK CMAKE_LIBRARY_ARCHITECTURE CMAKE_LIBRARY_ARCHITECTURE_REGEX CMAKE_LIBRARY_OUTPUT_DIRECTORY CMAKE_LIBRARY_PATH CMAKE_LIBRARY_PATH_FLAG CMAKE_LINK_DEF_FILE_FLAG CMAKE_LINK_DEPENDS_NO_SHARED CMAKE_LINK_INTERFACE_LIBRARIES CMAKE_LINK_LIBRARY_FILE_FLAG CMAKE_LINK_LIBRARY_FLAG CMAKE_LINK_LIBRARY_SUFFIX CMAKE_LINK_SEARCH_END_STATIC CMAKE_LINK_SEARCH_START_STATIC CMAKE_LINK_WHAT_YOU_USE CMAKE_MACOSX_BUNDLE CMAKE_MACOSX_RPATH CMAKE_MAJOR_VERSION CMAKE_MAKE_PROGRAM CMAKE_MATCH_COUNT CMAKE_MFC_FLAG CMAKE_MINIMUM_REQUIRED_VERSION CMAKE_MINOR_VERSION CMAKE_MODULE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS_INIT CMAKE_MODULE_PATH CMAKE_NINJA_OUTPUT_PATH_PREFIX CMAKE_NOT_USING_CONFIG_FLAGS CMAKE_NO_BUILTIN_CHRPATH CMAKE_NO_SYSTEM_FROM_IMPORTED CMAKE_OBJECT_PATH_MAX CMAKE_OSX_ARCHITECTURES CMAKE_OSX_DEPLOYMENT_TARGET CMAKE_OSX_SYSROOT CMAKE_PARENT_LIST_FILE CMAKE_PATCH_VERSION CMAKE_PDB_OUTPUT_DIRECTORY CMAKE_POSITION_INDEPENDENT_CODE CMAKE_PREFIX_PATH CMAKE_PROGRAM_PATH CMAKE_PROJECT_DESCRIPTION CMAKE_PROJECT_NAME CMAKE_RANLIB CMAKE_ROOT CMAKE_RUNTIME_OUTPUT_DIRECTORY CMAKE_SCRIPT_MODE_FILE CMAKE_SHARED_LIBRARY_PREFIX CMAKE_SHARED_LIBRARY_SUFFIX CMAKE_SHARED_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS_INIT CMAKE_SHARED_MODULE_PREFIX CMAKE_SHARED_MODULE_SUFFIX CMAKE_SIZEOF_VOID_P CMAKE_SKIP_BUILD_RPATH CMAKE_SKIP_INSTALL_ALL_DEPENDENCY CMAKE_SKIP_INSTALL_RPATH CMAKE_SKIP_INSTALL_RULES CMAKE_SKIP_RPATH CMAKE_SOURCE_DIR CMAKE_STAGING_PREFIX CMAKE_STATIC_LIBRARY_PREFIX CMAKE_STATIC_LIBRARY_SUFFIX CMAKE_STATIC_LINKER_FLAGS CMAKE_STATIC_LINKER_FLAGS_INIT CMAKE_SUBLIME_TEXT_2_ENV_SETTINGS CMAKE_SUBLIME_TEXT_2_EXCLUDE_BUILD_TREE CMAKE_SYSROOT CMAKE_SYSTEM CMAKE_SYSTEM_APPBUNDLE_PATH CMAKE_SYSTEM_FRAMEWORK_PATH CMAKE_SYSTEM_IGNORE_PATH CMAKE_SYSTEM_INCLUDE_PATH CMAKE_SYSTEM_LIBRARY_PATH CMAKE_SYSTEM_NAME CMAKE_SYSTEM_PREFIX_PATH CMAKE_SYSTEM_PROCESSOR CMAKE_SYSTEM_PROGRAM_PATH CMAKE_SYSTEM_VERSION CMAKE_Swift_LANGUAGE_VERSION CMAKE_TOOLCHAIN_FILE CMAKE_TRY_COMPILE_CONFIGURATION CMAKE_TRY_COMPILE_PLATFORM_VARIABLES CMAKE_TRY_COMPILE_TARGET_TYPE CMAKE_TWEAK_VERSION CMAKE_USER_MAKE_RULES_OVERRIDE CMAKE_USE_RELATIVE_PATHS CMAKE_VERBOSE_MAKEFILE CMAKE_VERSION CMAKE_VISIBILITY_INLINES_HIDDEN CMAKE_VS_DEVENV_COMMAND CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD CMAKE_VS_INCLUDE_PACKAGE_TO_DEFAULT_BUILD CMAKE_VS_INTEL_Fortran_PROJECT_VERSION CMAKE_VS_MSBUILD_COMMAND CMAKE_VS_NsightTegra_VERSION CMAKE_VS_PLATFORM_NAME CMAKE_VS_PLATFORM_TOOLSET CMAKE_VS_PLATFORM_TOOLSET_CUDA CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION CMAKE_WARN_DEPRECATED CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION CMAKE_WIN32_EXECUTABLE CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS CMAKE_XCODE_GENERATE_SCHEME CMAKE_XCODE_PLATFORM_TOOLSET CPACK_ABSOLUTE_DESTINATION_FILES CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION CPACK_INCLUDE_TOPLEVEL_DIRECTORY CPACK_INSTALL_SCRIPT CPACK_PACKAGING_INSTALL_PREFIX CPACK_SET_DESTDIR CPACK_WARN_ON_ABSOLUTE_INSTALL_DESTINATION CTEST_BINARY_DIRECTORY CTEST_BUILD_COMMAND CTEST_BUILD_NAME CTEST_BZR_COMMAND CTEST_BZR_UPDATE_OPTIONS CTEST_CHANGE_ID CTEST_CHECKOUT_COMMAND CTEST_CONFIGURATION_TYPE CTEST_CONFIGURE_COMMAND CTEST_COVERAGE_COMMAND CTEST_COVERAGE_EXTRA_FLAGS CTEST_CURL_OPTIONS CTEST_CUSTOM_COVERAGE_EXCLUDE CTEST_CUSTOM_ERROR_EXCEPTION CTEST_CUSTOM_ERROR_MATCH CTEST_CUSTOM_ERROR_POST_CONTEXT CTEST_CUSTOM_ERROR_PRE_CONTEXT CTEST_CUSTOM_MAXIMUM_FAILED_TEST_OUTPUT_SIZE CTEST_CUSTOM_MAXIMUM_NUMBER_OF_ERRORS CTEST_CUSTOM_MAXIMUM_NUMBER_OF_WARNINGS CTEST_CUSTOM_MAXIMUM_PASSED_TEST_OUTPUT_SIZE CTEST_CUSTOM_MEMCHECK_IGNORE CTEST_CUSTOM_POST_MEMCHECK CTEST_CUSTOM_POST_TEST CTEST_CUSTOM_PRE_MEMCHECK CTEST_CUSTOM_PRE_TEST CTEST_CUSTOM_TEST_IGNORE CTEST_CUSTOM_WARNING_EXCEPTION CTEST_CUSTOM_WARNING_MATCH CTEST_CVS_CHECKOUT CTEST_CVS_COMMAND CTEST_CVS_UPDATE_OPTIONS CTEST_DROP_LOCATION CTEST_DROP_METHOD CTEST_DROP_SITE CTEST_DROP_SITE_CDASH CTEST_DROP_SITE_PASSWORD CTEST_DROP_SITE_USER CTEST_EXTRA_COVERAGE_GLOB CTEST_GIT_COMMAND CTEST_GIT_INIT_SUBMODULES CTEST_GIT_UPDATE_CUSTOM CTEST_GIT_UPDATE_OPTIONS CTEST_HG_COMMAND CTEST_HG_UPDATE_OPTIONS CTEST_MEMORYCHECK_COMMAND CTEST_MEMORYCHECK_COMMAND_OPTIONS CTEST_MEMORYCHECK_SANITIZER_OPTIONS CTEST_MEMORYCHECK_SUPPRESSIONS_FILE CTEST_MEMORYCHECK_TYPE CTEST_NIGHTLY_START_TIME CTEST_P4_CLIENT CTEST_P4_COMMAND CTEST_P4_OPTIONS CTEST_P4_UPDATE_OPTIONS CTEST_SCP_COMMAND CTEST_SITE CTEST_SOURCE_DIRECTORY CTEST_SVN_COMMAND CTEST_SVN_OPTIONS CTEST_SVN_UPDATE_OPTIONS CTEST_TEST_LOAD CTEST_TEST_TIMEOUT CTEST_TRIGGER_SITE CTEST_UPDATE_COMMAND CTEST_UPDATE_OPTIONS CTEST_UPDATE_VERSION_ONLY CTEST_USE_LAUNCHERS CYGWIN ENV EXECUTABLE_OUTPUT_PATH GHS-MULTI LIBRARY_OUTPUT_PATH MINGW MSVC MSVC10 MSVC11 MSVC12 MSVC14 MSVC60 MSVC70 MSVC71 MSVC80 MSVC90 MSVC_IDE MSVC_VERSION PROJECT_BINARY_DIR PROJECT_DESCRIPTION PROJECT_NAME PROJECT_SOURCE_DIR PROJECT_VERSION PROJECT_VERSION_MAJOR PROJECT_VERSION_MINOR PROJECT_VERSION_PATCH PROJECT_VERSION_TWEAK UNIX WIN32 WINCE WINDOWS_PHONE WINDOWS_STORE XCODE XCODE_VERSION + \ ANDROID APPLE BORLAND BUILD_SHARED_LIBS CMAKE_ABSOLUTE_DESTINATION_FILES CMAKE_ANDROID_ANT_ADDITIONAL_OPTIONS CMAKE_ANDROID_API CMAKE_ANDROID_API_MIN CMAKE_ANDROID_ARCH CMAKE_ANDROID_ARCH_ABI CMAKE_ANDROID_ARM_MODE CMAKE_ANDROID_ARM_NEON CMAKE_ANDROID_ASSETS_DIRECTORIES CMAKE_ANDROID_GUI CMAKE_ANDROID_JAR_DEPENDENCIES CMAKE_ANDROID_JAR_DIRECTORIES CMAKE_ANDROID_JAVA_SOURCE_DIR CMAKE_ANDROID_NATIVE_LIB_DEPENDENCIES CMAKE_ANDROID_NATIVE_LIB_DIRECTORIES CMAKE_ANDROID_NDK CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION CMAKE_ANDROID_PROCESS_MAX CMAKE_ANDROID_PROGUARD CMAKE_ANDROID_PROGUARD_CONFIG_PATH CMAKE_ANDROID_SECURE_PROPS_PATH CMAKE_ANDROID_SKIP_ANT_STEP CMAKE_ANDROID_STANDALONE_TOOLCHAIN CMAKE_ANDROID_STL_TYPE CMAKE_APPBUNDLE_PATH CMAKE_AR CMAKE_ARCHIVE_OUTPUT_DIRECTORY CMAKE_ARGC CMAKE_ARGV0 CMAKE_AUTOMOC CMAKE_AUTOMOC_DEPEND_FILTERS CMAKE_AUTOMOC_MOC_OPTIONS CMAKE_AUTOMOC_RELAXED_MODE CMAKE_AUTORCC CMAKE_AUTORCC_OPTIONS CMAKE_AUTOUIC CMAKE_AUTOUIC_OPTIONS CMAKE_AUTOUIC_SEARCH_PATHS CMAKE_BACKWARDS_COMPATIBILITY CMAKE_BINARY_DIR CMAKE_BUILD_RPATH CMAKE_BUILD_TOOL CMAKE_BUILD_TYPE CMAKE_BUILD_WITH_INSTALL_NAME_DIR CMAKE_BUILD_WITH_INSTALL_RPATH CMAKE_CACHEFILE_DIR CMAKE_CACHE_MAJOR_VERSION CMAKE_CACHE_MINOR_VERSION CMAKE_CACHE_PATCH_VERSION CMAKE_CFG_INTDIR CMAKE_CL_64 CMAKE_CODELITE_USE_TARGETS CMAKE_COLOR_MAKEFILE CMAKE_COMMAND CMAKE_COMPILER_2005 CMAKE_COMPILER_IS_GNUCC CMAKE_COMPILER_IS_GNUCXX CMAKE_COMPILER_IS_GNUG77 CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY CMAKE_CONFIGURATION_TYPES CMAKE_CROSSCOMPILING CMAKE_CROSSCOMPILING_EMULATOR CMAKE_CTEST_COMMAND CMAKE_CUDA_EXTENSIONS CMAKE_CUDA_STANDARD CMAKE_CUDA_STANDARD_REQUIRED CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES CMAKE_CURRENT_BINARY_DIR CMAKE_CURRENT_LIST_DIR CMAKE_CURRENT_LIST_FILE CMAKE_CURRENT_LIST_LINE CMAKE_CURRENT_SOURCE_DIR CMAKE_CXX_COMPILE_FEATURES CMAKE_CXX_EXTENSIONS CMAKE_CXX_STANDARD CMAKE_CXX_STANDARD_REQUIRED CMAKE_C_COMPILE_FEATURES CMAKE_C_EXTENSIONS CMAKE_C_STANDARD CMAKE_C_STANDARD_REQUIRED CMAKE_DEBUG_POSTFIX CMAKE_DEBUG_TARGET_PROPERTIES CMAKE_DEPENDS_IN_PROJECT_ONLY CMAKE_DL_LIBS CMAKE_ECLIPSE_GENERATE_LINKED_RESOURCES CMAKE_ECLIPSE_GENERATE_SOURCE_PROJECT CMAKE_ECLIPSE_MAKE_ARGUMENTS CMAKE_ECLIPSE_VERSION CMAKE_EDIT_COMMAND CMAKE_ENABLE_EXPORTS CMAKE_ERROR_DEPRECATED CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION CMAKE_EXECUTABLE_SUFFIX CMAKE_EXE_LINKER_FLAGS CMAKE_EXE_LINKER_FLAGS_INIT CMAKE_EXPORT_COMPILE_COMMANDS CMAKE_EXPORT_NO_PACKAGE_REGISTRY CMAKE_EXTRA_GENERATOR CMAKE_EXTRA_SHARED_LIBRARY_SUFFIXES CMAKE_FIND_APPBUNDLE CMAKE_FIND_FRAMEWORK CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX CMAKE_FIND_LIBRARY_PREFIXES CMAKE_FIND_LIBRARY_SUFFIXES CMAKE_FIND_NO_INSTALL_PREFIX CMAKE_FIND_PACKAGE_NAME CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY CMAKE_FIND_PACKAGE_SORT_DIRECTION CMAKE_FIND_PACKAGE_SORT_ORDER CMAKE_FIND_PACKAGE_WARN_NO_MODULE CMAKE_FIND_ROOT_PATH CMAKE_FIND_ROOT_PATH_MODE_INCLUDE CMAKE_FIND_ROOT_PATH_MODE_LIBRARY CMAKE_FIND_ROOT_PATH_MODE_PACKAGE CMAKE_FIND_ROOT_PATH_MODE_PROGRAM CMAKE_FRAMEWORK_PATH CMAKE_Fortran_FORMAT CMAKE_Fortran_MODDIR_DEFAULT CMAKE_Fortran_MODDIR_FLAG CMAKE_Fortran_MODOUT_FLAG CMAKE_Fortran_MODULE_DIRECTORY CMAKE_GENERATOR CMAKE_GENERATOR_PLATFORM CMAKE_GENERATOR_TOOLSET CMAKE_GNUtoMS CMAKE_HOME_DIRECTORY CMAKE_HOST_APPLE CMAKE_HOST_SOLARIS CMAKE_HOST_SYSTEM CMAKE_HOST_SYSTEM_NAME CMAKE_HOST_SYSTEM_PROCESSOR CMAKE_HOST_SYSTEM_VERSION CMAKE_HOST_UNIX CMAKE_HOST_WIN32 CMAKE_IGNORE_PATH CMAKE_IMPORT_LIBRARY_PREFIX CMAKE_IMPORT_LIBRARY_SUFFIX CMAKE_INCLUDE_CURRENT_DIR CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE CMAKE_INCLUDE_DIRECTORIES_BEFORE CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE CMAKE_INCLUDE_PATH CMAKE_INSTALL_DEFAULT_COMPONENT_NAME CMAKE_INSTALL_MESSAGE CMAKE_INSTALL_NAME_DIR CMAKE_INSTALL_PREFIX CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT CMAKE_INSTALL_RPATH CMAKE_INSTALL_RPATH_USE_LINK_PATH CMAKE_INTERNAL_PLATFORM_ABI CMAKE_INTERPROCEDURAL_OPTIMIZATION CMAKE_IOS_INSTALL_COMBINED CMAKE_JOB_POOL_COMPILE CMAKE_JOB_POOL_LINK CMAKE_LIBRARY_ARCHITECTURE CMAKE_LIBRARY_ARCHITECTURE_REGEX CMAKE_LIBRARY_OUTPUT_DIRECTORY CMAKE_LIBRARY_PATH CMAKE_LIBRARY_PATH_FLAG CMAKE_LINK_DEF_FILE_FLAG CMAKE_LINK_DEPENDS_NO_SHARED CMAKE_LINK_INTERFACE_LIBRARIES CMAKE_LINK_LIBRARY_FILE_FLAG CMAKE_LINK_LIBRARY_FLAG CMAKE_LINK_LIBRARY_SUFFIX CMAKE_LINK_SEARCH_END_STATIC CMAKE_LINK_SEARCH_START_STATIC CMAKE_LINK_WHAT_YOU_USE CMAKE_MACOSX_BUNDLE CMAKE_MACOSX_RPATH CMAKE_MAJOR_VERSION CMAKE_MAKE_PROGRAM CMAKE_MATCH_COUNT CMAKE_MFC_FLAG CMAKE_MINIMUM_REQUIRED_VERSION CMAKE_MINOR_VERSION CMAKE_MODULE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS_INIT CMAKE_MODULE_PATH CMAKE_NINJA_OUTPUT_PATH_PREFIX CMAKE_NOT_USING_CONFIG_FLAGS CMAKE_NO_BUILTIN_CHRPATH CMAKE_NO_SYSTEM_FROM_IMPORTED CMAKE_OBJECT_PATH_MAX CMAKE_OSX_ARCHITECTURES CMAKE_OSX_DEPLOYMENT_TARGET CMAKE_OSX_SYSROOT CMAKE_PARENT_LIST_FILE CMAKE_PATCH_VERSION CMAKE_PDB_OUTPUT_DIRECTORY CMAKE_POSITION_INDEPENDENT_CODE CMAKE_PREFIX_PATH CMAKE_PROGRAM_PATH CMAKE_PROJECT_DESCRIPTION CMAKE_PROJECT_NAME CMAKE_RANLIB CMAKE_ROOT CMAKE_RUNTIME_OUTPUT_DIRECTORY CMAKE_SCRIPT_MODE_FILE CMAKE_SHARED_LIBRARY_PREFIX CMAKE_SHARED_LIBRARY_SUFFIX CMAKE_SHARED_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS_INIT CMAKE_SHARED_MODULE_PREFIX CMAKE_SHARED_MODULE_SUFFIX CMAKE_SIZEOF_VOID_P CMAKE_SKIP_BUILD_RPATH CMAKE_SKIP_INSTALL_ALL_DEPENDENCY CMAKE_SKIP_INSTALL_RPATH CMAKE_SKIP_INSTALL_RULES CMAKE_SKIP_RPATH CMAKE_SOURCE_DIR CMAKE_STAGING_PREFIX CMAKE_STATIC_LIBRARY_PREFIX CMAKE_STATIC_LIBRARY_SUFFIX CMAKE_STATIC_LINKER_FLAGS CMAKE_STATIC_LINKER_FLAGS_INIT CMAKE_SUBLIME_TEXT_2_ENV_SETTINGS CMAKE_SUBLIME_TEXT_2_EXCLUDE_BUILD_TREE CMAKE_SYSROOT CMAKE_SYSTEM CMAKE_SYSTEM_APPBUNDLE_PATH CMAKE_SYSTEM_FRAMEWORK_PATH CMAKE_SYSTEM_IGNORE_PATH CMAKE_SYSTEM_INCLUDE_PATH CMAKE_SYSTEM_LIBRARY_PATH CMAKE_SYSTEM_NAME CMAKE_SYSTEM_PREFIX_PATH CMAKE_SYSTEM_PROCESSOR CMAKE_SYSTEM_PROGRAM_PATH CMAKE_SYSTEM_VERSION CMAKE_Swift_LANGUAGE_VERSION CMAKE_TOOLCHAIN_FILE CMAKE_TRY_COMPILE_CONFIGURATION CMAKE_TRY_COMPILE_PLATFORM_VARIABLES CMAKE_TRY_COMPILE_TARGET_TYPE CMAKE_TWEAK_VERSION CMAKE_USER_MAKE_RULES_OVERRIDE CMAKE_USE_RELATIVE_PATHS CMAKE_VERBOSE_MAKEFILE CMAKE_VERSION CMAKE_VISIBILITY_INLINES_HIDDEN CMAKE_VS_DEVENV_COMMAND CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD CMAKE_VS_INCLUDE_PACKAGE_TO_DEFAULT_BUILD CMAKE_VS_INTEL_Fortran_PROJECT_VERSION CMAKE_VS_MSBUILD_COMMAND CMAKE_VS_NsightTegra_VERSION CMAKE_VS_PLATFORM_NAME CMAKE_VS_PLATFORM_TOOLSET CMAKE_VS_PLATFORM_TOOLSET_CUDA CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION CMAKE_WARN_DEPRECATED CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION CMAKE_WIN32_EXECUTABLE CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS CMAKE_XCODE_GENERATE_SCHEME CMAKE_XCODE_PLATFORM_TOOLSET CPACK_ABSOLUTE_DESTINATION_FILES CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION CPACK_INCLUDE_TOPLEVEL_DIRECTORY CPACK_INSTALL_SCRIPT CPACK_PACKAGING_INSTALL_PREFIX CPACK_SET_DESTDIR CPACK_WARN_ON_ABSOLUTE_INSTALL_DESTINATION CTEST_BINARY_DIRECTORY CTEST_BUILD_COMMAND CTEST_BUILD_NAME CTEST_BZR_COMMAND CTEST_BZR_UPDATE_OPTIONS CTEST_CHANGE_ID CTEST_CHECKOUT_COMMAND CTEST_CONFIGURATION_TYPE CTEST_CONFIGURE_COMMAND CTEST_COVERAGE_COMMAND CTEST_COVERAGE_EXTRA_FLAGS CTEST_CURL_OPTIONS CTEST_CUSTOM_COVERAGE_EXCLUDE CTEST_CUSTOM_ERROR_EXCEPTION CTEST_CUSTOM_ERROR_MATCH CTEST_CUSTOM_ERROR_POST_CONTEXT CTEST_CUSTOM_ERROR_PRE_CONTEXT CTEST_CUSTOM_MAXIMUM_FAILED_TEST_OUTPUT_SIZE CTEST_CUSTOM_MAXIMUM_NUMBER_OF_ERRORS CTEST_CUSTOM_MAXIMUM_NUMBER_OF_WARNINGS CTEST_CUSTOM_MAXIMUM_PASSED_TEST_OUTPUT_SIZE CTEST_CUSTOM_MEMCHECK_IGNORE CTEST_CUSTOM_POST_MEMCHECK CTEST_CUSTOM_POST_TEST CTEST_CUSTOM_PRE_MEMCHECK CTEST_CUSTOM_PRE_TEST CTEST_CUSTOM_TEST_IGNORE CTEST_CUSTOM_WARNING_EXCEPTION CTEST_CUSTOM_WARNING_MATCH CTEST_CVS_CHECKOUT CTEST_CVS_COMMAND CTEST_CVS_UPDATE_OPTIONS CTEST_DROP_LOCATION CTEST_DROP_METHOD CTEST_DROP_SITE CTEST_DROP_SITE_CDASH CTEST_DROP_SITE_PASSWORD CTEST_DROP_SITE_USER CTEST_EXTRA_COVERAGE_GLOB CTEST_GIT_COMMAND CTEST_GIT_INIT_SUBMODULES CTEST_GIT_UPDATE_CUSTOM CTEST_GIT_UPDATE_OPTIONS CTEST_HG_COMMAND CTEST_HG_UPDATE_OPTIONS CTEST_LABELS_FOR_SUBPROJECTS CTEST_MEMORYCHECK_COMMAND CTEST_MEMORYCHECK_COMMAND_OPTIONS CTEST_MEMORYCHECK_SANITIZER_OPTIONS CTEST_MEMORYCHECK_SUPPRESSIONS_FILE CTEST_MEMORYCHECK_TYPE CTEST_NIGHTLY_START_TIME CTEST_P4_CLIENT CTEST_P4_COMMAND CTEST_P4_OPTIONS CTEST_P4_UPDATE_OPTIONS CTEST_SCP_COMMAND CTEST_SITE CTEST_SOURCE_DIRECTORY CTEST_SVN_COMMAND CTEST_SVN_OPTIONS CTEST_SVN_UPDATE_OPTIONS CTEST_TEST_LOAD CTEST_TEST_TIMEOUT CTEST_TRIGGER_SITE CTEST_UPDATE_COMMAND CTEST_UPDATE_OPTIONS CTEST_UPDATE_VERSION_ONLY CTEST_USE_LAUNCHERS CYGWIN ENV EXECUTABLE_OUTPUT_PATH GHS-MULTI LIBRARY_OUTPUT_PATH MINGW MSVC MSVC10 MSVC11 MSVC12 MSVC14 MSVC60 MSVC70 MSVC71 MSVC80 MSVC90 MSVC_IDE MSVC_VERSION PROJECT_BINARY_DIR PROJECT_DESCRIPTION PROJECT_NAME PROJECT_SOURCE_DIR PROJECT_VERSION PROJECT_VERSION_MAJOR PROJECT_VERSION_MINOR PROJECT_VERSION_PATCH PROJECT_VERSION_TWEAK UNIX WIN32 WINCE WINDOWS_PHONE WINDOWS_STORE XCODE XCODE_VERSION syn keyword cmakeModule contained \ ExternalProject @@ -78,7 +77,7 @@ syn keyword cmakeKWbuild_name contained \ CMAKE_CXX_COMPILER syn keyword cmakeKWcmake_host_system_information contained - \ AVAILABLE_PHYSICAL_MEMORY AVAILABLE_VIRTUAL_MEMORY FQDN HOSTNAME NUMBER_OF_LOGICAL_CORES NUMBER_OF_PHYSICAL_CORES QUERY RESULT TOTAL_PHYSICAL_MEMORY TOTAL_VIRTUAL_MEMORY + \ AVAILABLE_PHYSICAL_MEMORY AVAILABLE_VIRTUAL_MEMORY FQDN HOSTNAME NUMBER_OF_LOGICAL_CORES NUMBER_OF_PHYSICAL_CORES QUERY RESULT TOTAL_PHYSICAL_MEMORY TOTAL_VIRTUAL_MEMORY IS_64BIT HAS_FPU HAS_MMX HAS_MMX_PLUS HAS_SSE HAS_SSE2 HAS_SSE_FP HAS_SSE_MMX HAS_AMD_3DNOW HAS_AMD_3DNOW_PLUS HAS_IA64 HAS_SERIAL_NUMBER PROCESSOR_SERIAL_NUMBER PROCESSOR_NAME OS_NAME OS_RELEASE OS_VERSION OS_PLATFORM syn keyword cmakeKWcmake_minimum_required contained \ FATAL_ERROR VERSION @@ -203,6 +202,9 @@ syn keyword cmakeKWinclude_directories contained syn keyword cmakeKWinclude_external_msproject contained \ GUID MAP_IMPORTED_CONFIG_ PLATFORM TYPE WIX +syn keyword cmakeKWinclude_guard contained + \ DIRECTORY GLOBAL + syn keyword cmakeKWinstall contained \ ARCHIVE BUNDLE CODE COMPONENT CONFIGURATIONS CVS DESTDIR DESTINATION DIRECTORY DIRECTORY_PERMISSIONS DLL EXCLUDE_FROM_ALL EXPORT EXPORT_ANDROID_MK EXPORT_LINK_INTERFACE_LIBRARIES FILES FILES_MATCHING FILE_PERMISSIONS FRAMEWORK GROUP_EXECUTE GROUP_READ GROUP_WRITE IMPORTED_ INCLUDES INSTALL_PREFIX INTERFACE_INCLUDE_DIRECTORIES LIBRARY MACOSX_BUNDLE MESSAGE_NEVER NAMELINK_ONLY NAMELINK_SKIP NAMESPACE NDK OBJECTS OPTIONAL OWNER_EXECUTE OWNER_READ OWNER_WRITE PATTERN PERMISSIONS POST_INSTALL_SCRIPT PRE_INSTALL_SCRIPT PRIVATE_HEADER PROGRAMS PUBLIC_HEADER REGEX RENAME RESOURCE RUNTIME SCRIPT SETGID SETUID SOVERSION TARGETS TRUE USE_SOURCE_PERMISSIONS VERSION WORLD_EXECUTE WORLD_READ WORLD_WRITE @@ -327,7 +329,7 @@ syn keyword cmakeGeneratorExpressions contained syn case ignore syn keyword cmakeCommand - \ add_compile_options add_custom_command add_custom_target add_definitions add_dependencies add_executable add_library add_subdirectory add_test aux_source_directory break build_command cmake_host_system_information cmake_minimum_required cmake_parse_arguments cmake_policy configure_file continue create_test_sourcelist ctest_build ctest_configure ctest_coverage ctest_empty_binary_directory ctest_memcheck ctest_read_custom_files ctest_run_script ctest_sleep ctest_start ctest_submit ctest_test ctest_update ctest_upload define_property enable_language enable_testing endfunction endmacro execute_process export file find_file find_library find_package find_path find_program fltk_wrap_ui function get_cmake_property get_directory_property get_filename_component get_property get_source_file_property get_target_property get_test_property include include_directories include_external_msproject include_regular_expression install link_directories list load_cache load_command macro mark_as_advanced math message option project qt_wrap_cpp qt_wrap_ui remove_definitions return separate_arguments set set_directory_properties set_property set_source_files_properties set_target_properties set_tests_properties site_name source_group string target_compile_definitions target_compile_features target_compile_options target_include_directories target_link_libraries target_sources try_compile try_run unset variable_watch + \ add_compile_options add_custom_command add_custom_target add_definitions add_dependencies add_executable add_library add_subdirectory add_test aux_source_directory break build_command cmake_host_system_information cmake_minimum_required cmake_parse_arguments cmake_policy configure_file continue create_test_sourcelist ctest_build ctest_configure ctest_coverage ctest_empty_binary_directory ctest_memcheck ctest_read_custom_files ctest_run_script ctest_sleep ctest_start ctest_submit ctest_test ctest_update ctest_upload define_property enable_language enable_testing endfunction endmacro execute_process export file find_file find_library find_package find_path find_program fltk_wrap_ui function get_cmake_property get_directory_property get_filename_component get_property get_source_file_property get_target_property get_test_property include include_directories include_external_msproject include_guard include_regular_expression install link_directories list load_cache load_command macro mark_as_advanced math message option project qt_wrap_cpp qt_wrap_ui remove_definitions return separate_arguments set set_directory_properties set_property set_source_files_properties set_target_properties set_tests_properties site_name source_group string target_compile_definitions target_compile_features target_compile_options target_include_directories target_link_libraries target_sources try_compile try_run unset variable_watch \ nextgroup=cmakeArguments syn keyword cmakeCommandConditional @@ -420,6 +422,7 @@ hi def link cmakeKWif ModeMsg hi def link cmakeKWinclude ModeMsg hi def link cmakeKWinclude_directories ModeMsg hi def link cmakeKWinclude_external_msproject ModeMsg +hi def link cmakeKWinclude_guard ModeMsg hi def link cmakeKWinstall ModeMsg hi def link cmakeKWinstall_files ModeMsg hi def link cmakeKWinstall_programs ModeMsg diff --git a/CMakeLists.txt b/CMakeLists.txt index ed924eb..67c4cdc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,13 +1,7 @@ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. -cmake_minimum_required(VERSION 2.8.12.2 FATAL_ERROR) -if(POLICY CMP0025) - cmake_policy(SET CMP0025 NEW) -endif() -if(POLICY CMP0053) - cmake_policy(SET CMP0053 NEW) -endif() +cmake_minimum_required(VERSION 3.1 FATAL_ERROR) project(CMake) # Make sure we can find internal find_package modules only used for @@ -21,6 +15,14 @@ if(CMAKE_BOOTSTRAP) endif() if(NOT CMake_TEST_EXTERNAL_CMAKE) + if(CMAKE_SYSTEM_NAME STREQUAL "HP-UX") + message(FATAL_ERROR + "CMake no longer compiles on HP-UX. See\n" + " https://gitlab.kitware.com/cmake/cmake/issues/17137\n" + "Use CMake 3.9 or lower instead." + ) + endif() + set(CMake_BIN_DIR ${CMake_BINARY_DIR}/bin) endif() @@ -72,6 +74,10 @@ if(NOT CMake_TEST_EXTERNAL_CMAKE) # check for available C++ features include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx_features.cmake) + + if(NOT CMake_HAVE_CXX_UNIQUE_PTR) + message(FATAL_ERROR "The C++ compiler does not support C++11 (e.g. std::unique_ptr).") + endif() endif() # set the internal encoding of CMake to UTF-8 @@ -333,11 +339,7 @@ macro (CMAKE_BUILD_UTILITIES) endif() if(CMAKE_USE_SYSTEM_LIBRHASH) - if(NOT CMAKE_VERSION VERSION_LESS 3.0) - find_package(LibRHash) - else() - message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBRHASH requires CMake >= 3.0") - endif() + find_package(LibRHash) if(NOT LibRHash_FOUND) message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBRHASH is ON but LibRHash is not found!") @@ -503,11 +505,7 @@ macro (CMAKE_BUILD_UTILITIES) #--------------------------------------------------------------------- # Build jsoncpp library. if(CMAKE_USE_SYSTEM_JSONCPP) - if(NOT CMAKE_VERSION VERSION_LESS 3.0) - find_package(JsonCpp) - else() - message(FATAL_ERROR "CMAKE_USE_SYSTEM_JSONCPP requires CMake >= 3.0") - endif() + find_package(JsonCpp) if(NOT JsonCpp_FOUND) message(FATAL_ERROR "CMAKE_USE_SYSTEM_JSONCPP is ON but a JsonCpp is not found!") @@ -521,45 +519,17 @@ macro (CMAKE_BUILD_UTILITIES) #--------------------------------------------------------------------- # Build libuv library. - if(NOT DEFINED CMAKE_USE_LIBUV) - set(CMAKE_USE_LIBUV 1) - if(APPLE) - include(CheckCSourceCompiles) - check_c_source_compiles(" -#include <CoreServices/CoreServices.h> -#include <AvailabilityMacros.h> -#ifndef MAC_OS_X_VERSION_10_5 -#error \"MAC_OS_X_VERSION_10_5 is not defined\" -#endif -int main(void) { return 0; } -" HAVE_CoreServices_OS_X_10_5) - if(NOT HAVE_CoreServices_OS_X_10_5) - set(CMAKE_USE_LIBUV 0) - endif() - elseif(CMAKE_SYSTEM_NAME STREQUAL "HP-UX") - # Disable until it can be ported. - set(CMAKE_USE_LIBUV 0) - endif() - endif() - if(CMAKE_USE_LIBUV) - if(CMAKE_USE_SYSTEM_LIBUV) - if(NOT CMAKE_VERSION VERSION_LESS 3.0) - find_package(LibUV 1.0.0) - else() - message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBUV requires CMake >= 3.0") - endif() - if(NOT LIBUV_FOUND) - message(FATAL_ERROR - "CMAKE_USE_SYSTEM_LIBUV is ON but a libuv is not found!") - endif() - set(CMAKE_LIBUV_LIBRARIES LibUV::LibUV) - else() - set(CMAKE_LIBUV_LIBRARIES cmlibuv) - add_subdirectory(Utilities/cmlibuv) - CMAKE_SET_TARGET_FOLDER(cmlibuv "Utilities/3rdParty") + if(CMAKE_USE_SYSTEM_LIBUV) + find_package(LibUV 1.0.0) + if(NOT LIBUV_FOUND) + message(FATAL_ERROR + "CMAKE_USE_SYSTEM_LIBUV is ON but a libuv is not found!") endif() + set(CMAKE_LIBUV_LIBRARIES LibUV::LibUV) else() - set(CMAKE_LIBUV_LIBRARIES) + set(CMAKE_LIBUV_LIBRARIES cmlibuv) + add_subdirectory(Utilities/cmlibuv) + CMAKE_SET_TARGET_FOLDER(cmlibuv "Utilities/3rdParty") endif() #--------------------------------------------------------------------- @@ -753,8 +723,7 @@ if(NOT CMake_TEST_EXTERNAL_CMAKE) if(NOT DEFINED CMake_ENABLE_SERVER_MODE) list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_auto_type CMake_HAVE_CXX_AUTO_TYPE) list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_range_for CMake_HAVE_CXX_RANGE_FOR) - if(CMAKE_USE_LIBUV - AND CMake_HAVE_CXX_AUTO_TYPE + if(CMake_HAVE_CXX_AUTO_TYPE AND CMake_HAVE_CXX_MAKE_UNIQUE AND CMake_HAVE_CXX_RANGE_FOR ) @@ -763,9 +732,6 @@ if(NOT CMake_TEST_EXTERNAL_CMAKE) set(CMake_ENABLE_SERVER_MODE 0) endif() endif() - if(CMake_ENABLE_SERVER_MODE AND NOT CMAKE_USE_LIBUV) - message(FATAL_ERROR "The server mode requires libuv!") - endif() else() set(CMake_ENABLE_SERVER_MODE 0) endif() diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index e219763..381769d 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -27,9 +27,13 @@ To contribute patches: #. Run `Utilities/SetupForDevelopment.sh`_ for local configuration. #. See the `CMake Source Code Guide`_ for coding guidelines. #. Base all new work on the upstream ``master`` branch. -#. Create commits making incremental, distinct, logically complete changes. + Base work on the upstream ``release`` branch only if it fixes a + regression or bug in a feature new to that release. +#. Create commits making incremental, distinct, logically complete changes + with appropriate `commit messages`_. #. Push a topic branch to a personal repository fork on GitLab. -#. Create a GitLab Merge Request targeting the upstream ``master`` branch. +#. Create a GitLab Merge Request targeting the upstream ``master`` branch + (even if the change is intended for merge to the ``release`` branch). The merge request will enter the `CMake Review Process`_ for consideration. @@ -37,6 +41,7 @@ The merge request will enter the `CMake Review Process`_ for consideration. .. _`CMake Repository`: https://gitlab.kitware.com/cmake/cmake .. _`Utilities/SetupForDevelopment.sh`: Utilities/SetupForDevelopment.sh .. _`CMake Source Code Guide`: Help/dev/source.rst +.. _`commit messages`: Help/dev/review.rst#commit-messages .. _`CMake Review Process`: Help/dev/review.rst License diff --git a/CTestCustom.cmake.in b/CTestCustom.cmake.in index fa2fbe3..6a37275 100644 --- a/CTestCustom.cmake.in +++ b/CTestCustom.cmake.in @@ -44,6 +44,7 @@ list(APPEND CTEST_CUSTOM_WARNING_EXCEPTION "Warning: LINN32: Last line.*is less.*" "Warning: Olimit was exceeded on function.*" "Warning: To override Olimit for all functions in file.*" + "WarningMessagesDialog\\.cxx" "warning.*directory name.*CMake-Xcode.*/bin/.*does not exist.*" "stl_deque.h:1051" "(Lexer|Parser).*warning.*conversion.*may (alter its value|change the sign)" diff --git a/CompileFlags.cmake b/CompileFlags.cmake index 7a9d4cd..9834b04 100644 --- a/CompileFlags.cmake +++ b/CompileFlags.cmake @@ -37,18 +37,6 @@ if(CMAKE_SYSTEM MATCHES "OSF1-V") endif() endif() -if(CMAKE_SYSTEM_NAME MATCHES "HP-UX" AND CMAKE_CXX_COMPILER_ID MATCHES "HP") - # HP aCC since version 3.80 supports the flag +hpxstd98 to get ANSI C++98 - # template support. It is known that version 6.25 doesn't need that flag. - # Versions prior to 3.80 will not be able to build CMake. Current assumption: - # it is needed for every version from 3.80 to 4 to get it working. - if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4 AND - NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.80) - # use new C++ library and improved template support - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -AA +hpxstd98") - endif() -endif() - # Workaround for short jump tables on PA-RISC if(CMAKE_SYSTEM_PROCESSOR MATCHES "^parisc") if(CMAKE_COMPILER_IS_GNUCC) diff --git a/Copyright.txt b/Copyright.txt index daaa1d1..b7af4c5 100644 --- a/Copyright.txt +++ b/Copyright.txt @@ -34,6 +34,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. The following individuals and institutions are among the Contributors: * Aaron C. Meadows <cmake@shadowguarddev.com> +* Adriaan de Groot <groot@kde.org> * Aleksey Avdeev <solo@altlinux.ru> * Alexander Neundorf <neundorf@kde.org> * Alexander Smorkalov <alexander.smorkalov@itseez.com> diff --git a/Help/command/cmake_host_system_information.rst b/Help/command/cmake_host_system_information.rst index 9402d57..7199874 100644 --- a/Help/command/cmake_host_system_information.rst +++ b/Help/command/cmake_host_system_information.rst @@ -13,13 +13,34 @@ queried. The list of queried values is stored in ``<variable>``. ``<key>`` can be one of the following values: -:: - - NUMBER_OF_LOGICAL_CORES = Number of logical cores. - NUMBER_OF_PHYSICAL_CORES = Number of physical cores. - HOSTNAME = Hostname. - FQDN = Fully qualified domain name. - TOTAL_VIRTUAL_MEMORY = Total virtual memory in megabytes. - AVAILABLE_VIRTUAL_MEMORY = Available virtual memory in megabytes. - TOTAL_PHYSICAL_MEMORY = Total physical memory in megabytes. - AVAILABLE_PHYSICAL_MEMORY = Available physical memory in megabytes. +============================= ================================================ +Key Description +============================= ================================================ +``NUMBER_OF_LOGICAL_CORES`` Number of logical cores +``NUMBER_OF_PHYSICAL_CORES`` Number of physical cores +``HOSTNAME`` Hostname +``FQDN`` Fully qualified domain name +``TOTAL_VIRTUAL_MEMORY`` Total virtual memory in megabytes +``AVAILABLE_VIRTUAL_MEMORY`` Available virtual memory in megabytes +``TOTAL_PHYSICAL_MEMORY`` Total physical memory in megabytes +``AVAILABLE_PHYSICAL_MEMORY`` Available physical memory in megabytes +``IS_64BIT`` One if processor is 64Bit +``HAS_FPU`` One if processor has floating point unit +``HAS_MMX`` One if processor supports MMX instructions +``HAS_MMX_PLUS`` One if porcessor supports Ext. MMX instructions +``HAS_SSE`` One if porcessor supports SSE instructions +``HAS_SSE2`` One if porcessor supports SSE2 instructions +``HAS_SSE_FP`` One if porcessor supports SSE FP instructions +``HAS_SSE_MMX`` One if porcessor supports SSE MMX instructions +``HAS_AMD_3DNOW`` One if porcessor supports 3DNow instructions +``HAS_AMD_3DNOW_PLUS`` One if porcessor supports 3DNow+ instructions +``HAS_IA64`` One if IA64 processor emulating x86 +``HAS_SERIAL_NUMBER`` One if processor has serial number +``PROCESSOR_SERIAL_NUMBER`` Processor serial number +``PROCESSOR_NAME`` Human readable processor name +``PROCESSOR_DESCRIPTION`` Human readable full processor description +``OS_NAME`` See :variable:`CMAKE_HOST_SYSTEM_NAME` +``OS_RELEASE`` The OS sub-type e.g. on Windows ``Professional`` +``OS_VERSION`` The OS build ID +``OS_PLATFORM`` See :variable:`CMAKE_HOST_SYSTEM_PROCESSOR` +============================= ================================================ diff --git a/Help/command/configure_file.rst b/Help/command/configure_file.rst index 4304f09..e08c573 100644 --- a/Help/command/configure_file.rst +++ b/Help/command/configure_file.rst @@ -30,9 +30,23 @@ a false constant by the :command:`if` command. The "..." content on the line after the variable name, if any, is processed as above. Input file lines of the form ``#cmakedefine01 VAR`` will be replaced with either ``#define VAR 1`` or ``#define VAR 0`` similarly. +The result lines (with the exception of the ``#undef`` comments) can be +indented using spaces and/or tabs between the ``#`` character +and the ``cmakedefine`` or ``cmakedefine01`` words. This whitespace +indentation will be preserved in the output lines:: + + # cmakedefine VAR + # cmakedefine01 VAR + +will be replaced, if ``VAR`` is defined, with:: + + # define VAR + # define VAR 1 If the input file is modified the build system will re-run CMake to re-configure the file and generate the build system again. +The generated file is modified and its timestamp updated on subsequent +cmake runs only if its content is changed. The arguments are: diff --git a/Help/command/execute_process.rst b/Help/command/execute_process.rst index d617243..799493f 100644 --- a/Help/command/execute_process.rst +++ b/Help/command/execute_process.rst @@ -10,6 +10,7 @@ Execute one or more child processes. [WORKING_DIRECTORY <directory>] [TIMEOUT <seconds>] [RESULT_VARIABLE <variable>] + [RESULTS_VARIABLE <variable>] [OUTPUT_VARIABLE <variable>] [ERROR_VARIABLE <variable>] [INPUT_FILE <file>] @@ -49,10 +50,16 @@ Options: specified number of seconds (fractions are allowed). ``RESULT_VARIABLE`` - The variable will be set to contain the result of running the processes. + The variable will be set to contain the result of last child process. This will be an integer return code from the last child or a string describing an error condition. +``RESULTS_VARIABLE <variable>`` + The variable will be set to contain the result of all processes as a + :ref:`;-list <CMake Language Lists>`, in order of the given ``COMMAND`` + arguments. Each entry will be an integer return code from the + corresponding child or a string describing an error condition. + ``OUTPUT_VARIABLE``, ``ERROR_VARIABLE`` The variable named will be set with the contents of the standard output and standard error pipes, respectively. If the same variable is named diff --git a/Help/command/file.rst b/Help/command/file.rst index b2e4eea..edccac5 100644 --- a/Help/command/file.rst +++ b/Help/command/file.rst @@ -13,8 +13,11 @@ File manipulation command. Write ``<content>`` into a file called ``<filename>``. If the file does not exist, it will be created. If the file already exists, ``WRITE`` mode will overwrite it and ``APPEND`` mode will append to the end. -(If the file is a build input, use the :command:`configure_file` command -to update the file only when its content changes.) +Any directories in the path specified by ``<filename>`` that do not +exist will be created. + +If the file is a build input, use the :command:`configure_file` command +to update the file only when its content changes. ------------------------------------------------------------------------------ @@ -105,9 +108,7 @@ Generate a list of files that match the ``<globbing-expressions>`` and store it into the ``<variable>``. Globbing expressions are similar to regular expressions, but much simpler. If ``RELATIVE`` flag is specified, the results will be returned as relative paths to the given -path. No specific order of results is defined other than that it is -deterministic. If order is important then sort the list explicitly -(e.g. using the :command:`list(SORT)` command). +path. The results will be ordered lexicographically. By default ``GLOB`` lists directories - directories are omited in result if ``LIST_DIRECTORIES`` is set to false. @@ -291,6 +292,8 @@ from the input content to produce the output content. The options are: ``INPUT <input-file>`` Use the content from a given file as input. + A relative path is treated with respect to the value of + :variable:`CMAKE_CURRENT_SOURCE_DIR`. See policy :policy:`CMP0070`. ``OUTPUT <output-file>`` Specify the output file name to generate. Use generator expressions @@ -298,11 +301,14 @@ from the input content to produce the output content. The options are: name. Multiple configurations may generate the same output file only if the generated content is identical. Otherwise, the ``<output-file>`` must evaluate to an unique name for each configuration. + A relative path (after evaluating generator expressions) is treated + with respect to the value of :variable:`CMAKE_CURRENT_BINARY_DIR`. + See policy :policy:`CMP0070`. Exactly one ``CONTENT`` or ``INPUT`` option must be given. A specific ``OUTPUT`` file may be named by at most one invocation of ``file(GENERATE)``. -Generated files are modified on subsequent cmake runs only if their content -is changed. +Generated files are modified and their timestamp updated on subsequent cmake +runs only if their content is changed. Note also that ``file(GENERATE)`` does not create the output file until the generation phase. The output file will not yet have been written when the diff --git a/Help/command/if.rst b/Help/command/if.rst index edd343d..f04f233 100644 --- a/Help/command/if.rst +++ b/Help/command/if.rst @@ -30,7 +30,7 @@ else and endif clause is optional. Long expressions can be used and there is a traditional order of precedence. Parenthetical expressions are evaluated first followed by unary tests such as ``EXISTS``, ``COMMAND``, and ``DEFINED``. Then any binary tests such as -``EQUAL``, ``LESS``, ``LESS_EQUAL, ``GREATER``, ``GREATER_EQUAL``, +``EQUAL``, ``LESS``, ``LESS_EQUAL``, ``GREATER``, ``GREATER_EQUAL``, ``STREQUAL``, ``STRLESS``, ``STRLESS_EQUAL``, ``STRGREATER``, ``STRGREATER_EQUAL``, ``VERSION_EQUAL``, ``VERSION_LESS``, ``VERSION_LESS_EQUAL``, ``VERSION_GREATER``, ``VERSION_GREATER_EQUAL``, diff --git a/Help/command/include_guard.rst b/Help/command/include_guard.rst new file mode 100644 index 0000000..62cce22 --- /dev/null +++ b/Help/command/include_guard.rst @@ -0,0 +1,46 @@ +include_guard +------------- + +Provides an include guard for the file currently being processed by CMake. + +:: + + include_guard([DIRECTORY|GLOBAL]) + +Sets up an include guard for the current CMake file (see the +:variable:`CMAKE_CURRENT_LIST_FILE` variable documentation). + +CMake will end its processing of the current file at the location of the +:command:`include_guard` command if the current file has already been +processed for the applicable scope (see below). This provides functionality +similar to the include guards commonly used in source headers or to the +``#pragma once`` directive. If the current file has been processed previously +for the applicable scope, the effect is as though :command:`return` had been +called. Do not call this command from inside a function being defined within +the current file. + +An optional argument specifying the scope of the guard may be provided. +Possible values for the option are: + +``DIRECTORY`` + The include guard applies within the current directory and below. The file + will only be included once within this directory scope, but may be included + again by other files outside of this directory (i.e. a parent directory or + another directory not pulled in by :command:`add_subdirectory` or + :command:`include` from the current file or its children). + +``GLOBAL`` + The include guard applies globally to the whole build. The current file + will only be included once regardless of the scope. + +If no arguments given, ``include_guard`` has the same scope as a variable, +meaning that the include guard effect is isolated by the most recent +function scope or current directory if no inner function scopes exist. +In this case the command behavior is the same as: + +.. code-block:: cmake + + if(__CURRENT_FILE_VAR__) + return() + endif() + set(__CURRENT_FILE_VAR__ TRUE) diff --git a/Help/command/string.rst b/Help/command/string.rst index 4f0c45c..ba4a412 100644 --- a/Help/command/string.rst +++ b/Help/command/string.rst @@ -132,6 +132,15 @@ APPEND Append all the input arguments to the string. +PREPEND +""""""" + +:: + + string(PREPEND <string variable> [<input>...]) + +Prepend all the input arguments to the string. + CONCAT """""" diff --git a/Help/dev/maint.rst b/Help/dev/maint.rst index 78c06df..bdfb3d0 100644 --- a/Help/dev/maint.rst +++ b/Help/dev/maint.rst @@ -8,6 +8,80 @@ See documentation on `CMake Development`_ for more information. .. contents:: Maintainer Processes: +Review a Merge Request +====================== + +The `CMake Review Process`_ requires a maintainer to issue the ``Do: merge`` +command to integrate a merge request. Please check at least the following: + +* If the MR source branch is not named well for the change it makes + (e.g. it is just ``master`` or the patch changed during review), + add a ``Topic-rename: <topic>`` trailing line to the MR description + to provide a better topic name. + +* If the MR introduces a new feature or a user-facing behavior change, + such as a policy, ensure that a ``Help/release/dev/$topic.rst`` file + is added with a release note. + +* If a commit changes a specific area, such as a module, its commit + message should have an ``area:`` prefix on its first line. + +* If a commit fixes a tracked issue, its commit message should have + a trailing line such as ``Fixes: #00000``. + +* Ensure that the MR adds sufficient documentation and test cases. + +* Ensure that the MR has been tested sufficiently. Typically it should + be staged for nightly testing with ``Do: stage``. Then manually + review the `CMake CDash Page`_ to verify that no regressions were + introduced. (Learn to tolerate spurious failures due to idiosyncrasies + of various nightly builders.) + +* Ensure that the MR targets the ``master`` branch. A MR intended for + the ``release`` branch should be based on ``release`` but still merged + to ``master`` first (via ``Do: merge``). A maintainer may then merge + the MR topic to ``release`` manually. + +Maintain Current Release +======================== + +The ``release`` branch is used to maintain the current release or release +candidate. The branch is published with no version number but maintained +using a local branch named ``release-$ver``, where ``$ver`` is the version +number of the current release in the form ``$major.$minor``. It is always +merged into ``master`` before publishing. + +To merge some ``$topic`` branch into ``release``, first create the local +branch: + +.. code-block:: shell + + git fetch origin + git checkout -b release-$ver origin/release + +Merge the ``$topic`` branch into the local ``release-$ver`` branch: + +.. code-block:: shell + + git merge --no-ff $topic + +Merge the ``release-$ver`` branch to ``master``: + +.. code-block:: shell + + git checkout master + git pull + git merge --no-ff release-$ver + +Publish both ``master`` and ``release`` simultaneously: + +.. code-block:: shell + + git push --atomic origin master release-$ver:release + +.. _`CMake Review Process`: review.rst +.. _`CMake CDash Page`: https://open.cdash.org/index.php?project=CMake + Branch a New Release ==================== diff --git a/Help/dev/review.rst b/Help/dev/review.rst index 9450bf0..985b1b7 100644 --- a/Help/dev/review.rst +++ b/Help/dev/review.rst @@ -185,6 +185,54 @@ commands to ``@kwrobot`` using the form ``Do: ...``: See the corresponding sections for details on permissions and options for each command. +Commit Messages +--------------- + +Part of the human review is to check that each commit message is appropriate. +The first line of the message should begin with one or two words indicating the +area the commit applies to, followed by a colon and then a brief summary. +Committers should aim to keep this first line short. Any subsequent lines +should be separated from the first by a blank line and provide relevant, useful +information. + +The appropriateness of the initial word describing the area the commit applies +to is not something the automatic robot review can judge, so it is up to the +human reviewer to confirm that the area is specified and that it is +appropriate. Good area words include the module name the commit is primarily +fixing, the main C++ source file being edited, ``Help`` for generic +documentation changes or a feature or functionality theme the changes apply to +(e.g. ``server`` or ``Autogen``). Examples of suitable first lines of a commit +message include: + +* ``Help: Fix example in cmake-buildsystem(7) manual`` +* ``FindBoost: Add support for 1.64`` +* ``Autogen: Extended mocInclude tests`` +* ``cmLocalGenerator: Explain standard flag selection logic in comments`` + +If the commit fixes a particular reported issue, this information should +ideally also be part of the commit message. The recommended way to do this is +to place a line at the end of the message in the form ``Fixes: #xxxxx`` where +``xxxxx`` is the GitLab issue number and to separate it from the rest of the +text by a blank line. For example:: + + Help: Fix FooBar example robustness issue + + FooBar supports option X, but the example provided + would not work if Y was also specified. + + Fixes: #12345 + +GitLab will automatically create relevant links to the merge request and will +close the issue when the commit is merged into master. GitLab understands a few +other synonyms for ``Fixes`` and allows much more flexible forms than the +above, but committers should aim for this format for consistency. Note that +such details can alternatively be specified in the merge request description. + +Reviewers are encouraged to ask the committer to amend commit messages to +follow these guidelines, but prefer to focus on the changes themselves as a +first priority. Maintainers will also make a check of commit messages before +merging. + Topic Testing ============= diff --git a/Help/dev/source.rst b/Help/dev/source.rst index 7e44995..b40a884 100644 --- a/Help/dev/source.rst +++ b/Help/dev/source.rst @@ -23,20 +23,18 @@ format only a subset of files, such as those that are locally modified. C++ Subset Permitted ==================== -CMake supports compiling as C++98 in addition to C++11 and C++14. -In order to support building on older toolchains some constructs -need to be handled with care: +CMake requires compiling as C++11 or above. However, in order to support +building on older toolchains some constructs need to be handled with care: -* Use ``CM_AUTO_PTR`` instead of ``std::auto_ptr``. +* Do not use ``CM_AUTO_PTR`` or ``std::auto_ptr``. - The ``std::auto_ptr`` template is deprecated in C++11. We want to use it - so we can build on C++98 compilers but we do not want to turn off compiler - warnings about deprecated interfaces in general. Use the ``CM_AUTO_PTR`` - macro instead. + The ``std::auto_ptr`` template is deprecated in C++11. The ``CM_AUTO_PTR`` + macro remains leftover from C++98 support until its uses can be ported to + ``std::unique_ptr``. Do not add new uses of the macro. * Use ``CM_EQ_DELETE;`` instead of ``= delete;``. - Defining functions as *deleted* is not supported in C++98. Using + Older C++11 compilers do not support deleting functions. Using ``CM_EQ_DELETE`` will delete the functions if the compiler supports it and give them no implementation otherwise. Calling such a function will lead to compiler errors if the compiler supports *deleted* functions and linker @@ -58,3 +56,50 @@ need to be handled with care: When assigning the result of ``.size()`` on a container for example, the result should be assigned to ``size_t`` not to ``std::size_t``, ``unsigned int`` or similar types. + +Source Tree Layout +================== + +The CMake source tree is organized as follows. + +* ``Auxiliary/``: + Shell and editor integration files. + +* ``Help/``: + Documentation. + + * ``Help/dev/``: + Developer documentation. + + * ``Help/release/dev/``: + Release note snippets for development since last release. + +* ``Licenses/``: + License files for third-party libraries in binary distributions. + +* ``Modules/``: + CMake language modules installed with CMake. + +* ``Packaging/``: + Files used for packaging CMake itself for distribution. + +* ``Source/``: + Source code of CMake itself. + +* ``Templates/``: + Files distributed with CMake as implementation details for generators, + packagers, etc. + +* ``Tests/``: + The test suite. See `Tests/README.rst`_. + +* ``Utilities/``: + Scripts, third-party source code. + + * ``Utilities/Sphinx/``: + Sphinx configuration to build CMake user documentation. + + * ``Utilities/Release/``: + Scripts used to package CMake itself for distribution on ``cmake.org``. + +.. _`Tests/README.rst`: ../../Tests/README.rst diff --git a/Help/manual/cmake-buildsystem.7.rst b/Help/manual/cmake-buildsystem.7.rst index 95f5b87..debaf23 100644 --- a/Help/manual/cmake-buildsystem.7.rst +++ b/Help/manual/cmake-buildsystem.7.rst @@ -266,7 +266,7 @@ The :command:`target_link_libraries` command has ``PRIVATE``, Because ``archive`` is a ``PUBLIC`` dependency of ``archiveExtras``, the usage requirements of it are propagated to ``consumer`` too. Because -``serialization`` is a ``PRIVATE`` dependency of ``archive``, the usage +``serialization`` is a ``PRIVATE`` dependency of ``archiveExtras``, the usage requirements of it are not propagated to ``consumer``. Generally, a dependency should be specified in a use of diff --git a/Help/manual/cmake-commands.7.rst b/Help/manual/cmake-commands.7.rst index 611c989..f8bfb32 100644 --- a/Help/manual/cmake-commands.7.rst +++ b/Help/manual/cmake-commands.7.rst @@ -44,6 +44,7 @@ These commands are always available. /command/get_property /command/if /command/include + /command/include_guard /command/list /command/macro /command/mark_as_advanced diff --git a/Help/manual/cmake-modules.7.rst b/Help/manual/cmake-modules.7.rst index 4a03b7a..fa6144c 100644 --- a/Help/manual/cmake-modules.7.rst +++ b/Help/manual/cmake-modules.7.rst @@ -60,6 +60,7 @@ All Modules /module/CPackCygwin /module/CPackDeb /module/CPackDMG + /module/CPackFreeBSD /module/CPackIFW /module/CPackIFWConfigureFile /module/CPackNSIS diff --git a/Help/manual/cmake-policies.7.rst b/Help/manual/cmake-policies.7.rst index 7b85817..c81ba59 100644 --- a/Help/manual/cmake-policies.7.rst +++ b/Help/manual/cmake-policies.7.rst @@ -51,6 +51,15 @@ The :variable:`CMAKE_MINIMUM_REQUIRED_VERSION` variable may also be used to determine whether to report an error on use of deprecated macros or functions. +Policies Introduced by CMake 3.10 +================================= + +.. toctree:: + :maxdepth: 1 + + CMP0071: Let AUTOMOC and AUTOUIC process GENERATED files. </policy/CMP0071> + CMP0070: Define file(GENERATE) behavior for relative paths. </policy/CMP0070> + Policies Introduced by CMake 3.9 ================================ diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst index ec25596..f1378c8 100644 --- a/Help/manual/cmake-properties.7.rst +++ b/Help/manual/cmake-properties.7.rst @@ -74,6 +74,7 @@ Properties on Directories /prop_dir/INCLUDE_REGULAR_EXPRESSION /prop_dir/INTERPROCEDURAL_OPTIMIZATION_CONFIG /prop_dir/INTERPROCEDURAL_OPTIMIZATION + /prop_dir/LABELS /prop_dir/LINK_DIRECTORIES /prop_dir/LISTFILE_STACK /prop_dir/MACROS @@ -83,7 +84,7 @@ Properties on Directories /prop_dir/RULE_LAUNCH_LINK /prop_dir/SOURCE_DIR /prop_dir/SUBDIRECTORIES - /prop_dir/TEST_INCLUDE_FILE + /prop_dir/TEST_INCLUDE_FILES /prop_dir/VARIABLES /prop_dir/VS_GLOBAL_SECTION_POST_section /prop_dir/VS_GLOBAL_SECTION_PRE_section @@ -122,6 +123,7 @@ Properties on Targets /prop_tgt/AUTOGEN_BUILD_DIR /prop_tgt/AUTOGEN_TARGET_DEPENDS /prop_tgt/AUTOMOC_DEPEND_FILTERS + /prop_tgt/AUTOMOC_MACRO_NAMES /prop_tgt/AUTOMOC_MOC_OPTIONS /prop_tgt/AUTOMOC /prop_tgt/AUTOUIC @@ -291,6 +293,7 @@ Properties on Targets /prop_tgt/VS_DEBUGGER_WORKING_DIRECTORY /prop_tgt/VS_DESKTOP_EXTENSIONS_VERSION /prop_tgt/VS_DOTNET_REFERENCE_refname + /prop_tgt/VS_DOTNET_REFERENCEPROP_refname_TAG_tagname /prop_tgt/VS_DOTNET_REFERENCES /prop_tgt/VS_DOTNET_REFERENCES_COPY_LOCAL /prop_tgt/VS_DOTNET_TARGET_FRAMEWORK_VERSION @@ -434,6 +437,7 @@ Deprecated Properties on Directories :maxdepth: 1 /prop_dir/COMPILE_DEFINITIONS_CONFIG + /prop_dir/TEST_INCLUDE_FILE Deprecated Properties on Targets diff --git a/Help/manual/cmake-qt.7.rst b/Help/manual/cmake-qt.7.rst index 00d6e6e..55121df 100644 --- a/Help/manual/cmake-qt.7.rst +++ b/Help/manual/cmake-qt.7.rst @@ -70,7 +70,11 @@ be included by the user in the C++ implementation file with a preprocessor Included ``moc_*.cpp`` and ``*.moc`` files will be generated in the ``<AUTOGEN_BUILD_DIR>/include`` directory which is automatically added to the target's :prop_tgt:`INCLUDE_DIRECTORIES`. -(This differs from CMake 3.7 and below; see their documentation for details.) + +* This differs from CMake 3.7 and below; see their documentation for details. + +* For multi configuration generators, the include directory is + ``<AUTOGEN_BUILD_DIR>/include_<CONFIG>``. * See :prop_tgt:`AUTOGEN_BUILD_DIR`. @@ -91,6 +95,10 @@ following targets by setting the :variable:`CMAKE_AUTOMOC` variable. The options to pass to ``moc``. The :variable:`CMAKE_AUTOMOC_MOC_OPTIONS` variable may be populated to pre-set the options for all following targets. +The appearance of the strings ``Q_OBJECT`` or ``Q_GADGET`` in a source file +determines if it needs to be ``moc`` processed. To search for additional +strings, list them in :prop_tgt:`AUTOMOC_MACRO_NAMES`. + Additional ``moc`` dependency file names can be extracted from source code by using :prop_tgt:`AUTOMOC_DEPEND_FILTERS`. @@ -107,15 +115,26 @@ inspects the C++ files in the target to determine if they require ``uic`` to be run, and to create rules to execute ``uic`` at the appropriate time. If a preprocessor ``#include`` directive is found which matches -``ui_<basename>.h``, and a ``<basename>.ui`` file exists, then ``uic`` will -be executed to generate the appropriate file. The ``<basename>.ui`` file is -searched for first in the vicinity of including file and afterwards in the -optional :prop_tgt:`AUTOUIC_SEARCH_PATHS` of the target. +``<path>ui_<basename>.h``, and a ``<basename>.ui`` file exists, +then ``uic`` will be executed to generate the appropriate file. +The ``<basename>.ui`` file is searched for in the following places + +1. ``<source_dir>/<basename>.ui`` +2. ``<source_dir>/<path><basename>.ui`` +3. ``<AUTOUIC_SEARCH_PATHS>/<basename>.ui`` +4. ``<AUTOUIC_SEARCH_PATHS>/<path><basename>.ui`` + +where ``<source_dir>`` is the directory of the C++ file and +:prop_tgt:`AUTOUIC_SEARCH_PATHS` is a list of additional search paths. The generated generated ``ui_*.h`` files are placed in the ``<AUTOGEN_BUILD_DIR>/include`` directory which is automatically added to the target's :prop_tgt:`INCLUDE_DIRECTORIES`. -(This differs from CMake 3.7 and below; see their documentation for details.) + +* This differs from CMake 3.7 and below; see their documentation for details. + +* For multi configuration generators, the include directory is + ``<AUTOGEN_BUILD_DIR>/include_<CONFIG>``. * See :prop_tgt:`AUTOGEN_BUILD_DIR`. diff --git a/Help/manual/cmake-server.7.rst b/Help/manual/cmake-server.7.rst index 9520cc1..c56e5a7 100644 --- a/Help/manual/cmake-server.7.rst +++ b/Help/manual/cmake-server.7.rst @@ -254,6 +254,11 @@ versions supported by the cmake server. These are JSON objects with "major" and as experimental. These will contain the "isExperimental" key set to true. Enabling these requires a special command line argument when starting the cmake server mode. +Within a "major" version all "minor" versions are fully backwards compatible. +New "minor" versions may introduce functionality in such a way that existing +clients of the same "major" version will continue to work, provided they +ignore keys in the output that they do not know about. + Example:: [== "CMake Server" ==[ @@ -268,8 +273,13 @@ The first request that the client may send to the server is of type "handshake". This request needs to pass one of the "supportedProtocolVersions" of the "hello" type response received earlier back to the server in the "protocolVersion" field. +Giving the "major" version of the requested protocol version will make the server +use the latest minor version of that protocol. Use this if you do not explicitly +need to depend on a specific minor version. -Each protocol version may request additional attributes to be present. +If the build directory already contains a CMake cache, it is sufficient to set +the "buildDirectory" attribute. To create a fresh build directory, additional +attributes are required depending on the protocol version. Protocol version 1.0 requires the following attributes to be set: @@ -496,6 +506,9 @@ Each target object can have the following keys: with the sysroot path. "fileGroups" contains the source files making up the target. +"crossReferences" + contains the location of the target in the corresponding CMakeLists.txt + file and the locations of the related statements like "target_link_libraries" FileGroups are used to group sources using similar settings together. @@ -521,6 +534,16 @@ Each fileGroup object may contain the following keys: All file paths in the fileGroup are either absolute or relative to the sourceDirectory of the target. +CrossReferences object is used to report the location of the target (including +the entire call stack if the target is defined in a function) and the related +"target_link_libraries", "target_include_directories", "target_compile_definitions" +and "target_compile_options" statements. + +See the example below for details on the internal format of the "crossReferences" object. +Line numbers stated in the "backtrace" entries are 1-based. The last entry of a backtrace +is a special entry with missing "line" and "name" fields that specifies the initial +CMakeLists.txt file. + Example:: [== "CMake Server" ==[ @@ -557,7 +580,34 @@ CMake will reply:: "linkerLanguage": "C", "name": "cmForm", "sourceDirectory": "/home/code/src/cmake/Source/CursesDialog/form", - "type": "STATIC_LIBRARY" + "type": "STATIC_LIBRARY", + "crossReferences": { + "backtrace": [ + { + "line": 7, + "name": "add_executable", + "path": "C:/full/path/CMakeLists.txt" + }, + { + "path": "c:/full/path/CMakeLists.txt" + } + ], + "relatedStatements": [ + { + "backtrace": [ + { + "line": 8, + "name": "target_link_libraries", + "path": "c:/full/path/CMakeLists.txt" + }, + { + "path": "c:/full/path/CMakeLists.txt" + } + ], + "type": "target_link_libraries" + } + ] + } } ] }, @@ -616,8 +666,7 @@ and will not survive the build directory getting cleaned out. Type "cache" ^^^^^^^^^^^^ -The "cache" request can be used once a project is configured and will -list the cached configuration values. +The "cache" request will list the cached configuration values. Example:: diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst index 1a2726d..bef1171 100644 --- a/Help/manual/cmake-variables.7.rst +++ b/Help/manual/cmake-variables.7.rst @@ -32,6 +32,7 @@ Variables that Provide Information /variable/CMAKE_CURRENT_LIST_FILE /variable/CMAKE_CURRENT_LIST_LINE /variable/CMAKE_CURRENT_SOURCE_DIR + /variable/CMAKE_DIRECTORY_LABELS /variable/CMAKE_DL_LIBS /variable/CMAKE_EDIT_COMMAND /variable/CMAKE_EXECUTABLE_SUFFIX @@ -269,6 +270,7 @@ Variables that Control the Build /variable/CMAKE_ARCHIVE_OUTPUT_DIRECTORY_CONFIG /variable/CMAKE_AUTOMOC /variable/CMAKE_AUTOMOC_DEPEND_FILTERS + /variable/CMAKE_AUTOMOC_MACRO_NAMES /variable/CMAKE_AUTOMOC_MOC_OPTIONS /variable/CMAKE_AUTORCC /variable/CMAKE_AUTORCC_OPTIONS @@ -319,6 +321,7 @@ Variables that Control the Build /variable/CMAKE_MODULE_LINKER_FLAGS_CONFIG /variable/CMAKE_MODULE_LINKER_FLAGS_CONFIG_INIT /variable/CMAKE_MODULE_LINKER_FLAGS_INIT + /variable/CMAKE_MSVCIDE_RUN_PATH /variable/CMAKE_NINJA_OUTPUT_PATH_PREFIX /variable/CMAKE_NO_BUILTIN_CHRPATH /variable/CMAKE_NO_SYSTEM_FROM_IMPORTED @@ -386,6 +389,7 @@ Variables for Languages /variable/CMAKE_LANG_ARCHIVE_FINISH /variable/CMAKE_LANG_COMPILER /variable/CMAKE_LANG_COMPILER_ABI + /variable/CMAKE_LANG_COMPILER_ARCHITECTURE_ID /variable/CMAKE_LANG_COMPILER_EXTERNAL_TOOLCHAIN /variable/CMAKE_LANG_COMPILER_ID /variable/CMAKE_LANG_COMPILER_LOADED @@ -480,6 +484,7 @@ Variables for CTest /variable/CTEST_GIT_UPDATE_OPTIONS /variable/CTEST_HG_COMMAND /variable/CTEST_HG_UPDATE_OPTIONS + /variable/CTEST_LABELS_FOR_SUBPROJECTS /variable/CTEST_MEMORYCHECK_COMMAND /variable/CTEST_MEMORYCHECK_COMMAND_OPTIONS /variable/CTEST_MEMORYCHECK_SANITIZER_OPTIONS diff --git a/Help/manual/cmake.1.rst b/Help/manual/cmake.1.rst index ba925e8..8aece23 100644 --- a/Help/manual/cmake.1.rst +++ b/Help/manual/cmake.1.rst @@ -262,6 +262,36 @@ Available commands are: 351abe79cd3800b38cdfb25d45015a15 file1.txt 052f86c15bbde68af55c7f7b340ab639 file2.txt +``sha1sum <file>...`` + Create SHA1 checksum of files in ``sha1sum`` compatible format:: + + 4bb7932a29e6f73c97bb9272f2bdc393122f86e0 file1.txt + 1df4c8f318665f9a5f2ed38f55adadb7ef9f559c file2.txt + +``sha224sum <file>...`` + Create SHA224 checksum of files in ``sha224sum`` compatible format:: + + b9b9346bc8437bbda630b0b7ddfc5ea9ca157546dbbf4c613192f930 file1.txt + 6dfbe55f4d2edc5fe5c9197bca51ceaaf824e48eba0cc453088aee24 file2.txt + +``sha256sum <file>...`` + Create SHA256 checksum of files in ``sha256sum`` compatible format:: + + 76713b23615d31680afeb0e9efe94d47d3d4229191198bb46d7485f9cb191acc file1.txt + 15b682ead6c12dedb1baf91231e1e89cfc7974b3787c1e2e01b986bffadae0ea file2.txt + +``sha384sum <file>...`` + Create SHA384 checksum of files in ``sha384sum`` compatible format:: + + acc049fedc091a22f5f2ce39a43b9057fd93c910e9afd76a6411a28a8f2b8a12c73d7129e292f94fc0329c309df49434 file1.txt + 668ddeb108710d271ee21c0f3acbd6a7517e2b78f9181c6a2ff3b8943af92b0195dcb7cce48aa3e17893173c0a39e23d file2.txt + +``sha512sum <file>...`` + Create SHA512 checksum of files in ``sha512sum`` compatible format:: + + 2a78d7a6c5328cfb1467c63beac8ff21794213901eaadafd48e7800289afbc08e5fb3e86aa31116c945ee3d7bf2a6194489ec6101051083d1108defc8e1dba89 file1.txt + 7a0b54896fe5e70cca6dd643ad6f672614b189bf26f8153061c4d219474b05dad08c4e729af9f4b009f1a1a280cb625454bf587c690f4617c27e3aebdf3b7a2d file2.txt + ``remove [-f] <file>...`` Remove the file(s). If any of the listed files already do not exist, the command returns a non-zero exit code, but no message diff --git a/Help/manual/ctest.1.rst b/Help/manual/ctest.1.rst index a89c4e9..03466ce 100644 --- a/Help/manual/ctest.1.rst +++ b/Help/manual/ctest.1.rst @@ -250,6 +250,13 @@ Options label associated with the tests run. If there are no labels on the tests, nothing extra is printed. + ``--no-subproject-summary`` + Disable timing summary information for subprojects. + + This option tells ctest not to print summary information for each + subproject associated with the tests run. If there are no subprojects on the + tests, nothing extra is printed. + ``--build-and-test <path-to-source> <path-to-build>`` Configure, build and run a test. @@ -758,6 +765,15 @@ Configuration settings include: * :module:`CTest` module variable: :variable:`CMAKE_COMMAND` followed by :variable:`PROJECT_SOURCE_DIR` +``LabelsForSubprojects`` + Specify a semicolon-separated list of labels that will be treated as + subprojects. This mapping will be passed on to CDash when configure, test or + build results are submitted. + + * `CTest Script`_ variable: :variable:`CTEST_LABELS_FOR_SUBPROJECTS` + * :module:`CTest` module variable: ``CTEST_LABELS_FOR_SUBPROJECTS`` + + .. _`CTest Build Step`: CTest Build Step @@ -780,6 +796,14 @@ Configuration settings include: * :module:`CTest` module variable: ``DEFAULT_CTEST_CONFIGURATION_TYPE``, initialized by the ``CMAKE_CONFIG_TYPE`` environment variable +``LabelsForSubprojects`` + Specify a semicolon-separated list of labels that will be treated as + subprojects. This mapping will be passed on to CDash when configure, test or + build results are submitted. + + * `CTest Script`_ variable: :variable:`CTEST_LABELS_FOR_SUBPROJECTS` + * :module:`CTest` module variable: ``CTEST_LABELS_FOR_SUBPROJECTS`` + ``MakeCommand`` Command-line to launch the software build process. It will be executed in the location specified by the @@ -815,6 +839,15 @@ Arguments to the command may specify some of the step settings. Configuration settings include: +``LabelsForSubprojects`` + Specify a semicolon-separated list of labels that will be treated as + subprojects. This mapping will be passed on to CDash when configure, test or + build results are submitted. + + * `CTest Script`_ variable: :variable:`CTEST_LABELS_FOR_SUBPROJECTS` + * :module:`CTest` module variable: ``CTEST_LABELS_FOR_SUBPROJECTS`` + + ``TestLoad`` While running tests in parallel (e.g. with ``-j``), try not to start tests when they may cause the CPU load to pass above a given threshold. diff --git a/Help/module/CPackFreeBSD.rst b/Help/module/CPackFreeBSD.rst new file mode 100644 index 0000000..083f0cb --- /dev/null +++ b/Help/module/CPackFreeBSD.rst @@ -0,0 +1 @@ +.. cmake-module:: ../../Modules/CPackFreeBSD.cmake diff --git a/Help/policy/CMP0070.rst b/Help/policy/CMP0070.rst new file mode 100644 index 0000000..0fb3617 --- /dev/null +++ b/Help/policy/CMP0070.rst @@ -0,0 +1,25 @@ +CMP0070 +------- + +Define :command:`file(GENERATE)` behavior for relative paths. + +CMake 3.10 and newer define that relative paths given to ``INPUT`` and +``OUTPUT`` arguments of ``file(GENERATE)`` are interpreted relative to the +current source and binary directories, respectively. CMake 3.9 and lower did +not define any behavior for relative paths but did not diagnose them either +and accidentally treated them relative to the process working directory. +Policy ``CMP0070`` provides compatibility with projects that used the old +undefined behavior. + +This policy affects behavior of relative paths given to ``file(GENERATE)``. +The ``OLD`` behavior for this policy is to treat the paths relative to the +working directory of CMake. The ``NEW`` behavior for this policy is to +interpret relative paths with respect to the current source or binary +directory of the caller. + +This policy was introduced in CMake version 3.10. CMake version +|release| warns when the policy is not set and uses ``OLD`` behavior. +Use the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` +explicitly. + +.. include:: DEPRECATED.txt diff --git a/Help/policy/CMP0071.rst b/Help/policy/CMP0071.rst new file mode 100644 index 0000000..61f14dc --- /dev/null +++ b/Help/policy/CMP0071.rst @@ -0,0 +1,34 @@ +CMP0071 +------- + +Let :prop_tgt:`AUTOMOC` and :prop_tgt:`AUTOUIC` process +:prop_sf:`GENERATED` files. + +CMake 3.10 and newer process regular *and* :prop_sf:`GENERATED` source files +in :prop_tgt:`AUTOMOC` and :prop_tgt:`AUTOUIC`. +In CMake 3.9 and lower, only regular source files were processed in +:prop_tgt:`AUTOMOC` and :prop_tgt:`AUTOUIC`, +:prop_sf:`GENERATED` source files were ignored. + +This policy affects how :prop_tgt:`AUTOMOC` and :prop_tgt:`AUTOUIC` process +source files that are :prop_sf:`GENERATED`. + +The ``OLD`` behavior for this policy is to *ignore* :prop_sf:`GENERATED` +source files in :prop_tgt:`AUTOMOC` and :prop_tgt:`AUTOUIC`. + +The ``NEW`` behavior for this policy is to process :prop_sf:`GENERATED` +source files in :prop_tgt:`AUTOMOC` and :prop_tgt:`AUTOUIC` just like regular +source files. + +.. note:: + To exclude source files from :prop_tgt:`AUTOMOC` and :prop_tgt:`AUTOUIC` + processing, the boolean source file properties + :prop_sf:`SKIP_AUTOMOC`, :prop_sf:`SKIP_AUTOUIC` and :prop_sf:`SKIP_AUTOGEN` + can be set accordingly. + +This policy was introduced in CMake version 3.10. CMake version +|release| warns when the policy is not set and uses ``OLD`` behavior. +Use the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` +explicitly. + +.. include:: DEPRECATED.txt diff --git a/Help/prop_dir/LABELS.rst b/Help/prop_dir/LABELS.rst new file mode 100644 index 0000000..de27d90 --- /dev/null +++ b/Help/prop_dir/LABELS.rst @@ -0,0 +1,13 @@ +LABELS +------ + +Specify a list of text labels associated with a directory and all of its +subdirectories. This is equivalent to setting the :prop_tgt:`LABELS` target +property and the :prop_test:`LABELS` test property on all targets and tests in +the current directory and subdirectories. Note: Launchers must enabled to +propagate labels to targets. + +The :variable:`CMAKE_DIRECTORY_LABELS` variable can be used to initialize this +property. + +The list is reported in dashboard submissions. diff --git a/Help/prop_dir/TEST_INCLUDE_FILE.rst b/Help/prop_dir/TEST_INCLUDE_FILE.rst index e477951..31b2382 100644 --- a/Help/prop_dir/TEST_INCLUDE_FILE.rst +++ b/Help/prop_dir/TEST_INCLUDE_FILE.rst @@ -1,7 +1,9 @@ TEST_INCLUDE_FILE ----------------- +Deprecated. Use :prop_dir:`TEST_INCLUDE_FILES` instead. + A cmake file that will be included when ctest is run. -If you specify TEST_INCLUDE_FILE, that file will be included and +If you specify ``TEST_INCLUDE_FILE``, that file will be included and processed when ctest is run on the directory. diff --git a/Help/prop_dir/TEST_INCLUDE_FILES.rst b/Help/prop_dir/TEST_INCLUDE_FILES.rst new file mode 100644 index 0000000..c3e4602 --- /dev/null +++ b/Help/prop_dir/TEST_INCLUDE_FILES.rst @@ -0,0 +1,7 @@ +TEST_INCLUDE_FILES +------------------ + +A list of cmake files that will be included when ctest is run. + +If you specify ``TEST_INCLUDE_FILES``, those files will be included and +processed when ctest is run on the directory. diff --git a/Help/prop_test/FIXTURES_CLEANUP.rst b/Help/prop_test/FIXTURES_CLEANUP.rst index f0a4be0..3075b4d 100644 --- a/Help/prop_test/FIXTURES_CLEANUP.rst +++ b/Help/prop_test/FIXTURES_CLEANUP.rst @@ -2,7 +2,8 @@ FIXTURES_CLEANUP ---------------- Specifies a list of fixtures for which the test is to be treated as a cleanup -test. +test. These fixture names are distinct from test case names and are not +required to have any similarity to the names of tests associated with them. Fixture cleanup tests are ordinary tests with all of the usual test functionality. Setting the ``FIXTURES_CLEANUP`` property for a test has two diff --git a/Help/prop_test/FIXTURES_REQUIRED.rst b/Help/prop_test/FIXTURES_REQUIRED.rst index e37dfb5..e3f60c4 100644 --- a/Help/prop_test/FIXTURES_REQUIRED.rst +++ b/Help/prop_test/FIXTURES_REQUIRED.rst @@ -2,7 +2,7 @@ FIXTURES_REQUIRED ----------------- Specifies a list of fixtures the test requires. Fixture names are case -sensitive. +sensitive and they are not required to have any similarity to test names. Fixtures are a way to attach setup and cleanup tasks to a set of tests. If a test requires a given fixture, then all tests marked as setup tasks for that @@ -19,7 +19,9 @@ some setup tests fail. When CTest is asked to execute only a subset of tests (e.g. by the use of regular expressions or when run with the ``--rerun-failed`` command line option), it will automatically add any setup or cleanup tests for fixtures -required by any of the tests that are in the execution set. +required by any of the tests that are in the execution set. This behavior can +be overridden with the ``-FS``, ``-FC`` and ``-FA`` command line options to +:manual:`ctest(1)` if desired. Since setup and cleanup tasks are also tests, they can have an ordering specified by the :prop_test:`DEPENDS` test property just like any other tests. diff --git a/Help/prop_test/FIXTURES_SETUP.rst b/Help/prop_test/FIXTURES_SETUP.rst index a220215..fdb21cc 100644 --- a/Help/prop_test/FIXTURES_SETUP.rst +++ b/Help/prop_test/FIXTURES_SETUP.rst @@ -2,14 +2,15 @@ FIXTURES_SETUP -------------- Specifies a list of fixtures for which the test is to be treated as a setup -test. +test. These fixture names are distinct from test case names and are not +required to have any similarity to the names of tests associated with them. Fixture setup tests are ordinary tests with all of the usual test functionality. Setting the ``FIXTURES_SETUP`` property for a test has two primary effects: - CTest will ensure the test executes before any other test which lists the - fixture(s) in its :prop_test:`FIXTURES_REQUIRED` property. + fixture name(s) in its :prop_test:`FIXTURES_REQUIRED` property. - If CTest is asked to run only a subset of tests (e.g. using regular expressions or the ``--rerun-failed`` option) and the setup test is not in diff --git a/Help/prop_tgt/AUTOMOC.rst b/Help/prop_tgt/AUTOMOC.rst index 0171d20..61813be68 100644 --- a/Help/prop_tgt/AUTOMOC.rst +++ b/Help/prop_tgt/AUTOMOC.rst @@ -5,8 +5,8 @@ Should the target be processed with automoc (for Qt projects). AUTOMOC is a boolean specifying whether CMake will handle the Qt ``moc`` preprocessor automatically, i.e. without having to use the -:module:`QT4_WRAP_CPP() <FindQt4>` or QT5_WRAP_CPP() macro. Currently Qt4 and Qt5 are -supported. +:module:`QT4_WRAP_CPP() <FindQt4>` or QT5_WRAP_CPP() macro. +Currently Qt4 and Qt5 are supported. When this property is set ``ON``, CMake will scan the header and source files at build time and invoke moc accordingly. @@ -20,6 +20,9 @@ source files at build time and invoke moc accordingly. This allows the compiler to find the included ``moc_<basename>.cpp`` file regardless of the location the original source. + * For multi configuration generators, the include directory is + ``<AUTOGEN_BUILD_DIR>/include_<CONFIG>``. + * See :prop_tgt:`AUTOGEN_BUILD_DIR`. * If an ``#include`` statement like ``#include "<basename>.moc"`` is found, @@ -34,7 +37,7 @@ source files at build time and invoke moc accordingly. which is compiled as part of the target. * The custom directories with checksum - based names help to avoid name collisions for moc files with the same + based names help to avoid name collisions for ``moc`` files with the same ``<basename>``. * See :prop_tgt:`AUTOGEN_BUILD_DIR`. @@ -53,11 +56,11 @@ source files at build time and invoke moc accordingly. This property is initialized by the value of the :variable:`CMAKE_AUTOMOC` variable if it is set when a target is created. -Additional command line options for moc can be set via the +Additional command line options for ``moc`` can be set via the :prop_tgt:`AUTOMOC_MOC_OPTIONS` property. By enabling the :variable:`CMAKE_AUTOMOC_RELAXED_MODE` variable the -rules for searching the files which will be processed by moc can be relaxed. +rules for searching the files which will be processed by ``moc`` can be relaxed. See the documentation for this variable for more details. The global property :prop_gbl:`AUTOGEN_TARGETS_FOLDER` can be used to group the @@ -66,6 +69,10 @@ automoc targets together in an IDE, e.g. in MSVS. The global property :prop_gbl:`AUTOGEN_SOURCE_GROUP` can be used to group files generated by :prop_tgt:`AUTOMOC` together in an IDE, e.g. in MSVS. +The appearance of the strings ``Q_OBJECT`` or ``Q_GADGET`` in a source file +determines if it needs to be ``moc`` processed. To search for additional +strings, list them in :prop_tgt:`AUTOMOC_MACRO_NAMES`. + Additional ``moc`` dependency file names can be extracted from source code by using :prop_tgt:`AUTOMOC_DEPEND_FILTERS`. diff --git a/Help/prop_tgt/AUTOMOC_MACRO_NAMES.rst b/Help/prop_tgt/AUTOMOC_MACRO_NAMES.rst new file mode 100644 index 0000000..0639bc8 --- /dev/null +++ b/Help/prop_tgt/AUTOMOC_MACRO_NAMES.rst @@ -0,0 +1,28 @@ +AUTOMOC_MACRO_NAMES +------------------- + +Additional macro names used by :prop_tgt:`AUTOMOC` +to determine if a C++ file needs to be processed by ``moc``. + +This property is only used if the :prop_tgt:`AUTOMOC` property is ``ON`` +for this target. + +CMake searches for the strings ``Q_OBJECT`` and ``Q_GADGET`` to +determine if a file needs to be processed by ``moc``. +:prop_tgt:`AUTOMOC_MACRO_NAMES` allows to add additional strings to the +search list. This is useful for cases where the ``Q_OBJECT`` or ``Q_GADGET`` +macro is hidden inside another macro. + +By default :prop_tgt:`AUTOMOC_MACRO_NAMES` is initialized from +:variable:`CMAKE_AUTOMOC_MACRO_NAMES`, which is empty by default. + +See the :manual:`cmake-qt(7)` manual for more information on using CMake +with Qt. + +Example +------- +In this case the the ``Q_OBJECT`` macro is hidden inside an other macro +called ``CUSTOM_MACRO``. To let CMake know that source files, that contain +``CUSTOM_MACRO``, need to be ``moc`` processed, we call:: + + set_property(TARGET tgt PROPERTY AUTOMOC_MACRO_NAMES "CUSTOM_MACRO") diff --git a/Help/prop_tgt/AUTOUIC.rst b/Help/prop_tgt/AUTOUIC.rst index 6493bbc..2fc2167 100644 --- a/Help/prop_tgt/AUTOUIC.rst +++ b/Help/prop_tgt/AUTOUIC.rst @@ -17,6 +17,9 @@ optional :prop_tgt:`AUTOUIC_SEARCH_PATHS` of the target. ``<AUTOGEN_BUILD_DIR>/include``, which is automatically added to the target's :prop_tgt:`INCLUDE_DIRECTORIES`. +* For multi configuration generators, the include directory is + ``<AUTOGEN_BUILD_DIR>/include_<CONFIG>``. + * See :prop_tgt:`AUTOGEN_BUILD_DIR`. This property is initialized by the value of the :variable:`CMAKE_AUTOUIC` diff --git a/Help/prop_tgt/LANG_COMPILER_LAUNCHER.rst b/Help/prop_tgt/LANG_COMPILER_LAUNCHER.rst index 0fe0b31..28925fc 100644 --- a/Help/prop_tgt/LANG_COMPILER_LAUNCHER.rst +++ b/Help/prop_tgt/LANG_COMPILER_LAUNCHER.rst @@ -1,7 +1,8 @@ <LANG>_COMPILER_LAUNCHER ------------------------ -This property is implemented only when ``<LANG>`` is ``C`` or ``CXX``. +This property is implemented only when ``<LANG>`` is ``C``, ``CXX``, +or ``CUDA``. Specify a :ref:`;-list <CMake Language Lists>` containing a command line for a compiler launching tool. The :ref:`Makefile Generators` and the diff --git a/Help/prop_tgt/VS_DOTNET_REFERENCEPROP_refname_TAG_tagname.rst b/Help/prop_tgt/VS_DOTNET_REFERENCEPROP_refname_TAG_tagname.rst new file mode 100644 index 0000000..ab311ea --- /dev/null +++ b/Help/prop_tgt/VS_DOTNET_REFERENCEPROP_refname_TAG_tagname.rst @@ -0,0 +1,14 @@ +VS_DOTNET_REFERENCEPROP_<refname>_TAG_<tagname> +----------------------------------------------- + +Defines an XML property ``<tagname>`` for a .NET reference +``<refname>``. + +Reference properties can be set for .NET references which are +defined by the target properties :prop_tgt:`VS_DOTNET_REFERENCES`, +:prop_tgt:`VS_DOTNET_REFERENCE_<refname>` +and also for project references to other C# targets which are +established by :command:`target_link_libraries()`. + +This property is only applicable to C# targets and Visual Studio +generators 2010 and later. diff --git a/Help/release/3.9.rst b/Help/release/3.9.rst index ae55105..5087b43 100644 --- a/Help/release/3.9.rst +++ b/Help/release/3.9.rst @@ -310,9 +310,6 @@ Other Changes in dependent targets may now compile without waiting for their targets' dependencies to link. -* On macOS, the default application bundle ``Info.plist`` file now enables - Hi-DPI support. - * On macOS, ``RPATH`` settings such as :prop_tgt:`BUILD_WITH_INSTALL_RPATH` no longer affect the ``install_name`` field. See policy :policy:`CMP0068`. @@ -333,3 +330,10 @@ Changes made since CMake 3.9.0 include the following. CMake 3.9.0 has been removed for the 3.9 series due to regressions caused by new use of ``<PackageName>_ROOT`` variables. The behavior may be re-introduced in the future in a more-compatible way. + +3.9.2 +----- + +* On macOS, the default application bundle ``Info.plist`` file no longer + enables Hi-DPI support as it did in 3.9.0 and 3.9.1. The change had + to be reverted because it broke iOS applications. diff --git a/Help/release/dev/0-sample-topic.rst b/Help/release/dev/0-sample-topic.rst new file mode 100644 index 0000000..e4cc01e --- /dev/null +++ b/Help/release/dev/0-sample-topic.rst @@ -0,0 +1,7 @@ +0-sample-topic +-------------- + +* This is a sample release note for the change in a topic. + Developers should add similar notes for each topic branch + making a noteworthy change. Each document should be named + and titled to match the topic name to avoid merge conflicts. diff --git a/Help/release/dev/GoogleTest.rst b/Help/release/dev/GoogleTest.rst new file mode 100644 index 0000000..1e4a10e --- /dev/null +++ b/Help/release/dev/GoogleTest.rst @@ -0,0 +1,11 @@ +GoogleTest +---------- + +* The :module:`GoogleTest` module gained a new command + :command:`gtest_discover_tests` implementing dynamic (build-time) test + discovery. Unlike the source parsing approach, dynamic discovery executes + the test (in 'list available tests' mode) at build time to discover tests. + This is robust against unusual ways of labeling tests, provides much better + support for advanced features such as parameterized tests, and does not + require re-running CMake to discover added or removed tests within a test + executable. diff --git a/Help/release/dev/VS_DOTNET_REFERENCEPROP_refname_TAG_tagname.rst b/Help/release/dev/VS_DOTNET_REFERENCEPROP_refname_TAG_tagname.rst new file mode 100644 index 0000000..0e258fd --- /dev/null +++ b/Help/release/dev/VS_DOTNET_REFERENCEPROP_refname_TAG_tagname.rst @@ -0,0 +1,6 @@ +vs-dotnet-custom-reference-tags +------------------------------- + +* The :prop_tgt:`VS_DOTNET_REFERENCEPROP_<refname>_TAG_<tagname>` + target property was added to support custom XML tags for reference + assemblies in C# targets. diff --git a/Help/release/dev/autogen-configs.rst b/Help/release/dev/autogen-configs.rst new file mode 100644 index 0000000..7613c68 --- /dev/null +++ b/Help/release/dev/autogen-configs.rst @@ -0,0 +1,8 @@ +autogen-configs +--------------- + +* When using :prop_tgt:`AUTOMOC` or :prop_tgt:`AUTOUIC` with a + multi configuration generator (e.g. :generator:`Xcode`), + included ``*.moc``, ``moc_*.cpp`` and ``ui_*.h`` files are generated in + ``<AUTOGEN_BUILD_DIR>/include_<CONFIG>`` instead of + ``<AUTOGEN_BUILD_DIR>/include``. diff --git a/Help/release/dev/autogen-generated-files.rst b/Help/release/dev/autogen-generated-files.rst new file mode 100644 index 0000000..da2fc4e --- /dev/null +++ b/Help/release/dev/autogen-generated-files.rst @@ -0,0 +1,8 @@ +autogen-generated-files +----------------------- + +* When using :prop_tgt:`AUTOMOC` or :prop_tgt:`AUTOUIC`, + source files that are :prop_sf:`GENERATED` will be processed as well. + They were ignored by :prop_tgt:`AUTOMOC` and :prop_tgt:`AUTOUIC` + in earlier releases. + See policy :policy:`CMP0071`. diff --git a/Help/release/dev/autogen-macro-names.rst b/Help/release/dev/autogen-macro-names.rst new file mode 100644 index 0000000..736dd3a --- /dev/null +++ b/Help/release/dev/autogen-macro-names.rst @@ -0,0 +1,12 @@ +autogen-macro-names +------------------- + +* When using :prop_tgt:`AUTOMOC`, CMake searches for the strings ``Q_OBJECT`` + and ``Q_OBJECT`` in a source file to determine if it needs to be ``moc`` + processed. The new variable :variable:`CMAKE_AUTOMOC_MACRO_NAMES` allows to + register additional strings (macro names) so search for. + +* When using :prop_tgt:`AUTOMOC`, CMake searches for the strings ``Q_OBJECT`` + and ``Q_OBJECT`` in a source file to determine if it needs to be ``moc`` + processed. The new target property :prop_tgt:`AUTOMOC_MACRO_NAMES` allows to + register additional strings (macro names) so search for. diff --git a/Help/release/dev/cmake-command-mode-shasum.rst b/Help/release/dev/cmake-command-mode-shasum.rst new file mode 100644 index 0000000..681e0c0 --- /dev/null +++ b/Help/release/dev/cmake-command-mode-shasum.rst @@ -0,0 +1,5 @@ +cmake-command-mode-shasum +------------------------- + +* Added sha1sum, sha224sum, sha256sum, sha384sum and sha512sum + as an equivalent to existing md5sum to cmake command mode. diff --git a/Help/release/dev/cmake_host_system_information-extend.rst b/Help/release/dev/cmake_host_system_information-extend.rst new file mode 100644 index 0000000..d1c882d --- /dev/null +++ b/Help/release/dev/cmake_host_system_information-extend.rst @@ -0,0 +1,6 @@ +cmake_host_system_information-extend +------------------------------------ + +* The :command:`cmake_host_system_information` command learned more keys + to get information about the processor capabilities and the host OS + version. diff --git a/Help/release/dev/cpack-freebsd-pkg.rst b/Help/release/dev/cpack-freebsd-pkg.rst new file mode 100644 index 0000000..1732581 --- /dev/null +++ b/Help/release/dev/cpack-freebsd-pkg.rst @@ -0,0 +1,5 @@ +cpack-freebsd-pkg +----------------- + +* CPack gained a ``FREEBSD`` generator for FreeBSD ``pkg(8)``, configured + by the :module:`CPackFreeBSD` module. diff --git a/Help/release/dev/cpackifw-package-file-extension.rst b/Help/release/dev/cpackifw-package-file-extension.rst new file mode 100644 index 0000000..e264081 --- /dev/null +++ b/Help/release/dev/cpackifw-package-file-extension.rst @@ -0,0 +1,6 @@ +cpackifw-package-file-extension +------------------------------- + +* The :module:`CPackIFW` module gained new + :variable:`CPACK_IFW_PACKAGE_FILE_EXTENSION` variable to customize + target binary format. diff --git a/Help/release/dev/cuda-compiler-launcher.rst b/Help/release/dev/cuda-compiler-launcher.rst new file mode 100644 index 0000000..f217780 --- /dev/null +++ b/Help/release/dev/cuda-compiler-launcher.rst @@ -0,0 +1,8 @@ +cuda-compiler-launcher +---------------------- + +* The :ref:`Makefile Generators` and the :generator:`Ninja` generator learned + to add compiler launcher tools like ccache along with the compiler for the + ``CUDA`` language (``C`` and ``CXX`` were supported previously). See the + :variable:`CMAKE_<LANG>_COMPILER_LAUNCHER` variable and + :prop_tgt:`<LANG>_COMPILER_LAUNCHER` target property for details. diff --git a/Help/release/dev/deb-on-windows.rst b/Help/release/dev/deb-on-windows.rst new file mode 100644 index 0000000..b307720 --- /dev/null +++ b/Help/release/dev/deb-on-windows.rst @@ -0,0 +1,7 @@ +deb-on-windows +-------------- + +* The CPack ``DEB`` generator, configured by the :module:`CPackDeb` module, + was enabled on Windows. While not fully featured (due to the lack of + external UNIX tools) this will allow building basic cross-platform Debian + packages. diff --git a/Help/release/dev/drop-HP-UX.rst b/Help/release/dev/drop-HP-UX.rst new file mode 100644 index 0000000..199fa09 --- /dev/null +++ b/Help/release/dev/drop-HP-UX.rst @@ -0,0 +1,8 @@ +drop-HP-UX +---------- + +* Support for building CMake on HP-UX has been dropped pending better + support for C++11 and a port of libuv. See `CMake Issue 17137`_. + Use CMake 3.9 or lower instead for HP-UX support. + +.. _`CMake Issue 17137`: https://gitlab.kitware.com/cmake/cmake/issues/17137 diff --git a/Help/release/dev/execute_process-pipeline-results.rst b/Help/release/dev/execute_process-pipeline-results.rst new file mode 100644 index 0000000..9755ef5 --- /dev/null +++ b/Help/release/dev/execute_process-pipeline-results.rst @@ -0,0 +1,6 @@ +execute_process-pipeline-results +-------------------------------- + +* The :command:`execute_process` command gained a ``RESULTS_VARIABLE`` + option to collect a list of results from all children in a pipeline + of processes when multiple ``COMMAND`` arguments are given. diff --git a/Help/release/dev/file-generate-relative-paths.rst b/Help/release/dev/file-generate-relative-paths.rst new file mode 100644 index 0000000..fdeb9e0e --- /dev/null +++ b/Help/release/dev/file-generate-relative-paths.rst @@ -0,0 +1,7 @@ +file-generate-relative-paths +---------------------------- + +* The :command:`file(GENERATE)` command now interprets relative paths + given to its ``OUTPUT`` and ``INPUT`` arguments with respect to the + caller's current binary and source directories, respectively. + See policy :policy:`CMP0070`. diff --git a/Help/release/dev/iar.rst b/Help/release/dev/iar.rst new file mode 100644 index 0000000..c6678eb --- /dev/null +++ b/Help/release/dev/iar.rst @@ -0,0 +1,4 @@ +iar +--- + +* Support for the IAR ARM Compiler was improved. diff --git a/Help/release/dev/include-guard.rst b/Help/release/dev/include-guard.rst new file mode 100644 index 0000000..9b0c64c --- /dev/null +++ b/Help/release/dev/include-guard.rst @@ -0,0 +1,8 @@ +include_guard +------------- + +* The :command:`include_guard` command was introduced to allow guarding + CMake scripts from being included more than once. The command supports + ``DIRECTORY`` and ``GLOBAL`` options to adjust the corresponding include guard + scope. If no options given, include guard is similar to basic variable-based + check. diff --git a/Help/release/dev/indented_cmakedefine.rst b/Help/release/dev/indented_cmakedefine.rst new file mode 100644 index 0000000..fd28b25 --- /dev/null +++ b/Help/release/dev/indented_cmakedefine.rst @@ -0,0 +1,7 @@ +indented_cmakedefine +-------------------- + +* The :command:`configure_file` command learned to support indented + ``# cmakedefine`` and ``# cmakedefine01``. Spaces and/or tabs between + the ``#`` character and the ``cmakedefine``/``cmakedefine01`` words + are now understood and preserved in the output. diff --git a/Help/release/dev/labels_for_subprojects.rst b/Help/release/dev/labels_for_subprojects.rst new file mode 100644 index 0000000..7344502 --- /dev/null +++ b/Help/release/dev/labels_for_subprojects.rst @@ -0,0 +1,14 @@ +labels_for_subprojects +---------------------- + +* A :variable:`CTEST_LABELS_FOR_SUBPROJECTS` CTest module variable and CTest + script variable was added to specify a list of labels that should be treated + as subprojects by CDash. To use this value in both the CTest module and the + ctest command line `Dashboard Client` mode (e.g. ctest -S) set it in the + CTestConfig.cmake config file. + +* A :prop_dir:`LABELS` directory property was added to specify labels + for all targets and tests in a directory. + +* A :variable:`CMAKE_DIRECTORY_LABELS` variable was added to specify + labels for all tests in a directory. diff --git a/Help/release/dev/require-c++11.rst b/Help/release/dev/require-c++11.rst new file mode 100644 index 0000000..7b849e7 --- /dev/null +++ b/Help/release/dev/require-c++11.rst @@ -0,0 +1,5 @@ +require-c++11 +------------- + +* Support for building CMake itself with C++98 compilers was dropped. + CMake is now implemented using C++11. diff --git a/Help/release/dev/string_prepend.rst b/Help/release/dev/string_prepend.rst new file mode 100644 index 0000000..f896e91 --- /dev/null +++ b/Help/release/dev/string_prepend.rst @@ -0,0 +1,4 @@ +string_prepend +-------------- + +* The :command:`string` command learned a new ``PREPEND`` subcommand. diff --git a/Help/release/dev/test_include_files.rst b/Help/release/dev/test_include_files.rst new file mode 100644 index 0000000..b75dd0d --- /dev/null +++ b/Help/release/dev/test_include_files.rst @@ -0,0 +1,7 @@ +test_include_files +------------------ + +* A :prop_dir:`TEST_INCLUDE_FILES` directory property was added to + list any number of files to be included when running tests with + :manual:`ctest(1)`. This generalizes the :prop_dir:`TEST_INCLUDE_FILE` + property. diff --git a/Help/release/index.rst b/Help/release/index.rst index 6af282c..6c68e65 100644 --- a/Help/release/index.rst +++ b/Help/release/index.rst @@ -7,6 +7,8 @@ CMake Release Notes This file should include the adjacent "dev.txt" file in development versions but not in release versions. +.. include:: dev.txt + Releases ======== diff --git a/Help/variable/CMAKE_AUTOMOC_MACRO_NAMES.rst b/Help/variable/CMAKE_AUTOMOC_MACRO_NAMES.rst new file mode 100644 index 0000000..7ed3445 --- /dev/null +++ b/Help/variable/CMAKE_AUTOMOC_MACRO_NAMES.rst @@ -0,0 +1,19 @@ +CMAKE_AUTOMOC_MACRO_NAMES +---------------------------- + +Additional macro names used by :variable:`CMAKE_AUTOMOC` +to determine if a C++ file needs to be processed by ``moc``. + +This variable is used to initialize the :prop_tgt:`AUTOMOC_MACRO_NAMES` +property on all the targets. See that target property for additional +information. + +By default it is empty. + +Example +------- +Let CMake know that source files that contain ``CUSTOM_MACRO`` must be ``moc`` +processed as well:: + + set(CMAKE_AUTOMOC ON) + set(CMAKE_AUTOMOC_MACRO_NAMES "CUSTOM_MACRO") diff --git a/Help/variable/CMAKE_DIRECTORY_LABELS.rst b/Help/variable/CMAKE_DIRECTORY_LABELS.rst new file mode 100644 index 0000000..2a6c410 --- /dev/null +++ b/Help/variable/CMAKE_DIRECTORY_LABELS.rst @@ -0,0 +1,6 @@ +CMAKE_DIRECTORY_LABELS +----------------------- + +Specify labels for the current directory. + +This is used to initialize the :prop_dir:`LABELS` directory property. diff --git a/Help/variable/CMAKE_LANG_COMPILER_ARCHITECTURE_ID.rst b/Help/variable/CMAKE_LANG_COMPILER_ARCHITECTURE_ID.rst new file mode 100644 index 0000000..054c648 --- /dev/null +++ b/Help/variable/CMAKE_LANG_COMPILER_ARCHITECTURE_ID.rst @@ -0,0 +1,8 @@ +CMAKE_<LANG>_COMPILER_ARCHITECTURE_ID +------------------------------------- + +An internal variable subject to change. + +This is used to identify the variant of a compiler based on its target +architecture. For some compilers this is needed to determine the correct +usage. diff --git a/Help/variable/CMAKE_LANG_COMPILER_ID.rst b/Help/variable/CMAKE_LANG_COMPILER_ID.rst index 0fab10c..5204044 100644 --- a/Help/variable/CMAKE_LANG_COMPILER_ID.rst +++ b/Help/variable/CMAKE_LANG_COMPILER_ID.rst @@ -20,6 +20,7 @@ include: G95 = G95 Fortran (g95.org) GNU = GNU Compiler Collection (gcc.gnu.org) HP = Hewlett-Packard Compiler (hp.com) + IAR = IAR Systems (iar.com) Intel = Intel Compiler (intel.com) MIPSpro = SGI MIPSpro (sgi.com) MSVC = Microsoft Visual Studio (microsoft.com) diff --git a/Help/variable/CMAKE_LANG_COMPILER_LAUNCHER.rst b/Help/variable/CMAKE_LANG_COMPILER_LAUNCHER.rst index 7961f60..f4e2ba5 100644 --- a/Help/variable/CMAKE_LANG_COMPILER_LAUNCHER.rst +++ b/Help/variable/CMAKE_LANG_COMPILER_LAUNCHER.rst @@ -3,4 +3,4 @@ CMAKE_<LANG>_COMPILER_LAUNCHER Default value for :prop_tgt:`<LANG>_COMPILER_LAUNCHER` target property. This variable is used to initialize the property on each target as it is -created. This is done only when ``<LANG>`` is ``C`` or ``CXX``. +created. This is done only when ``<LANG>`` is ``C``, ``CXX``, or ``CUDA``. diff --git a/Help/variable/CMAKE_MSVCIDE_RUN_PATH.rst b/Help/variable/CMAKE_MSVCIDE_RUN_PATH.rst new file mode 100644 index 0000000..22e727f --- /dev/null +++ b/Help/variable/CMAKE_MSVCIDE_RUN_PATH.rst @@ -0,0 +1,10 @@ +CMAKE_MSVCIDE_RUN_PATH +---------------------- + +Extra PATH locations that should be used when executing +:command:`add_custom_command` or :command:`add_custom_target` when using the +:generator:`Visual Studio 9 2008` (or above) generator. This allows +for running commands and using dll's that the IDE environment is not aware of. + +If not set explicitly the value is initialized by the ``CMAKE_MSVCIDE_RUN_PATH`` +environment variable, if set, and otherwise left empty. diff --git a/Help/variable/CTEST_LABELS_FOR_SUBPROJECTS.rst b/Help/variable/CTEST_LABELS_FOR_SUBPROJECTS.rst new file mode 100644 index 0000000..959596b --- /dev/null +++ b/Help/variable/CTEST_LABELS_FOR_SUBPROJECTS.rst @@ -0,0 +1,5 @@ +CTEST_LABELS_FOR_SUBPROJECTS +---------------------------- + +Specify the CTest ``LabelsForSubprojects`` setting +in a :manual:`ctest(1)` dashboard client script. diff --git a/Modules/AutogenInfo.cmake.in b/Modules/AutogenInfo.cmake.in index 4e85474..e1a9c39 100644 --- a/Modules/AutogenInfo.cmake.in +++ b/Modules/AutogenInfo.cmake.in @@ -18,6 +18,7 @@ set(AM_MOC_DEFINITIONS @_moc_compile_defs@) set(AM_MOC_INCLUDES @_moc_incs@) set(AM_MOC_OPTIONS @_moc_options@) set(AM_MOC_RELAXED_MODE @_moc_relaxed_mode@) +set(AM_MOC_MACRO_NAMES @_moc_macro_names@) set(AM_MOC_DEPEND_FILTERS @_moc_depend_filters@) set(AM_MOC_PREDEFS_CMD @_moc_predefs_cmd@) # UIC settings diff --git a/Modules/CMakeASMCompiler.cmake.in b/Modules/CMakeASMCompiler.cmake.in index 7b94d0f..a6465f6 100644 --- a/Modules/CMakeASMCompiler.cmake.in +++ b/Modules/CMakeASMCompiler.cmake.in @@ -7,8 +7,11 @@ set(CMAKE_ASM@ASM_DIALECT@_COMPILER_RANLIB "@_CMAKE_ASM_COMPILER_RANLIB@") set(CMAKE_LINKER "@CMAKE_LINKER@") set(CMAKE_ASM@ASM_DIALECT@_COMPILER_LOADED 1) set(CMAKE_ASM@ASM_DIALECT@_COMPILER_ID "@_CMAKE_ASM_COMPILER_ID@") +set(CMAKE_ASM@ASM_DIALECT@_COMPILER_VERSION "@_CMAKE_ASM_COMPILER_VERSION@") set(CMAKE_ASM@ASM_DIALECT@_COMPILER_ENV_VAR "@_CMAKE_ASM_COMPILER_ENV_VAR@") +@_SET_CMAKE_ASM_COMPILER_ARCHITECTURE_ID@ set(CMAKE_ASM@ASM_DIALECT@_IGNORE_EXTENSIONS h;H;o;O;obj;OBJ;def;DEF;rc;RC) set(CMAKE_ASM@ASM_DIALECT@_LINKER_PREFERENCE 0) +@CMAKE_ASM_COMPILER_CUSTOM_CODE@ diff --git a/Modules/CMakeCCompiler.cmake.in b/Modules/CMakeCCompiler.cmake.in index 974a579..92259dd 100644 --- a/Modules/CMakeCCompiler.cmake.in +++ b/Modules/CMakeCCompiler.cmake.in @@ -12,6 +12,7 @@ set(CMAKE_C11_COMPILE_FEATURES "@CMAKE_C11_COMPILE_FEATURES@") set(CMAKE_C_PLATFORM_ID "@CMAKE_C_PLATFORM_ID@") set(CMAKE_C_SIMULATE_ID "@CMAKE_C_SIMULATE_ID@") set(CMAKE_C_SIMULATE_VERSION "@CMAKE_C_SIMULATE_VERSION@") +@_SET_CMAKE_C_COMPILER_ARCHITECTURE_ID@ @SET_MSVC_C_ARCHITECTURE_ID@ @SET_CMAKE_XCODE_CURRENT_ARCH@ set(CMAKE_AR "@CMAKE_AR@") diff --git a/Modules/CMakeCSharpInformation.cmake b/Modules/CMakeCSharpInformation.cmake index cd86016..d474c29 100644 --- a/Modules/CMakeCSharpInformation.cmake +++ b/Modules/CMakeCSharpInformation.cmake @@ -10,7 +10,7 @@ get_filename_component(CMAKE_BASE_NAME "${CMAKE_CSharp_COMPILER}" NAME_WE) set(CMAKE_BUILD_TYPE_INIT Debug) -set(CMAKE_CSharp_FLAGS_INIT "/define:TRACE /langversion:3 /nowin32manifest") +set(CMAKE_CSharp_FLAGS_INIT "/define:TRACE /langversion:3") set(CMAKE_CSharp_FLAGS_DEBUG_INIT "/debug:full /optimize- /warn:3 /errorreport:prompt /define:DEBUG") set(CMAKE_CSharp_FLAGS_RELEASE_INIT "/debug:none /optimize /warn:1 /errorreport:queue") set(CMAKE_CSharp_FLAGS_RELWITHDEBINFO_INIT "/debug:full /optimize-") diff --git a/Modules/CMakeCUDAInformation.cmake b/Modules/CMakeCUDAInformation.cmake index 9bba847..f4609cd 100644 --- a/Modules/CMakeCUDAInformation.cmake +++ b/Modules/CMakeCUDAInformation.cmake @@ -198,11 +198,11 @@ endif() #These are used when linking relocatable (dc) cuda code if(NOT CMAKE_CUDA_DEVICE_LINK_LIBRARY) set(CMAKE_CUDA_DEVICE_LINK_LIBRARY - "<CMAKE_CUDA_COMPILER> <CMAKE_CUDA_LINK_FLAGS> <LANGUAGE_COMPILE_FLAGS> ${CMAKE_CUDA_COMPILE_OPTIONS_PIC} ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") + "<CMAKE_CUDA_COMPILER> ${CMAKE_CUDA_HOST_FLAGS} <CMAKE_CUDA_LINK_FLAGS> <LANGUAGE_COMPILE_FLAGS> ${CMAKE_CUDA_COMPILE_OPTIONS_PIC} ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") endif() if(NOT CMAKE_CUDA_DEVICE_LINK_EXECUTABLE) set(CMAKE_CUDA_DEVICE_LINK_EXECUTABLE - "<CMAKE_CUDA_COMPILER> <FLAGS> <CMAKE_CUDA_LINK_FLAGS> ${CMAKE_CUDA_COMPILE_OPTIONS_PIC} ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") + "<CMAKE_CUDA_COMPILER> ${CMAKE_CUDA_HOST_FLAGS} <FLAGS> <CMAKE_CUDA_LINK_FLAGS> ${CMAKE_CUDA_COMPILE_OPTIONS_PIC} ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") endif() unset(_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS) diff --git a/Modules/CMakeCXXCompiler.cmake.in b/Modules/CMakeCXXCompiler.cmake.in index fda7950..47fc624 100644 --- a/Modules/CMakeCXXCompiler.cmake.in +++ b/Modules/CMakeCXXCompiler.cmake.in @@ -13,6 +13,7 @@ set(CMAKE_CXX17_COMPILE_FEATURES "@CMAKE_CXX17_COMPILE_FEATURES@") set(CMAKE_CXX_PLATFORM_ID "@CMAKE_CXX_PLATFORM_ID@") set(CMAKE_CXX_SIMULATE_ID "@CMAKE_CXX_SIMULATE_ID@") set(CMAKE_CXX_SIMULATE_VERSION "@CMAKE_CXX_SIMULATE_VERSION@") +@_SET_CMAKE_CXX_COMPILER_ARCHITECTURE_ID@ @SET_MSVC_CXX_ARCHITECTURE_ID@ @SET_CMAKE_XCODE_CURRENT_ARCH@ set(CMAKE_AR "@CMAKE_AR@") diff --git a/Modules/CMakeCXXCompilerId.cpp.in b/Modules/CMakeCXXCompilerId.cpp.in index 9aa096d..6572bb3 100644 --- a/Modules/CMakeCXXCompilerId.cpp.in +++ b/Modules/CMakeCXXCompilerId.cpp.in @@ -27,12 +27,18 @@ char const *info_cray = "INFO" ":" "compiler_wrapper[CrayPrgEnv]"; @CMAKE_CXX_COMPILER_ID_PLATFORM_CONTENT@ @CMAKE_CXX_COMPILER_ID_ERROR_FOR_TEST@ +#if defined(_MSC_VER) && defined(_MSVC_LANG) +#define CXX_STD _MSVC_LANG +#else +#define CXX_STD __cplusplus +#endif + const char* info_language_dialect_default = "INFO" ":" "dialect_default[" -#if __cplusplus > 201402L +#if CXX_STD > 201402L "17" -#elif __cplusplus >= 201402L +#elif CXX_STD >= 201402L "14" -#elif __cplusplus >= 201103L +#elif CXX_STD >= 201103L "11" #else "98" diff --git a/Modules/CMakeDetermineASMCompiler.cmake b/Modules/CMakeDetermineASMCompiler.cmake index 87c6b28..f7cf54a 100644 --- a/Modules/CMakeDetermineASMCompiler.cmake +++ b/Modules/CMakeDetermineASMCompiler.cmake @@ -84,7 +84,7 @@ if(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER_ID) set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_TI "-h") set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_TI "Texas Instruments") - list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS GNU IAR) + list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS IAR) set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_IAR ) set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_IAR "IAR Assembler") @@ -103,10 +103,31 @@ if(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER_ID) include(CMakeDetermineCompilerId) set(userflags) CMAKE_DETERMINE_COMPILER_ID_VENDOR(ASM${ASM_DIALECT} "${userflags}") + if("x${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID}" STREQUAL "xIAR") + # primary necessary to detect architecture, so the right archiver and linker can be picked + # eg. IAR Assembler V8.10.1.12857/W32 for ARM + # Cut out identification first, newline handling is a pain + string(REGEX MATCH "IAR Assembler[^\r\n]*" _compileid "${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_OUTPUT}") + if("${_compileid}" MATCHES "V([0-9]+\\.[0-9]+\\.[0-9]+)") + set(CMAKE_ASM${ASM_DIALECT}_COMPILER_VERSION ${CMAKE_MATCH_1}) + endif() + if("${_compileid}" MATCHES "for[ ]+([A-Za-z0-9]+)") + set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID ${CMAKE_MATCH_1}) + endif() + endif() + unset(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_OUTPUT) + unset(_compileid) endif() + if(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID) - message(STATUS "The ASM${ASM_DIALECT} compiler identification is ${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID}") + if(CMAKE_ASM${ASM_DIALECT}_COMPILER_VERSION) + set(_version " ${CMAKE_ASM${ASM_DIALECT}_COMPILER_VERSION}") + else() + set(_version "") + endif() + message(STATUS "The ASM${ASM_DIALECT} compiler identification is ${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID}${_version}") + unset(_version) else() message(STATUS "The ASM${ASM_DIALECT} compiler identification is unknown") endif() @@ -143,6 +164,9 @@ endif () include(CMakeFindBinUtils) +set(_CMAKE_PROCESSING_LANGUAGE "ASM") +include(Compiler/${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID}-FindBinUtils OPTIONAL) +unset(_CMAKE_PROCESSING_LANGUAGE) set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ENV_VAR "ASM${ASM_DIALECT}") @@ -152,20 +176,37 @@ else() message(STATUS "Didn't find assembler") endif() - -set(_CMAKE_ASM_COMPILER "${CMAKE_ASM${ASM_DIALECT}_COMPILER}") -set(_CMAKE_ASM_COMPILER_ID "${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID}") -set(_CMAKE_ASM_COMPILER_ARG1 "${CMAKE_ASM${ASM_DIALECT}_COMPILER_ARG1}") -set(_CMAKE_ASM_COMPILER_ENV_VAR "${CMAKE_ASM${ASM_DIALECT}_COMPILER_ENV_VAR}") -set(_CMAKE_ASM_COMPILER_AR "${CMAKE_ASM${ASM_DIALECT}_COMPILER_AR}") -set(_CMAKE_ASM_COMPILER_RANLIB "${CMAKE_ASM${ASM_DIALECT}_COMPILER_RANLIB}") +foreach(_var + COMPILER + COMPILER_ID + COMPILER_ARG1 + COMPILER_ENV_VAR + COMPILER_AR + COMPILER_RANLIB + COMPILER_VERSION + ) + set(_CMAKE_ASM_${_var} "${CMAKE_ASM${ASM_DIALECT}_${_var}}") +endforeach() + +if(CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID) + set(_SET_CMAKE_ASM_COMPILER_ARCHITECTURE_ID + "set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID ${CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID})") +else() + set(_SET_CMAKE_ASM_COMPILER_ARCHITECTURE_ID "") +endif() # configure variables set in this file for fast reload later on configure_file(${CMAKE_ROOT}/Modules/CMakeASMCompiler.cmake.in ${CMAKE_PLATFORM_INFO_DIR}/CMakeASM${ASM_DIALECT}Compiler.cmake @ONLY) -set(_CMAKE_ASM_COMPILER) -set(_CMAKE_ASM_COMPILER_ARG1) -set(_CMAKE_ASM_COMPILER_ENV_VAR) -set(_CMAKE_ASM_COMPILER_AR) -set(_CMAKE_ASM_COMPILER_RANLIB) +foreach(_var + COMPILER + COMPILER_ID + COMPILER_ARG1 + COMPILER_ENV_VAR + COMPILER_AR + COMPILER_RANLIB + COMPILER_VERSION + ) + unset(_CMAKE_ASM_${_var}) +endforeach() diff --git a/Modules/CMakeDetermineCCompiler.cmake b/Modules/CMakeDetermineCCompiler.cmake index 3caccde..fcbda20 100644 --- a/Modules/CMakeDetermineCCompiler.cmake +++ b/Modules/CMakeDetermineCCompiler.cmake @@ -170,6 +170,13 @@ set(_CMAKE_PROCESSING_LANGUAGE "C") include(Compiler/${CMAKE_C_COMPILER_ID}-FindBinUtils OPTIONAL) unset(_CMAKE_PROCESSING_LANGUAGE) +if(CMAKE_C_COMPILER_ARCHITECTURE_ID) + set(_SET_CMAKE_C_COMPILER_ARCHITECTURE_ID + "set(CMAKE_C_COMPILER_ARCHITECTURE_ID ${CMAKE_C_COMPILER_ARCHITECTURE_ID})") +else() + set(_SET_CMAKE_C_COMPILER_ARCHITECTURE_ID "") +endif() + if(MSVC_C_ARCHITECTURE_ID) set(SET_MSVC_C_ARCHITECTURE_ID "set(MSVC_C_ARCHITECTURE_ID ${MSVC_C_ARCHITECTURE_ID})") diff --git a/Modules/CMakeDetermineCXXCompiler.cmake b/Modules/CMakeDetermineCXXCompiler.cmake index 9150962..8c33eb6 100644 --- a/Modules/CMakeDetermineCXXCompiler.cmake +++ b/Modules/CMakeDetermineCXXCompiler.cmake @@ -73,6 +73,9 @@ else() set(CMAKE_CXX_COMPILER_ID_TEST_FLAGS # Try compiling to an object file only. "-c" + # IAR does not detect language automatically + "--c++" + "--ec++" ) endif() @@ -165,6 +168,13 @@ set(_CMAKE_PROCESSING_LANGUAGE "CXX") include(Compiler/${CMAKE_CXX_COMPILER_ID}-FindBinUtils OPTIONAL) unset(_CMAKE_PROCESSING_LANGUAGE) +if(CMAKE_CXX_COMPILER_ARCHITECTURE_ID) + set(_SET_CMAKE_CXX_COMPILER_ARCHITECTURE_ID + "set(CMAKE_CXX_COMPILER_ARCHITECTURE_ID ${CMAKE_CXX_COMPILER_ARCHITECTURE_ID})") +else() + set(_SET_CMAKE_CXX_COMPILER_ARCHITECTURE_ID "") +endif() + if(MSVC_CXX_ARCHITECTURE_ID) set(SET_MSVC_CXX_ARCHITECTURE_ID "set(MSVC_CXX_ARCHITECTURE_ID ${MSVC_CXX_ARCHITECTURE_ID})") diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index eeb806f..8d4e6aa 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -102,6 +102,7 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src) set(CMAKE_${lang}_COMPILER_ID "${CMAKE_${lang}_COMPILER_ID}" PARENT_SCOPE) set(CMAKE_${lang}_PLATFORM_ID "${CMAKE_${lang}_PLATFORM_ID}" PARENT_SCOPE) + set(CMAKE_${lang}_COMPILER_ARCHITECTURE_ID "${CMAKE_${lang}_COMPILER_ARCHITECTURE_ID}" PARENT_SCOPE) set(MSVC_${lang}_ARCHITECTURE_ID "${MSVC_${lang}_ARCHITECTURE_ID}" PARENT_SCOPE) set(CMAKE_${lang}_XCODE_CURRENT_ARCH "${CMAKE_${lang}_XCODE_CURRENT_ARCH}" PARENT_SCOPE) @@ -576,6 +577,7 @@ function(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file) if(COMPILER_ID AND NOT COMPILER_ID_TWICE) set(CMAKE_${lang}_COMPILER_ID "${COMPILER_ID}") set(CMAKE_${lang}_PLATFORM_ID "${PLATFORM_ID}") + set(CMAKE_${lang}_COMPILER_ARCHITECTURE_ID "${ARCHITECTURE_ID}") set(MSVC_${lang}_ARCHITECTURE_ID "${ARCHITECTURE_ID}") set(CMAKE_${lang}_COMPILER_VERSION "${COMPILER_VERSION}") set(CMAKE_${lang}_SIMULATE_ID "${SIMULATE_ID}") @@ -625,6 +627,7 @@ function(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file) # Return the information extracted. set(CMAKE_${lang}_COMPILER_ID "${CMAKE_${lang}_COMPILER_ID}" PARENT_SCOPE) set(CMAKE_${lang}_PLATFORM_ID "${CMAKE_${lang}_PLATFORM_ID}" PARENT_SCOPE) + set(CMAKE_${lang}_COMPILER_ARCHITECTURE_ID "${CMAKE_${lang}_COMPILER_ARCHITECTURE_ID}" PARENT_SCOPE) set(MSVC_${lang}_ARCHITECTURE_ID "${MSVC_${lang}_ARCHITECTURE_ID}" PARENT_SCOPE) set(CMAKE_${lang}_COMPILER_VERSION "${CMAKE_${lang}_COMPILER_VERSION}" PARENT_SCOPE) @@ -675,6 +678,7 @@ function(CMAKE_DETERMINE_COMPILER_ID_VENDOR lang userflags) "Checking whether the ${lang} compiler is ${vendor} using \"${flags}\" " "matched \"${regex}\":\n${output}") set(CMAKE_${lang}_COMPILER_ID "${vendor}" PARENT_SCOPE) + set(CMAKE_${lang}_COMPILER_ID_OUTPUT "${output}" PARENT_SCOPE) break() else() if("${result}" MATCHES "timeout") diff --git a/Modules/CMakeDetermineFortranCompiler.cmake b/Modules/CMakeDetermineFortranCompiler.cmake index d5220b4..5559640 100644 --- a/Modules/CMakeDetermineFortranCompiler.cmake +++ b/Modules/CMakeDetermineFortranCompiler.cmake @@ -261,6 +261,13 @@ set(_CMAKE_PROCESSING_LANGUAGE "Fortran") include(Compiler/${CMAKE_Fortran_COMPILER_ID}-FindBinUtils OPTIONAL) unset(_CMAKE_PROCESSING_LANGUAGE) +if(CMAKE_Fortran_COMPILER_ARCHITECTURE_ID) + set(_SET_CMAKE_Fortran_COMPILER_ARCHITECTURE_ID + "set(CMAKE_Fortran_COMPILER_ARCHITECTURE_ID ${CMAKE_Fortran_COMPILER_ARCHITECTURE_ID})") +else() + set(_SET_CMAKE_Fortran_COMPILER_ARCHITECTURE_ID "") +endif() + if(MSVC_Fortran_ARCHITECTURE_ID) set(SET_MSVC_Fortran_ARCHITECTURE_ID "set(MSVC_Fortran_ARCHITECTURE_ID ${MSVC_Fortran_ARCHITECTURE_ID})") diff --git a/Modules/CMakeFortranCompiler.cmake.in b/Modules/CMakeFortranCompiler.cmake.in index d521190..2e34cbb 100644 --- a/Modules/CMakeFortranCompiler.cmake.in +++ b/Modules/CMakeFortranCompiler.cmake.in @@ -6,6 +6,7 @@ set(CMAKE_Fortran_COMPILER_WRAPPER "@CMAKE_Fortran_COMPILER_WRAPPER@") set(CMAKE_Fortran_PLATFORM_ID "@CMAKE_Fortran_PLATFORM_ID@") set(CMAKE_Fortran_SIMULATE_ID "@CMAKE_Fortran_SIMULATE_ID@") set(CMAKE_Fortran_SIMULATE_VERSION "@CMAKE_Fortran_SIMULATE_VERSION@") +@_SET_CMAKE_Fortran_COMPILER_ARCHITECTURE_ID@ @SET_MSVC_Fortran_ARCHITECTURE_ID@ set(CMAKE_AR "@CMAKE_AR@") set(CMAKE_Fortran_COMPILER_AR "@CMAKE_Fortran_COMPILER_AR@") diff --git a/Modules/CMakePlatformId.h.in b/Modules/CMakePlatformId.h.in index 47eb00a..c7065b2 100644 --- a/Modules/CMakePlatformId.h.in +++ b/Modules/CMakePlatformId.h.in @@ -144,6 +144,16 @@ # define ARCHITECTURE_ID "" # endif +#elif defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC) +# if defined(__ICCARM__) +# define ARCHITECTURE_ID "ARM" + +# elif defined(__ICCAVR__) +# define ARCHITECTURE_ID "AVR" + +# else /* unknown architecture */ +# define ARCHITECTURE_ID "" +# endif #else # define ARCHITECTURE_ID #endif diff --git a/Modules/CMakePushCheckState.cmake b/Modules/CMakePushCheckState.cmake index 2a527d5..98eea05 100644 --- a/Modules/CMakePushCheckState.cmake +++ b/Modules/CMakePushCheckState.cmake @@ -62,7 +62,7 @@ macro(CMAKE_PUSH_CHECK_STATE) set(_CMAKE_REQUIRED_FLAGS_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_REQUIRED_FLAGS}) set(_CMAKE_REQUIRED_QUIET_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_REQUIRED_QUIET}) - if (ARGC GREATER 0 AND ARGV0 STREQUAL "RESET") + if (${ARGC} GREATER 0 AND "${ARGV0}" STREQUAL "RESET") cmake_reset_check_state() endif() diff --git a/Modules/CPack.STGZ_Header.sh.in b/Modules/CPack.STGZ_Header.sh.in index c615851..70f63d2 100755 --- a/Modules/CPack.STGZ_Header.sh.in +++ b/Modules/CPack.STGZ_Header.sh.in @@ -7,9 +7,11 @@ cpack_usage() Usage: $0 [options] Options: [defaults in brackets after descriptions] --help print this message + --version print cmake installer version --prefix=dir directory in which to install --include-subdir include the @CPACK_PACKAGE_FILE_NAME@ subdirectory --exclude-subdir exclude the @CPACK_PACKAGE_FILE_NAME@ subdirectory + --skip-license accept license EOF exit 1 } diff --git a/Modules/CPack.cmake b/Modules/CPack.cmake index a63fc83..3915943 100644 --- a/Modules/CPack.cmake +++ b/Modules/CPack.cmake @@ -471,6 +471,7 @@ if(NOT CPACK_GENERATOR) option(CPACK_BINARY_TZ "Enable to build TZ packages" ON) endif() option(CPACK_BINARY_DEB "Enable to build Debian packages" OFF) + option(CPACK_BINARY_FREEBSD "Enable to build FreeBSD packages" OFF) option(CPACK_BINARY_NSIS "Enable to build NSIS packages" OFF) option(CPACK_BINARY_RPM "Enable to build RPM packages" OFF) option(CPACK_BINARY_STGZ "Enable to build STGZ packages" ON) @@ -491,6 +492,7 @@ if(NOT CPACK_GENERATOR) cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_CYGWIN CygwinBinary) cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_DEB DEB) cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_DRAGNDROP DragNDrop) + cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_FREEBSD FREEBSD) cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_IFW IFW) cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_NSIS NSIS) cpack_optional_append(CPACK_GENERATOR CPACK_BINARY_OSXX11 OSXX11) @@ -542,6 +544,7 @@ mark_as_advanced( CPACK_BINARY_CYGWIN CPACK_BINARY_DEB CPACK_BINARY_DRAGNDROP + CPACK_BINARY_FREEBSD CPACK_BINARY_IFW CPACK_BINARY_NSIS CPACK_BINARY_OSXX11 diff --git a/Modules/CPackComponent.cmake b/Modules/CPackComponent.cmake index 3a10b99..2374fbd 100644 --- a/Modules/CPackComponent.cmake +++ b/Modules/CPackComponent.cmake @@ -37,6 +37,16 @@ # components defined by the project. The user may set it to only include the # specified components. # +# Instead of specifying all the desired components, it is possible to obtain a +# list of all defined components and then remove the unwanted ones from the +# list. The :command:`get_cmake_property` command can be used to obtain the +# ``COMPONENTS`` property, then the :command:`list(REMOVE_ITEM)` command can be +# used to remove the unwanted ones. For example, to use all defined components +# except ``foo`` and ``bar``:: +# +# get_cmake_property(CPACK_COMPONENTS_ALL COMPONENTS) +# list(REMOVE_ITEM CPACK_COMPONENTS_ALL "foo" "bar") +# # .. variable:: CPACK_<GENNAME>_COMPONENT_INSTALL # # Enable/Disable component install for CPack generator <GENNAME>. diff --git a/Modules/CPackDeb.cmake b/Modules/CPackDeb.cmake index ddf8b23..85d564e 100644 --- a/Modules/CPackDeb.cmake +++ b/Modules/CPackDeb.cmake @@ -73,7 +73,8 @@ # # <PackageName>_<VersionNumber>-<DebianRevisionNumber>_<DebianArchitecture>.deb # -# Alternatively provided package file name must end with ``.deb`` suffix. +# Alternatively provided package file name must end +# with either ``.deb`` or ``.ipk`` suffix. # # .. note:: # @@ -497,6 +498,16 @@ # # This value is not interpreted. It is possible to pass an optional # revision number of the referenced source package as well. +# +# Building Debian packages on Windows +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +# +# To communicate UNIX file permissions from the install stage +# to the CPack DEB generator the "cmake_mode_t" NTFS +# alternate data stream (ADT) is used. +# +# When a filesystem without ADT support is used only owner read/write +# permissions can be preserved. # CPack script for creating Debian package # Author: Mathieu Malaterre @@ -507,10 +518,6 @@ if(CMAKE_BINARY_DIR) message(FATAL_ERROR "CPackDeb.cmake may only be used by CPack internally.") endif() -if(NOT UNIX) - message(FATAL_ERROR "CPackDeb.cmake may only be used under UNIX.") -endif() - function(cpack_deb_variable_fallback OUTPUT_VAR_NAME) set(FALLBACK_VAR_NAMES ${ARGN}) @@ -971,9 +978,9 @@ function(cpack_deb_prepare_package_vars) else() cmake_policy(PUSH) cmake_policy(SET CMP0010 NEW) - if(NOT CPACK_DEBIAN_FILE_NAME MATCHES ".*\\.deb") + if(NOT CPACK_DEBIAN_FILE_NAME MATCHES ".*\\.(deb|ipk)") cmake_policy(POP) - message(FATAL_ERROR "'${CPACK_DEBIAN_FILE_NAME}' is not a valid DEB package file name as it must end with '.deb'!") + message(FATAL_ERROR "'${CPACK_DEBIAN_FILE_NAME}' is not a valid DEB package file name as it must end with '.deb' or '.ipk'!") endif() cmake_policy(POP) diff --git a/Modules/CPackFreeBSD.cmake b/Modules/CPackFreeBSD.cmake new file mode 100644 index 0000000..7fec78a --- /dev/null +++ b/Modules/CPackFreeBSD.cmake @@ -0,0 +1,246 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +CPackFreeBSD +------------ + +The built in (binary) CPack FreeBSD (pkg) generator (Unix only) + +Variables specific to CPack FreeBSD (pkg) generator +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +CPackFreeBSD may be used to create pkg(8) packages -- these may be used +on FreeBSD, DragonflyBSD, NetBSD, OpenBSD, but also on Linux or OSX, +depending on the installed package-management tools -- using :module:`CPack`. + +CPackFreeBSD is a :module:`CPack` generator and uses the ``CPACK_XXX`` +variables used by :module:`CPack`. It tries to re-use packaging information +that may already be specified for Debian packages for the :module:`CPackDeb` +generator. it also tries to re-use RPM packaging information when Debian +does not specify. + +CPackFreeBSD generator should work on any host with libpkg installed. The +packages it produces are specific to the host architecture and ABI. + +CPackFreeBSD sets package-metadata through :code:`CPACK_FREEBSD_XXX` variables. +CPackFreeBSD, unlike CPackDeb, does not specially support componentized +packages; a single package is created from all the software artifacts +created through CMake. + +All of the variables can be set specifically for FreeBSD packaging in +the CPackConfig file or in CMakeLists.txt, but most of them have defaults +that use general settings (e.g. CMAKE_PROJECT_NAME) or Debian-specific +variables when those make sense (e.g. the homepage of an upstream project +is usually unchanged by the flavor of packaging). When there is no Debian +information to fall back on, but the RPM packaging has it, fall back to +the RPM information (e.g. package license). + +.. variable:: CPACK_FREEBSD_PACKAGE_NAME + + Sets the package name (in the package manifest, but also affects the + output filename). + + * Mandatory: YES + * Default: + + - :variable:`CPACK_PACKAGE_NAME` (this is always set by CPack itself, + based on CMAKE_PROJECT_NAME). + +.. variable:: CPACK_FREEBSD_PACKAGE_COMMENT + + Sets the package comment. This is the short description displayed by + pkg(8) in standard "pkg info" output. + + * Mandatory: YES + * Default: + + - :variable:`CPACK_PACKAGE_DESCRIPTION_SUMMARY` (this is always set + by CPack itself, if nothing else sets it explicitly). + - :variable:`PROJECT_DESCRIPTION` (this can be set with the DESCRIPTION + parameter for :command:`project`). + +.. variable:: CPACK_FREEBSD_PACKAGE_DESCRIPTION + + Sets the package description. This is the long description of the package, + given by "pkg info" with a specific package as argument. + + * Mandatory: YES + * Default: + + - :variable:`CPACK_DEBIAN_PACKAGE_DESCRIPTION` (this may be set already + for Debian packaging, so we may as well re-use it). + +.. variable:: CPACK_FREEBSD_PACKAGE_WWW + + The URL of the web site for this package, preferably (when applicable) the + site from which the original source can be obtained and any additional + upstream documentation or information may be found. + + * Mandatory: YES + * Default: + + - :variable:`CPACK_DEBIAN_PACKAGE_HOMEPAGE` (this may be set already + for Debian packaging, so we may as well re-use it). + +.. variable:: CPACK_FREEBSD_PACKAGE_LICENSE + + The license, or licenses, which apply to this software package. This must + be one or more license-identifiers that pkg recognizes as acceptable license + identifiers (e.g. "GPLv2"). + + * Mandatory: YES + * Default: + + - :variable:`CPACK_RPM_PACKAGE_LICENSE` + +.. variable:: CPACK_FREEBSD_PACKAGE_LICENSE_LOGIC + + This variable is only of importance if there is more than one license. + The default is "single", which is only applicable to a single license. + Other acceptable values are determined by pkg -- those are "dual" or "multi" -- + meaning choice (OR) or simultaneous (AND) application of the licenses. + + * Mandatory: NO + * Default: single + +.. variable:: CPACK_FREEBSD_PACKAGE_MAINTAINER + + The FreeBSD maintainer (e.g. kde@freebsd.org) of this package. + + * Mandatory: YES + * Default: none + +.. variable:: CPACK_FREEBSD_PACKAGE_ORIGIN + + The origin (ports label) of this package; for packages built by CPack + outside of the ports system this is of less importance. The default + puts the package somewhere under misc/, as a stopgap. + + * Mandatory: YES + * Default: misc/<package name> + +.. variable:: CPACK_FREEBSD_PACKAGE_CATEGORIES + + The ports categories where this package lives (if it were to be built + from ports). If none is set a single category is determined based on + the package origin. + + * Mandatory: YES + * Default: derived from ORIGIN + +.. variable:: CPACK_FREEBSD_PACKAGE_DEPS + + A list of package origins that should be added as package dependencies. + These are in the form <category>/<packagename>, e.g. x11/libkonq. + No version information needs to be provided (this is not included + in the manifest). + + * Mandatory: NO + * Default: empty +#]=======================================================================] + + + +if(CMAKE_BINARY_DIR) + message(FATAL_ERROR "CPackFreeBSD.cmake may only be used by CPack internally.") +endif() + +if(NOT UNIX) + message(FATAL_ERROR "CPackFreeBSD.cmake may only be used under UNIX.") +endif() + + +### +# +# These bits are copied from the Debian packaging file; slightly modified. +# They are used for filling in FreeBSD-packaging variables that can take +# on values from elsewhere -- e.g. the package description may as well be +# copied from Debian. +# +function(_cpack_freebsd_fallback_var OUTPUT_VAR_NAME) + set(FALLBACK_VAR_NAMES ${ARGN}) + + set(VALUE "${${OUTPUT_VAR_NAME}}") + if(VALUE) + return() + endif() + + foreach(variable_name IN LISTS FALLBACK_VAR_NAMES) + if(${variable_name}) + set(${OUTPUT_VAR_NAME} "${${variable_name}}" PARENT_SCOPE) + set(VALUE "${${variable_name}}") + break() + endif() + endforeach() + if(NOT VALUE) + message(WARNING "Variable ${OUTPUT_VAR_NAME} could not be given a fallback value from any variable ${FALLBACK_VAR_NAMES}.") + endif() +endfunction() + +function(check_required_var VAR_NAME) + if(NOT ${VAR_NAME}) + message(FATAL_ERROR "Variable ${VAR_NAME} is not set.") + endif() +endfunction() + +set(_cpack_freebsd_fallback_origin "misc/bogus") + +_cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_NAME" + "CPACK_PACKAGE_NAME" + "CMAKE_PROJECT_NAME" + ) + +set(_cpack_freebsd_fallback_www "http://example.com/?pkg=${CPACK_FREEBSD_PACKAGE_NAME}") + +_cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_COMMENT" + "CPACK_PACKAGE_DESCRIPTION_SUMMARY" + ) + +# TODO: maybe read the PACKAGE_DESCRIPTION file for the longer +# FreeBSD pkg-descr? +_cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_DESCRIPTION" + "CPACK_DEBIAN_PACKAGE_DESCRIPTION" + "CPACK_PACKAGE_DESCRIPTION_SUMMARY" + "PACKAGE_DESCRIPTION" + ) + +# There's really only one homepage for a project, so +# re-use the Debian setting if it's there. +_cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_WWW" + "CPACK_DEBIAN_PACKAGE_HOMEPAGE" + "_cpack_freebsd_fallback_www" + ) + +_cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_VERSION" + "CMAKE_PROJECT_VERSION" + "${CMAKE_PROJECT_NAME}_VERSION" + "PROJECT_VERSION" + "CPACK_PACKAGE_VERSION" + "CPACK_PACKAGE_VERSION" + ) + +_cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_MAINTAINER" + "CPACK_PACKAGE_CONTACT" + ) + +_cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_LICENSE" + "CPACK_RPM_PACKAGE_LICENSE" + ) + +_cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_ORIGIN" + "_cpack_freebsd_fallback_origin" + ) + +if(NOT CPACK_FREEBSD_PACKAGE_CATEGORIES) + string(REGEX REPLACE "/.*" "" CPACK_FREEBSD_PACKAGE_CATEGORIES ${CPACK_FREEBSD_PACKAGE_ORIGIN}) +endif() + +check_required_var("CPACK_FREEBSD_PACKAGE_NAME") +check_required_var("CPACK_FREEBSD_PACKAGE_ORIGIN") +check_required_var("CPACK_FREEBSD_PACKAGE_VERSION") +check_required_var("CPACK_FREEBSD_PACKAGE_MAINTAINER") +check_required_var("CPACK_FREEBSD_PACKAGE_COMMENT") +check_required_var("CPACK_FREEBSD_PACKAGE_DESCRIPTION") +check_required_var("CPACK_FREEBSD_PACKAGE_WWW") +check_required_var("CPACK_FREEBSD_PACKAGE_LICENSE") diff --git a/Modules/CPackIFW.cmake b/Modules/CPackIFW.cmake index c1cb52f..0210410 100644 --- a/Modules/CPackIFW.cmake +++ b/Modules/CPackIFW.cmake @@ -221,6 +221,19 @@ # You can use :command:`cpack_ifw_add_package_resources` command to resolve # relative paths. # +# .. variable:: CPACK_IFW_PACKAGE_FILE_EXTENSION +# +# The target binary extension. +# +# On Linux, the name of the target binary is automatically extended with +# '.run', if you do not specify the extension. +# +# On Windows, the target is created as an application with the extension +# '.exe', which is automatically added, if not supplied. +# +# On Mac, the target is created as an DMG disk image with the extension +# '.dmg', which is automatically added, if not supplied. +# # .. variable:: CPACK_IFW_REPOSITORIES_ALL # # The list of remote repositories. diff --git a/Modules/CPackRPM.cmake b/Modules/CPackRPM.cmake index fa2a6e4..3913494 100644 --- a/Modules/CPackRPM.cmake +++ b/Modules/CPackRPM.cmake @@ -2422,7 +2422,11 @@ mv *.rpm %_rpmdir" set(RPMBUILD_FLAGS "-bs") file(WRITE ${CPACK_RPM_BINARY_SPECFILE}.in - "# -*- rpm-spec -*- + "# Restore old style debuginfo creation for rpm >= 4.14. +%undefine _debugsource_packages +%undefine _debuginfo_subpackages + +# -*- rpm-spec -*- BuildRoot: %_topdir/\@CPACK_PACKAGE_FILE_NAME\@ Summary: \@CPACK_RPM_PACKAGE_SUMMARY\@ Name: \@CPACK_RPM_PACKAGE_NAME\@ @@ -2527,7 +2531,11 @@ Vendor: \@CPACK_RPM_PACKAGE_VENDOR\@ if(CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE OR NOT CPACK_RPM_USER_BINARY_SPECFILE) file(WRITE ${CPACK_RPM_BINARY_SPECFILE}.in - "# -*- rpm-spec -*- + "# Restore old style debuginfo creation for rpm >= 4.14. +%undefine _debugsource_packages +%undefine _debuginfo_subpackages + +# -*- rpm-spec -*- BuildRoot: %_topdir/\@CPACK_PACKAGE_FILE_NAME\@\@CPACK_RPM_PACKAGE_COMPONENT_PART_PATH\@ Summary: \@CPACK_RPM_PACKAGE_SUMMARY\@ Name: \@CPACK_RPM_PACKAGE_NAME\@ diff --git a/Modules/CheckCCompilerFlag.cmake b/Modules/CheckCCompilerFlag.cmake index 1ba67fc..5a7298b 100644 --- a/Modules/CheckCCompilerFlag.cmake +++ b/Modules/CheckCCompilerFlag.cmake @@ -1,26 +1,36 @@ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. -#.rst: -# CheckCCompilerFlag -# ------------------ -# -# Check whether the C compiler supports a given flag. -# -# CHECK_C_COMPILER_FLAG(<flag> <var>) -# -# :: -# -# <flag> - the compiler flag -# <var> - variable to store the result -# Will be created as an internal cache variable. -# -# This internally calls the check_c_source_compiles macro and sets -# CMAKE_REQUIRED_DEFINITIONS to <flag>. See help for -# CheckCSourceCompiles for a listing of variables that can otherwise -# modify the build. The result only tells that the compiler does not -# give an error message when it encounters the flag. If the flag has -# any effect or even a specific one is beyond the scope of this module. +#[=======================================================================[.rst: +CheckCCompilerFlag +------------------ + +Check whether the C compiler supports a given flag. + +.. command:: check_c_compiler_flag + + :: + + check_c_compiler_flag(<flag> <var>) + + Check that the ``<flag>`` is accepted by the compiler without + a diagnostic. Stores the result in an internal cache entry + named ``<var>``. + +This command temporarily sets the ``CMAKE_REQUIRED_DEFINITIONS`` variable +and calls the ``check_c_source_compiles`` macro from the +:module:`CheckCSourceCompiles` module. See documentation of that +module for a listing of variables that can otherwise modify the build. + +A positive result from this check indicates only that the compiler did not +issue a diagnostic message when given the flag. Whether the flag has any +effect or even a specific one is beyond the scope of this module. + +.. note:: + Since the :command:`try_compile` command forwards flags from variables + like :variable:`CMAKE_C_FLAGS <CMAKE_<LANG>_FLAGS>`, unknown flags + in such variables may cause a false negative for this check. +#]=======================================================================] include(CheckCSourceCompiles) include(CMakeCheckCompilerFlagCommonPatterns) diff --git a/Modules/CheckCSourceCompiles.cmake b/Modules/CheckCSourceCompiles.cmake index ac2c6c5..56e68d5 100644 --- a/Modules/CheckCSourceCompiles.cmake +++ b/Modules/CheckCSourceCompiles.cmake @@ -1,31 +1,65 @@ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. -#.rst: -# CheckCSourceCompiles -# -------------------- -# -# Check if given C source compiles and links into an executable -# -# CHECK_C_SOURCE_COMPILES(<code> <var> [FAIL_REGEX <fail-regex>]) -# -# :: -# -# <code> - source code to try to compile, must define 'main' -# <var> - variable to store whether the source code compiled -# Will be created as an internal cache variable. -# <fail-regex> - fail if test output matches this regex -# -# The following variables may be set before calling this macro to modify -# the way the check is run: -# -# :: -# -# CMAKE_REQUIRED_FLAGS = string of compile command line flags -# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar) -# CMAKE_REQUIRED_INCLUDES = list of include directories -# CMAKE_REQUIRED_LIBRARIES = list of libraries to link -# CMAKE_REQUIRED_QUIET = execute quietly without messages +#[=======================================================================[.rst: +CheckCSourceCompiles +-------------------- + +Check if given C source compiles and links into an executable. + +.. command:: check_c_source_compiles + + :: + + check_c_source_compiles(code resultVar [FAIL_REGEX regex1 [regex2...]]) + + Check that the source supplied in ``code`` can be compiled as a C source + file and linked as an executable (so it must contain at least a ``main()`` + function). The result will be stored in the internal cache variable specified + by ``resultVar``, with a boolean true value for success and boolean false for + failure. If ``FAIL_REGEX`` is provided, then failure is determined by + checking if anything in the output matches any of the specified regular + expressions. + + The underlying check is performed by the :command:`try_compile` command. The + compile and link commands can be influenced by setting any of the following + variables prior to calling ``check_c_source_compiles()``: + + ``CMAKE_REQUIRED_FLAGS`` + Additional flags to pass to the compiler. Note that the contents of + :variable:`CMAKE_C_FLAGS <CMAKE_<LANG>_FLAGS>` and its associated + configuration-specific variable are automatically added to the compiler + command before the contents of ``CMAKE_REQUIRED_FLAGS``. + + ``CMAKE_REQUIRED_DEFINITIONS`` + A :ref:`;-list <CMake Language Lists>` of compiler definitions of the form + ``-DFOO`` or ``-DFOO=bar``. A definition for the name specified by + ``resultVar`` will also be added automatically. + + ``CMAKE_REQUIRED_INCLUDES`` + A :ref:`;-list <CMake Language Lists>` of header search paths to pass to + the compiler. These will be the only header search paths used by + ``try_compile()``, i.e. the contents of the :prop_dir:`INCLUDE_DIRECTORIES` + directory property will be ignored. + + ``CMAKE_REQUIRED_LIBRARIES`` + A :ref:`;-list <CMake Language Lists>` of libraries to add to the link + command. These can be the name of system libraries or they can be + :ref:`Imported Targets <Imported Targets>` (see :command:`try_compile` for + further details). + + ``CMAKE_REQUIRED_QUIET`` + If this variable evaluates to a boolean true value, all status messages + associated with the check will be suppressed. + + The check is only performed once, with the result cached in the variable + named by ``resultVar``. Every subsequent CMake run will re-use this cached + value rather than performing the check again, even if the ``code`` changes. + In order to force the check to be re-evaluated, the variable named by + ``resultVar`` must be manually removed from the cache. + +#]=======================================================================] + macro(CHECK_C_SOURCE_COMPILES SOURCE VAR) if(NOT DEFINED "${VAR}") diff --git a/Modules/CheckCSourceRuns.cmake b/Modules/CheckCSourceRuns.cmake index 70aa9fd..8da9f1e 100644 --- a/Modules/CheckCSourceRuns.cmake +++ b/Modules/CheckCSourceRuns.cmake @@ -1,31 +1,64 @@ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. -#.rst: -# CheckCSourceRuns -# ---------------- -# -# Check if the given C source code compiles and runs. -# -# CHECK_C_SOURCE_RUNS(<code> <var>) -# -# :: -# -# <code> - source code to try to compile -# <var> - variable to store the result -# (1 for success, empty for failure) -# Will be created as an internal cache variable. -# -# The following variables may be set before calling this macro to modify -# the way the check is run: -# -# :: -# -# CMAKE_REQUIRED_FLAGS = string of compile command line flags -# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar) -# CMAKE_REQUIRED_INCLUDES = list of include directories -# CMAKE_REQUIRED_LIBRARIES = list of libraries to link -# CMAKE_REQUIRED_QUIET = execute quietly without messages +#[=======================================================================[.rst: +CheckCSourceRuns +---------------- + +Check if given C source compiles and links into an executable and can +subsequently be run. + +.. command:: check_c_source_runs + + :: + + check_c_source_runs(code resultVar) + + Check that the source supplied in ``code`` can be compiled as a C source + file, linked as an executable and then run. The ``code`` must contain at + least a ``main()`` function. If the code could be built and run successfully, + the internal cache variable specified by ``resultVar`` will be set to 1, + otherwise it will be set to an value that evaluates to boolean false (e.g. + an empty string or an error message). + + The underlying check is performed by the :command:`try_run` command. The + compile and link commands can be influenced by setting any of the following + variables prior to calling ``check_c_source_runs()``: + + ``CMAKE_REQUIRED_FLAGS`` + Additional flags to pass to the compiler. Note that the contents of + :variable:`CMAKE_C_FLAGS <CMAKE_<LANG>_FLAGS>` and its associated + configuration-specific variable are automatically added to the compiler + command before the contents of ``CMAKE_REQUIRED_FLAGS``. + + ``CMAKE_REQUIRED_DEFINITIONS`` + A :ref:`;-list <CMake Language Lists>` of compiler definitions of the form + ``-DFOO`` or ``-DFOO=bar``. A definition for the name specified by + ``resultVar`` will also be added automatically. + + ``CMAKE_REQUIRED_INCLUDES`` + A :ref:`;-list <CMake Language Lists>` of header search paths to pass to + the compiler. These will be the only header search paths used by + ``try_run()``, i.e. the contents of the :prop_dir:`INCLUDE_DIRECTORIES` + directory property will be ignored. + + ``CMAKE_REQUIRED_LIBRARIES`` + A :ref:`;-list <CMake Language Lists>` of libraries to add to the link + command. These can be the name of system libraries or they can be + :ref:`Imported Targets <Imported Targets>` (see :command:`try_run` for + further details). + + ``CMAKE_REQUIRED_QUIET`` + If this variable evaluates to a boolean true value, all status messages + associated with the check will be suppressed. + + The check is only performed once, with the result cached in the variable + named by ``resultVar``. Every subsequent CMake run will re-use this cached + value rather than performing the check again, even if the ``code`` changes. + In order to force the check to be re-evaluated, the variable named by + ``resultVar`` must be manually removed from the cache. + +#]=======================================================================] macro(CHECK_C_SOURCE_RUNS SOURCE VAR) if(NOT DEFINED "${VAR}") diff --git a/Modules/CheckCXXCompilerFlag.cmake b/Modules/CheckCXXCompilerFlag.cmake index afbb231..f731b70 100644 --- a/Modules/CheckCXXCompilerFlag.cmake +++ b/Modules/CheckCXXCompilerFlag.cmake @@ -1,25 +1,36 @@ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. -#.rst: -# CheckCXXCompilerFlag -# -------------------- -# -# Check whether the CXX compiler supports a given flag. -# -# CHECK_CXX_COMPILER_FLAG(<flag> <var>) -# -# :: -# -# <flag> - the compiler flag -# <var> - variable to store the result -# -# This internally calls the check_cxx_source_compiles macro and sets -# CMAKE_REQUIRED_DEFINITIONS to <flag>. See help for -# CheckCXXSourceCompiles for a listing of variables that can otherwise -# modify the build. The result only tells that the compiler does not -# give an error message when it encounters the flag. If the flag has -# any effect or even a specific one is beyond the scope of this module. +#[=======================================================================[.rst: +CheckCXXCompilerFlag +------------------------ + +Check whether the CXX compiler supports a given flag. + +.. command:: check_cxx_compiler_flag + + :: + + check_cxx_compiler_flag(<flag> <var>) + + Check that the ``<flag>`` is accepted by the compiler without + a diagnostic. Stores the result in an internal cache entry + named ``<var>``. + +This command temporarily sets the ``CMAKE_REQUIRED_DEFINITIONS`` variable +and calls the ``check_cxx_source_compiles`` macro from the +:module:`CheckCXXSourceCompiles` module. See documentation of that +module for a listing of variables that can otherwise modify the build. + +A positive result from this check indicates only that the compiler did not +issue a diagnostic message when given the flag. Whether the flag has any +effect or even a specific one is beyond the scope of this module. + +.. note:: + Since the :command:`try_compile` command forwards flags from variables + like :variable:`CMAKE_CXX_FLAGS <CMAKE_<LANG>_FLAGS>`, unknown flags + in such variables may cause a false negative for this check. +#]=======================================================================] include(CheckCXXSourceCompiles) include(CMakeCheckCompilerFlagCommonPatterns) diff --git a/Modules/CheckCXXSourceCompiles.cmake b/Modules/CheckCXXSourceCompiles.cmake index e54d09e..4634a7b 100644 --- a/Modules/CheckCXXSourceCompiles.cmake +++ b/Modules/CheckCXXSourceCompiles.cmake @@ -1,31 +1,64 @@ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. -#.rst: -# CheckCXXSourceCompiles -# ---------------------- -# -# Check if given C++ source compiles and links into an executable -# -# CHECK_CXX_SOURCE_COMPILES(<code> <var> [FAIL_REGEX <fail-regex>]) -# -# :: -# -# <code> - source code to try to compile, must define 'main' -# <var> - variable to store whether the source code compiled -# Will be created as an internal cache variable. -# <fail-regex> - fail if test output matches this regex -# -# The following variables may be set before calling this macro to modify -# the way the check is run: -# -# :: -# -# CMAKE_REQUIRED_FLAGS = string of compile command line flags -# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar) -# CMAKE_REQUIRED_INCLUDES = list of include directories -# CMAKE_REQUIRED_LIBRARIES = list of libraries to link -# CMAKE_REQUIRED_QUIET = execute quietly without messages +#[=======================================================================[.rst: +CheckCXXSourceCompiles +---------------------- + +Check if given C++ source compiles and links into an executable. + +.. command:: check_cxx_source_compiles + + :: + + check_cxx_source_compiles(code resultVar [FAIL_REGEX regex1 [regex2...]]) + + Check that the source supplied in ``code`` can be compiled as a C++ source + file and linked as an executable (so it must contain at least a ``main()`` + function). The result will be stored in the internal cache variable specified + by ``resultVar``, with a boolean true value for success and boolean false for + failure. If ``FAIL_REGEX`` is provided, then failure is determined by + checking if anything in the output matches any of the specified regular + expressions. + + The underlying check is performed by the :command:`try_compile` command. The + compile and link commands can be influenced by setting any of the following + variables prior to calling ``check_cxx_source_compiles()``: + + ``CMAKE_REQUIRED_FLAGS`` + Additional flags to pass to the compiler. Note that the contents of + :variable:`CMAKE_CXX_FLAGS <CMAKE_<LANG>_FLAGS>` and its associated + configuration-specific variable are automatically added to the compiler + command before the contents of ``CMAKE_REQUIRED_FLAGS``. + + ``CMAKE_REQUIRED_DEFINITIONS`` + A :ref:`;-list <CMake Language Lists>` of compiler definitions of the form + ``-DFOO`` or ``-DFOO=bar``. A definition for the name specified by + ``resultVar`` will also be added automatically. + + ``CMAKE_REQUIRED_INCLUDES`` + A :ref:`;-list <CMake Language Lists>` of header search paths to pass to + the compiler. These will be the only header search paths used by + ``try_compile()``, i.e. the contents of the :prop_dir:`INCLUDE_DIRECTORIES` + directory property will be ignored. + + ``CMAKE_REQUIRED_LIBRARIES`` + A :ref:`;-list <CMake Language Lists>` of libraries to add to the link + command. These can be the name of system libraries or they can be + :ref:`Imported Targets <Imported Targets>` (see :command:`try_compile` for + further details). + + ``CMAKE_REQUIRED_QUIET`` + If this variable evaluates to a boolean true value, all status messages + associated with the check will be suppressed. + + The check is only performed once, with the result cached in the variable + named by ``resultVar``. Every subsequent CMake run will re-use this cached + value rather than performing the check again, even if the ``code`` changes. + In order to force the check to be re-evaluated, the variable named by + ``resultVar`` must be manually removed from the cache. + +#]=======================================================================] macro(CHECK_CXX_SOURCE_COMPILES SOURCE VAR) if(NOT DEFINED "${VAR}") diff --git a/Modules/CheckCXXSourceRuns.cmake b/Modules/CheckCXXSourceRuns.cmake index e083659..558708c 100644 --- a/Modules/CheckCXXSourceRuns.cmake +++ b/Modules/CheckCXXSourceRuns.cmake @@ -1,31 +1,64 @@ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. -#.rst: -# CheckCXXSourceRuns -# ------------------ -# -# Check if the given C++ source code compiles and runs. -# -# CHECK_CXX_SOURCE_RUNS(<code> <var>) -# -# :: -# -# <code> - source code to try to compile -# <var> - variable to store the result -# (1 for success, empty for failure) -# Will be created as an internal cache variable. -# -# The following variables may be set before calling this macro to modify -# the way the check is run: -# -# :: -# -# CMAKE_REQUIRED_FLAGS = string of compile command line flags -# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar) -# CMAKE_REQUIRED_INCLUDES = list of include directories -# CMAKE_REQUIRED_LIBRARIES = list of libraries to link -# CMAKE_REQUIRED_QUIET = execute quietly without messages +#[=======================================================================[.rst: +CheckCXXSourceRuns +------------------ + +Check if given C++ source compiles and links into an executable and can +subsequently be run. + +.. command:: check_cxx_source_runs + + :: + + check_cxx_source_runs(code resultVar) + + Check that the source supplied in ``code`` can be compiled as a C++ source + file, linked as an executable and then run. The ``code`` must contain at + least a ``main()`` function. If the code could be built and run successfully, + the internal cache variable specified by ``resultVar`` will be set to 1, + otherwise it will be set to an value that evaluates to boolean false (e.g. + an empty string or an error message). + + The underlying check is performed by the :command:`try_run` command. The + compile and link commands can be influenced by setting any of the following + variables prior to calling ``check_cxx_source_runs()``: + + ``CMAKE_REQUIRED_FLAGS`` + Additional flags to pass to the compiler. Note that the contents of + :variable:`CMAKE_CXX_FLAGS <CMAKE_<LANG>_FLAGS>` and its associated + configuration-specific variable are automatically added to the compiler + command before the contents of ``CMAKE_REQUIRED_FLAGS``. + + ``CMAKE_REQUIRED_DEFINITIONS`` + A :ref:`;-list <CMake Language Lists>` of compiler definitions of the form + ``-DFOO`` or ``-DFOO=bar``. A definition for the name specified by + ``resultVar`` will also be added automatically. + + ``CMAKE_REQUIRED_INCLUDES`` + A :ref:`;-list <CMake Language Lists>` of header search paths to pass to + the compiler. These will be the only header search paths used by + ``try_run()``, i.e. the contents of the :prop_dir:`INCLUDE_DIRECTORIES` + directory property will be ignored. + + ``CMAKE_REQUIRED_LIBRARIES`` + A :ref:`;-list <CMake Language Lists>` of libraries to add to the link + command. These can be the name of system libraries or they can be + :ref:`Imported Targets <Imported Targets>` (see :command:`try_run` for + further details). + + ``CMAKE_REQUIRED_QUIET`` + If this variable evaluates to a boolean true value, all status messages + associated with the check will be suppressed. + + The check is only performed once, with the result cached in the variable + named by ``resultVar``. Every subsequent CMake run will re-use this cached + value rather than performing the check again, even if the ``code`` changes. + In order to force the check to be re-evaluated, the variable named by + ``resultVar`` must be manually removed from the cache. + +#]=======================================================================] macro(CHECK_CXX_SOURCE_RUNS SOURCE VAR) if(NOT DEFINED "${VAR}") diff --git a/Modules/CheckCXXSymbolExists.cmake b/Modules/CheckCXXSymbolExists.cmake index 354eea3..8552154 100644 --- a/Modules/CheckCXXSymbolExists.cmake +++ b/Modules/CheckCXXSymbolExists.cmake @@ -35,5 +35,5 @@ include(CheckSymbolExists) macro(CHECK_CXX_SYMBOL_EXISTS SYMBOL FILES VARIABLE) - _CHECK_SYMBOL_EXISTS("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.cxx" "${SYMBOL}" "${FILES}" "${VARIABLE}" ) + __CHECK_SYMBOL_EXISTS_IMPL("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.cxx" "${SYMBOL}" "${FILES}" "${VARIABLE}" ) endmacro() diff --git a/Modules/CheckFortranCompilerFlag.cmake b/Modules/CheckFortranCompilerFlag.cmake index 8519fcc..8a1a8b9 100644 --- a/Modules/CheckFortranCompilerFlag.cmake +++ b/Modules/CheckFortranCompilerFlag.cmake @@ -1,27 +1,36 @@ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. -#.rst: -# CheckFortranCompilerFlag -# ------------------------ -# -# Check whether the Fortran compiler supports a given flag. -# -# CHECK_Fortran_COMPILER_FLAG(<flag> <var>) -# -# :: -# -# <flag> - the compiler flag -# <var> - variable to store the result -# Will be created as an internal cache variable. -# -# This internally calls the check_fortran_source_compiles macro and -# sets CMAKE_REQUIRED_DEFINITIONS to <flag>. See help for -# CheckFortranSourceCompiles for a listing of variables that can -# otherwise modify the build. The result only tells that the compiler -# does not give an error message when it encounters the flag. If the -# flag has any effect or even a specific one is beyond the scope of -# this module. +#[=======================================================================[.rst: +CheckFortranCompilerFlag +------------------------ + +Check whether the Fortran compiler supports a given flag. + +.. command:: check_fortran_compiler_flag + + :: + + check_fortran_compiler_flag(<flag> <var>) + + Check that the ``<flag>`` is accepted by the compiler without + a diagnostic. Stores the result in an internal cache entry + named ``<var>``. + +This command temporarily sets the ``CMAKE_REQUIRED_DEFINITIONS`` variable +and calls the ``check_fortran_source_compiles`` macro from the +:module:`CheckFortranSourceCompiles` module. See documentation of that +module for a listing of variables that can otherwise modify the build. + +A positive result from this check indicates only that the compiler did not +issue a diagnostic message when given the flag. Whether the flag has any +effect or even a specific one is beyond the scope of this module. + +.. note:: + Since the :command:`try_compile` command forwards flags from variables + like :variable:`CMAKE_Fortran_FLAGS <CMAKE_<LANG>_FLAGS>`, unknown flags + in such variables may cause a false negative for this check. +#]=======================================================================] include(CheckFortranSourceCompiles) include(CMakeCheckCompilerFlagCommonPatterns) diff --git a/Modules/CheckFortranSourceCompiles.cmake b/Modules/CheckFortranSourceCompiles.cmake index c42254c..4df17e3 100644 --- a/Modules/CheckFortranSourceCompiles.cmake +++ b/Modules/CheckFortranSourceCompiles.cmake @@ -1,35 +1,71 @@ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. -#.rst: -# CheckFortranSourceCompiles -# -------------------------- -# -# Check if given Fortran source compiles and links into an executable:: -# -# CHECK_Fortran_SOURCE_COMPILES(<code> <var> [FAIL_REGEX <fail-regex>] -# [SRC_EXT <ext>]) -# -# The arguments are: -# -# ``<code>`` -# Source code to try to compile. It must define a PROGRAM entry point. -# ``<var>`` -# Variable to store whether the source code compiled. -# Will be created as an internal cache variable. -# ``FAIL_REGEX <fail-regex>`` -# Fail if test output matches this regex. -# ``SRC_EXT <ext>`` -# Use source extension ``.<ext>`` instead of the default ``.F``. -# -# The following variables may be set before calling this macro to modify -# the way the check is run:: -# -# CMAKE_REQUIRED_FLAGS = string of compile command line flags -# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar) -# CMAKE_REQUIRED_INCLUDES = list of include directories -# CMAKE_REQUIRED_LIBRARIES = list of libraries to link -# CMAKE_REQUIRED_QUIET = execute quietly without messages +#[=======================================================================[.rst: +CheckFortranSourceCompiles +-------------------------- + +Check if given Fortran source compiles and links into an executable. + +.. command:: check_fortran_source_compiles + + :: + + check_fortran_source_compiles(code resultVar + [FAIL_REGEX regex1 [regex2...]] + [SRC_EXT ext] + ) + + Check that the source supplied in ``code`` can be compiled as a Fortran + source file and linked as an executable (so it must contain at least a + ``PROGRAM`` entry point). The result will be stored in the internal cache + variable specified by ``resultVar``, with a boolean true value for success + and boolean false for failure. If ``FAIL_REGEX`` is provided, then failure is + determined by checking if anything in the output matches any of the specified + regular expressions. + + By default, the test source file will be given a ``.F`` file extension. The + ``SRC_EXT`` option can be used to override this with ``.ext`` instead. + + The underlying check is performed by the :command:`try_compile` command. The + compile and link commands can be influenced by setting any of the following + variables prior to calling ``check_fortran_source_compiles()``: + + ``CMAKE_REQUIRED_FLAGS`` + Additional flags to pass to the compiler. Note that the contents of + :variable:`CMAKE_Fortran_FLAGS <CMAKE_<LANG>_FLAGS>` and its associated + configuration-specific variable are automatically added to the compiler + command before the contents of ``CMAKE_REQUIRED_FLAGS``. + + ``CMAKE_REQUIRED_DEFINITIONS`` + A :ref:`;-list <CMake Language Lists>` of compiler definitions of the form + ``-DFOO`` or ``-DFOO=bar``. A definition for the name specified by + ``resultVar`` will also be added automatically. + + ``CMAKE_REQUIRED_INCLUDES`` + A :ref:`;-list <CMake Language Lists>` of header search paths to pass to + the compiler. These will be the only header search paths used by + ``try_compile()``, i.e. the contents of the :prop_dir:`INCLUDE_DIRECTORIES` + directory property will be ignored. + + ``CMAKE_REQUIRED_LIBRARIES`` + A :ref:`;-list <CMake Language Lists>` of libraries to add to the link + command. These can be the name of system libraries or they can be + :ref:`Imported Targets <Imported Targets>` (see :command:`try_compile` for + further details). + + ``CMAKE_REQUIRED_QUIET`` + If this variable evaluates to a boolean true value, all status messages + associated with the check will be suppressed. + + The check is only performed once, with the result cached in the variable + named by ``resultVar``. Every subsequent CMake run will re-use this cached + value rather than performing the check again, even if the ``code`` changes. + In order to force the check to be re-evaluated, the variable named by + ``resultVar`` must be manually removed from the cache. + +#]=======================================================================] + macro(CHECK_Fortran_SOURCE_COMPILES SOURCE VAR) if(NOT DEFINED "${VAR}") diff --git a/Modules/CheckSymbolExists.cmake b/Modules/CheckSymbolExists.cmake index 6f1afcf..6d52d56 100644 --- a/Modules/CheckSymbolExists.cmake +++ b/Modules/CheckSymbolExists.cmake @@ -45,15 +45,15 @@ the way the check is run: macro(CHECK_SYMBOL_EXISTS SYMBOL FILES VARIABLE) if(CMAKE_C_COMPILER_LOADED) - _CHECK_SYMBOL_EXISTS("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.c" "${SYMBOL}" "${FILES}" "${VARIABLE}" ) + __CHECK_SYMBOL_EXISTS_IMPL("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.c" "${SYMBOL}" "${FILES}" "${VARIABLE}" ) elseif(CMAKE_CXX_COMPILER_LOADED) - _CHECK_SYMBOL_EXISTS("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.cxx" "${SYMBOL}" "${FILES}" "${VARIABLE}" ) + __CHECK_SYMBOL_EXISTS_IMPL("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.cxx" "${SYMBOL}" "${FILES}" "${VARIABLE}" ) else() message(FATAL_ERROR "CHECK_SYMBOL_EXISTS needs either C or CXX language enabled") endif() endmacro() -macro(_CHECK_SYMBOL_EXISTS SOURCEFILE SYMBOL FILES VARIABLE) +macro(__CHECK_SYMBOL_EXISTS_IMPL SOURCEFILE SYMBOL FILES VARIABLE) if(NOT DEFINED "${VARIABLE}" OR "x${${VARIABLE}}" STREQUAL "x${VARIABLE}") set(CMAKE_CONFIGURABLE_FILE_CONTENT "/* */\n") set(MACRO_CHECK_SYMBOL_EXISTS_FLAGS ${CMAKE_REQUIRED_FLAGS}) diff --git a/Modules/CheckTypeSize.c.in b/Modules/CheckTypeSize.c.in index b6c3688..2303c4e 100644 --- a/Modules/CheckTypeSize.c.in +++ b/Modules/CheckTypeSize.c.in @@ -9,6 +9,12 @@ # define KEY '_','_','p','p','c','_','_' #elif defined(__ppc64__) # define KEY '_','_','p','p','c','6','4','_','_' +#elif defined(__aarch64__) +# define KEY '_','_','a','a','r','c','h','6','4','_','_' +#elif defined(__ARM_ARCH_7A__) +# define KEY '_','_','A','R','M','_','A','R','C','H','_','7','A','_','_' +#elif defined(__ARM_ARCH_7S__) +# define KEY '_','_','A','R','M','_','A','R','C','H','_','7','S','_','_' #endif #define SIZE (sizeof(@type@)) diff --git a/Modules/Compiler/Clang-C.cmake b/Modules/Compiler/Clang-C.cmake index b881e2b..a5f9d84 100644 --- a/Modules/Compiler/Clang-C.cmake +++ b/Modules/Compiler/Clang-C.cmake @@ -7,14 +7,30 @@ if(WIN32 OR (APPLE AND NOT appleClangPolicy STREQUAL NEW)) endif() if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 3.4) - set(CMAKE_C90_STANDARD_COMPILE_OPTION "-std=c90") - set(CMAKE_C90_EXTENSION_COMPILE_OPTION "-std=gnu90") + if(NOT "x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC") + set(CMAKE_C90_STANDARD_COMPILE_OPTION "-std=c90") + set(CMAKE_C90_EXTENSION_COMPILE_OPTION "-std=gnu90") - set(CMAKE_C99_STANDARD_COMPILE_OPTION "-std=c99") - set(CMAKE_C99_EXTENSION_COMPILE_OPTION "-std=gnu99") + set(CMAKE_C99_STANDARD_COMPILE_OPTION "-std=c99") + set(CMAKE_C99_EXTENSION_COMPILE_OPTION "-std=gnu99") - set(CMAKE_C11_STANDARD_COMPILE_OPTION "-std=c11") - set(CMAKE_C11_EXTENSION_COMPILE_OPTION "-std=gnu11") + set(CMAKE_C11_STANDARD_COMPILE_OPTION "-std=c11") + set(CMAKE_C11_EXTENSION_COMPILE_OPTION "-std=gnu11") + else() + # clang-cl doesn't have any of these + set(CMAKE_C90_STANDARD_COMPILE_OPTION "") + set(CMAKE_C90_EXTENSION_COMPILE_OPTION "") + + set(CMAKE_C99_STANDARD_COMPILE_OPTION "") + set(CMAKE_C99_EXTENSION_COMPILE_OPTION "") + + set(CMAKE_C11_STANDARD_COMPILE_OPTION "") + set(CMAKE_C11_EXTENSION_COMPILE_OPTION "") + endif() endif() -__compiler_check_default_language_standard(C 3.4 99 3.6 11) +if(NOT "x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC") + __compiler_check_default_language_standard(C 3.4 99 3.6 11) +else() + set(CMAKE_C_STANDARD_DEFAULT "") +endif() diff --git a/Modules/Compiler/Clang-CXX.cmake b/Modules/Compiler/Clang-CXX.cmake index d3707ee..efc68b3 100644 --- a/Modules/Compiler/Clang-CXX.cmake +++ b/Modules/Compiler/Clang-CXX.cmake @@ -10,30 +10,46 @@ if(APPLE AND NOT appleClangPolicy STREQUAL NEW) return() endif() -if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 2.1) - set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "-std=c++98") - set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "-std=gnu++98") -endif() +if(NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC") + if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 2.1) + set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "-std=c++98") + set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "-std=gnu++98") + endif() -if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.1) - set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++11") - set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++11") -elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 2.1) - set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++0x") - set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++0x") -endif() + if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.1) + set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++11") + set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++11") + elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 2.1) + set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++0x") + set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++0x") + endif() -if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5) - set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std=c++14") - set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std=gnu++14") -elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4) - set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std=c++1y") - set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std=gnu++1y") -endif() + if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5) + set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std=c++14") + set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std=gnu++14") + elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4) + set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std=c++1y") + set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std=gnu++1y") + endif() -if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5) - set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "-std=c++1z") - set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-std=gnu++1z") + if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5) + set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "-std=c++1z") + set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-std=gnu++1z") + endif() +else() + # clang-cl does not know these options because it behaves like cl.exe + set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "") + set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "") + set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "") + set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "") + set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "") + set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "") + set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "") + set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "") endif() -__compiler_check_default_language_standard(CXX 2.1 98) +if(NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC") + __compiler_check_default_language_standard(CXX 2.1 98) +else() + set(CMAKE_CXX_STANDARD_DEFAULT "") +endif() diff --git a/Modules/Compiler/Clang-FindBinUtils.cmake b/Modules/Compiler/Clang-FindBinUtils.cmake index e2822a1..b852660 100644 --- a/Modules/Compiler/Clang-FindBinUtils.cmake +++ b/Modules/Compiler/Clang-FindBinUtils.cmake @@ -2,6 +2,12 @@ if(NOT DEFINED _CMAKE_PROCESSING_LANGUAGE OR _CMAKE_PROCESSING_LANGUAGE STREQUAL message(FATAL_ERROR "Internal error: _CMAKE_PROCESSING_LANGUAGE is not set") endif() +# Debian: +# * /usr/bin/llvm-ar-4.0 +# * /usr/bin/llvm-ranlib-4.0 +string(REGEX MATCH "^([0-9]+\\.[0-9]+)" __version_x_y + "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_VERSION}") + # Try to find tools in the same directory as Clang itself get_filename_component(__clang_hint_1 "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER}" REALPATH) get_filename_component(__clang_hint_1 "${__clang_hint_1}" DIRECTORY) @@ -12,6 +18,7 @@ set(__clang_hints ${__clang_hint_1} ${__clang_hint_2}) # http://manpages.ubuntu.com/manpages/precise/en/man1/llvm-ar.1.html find_program(CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_AR NAMES + "${_CMAKE_TOOLCHAIN_PREFIX}llvm-ar-${__version_x_y}" "${_CMAKE_TOOLCHAIN_PREFIX}llvm-ar" HINTS ${__clang_hints} DOC "LLVM archiver" @@ -20,6 +27,7 @@ mark_as_advanced(CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_AR) # http://manpages.ubuntu.com/manpages/precise/en/man1/llvm-ranlib.1.html find_program(CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_RANLIB NAMES + "${_CMAKE_TOOLCHAIN_PREFIX}llvm-ranlib-${__version_x_y}" "${_CMAKE_TOOLCHAIN_PREFIX}llvm-ranlib" HINTS ${__clang_hints} DOC "Generate index for LLVM archive" diff --git a/Modules/Compiler/IAR-ASM.cmake b/Modules/Compiler/IAR-ASM.cmake index 844c30e..651bc3a 100644 --- a/Modules/Compiler/IAR-ASM.cmake +++ b/Modules/Compiler/IAR-ASM.cmake @@ -2,13 +2,20 @@ include(Compiler/IAR) -set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT>") - -if("${IAR_TARGET_ARCHITECTURE}" STREQUAL "ARM") +if("${CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID}" STREQUAL "ARM") +set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> -S <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT>") + __compiler_iar_ARM(ASM) set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS s;asm;msa) -endif() + string(APPEND CMAKE_ASM_FLAGS_INIT " ") + string(APPEND CMAKE_ASM_FLAGS_DEBUG_INIT " -r") + string(APPEND CMAKE_ASM_FLAGS_MINSIZEREL_INIT " -DNDEBUG") + string(APPEND CMAKE_ASM_FLAGS_RELEASE_INIT " -DNDEBUG") + string(APPEND CMAKE_ASM_FLAGS_RELWITHDEBINFO_INIT " -r -DNDEBUG") -if("${IAR_TARGET_ARCHITECTURE}" STREQUAL "AVR") +elseif("${CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID}" STREQUAL "AVR") + set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> -S <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT>") + __compiler_iar_AVR(ASM) set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS s90;asm;msa) + endif() diff --git a/Modules/Compiler/IAR-C.cmake b/Modules/Compiler/IAR-C.cmake index f65b0c7..55e019e 100644 --- a/Modules/Compiler/IAR-C.cmake +++ b/Modules/Compiler/IAR-C.cmake @@ -1,25 +1,32 @@ # This file is processed when the IAR compiler is used for a C file - include(Compiler/IAR) - -set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT>") -set(CMAKE_C_CREATE_PREPROCESSED_SOURCE "<CMAKE_C_COMPILER> <SOURCE> <DEFINES> <INCLUDES> <FLAGS> --preprocess=cnl <PREPROCESSED_SOURCE>") -set(CMAKE_C_CREATE_ASSEMBLY_SOURCE "<CMAKE_C_COMPILER> <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -lAH <ASSEMBLY_SOURCE> -o <OBJECT>.dummy") - -set(CMAKE_C_RESPONSE_FILE_LINK_FLAG "-f ") -set(CMAKE_DEPFILE_FLAGS_C "--dependencies=ns <DEPFILE>") +include(Compiler/CMakeCommonCompilerMacros) # The toolchains for ARM and AVR are quite different: -if("${IAR_TARGET_ARCHITECTURE}" STREQUAL "ARM") +if("${CMAKE_C_COMPILER_ARCHITECTURE_ID}" STREQUAL "ARM") - set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_LINKER> <OBJECTS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES> -o <TARGET>") - set(CMAKE_C_CREATE_STATIC_LIBRARY "<CMAKE_AR> <TARGET> --create <LINK_FLAGS> <OBJECTS> ") + set(CMAKE_C_EXTENSION_COMPILE_OPTION -e) -endif() + set(CMAKE_C90_STANDARD_COMPILE_OPTION "") + set(CMAKE_C90_EXTENSION_COMPILE_OPTION -e) + if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 6.10) + set(CMAKE_C90_STANDARD_COMPILE_OPTION --c89) + set(CMAKE_C90_EXTENSION_COMPILE_OPTION --c89 -e) + set(CMAKE_C99_STANDARD_COMPILE_OPTION "") + set(CMAKE_C99_EXTENSION_COMPILE_OPTION -e) + endif() + if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 8.10) + set(CMAKE_C11_STANDARD_COMPILE_OPTION "") + set(CMAKE_C11_EXTENSION_COMPILE_OPTION -e) + endif() -if("${IAR_TARGET_ARCHITECTURE}" STREQUAL "AVR") + __compiler_iar_ARM(C) + __compiler_check_default_language_standard(C 1.10 90 6.10 99 8.10 11) + +elseif("${CMAKE_C_COMPILER_ARCHITECTURE_ID}" STREQUAL "AVR") + __compiler_iar_AVR(C) set(CMAKE_C_OUTPUT_EXTENSION ".r90") if(NOT CMAKE_C_LINK_FLAGS) @@ -29,9 +36,8 @@ if("${IAR_TARGET_ARCHITECTURE}" STREQUAL "AVR") set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_LINKER> <OBJECTS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES> -o <TARGET>") set(CMAKE_C_CREATE_STATIC_LIBRARY "<CMAKE_AR> -o <TARGET> <OBJECTS> ") + # add the target specific include directory: + get_filename_component(_compilerDir "${CMAKE_C_COMPILER}" PATH) + get_filename_component(_compilerDir "${_compilerDir}" PATH) + include_directories("${_compilerDir}/inc" ) endif() - -# add the target specific include directory: -get_filename_component(_compilerDir "${CMAKE_C_COMPILER}" PATH) -get_filename_component(_compilerDir "${_compilerDir}" PATH) -include_directories("${_compilerDir}/inc" ) diff --git a/Modules/Compiler/IAR-CXX.cmake b/Modules/Compiler/IAR-CXX.cmake index f49968e..8d86100 100644 --- a/Modules/Compiler/IAR-CXX.cmake +++ b/Modules/Compiler/IAR-CXX.cmake @@ -1,24 +1,41 @@ # This file is processed when the IAR compiler is used for a C++ file include(Compiler/IAR) +include(Compiler/CMakeCommonCompilerMacros) + +if("${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" STREQUAL "ARM") + # "(extended) embedded C++" Mode + # old version: --ec++ or --eec++ + # since 8.10: --c++ --no_exceptions --no_rtti + # + # --c++ is full C++ and supported since 6.10 + if(NOT CMAKE_IAR_CXX_FLAG) + if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.10) + set(CMAKE_IAR_CXX_FLAG --c++) + else() + set(CMAKE_IAR_CXX_FLAG --eec++) + endif() + endif() -set(CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT>") - -set(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE "<CMAKE_CXX_COMPILER> <SOURCE> <DEFINES> <INCLUDES> <FLAGS> --preprocess=cnl <PREPROCESSED_SOURCE>") -set(CMAKE_CXX_CREATE_ASSEMBLY_SOURCE "<CMAKE_CXX_COMPILER> <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -lAH <ASSEMBLY_SOURCE> -o <OBJECT>.dummy") - -set(CMAKE_CXX_RESPONSE_FILE_LINK_FLAG "-f ") -set(CMAKE_DEPFILE_FLAGS_CXX "--dependencies=ns <DEPFILE>") - -if("${IAR_TARGET_ARCHITECTURE}" STREQUAL "ARM") + set(CMAKE_CXX_EXTENSION_COMPILE_OPTION -e) - set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_LINKER> <OBJECTS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES> -o <TARGET>") - set(CMAKE_CXX_CREATE_STATIC_LIBRARY "<CMAKE_AR> <TARGET> --create <LINK_FLAGS> <OBJECTS> ") + set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "") + set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION -e) -endif() + if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.10) + set(CMAKE_CXX03_STANDARD_COMPILE_OPTION "") + set(CMAKE_CXX03_EXTENSION_COMPILE_OPTION -e) + set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "") + set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION -e) + set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "") + set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION -e) + endif() + __compiler_iar_ARM(CXX) + __compiler_check_default_language_standard(CXX 6.10 98 8.10 14) -if("${IAR_TARGET_ARCHITECTURE}" STREQUAL "AVR") +elseif("${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" STREQUAL "AVR") + __compiler_iar_AVR(CXX) set(CMAKE_CXX_OUTPUT_EXTENSION ".r90") if(NOT CMAKE_CXX_LINK_FLAGS) set(CMAKE_CXX_LINK_FLAGS "-Fmotorola") @@ -27,9 +44,8 @@ if("${IAR_TARGET_ARCHITECTURE}" STREQUAL "AVR") set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_LINKER> <OBJECTS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES> -o <TARGET>") set(CMAKE_CXX_CREATE_STATIC_LIBRARY "<CMAKE_AR> -o <TARGET> <OBJECTS> ") + # add the target specific include directory: + get_filename_component(_compilerDir "${CMAKE_C_COMPILER}" PATH) + get_filename_component(_compilerDir "${_compilerDir}" PATH) + include_directories("${_compilerDir}/inc") endif() - -# add the target specific include directory: -get_filename_component(_compilerDir "${CMAKE_C_COMPILER}" PATH) -get_filename_component(_compilerDir "${_compilerDir}" PATH) -include_directories("${_compilerDir}/inc") diff --git a/Modules/Compiler/IAR-DetermineCompiler.cmake b/Modules/Compiler/IAR-DetermineCompiler.cmake index c39810a..4ef587b 100644 --- a/Modules/Compiler/IAR-DetermineCompiler.cmake +++ b/Modules/Compiler/IAR-DetermineCompiler.cmake @@ -1,4 +1,18 @@ - # IAR Systems compiler for embedded systems. # http://www.iar.com -set(_compiler_id_pp_test "defined(__IAR_SYSTEMS_ICC__ ) || defined(__IAR_SYSTEMS_ICC)") +# http://supp.iar.com/FilesPublic/UPDINFO/004916/arm/doc/EWARM_DevelopmentGuide.ENU.pdf +# +# __IAR_SYSTEMS_ICC__ An integer that identifies the IAR compiler platform. The current value is 8. Note that +# the number could be higher in a future version of the product +# __ICCARM__ An integer that is set to 1 when the code is compiled with the IAR C/C++ Compiler for ARM +# __VER__ An integer that identifies the version number of the IAR compiler in use. For example, +# version 5.11.3 is returned as 5011003. + +set(_compiler_id_pp_test "defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC)") + +set(_compiler_id_version_compute " +# if defined(__VER__) +# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@((__VER__) / 1000000) +# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(((__VER__) / 1000) % 1000) +# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@((__VER__) % 1000) +# endif") diff --git a/Modules/Compiler/IAR-FindBinUtils.cmake b/Modules/Compiler/IAR-FindBinUtils.cmake new file mode 100644 index 0000000..2b04795 --- /dev/null +++ b/Modules/Compiler/IAR-FindBinUtils.cmake @@ -0,0 +1,54 @@ +if(NOT DEFINED _CMAKE_PROCESSING_LANGUAGE OR _CMAKE_PROCESSING_LANGUAGE STREQUAL "") + message(FATAL_ERROR "Internal error: _CMAKE_PROCESSING_LANGUAGE is not set") +endif() + +# Try to find tools in the same directory as Clang itself +get_filename_component(__iar_hint_1 "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER}" REALPATH) +get_filename_component(__iar_hint_1 "${__iar_hint_1}" DIRECTORY) + +get_filename_component(__iar_hint_2 "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER}" DIRECTORY) + +set(__iar_hints "${__iar_hint_1}" "${__iar_hint_2}") + +if("${CMAKE_C_COMPILER_ARCHITECTURE_ID}" STREQUAL "ARM") + # could allow using normal binutils ar, since objects are normal ELF files? + find_program(CMAKE_IAR_LINKARM ilinkarm.exe HINTS ${__iar_hints} + DOC "The IAR ARM linker") + find_program(CMAKE_IAR_ARCHIVE iarchive.exe HINTS ${__iar_hints} + DOC "The IAR archiver") + + # find auxillary tools + find_program(CMAKE_IAR_ELFTOOL ielftool.exe HINTS ${__iar_hints} + DOC "The IAR ELF Tool") + find_program(CMAKE_IAR_ELFDUMP ielfdumparm.exe HINTS ${__iar_hints} + DOC "The IAR ELF Dumper") + find_program(CMAKE_IAR_OBJMANIP iobjmanip.exe HINTS ${__iar_hints} + DOC "The IAR ELF Object Tool") + find_program(CMAKE_IAR_SYMEXPORT isymexport.exe HINTS ${__iar_hints} + DOC "The IAR Absolute Symbol Exporter") + mark_as_advanced(CMAKE_IAR_LINKARM CMAKE_IAR_ARCHIVE CMAKE_IAR_ELFTOOL CMAKE_IAR_ELFDUMP CMAKE_IAR_OBJMANIP CMAKE_IAR_SYMEXPORT) + + set(CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_CUSTOM_CODE +"set(CMAKE_IAR_LINKARM \"${CMAKE_IAR_LINKARM}\") +set(CMAKE_IAR_ARCHIVE \"${CMAKE_IAR_ARCHIVE}\") +set(CMAKE_IAR_ELFTOOL \"${CMAKE_IAR_ELFTOOL}\") +set(CMAKE_IAR_ELFDUMP \"${CMAKE_IAR_ELFDUMP}\") +set(CMAKE_IAR_OBJMANIP \"${CMAKE_IAR_OBJMANIP}\") +set(CMAKE_IAR_LINKARM \"${CMAKE_IAR_LINKARM}\") +") + + +elseif("${CMAKE_C_COMPILER_ARCHITECTURE_ID}" STREQUAL "AVR") + + # For AVR and AVR32, IAR uses the "xlink" linker and the "xar" archiver: + find_program(CMAKE_IAR_LINKER xlink.exe HINTS ${__iar_hints} + DOC "The IAR AVR linker") + find_program(CMAKE_IAR_AR xar.exe HINTS ${__iar_hints} + DOC "The IAR archiver") + mark_as_advanced(CMAKE_IAR_LINKER CMAKE_IAR_AR) + + set(CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_CUSTOM_CODE +"set(CMAKE_IAR_LINKER \"${CMAKE_IAR_LINKER}\") +set(CMAKE_IAR_AR \"${CMAKE_IAR_AR}\") +") +endif() diff --git a/Modules/Compiler/IAR.cmake b/Modules/Compiler/IAR.cmake index 8c45276..52ebaf2 100644 --- a/Modules/Compiler/IAR.cmake +++ b/Modules/Compiler/IAR.cmake @@ -2,46 +2,75 @@ # Documentation can be downloaded here: http://www.iar.com/website1/1.0.1.0/675/1/ # The initial feature request is here: https://gitlab.kitware.com/cmake/cmake/issues/10176 # It also contains additional links and information. +# See USER GUIDES -> C/C++ Development Guide and ReleaseNotes for: +# version 6.30.8: http://supp.iar.com/FilesPublic/UPDINFO/006607/arm/doc/infocenter/index.ENU.html +# version 7.60.1: http://supp.iar.com/FilesPublic/UPDINFO/011006/arm/doc/infocenter/index.ENU.html +# version 8.10.1: http://netstorage.iar.com/SuppDB/Public/UPDINFO/011854/arm/doc/infocenter/index.ENU.html -if(_IAR_CMAKE_LOADED) +# C/C++ Standard versions +# +# IAR typically only supports one C and C++ Standard version, +# the exception is C89 which is always supported and can be selected +# if its not the default +# +# C++ is trickier, there were historically 3 switches, +# and some IAR versions support multiple of those. +# they are --eec++, --ec++ and --c++ and where used to +# enable various language features like exceptions +# +# recent versions only have --c++ for full support +# but can choose to disable features with further arguments +# +# C/C++ Standard compliance +# +# IAR has 3 modes: default, strict and extended +# the extended mode is needed for popular libraries like CMSIS +# +# "Silent" Operation +# +# this really is different to most programs I know. +# nothing meaningfull from the operation is lost, just some redundant +# code and data size printouts (that can be inspected with common tools). + +# This module is shared by multiple languages; use include blocker. +if(_IARARM_CMAKE_LOADED) return() endif() -set(_IAR_CMAKE_LOADED TRUE) +set(_IARARM_CMAKE_LOADED 1) +macro(__compiler_iar_ARM lang) + set(CMAKE_EXECUTABLE_SUFFIX ".elf") + if (${lang} STREQUAL "C" OR ${lang} STREQUAL "CXX") -get_filename_component(_CMAKE_C_TOOLCHAIN_LOCATION "${CMAKE_C_COMPILER}" PATH) -get_filename_component(_CMAKE_CXX_TOOLCHAIN_LOCATION "${CMAKE_CXX_COMPILER}" PATH) -get_filename_component(_CMAKE_ASM_TOOLCHAIN_LOCATION "${CMAKE_ASM_COMPILER}" PATH) + set(CMAKE_${lang}_COMPILE_OBJECT "<CMAKE_${lang}_COMPILER> ${CMAKE_IAR_${lang}_FLAG} --silent <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT>") + set(CMAKE_${lang}_CREATE_PREPROCESSED_SOURCE "<CMAKE_${lang}_COMPILER> ${CMAKE_IAR_${lang}_FLAG} --silent <SOURCE> <DEFINES> <INCLUDES> <FLAGS> --preprocess=cnl <PREPROCESSED_SOURCE>") + set(CMAKE_${lang}_CREATE_ASSEMBLY_SOURCE "<CMAKE_${lang}_COMPILER> ${CMAKE_IAR_${lang}_FLAG} --silent <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -lAH <ASSEMBLY_SOURCE> -o <OBJECT>.dummy") + set(CMAKE_${lang}_RESPONSE_FILE_LINK_FLAG "-f ") + set(CMAKE_DEPFILE_FLAGS_${lang} "--dependencies=ns <DEPFILE>") -if("${CMAKE_C_COMPILER}" MATCHES "arm" OR "${CMAKE_CXX_COMPILER}" MATCHES "arm" OR "${CMAKE_ASM_COMPILER}" MATCHES "arm") - set(CMAKE_EXECUTABLE_SUFFIX ".elf") + string(APPEND CMAKE_${lang}_FLAGS_INIT " ") + string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " -r") + string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " -Ohz -DNDEBUG") + string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -Oh -DNDEBUG") + string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " -Oh -r -DNDEBUG") + endif() - # For arm, IAR uses the "ilinkarm" linker and "iarchive" archiver: - find_program(CMAKE_IAR_LINKER ilinkarm HINTS "${_CMAKE_C_TOOLCHAIN_LOCATION}" "${_CMAKE_CXX_TOOLCHAIN_LOCATION}" "${_CMAKE_ASM_TOOLCHAIN_LOCATION}") - find_program(CMAKE_IAR_AR iarchive HINTS "${_CMAKE_C_TOOLCHAIN_LOCATION}" "${_CMAKE_CXX_TOOLCHAIN_LOCATION}" "${_CMAKE_ASM_TOOLCHAIN_LOCATION}" ) + set(CMAKE_${lang}_LINK_EXECUTABLE "\"${CMAKE_IAR_LINKARM}\" --silent <OBJECTS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES> -o <TARGET>") + set(CMAKE_${lang}_CREATE_STATIC_LIBRARY "\"${CMAKE_IAR_ARCHIVE}\" <TARGET> --create <LINK_FLAGS> <OBJECTS>") + set(CMAKE_${lang}_ARCHIVE_CREATE "\"${CMAKE_IAR_ARCHIVE}\" <TARGET> --create <LINK_FLAGS> <OBJECTS>") + set(CMAKE_${lang}_ARCHIVE_APPEND "\"${CMAKE_IAR_ARCHIVE}\" <TARGET> --replace <LINK_FLAGS> <OBJECTS>") + set(CMAKE_${lang}_ARCHIVE_FINISH "") - set(IAR_TARGET_ARCHITECTURE "ARM" CACHE STRING "IAR compiler target architecture") -endif() + set(CMAKE_LINKER "${CMAKE_IAR_LINKARM}" CACHE FILEPATH "The IAR linker" FORCE) + set(CMAKE_AR "${CMAKE_IAR_ARCHIVE}" CACHE FILEPATH "The IAR archiver" FORCE) +endmacro() -if("${CMAKE_C_COMPILER}" MATCHES "avr" OR "${CMAKE_CXX_COMPILER}" MATCHES "avr" OR "${CMAKE_ASM_COMPILER}" MATCHES "avr") +macro(__compiler_iar_AVR lang) set(CMAKE_EXECUTABLE_SUFFIX ".bin") - # For AVR and AVR32, IAR uses the "xlink" linker and the "xar" archiver: - find_program(CMAKE_IAR_LINKER xlink HINTS "${_CMAKE_C_TOOLCHAIN_LOCATION}" "${_CMAKE_CXX_TOOLCHAIN_LOCATION}" "${_CMAKE_ASM_TOOLCHAIN_LOCATION}" ) - find_program(CMAKE_IAR_AR xar HINTS "${_CMAKE_C_TOOLCHAIN_LOCATION}" "${_CMAKE_CXX_TOOLCHAIN_LOCATION}" "${_CMAKE_ASM_TOOLCHAIN_LOCATION}" ) - - set(IAR_TARGET_ARCHITECTURE "AVR" CACHE STRING "IAR compiler target architecture") - set(CMAKE_LIBRARY_PATH_FLAG "-I") -endif() - -if(NOT IAR_TARGET_ARCHITECTURE) - message(FATAL_ERROR "The IAR compiler for this architecture is not yet supported " - "by CMake. Please go to https://gitlab.kitware.com/cmake/cmake/issues " - "and enter a feature request there.") -endif() - -set(CMAKE_LINKER "${CMAKE_IAR_LINKER}" CACHE FILEPATH "The IAR linker" FORCE) -set(CMAKE_AR "${CMAKE_IAR_AR}" CACHE FILEPATH "The IAR archiver" FORCE) + set(CMAKE_LINKER "${CMAKE_IAR_LINKER}" CACHE FILEPATH "The IAR linker" FORCE) + set(CMAKE_AR "${CMAKE_IAR_AR}" CACHE FILEPATH "The IAR archiver" FORCE) +endmacro() diff --git a/Modules/Compiler/MSVC-CXX.cmake b/Modules/Compiler/MSVC-CXX.cmake index 9371301..f478b85 100644 --- a/Modules/Compiler/MSVC-CXX.cmake +++ b/Modules/Compiler/MSVC-CXX.cmake @@ -3,7 +3,25 @@ include(Compiler/CMakeCommonCompilerMacros) -if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16.0) +if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.10.25017) + # VS 2015 Update 3 and above support language standard level flags, + # with the default and minimum level being C++14. + set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "") + set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "") + set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "") + set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "") + set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std:c++14") + set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std:c++14") + if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.11.25505) + set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "-std:c++17") + set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-std:c++17") + else() + set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "-std:c++latest") + set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-std:c++latest") + endif() + + __compiler_check_default_language_standard(CXX 19.0 14) +elseif (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16.0) # MSVC has no specific options to set language standards, but set them as # empty strings anyways so the feature test infrastructure can at least check # to see if they are defined. diff --git a/Modules/DartConfiguration.tcl.in b/Modules/DartConfiguration.tcl.in index 0ff2eed..b86a5a9 100644 --- a/Modules/DartConfiguration.tcl.in +++ b/Modules/DartConfiguration.tcl.in @@ -16,6 +16,9 @@ Site: @SITE@ # Build name is osname-revision-compiler, i.e. Linux-2.4.2-2smp-c++ BuildName: @BUILDNAME@ +# Subprojects +LabelsForSubprojects: @CTEST_LABELS_FOR_SUBPROJECTS@ + # Submission information IsCDash: @CTEST_DROP_SITE_CDASH@ CDashVersion: @CTEST_CDASH_VERSION@ diff --git a/Modules/ExternalProject.cmake b/Modules/ExternalProject.cmake index 2495736..d92eb5f 100644 --- a/Modules/ExternalProject.cmake +++ b/Modules/ExternalProject.cmake @@ -5,413 +5,860 @@ ExternalProject --------------- -Create custom targets to build projects in external trees +.. only:: html + + .. contents:: + +External Project Definition +^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. command:: ExternalProject_Add - The ``ExternalProject_Add`` function creates a custom target to drive + The ``ExternalProject_Add()`` function creates a custom target to drive download, update/patch, configure, build, install and test steps of an external project:: - ExternalProject_Add(<name> [<option>...]) - - General options are: - - ``DEPENDS <projects>...`` - Targets on which the project depends - ``PREFIX <dir>`` - Root dir for entire project - ``LIST_SEPARATOR <sep>`` - Sep to be replaced by ; in cmd lines - ``TMP_DIR <dir>`` - Directory to store temporary files - ``STAMP_DIR <dir>`` - Directory to store step timestamps - ``EXCLUDE_FROM_ALL 1`` - The "all" target does not depend on this - - Download step options are: - - ``DOWNLOAD_NAME <fname>`` - File name to store (if not end of URL) - ``DOWNLOAD_DIR <dir>`` - Directory to store downloaded files - ``DOWNLOAD_COMMAND <cmd>...`` - Command to download source tree - ``DOWNLOAD_NO_PROGRESS 1`` - Disable download progress reports - ``CVS_REPOSITORY <cvsroot>`` - CVSROOT of CVS repository - ``CVS_MODULE <mod>`` - Module to checkout from CVS repo - ``CVS_TAG <tag>`` - Tag to checkout from CVS repo - ``SVN_REPOSITORY <url>`` - URL of Subversion repo - ``SVN_REVISION -r<rev>`` - Revision to checkout from Subversion repo - ``SVN_USERNAME <username>`` - Username for Subversion checkout and update - ``SVN_PASSWORD <password>`` - Password for Subversion checkout and update - ``SVN_TRUST_CERT 1`` - Trust the Subversion server site certificate - ``GIT_REPOSITORY <url>`` - URL of git repo - ``GIT_TAG <tag>`` - Git branch name, commit id or tag - ``GIT_REMOTE_NAME <name>`` - The optional name of the remote, default to ``origin`` - ``GIT_SUBMODULES <module>...`` - Git submodules that shall be updated, all if empty - ``GIT_SHALLOW 1`` - Tell Git to clone with ``--depth 1``. Use when ``GIT_TAG`` is not - specified or when it names a branch in order to download only the - tip of the branch without the rest of its history. - ``GIT_PROGRESS 1`` - Tell Git to clone with ``--progress``. For large projects, the clone step - does not output anything which can make the build appear to have stalled. - This option forces Git to output progress information during the clone step - so that forward progress is indicated. - ``GIT_CONFIG <option>...`` - Tell Git to clone with ``--config <option>``. Use additional configuration - parameters when cloning the project (``key=value`` as expected by ``git - config``). - ``HG_REPOSITORY <url>`` - URL of mercurial repo - ``HG_TAG <tag>`` - Mercurial branch name, commit id or tag - ``URL /.../src.tgz [/.../src.tgz]...`` - Full path or URL(s) of source. Multiple URLs are allowed as mirrors. - ``URL_HASH ALGO=value`` - Hash of file at URL - ``URL_MD5 md5`` - Equivalent to URL_HASH MD5=md5 - ``HTTP_USERNAME <username>`` - Username for download operation - ``HTTP_PASSWORD <username>`` - Password for download operation - ``HTTP_HEADER <header>`` - HTTP header for download operation. Suboption can be repeated several times. - ``TLS_VERIFY <bool>`` - Should certificate for https be checked - ``TLS_CAINFO <file>`` - Path to a certificate authority file - ``TIMEOUT <seconds>`` - Time allowed for file download operations - ``DOWNLOAD_NO_EXTRACT 1`` - Just download the file and do not extract it; the full path to the - downloaded file is available as ``<DOWNLOADED_FILE>``. - - Update/Patch step options are: - - ``UPDATE_COMMAND <cmd>...`` - Source work-tree update command - ``UPDATE_DISCONNECTED 1`` - Never update automatically from the remote repository - ``PATCH_COMMAND <cmd>...`` - Command to patch downloaded source - - Configure step options are: - - ``SOURCE_DIR <dir>`` - Source dir to be used for build - ``SOURCE_SUBDIR <dir>`` - Path to source CMakeLists.txt relative to ``SOURCE_DIR`` - ``CONFIGURE_COMMAND <cmd>...`` - Build tree configuration command - ``CMAKE_COMMAND /.../cmake`` - Specify alternative cmake executable - ``CMAKE_GENERATOR <gen>`` - Specify generator for native build - ``CMAKE_GENERATOR_PLATFORM <platform>`` - Generator-specific platform name - ``CMAKE_GENERATOR_TOOLSET <toolset>`` - Generator-specific toolset name - ``CMAKE_ARGS <arg>...`` - Arguments to CMake command line. - These arguments are passed to CMake command line, and can contain - arguments other than cache values, see also - :manual:`CMake Options <cmake(1)>`. Arguments in the form - ``-Dvar:string=on`` are always passed to the command line, and - therefore cannot be changed by the user. - Arguments may use - :manual:`generator expressions <cmake-generator-expressions(7)>`. - ``CMAKE_CACHE_ARGS <arg>...`` - Initial cache arguments, of the form ``-Dvar:string=on``. - These arguments are written in a pre-load a script that populates - CMake cache, see also :manual:`cmake -C <cmake(1)>`. This allows one to - overcome command line length limits. - These arguments are :command:`set` using the ``FORCE`` argument, - and therefore cannot be changed by the user. - Arguments may use - :manual:`generator expressions <cmake-generator-expressions(7)>`. - ``CMAKE_CACHE_DEFAULT_ARGS <arg>...`` - Initial default cache arguments, of the form ``-Dvar:string=on``. - These arguments are written in a pre-load a script that populates - CMake cache, see also :manual:`cmake -C <cmake(1)>`. This allows one to - overcome command line length limits. - These arguments can be used as default value that will be set if no - previous value is found in the cache, and that the user can change - later. - Arguments may use - :manual:`generator expressions <cmake-generator-expressions(7)>`. - - Build step options are: - - ``BINARY_DIR <dir>`` - Specify build dir location - ``BUILD_COMMAND <cmd>...`` - Command to drive the native build - ``BUILD_IN_SOURCE 1`` - Use source dir for build dir - ``BUILD_ALWAYS 1`` - No stamp file, build step always runs - ``BUILD_BYPRODUCTS <file>...`` - Files that will be generated by the build command but may or may - not have their modification time updated by subsequent builds. - - Install step options are: - - ``INSTALL_DIR <dir>`` - Installation prefix to be placed in the ``<INSTALL_DIR>`` placeholder. - This does not actually configure the external project to install to - the given prefix. That must be done by passing appropriate arguments - to the external project configuration step, e.g. using ``<INSTALL_DIR>``. - ``INSTALL_COMMAND <cmd>...`` - Command to drive installation of the external project after it has been - built. This only happens at the *build* time of the calling project. - In order to install files from the external project alongside the - locally-built files, a separate local :command:`install` call must be - added to pick the files up from one of the external project trees. - - Test step options are: - - ``TEST_BEFORE_INSTALL 1`` - Add test step executed before install step - ``TEST_AFTER_INSTALL 1`` - Add test step executed after install step - ``TEST_EXCLUDE_FROM_MAIN 1`` - Main target does not depend on the test step - ``TEST_COMMAND <cmd>...`` - Command to drive test - - Output logging options are: - - ``LOG_DOWNLOAD 1`` - Wrap download in script to log output - ``LOG_UPDATE 1`` - Wrap update in script to log output - ``LOG_CONFIGURE 1`` - Wrap configure in script to log output - ``LOG_BUILD 1`` - Wrap build in script to log output - ``LOG_TEST 1`` - Wrap test in script to log output - ``LOG_INSTALL 1`` - Wrap install in script to log output - - Steps can be given direct access to the terminal if possible. With - the :generator:`Ninja` generator, this places the steps in the - ``console`` :prop_gbl:`pool <JOB_POOLS>`. Options are: - - ``USES_TERMINAL_DOWNLOAD 1`` - Give download terminal access. - ``USES_TERMINAL_UPDATE 1`` - Give update terminal access. - ``USES_TERMINAL_CONFIGURE 1`` - Give configure terminal access. - ``USES_TERMINAL_BUILD 1`` - Give build terminal access. - ``USES_TERMINAL_TEST 1`` - Give test terminal access. - ``USES_TERMINAL_INSTALL 1`` - Give install terminal access. - - Other options are: - - ``STEP_TARGETS <step-target>...`` - Generate custom targets for these steps - ``INDEPENDENT_STEP_TARGETS <step-target>...`` - Generate custom targets for these steps that do not depend on other - external projects even if a dependency is set - - The ``*_DIR`` options specify directories for the project, with default - directories computed as follows. If the ``PREFIX`` option is given to - ``ExternalProject_Add()`` or the ``EP_PREFIX`` directory property is set, - then an external project is built and installed under the specified prefix:: - - TMP_DIR = <prefix>/tmp - STAMP_DIR = <prefix>/src/<name>-stamp - DOWNLOAD_DIR = <prefix>/src - SOURCE_DIR = <prefix>/src/<name> - BINARY_DIR = <prefix>/src/<name>-build - INSTALL_DIR = <prefix> - - Otherwise, if the ``EP_BASE`` directory property is set then components - of an external project are stored under the specified base:: - - TMP_DIR = <base>/tmp/<name> - STAMP_DIR = <base>/Stamp/<name> - DOWNLOAD_DIR = <base>/Download/<name> - SOURCE_DIR = <base>/Source/<name> - BINARY_DIR = <base>/Build/<name> - INSTALL_DIR = <base>/Install/<name> - - If no ``PREFIX``, ``EP_PREFIX``, or ``EP_BASE`` is specified then the - default is to set ``PREFIX`` to ``<name>-prefix``. Relative paths are - interpreted with respect to the build directory corresponding to the - source directory in which ``ExternalProject_Add`` is invoked. - - If ``SOURCE_SUBDIR`` is set and no ``CONFIGURE_COMMAND`` is specified, the - configure command will run CMake using the ``CMakeLists.txt`` located in the - relative path specified by ``SOURCE_SUBDIR``, relative to the ``SOURCE_DIR``. - If no ``SOURCE_SUBDIR`` is given, ``SOURCE_DIR`` is used. - - If ``SOURCE_DIR`` is explicitly set to an existing directory the project - will be built from it. Otherwise a download step must be specified - using one of the ``DOWNLOAD_COMMAND``, ``CVS_*``, ``SVN_*``, or ``URL`` - options. The ``URL`` option may refer locally to a directory or source - tarball, or refer to a remote tarball (e.g. ``http://.../src.tgz``). - - If ``UPDATE_DISCONNECTED`` is set, the update step is not executed - automatically when building the main target. The update step can still - be added as a step target and called manually. This is useful if you - want to allow one to build the project when you are disconnected from the - network (you might still need the network for the download step). - This is disabled by default. - The directory property ``EP_UPDATE_DISCONNECTED`` can be used to change - the default value for all the external projects in the current - directory and its subdirectories. + ExternalProject_Add(<name> [<option>...]) + + The individual steps within the process can be driven independently if + required (e.g. for CDash submission) and extra custom steps can be defined, + along with the ability to control the step dependencies. The directory + structure used for the management of the external project can also be + customized. The function supports a large number of options which can be used + to tailor the external project behavior. + + **Directory Options:** + Most of the time, the default directory layout is sufficient. It is largely + an implementation detail that the main project usually doesn't need to + change. In some circumstances, however, control over the directory layout + can be useful or necessary. The directory options are potentially more + useful from the point of view that the main build can use the + :command:`ExternalProject_Get_Property` command to retrieve their values, + thereby allowing the main project to refer to build artifacts of the + external project. + + ``PREFIX <dir>`` + Root directory for the external project. Unless otherwise noted below, + all other directories associated with the external project will be + created under here. + + ``TMP_DIR <dir>`` + Directory in which to store temporary files. + + ``STAMP_DIR <dir>`` + Directory in which to store the timestamps of each step. Log files from + individual steps are also created in here (see *Logging Options* below). + + ``DOWNLOAD_DIR <dir>`` + Directory in which to store downloaded files before unpacking them. This + directory is only used by the URL download method, all other download + methods use ``SOURCE_DIR`` directly instead. + + ``SOURCE_DIR <dir>`` + Source directory into which downloaded contents will be unpacked, or for + non-URL download methods, the directory in which the repository should be + checked out, cloned, etc. If no download method is specified, this must + point to an existing directory where the external project has already + been unpacked or cloned/checked out. + + .. note:: + If a download method is specified, any existing contents of the source + directory may be deleted. Only the URL download method checks whether + this directory is either missing or empty before initiating the + download, stopping with an error if it is not empty. All other + download methods silently discard any previous contents of the source + directory. + + ``BINARY_DIR <dir>`` + Specify the build directory location. This option is ignored if + ``BUILD_IN_SOURCE`` is enabled. + + ``INSTALL_DIR <dir>`` + Installation prefix to be placed in the ``<INSTALL_DIR>`` placeholder. + This does not actually configure the external project to install to + the given prefix. That must be done by passing appropriate arguments + to the external project configuration step, e.g. using ``<INSTALL_DIR>``. + + If any of the above ``..._DIR`` options are not specified, their defaults + are computed as follows. If the ``PREFIX`` option is given or the + ``EP_PREFIX`` directory property is set, then an external project is built + and installed under the specified prefix:: + + TMP_DIR = <prefix>/tmp + STAMP_DIR = <prefix>/src/<name>-stamp + DOWNLOAD_DIR = <prefix>/src + SOURCE_DIR = <prefix>/src/<name> + BINARY_DIR = <prefix>/src/<name>-build + INSTALL_DIR = <prefix> + + Otherwise, if the ``EP_BASE`` directory property is set then components + of an external project are stored under the specified base:: + + TMP_DIR = <base>/tmp/<name> + STAMP_DIR = <base>/Stamp/<name> + DOWNLOAD_DIR = <base>/Download/<name> + SOURCE_DIR = <base>/Source/<name> + BINARY_DIR = <base>/Build/<name> + INSTALL_DIR = <base>/Install/<name> + + If no ``PREFIX``, ``EP_PREFIX``, or ``EP_BASE`` is specified, then the + default is to set ``PREFIX`` to ``<name>-prefix``. Relative paths are + interpreted with respect to :variable:`CMAKE_CURRENT_BINARY_DIR` at the + point where ``ExternalProject_Add()`` is called. + + **Download Step Options:** + A download method can be omitted if the ``SOURCE_DIR`` option is used to + point to an existing non-empty directory. Otherwise, one of the download + methods below must be specified (multiple download methods should not be + given) or a custom ``DOWNLOAD_COMMAND`` provided. + + ``DOWNLOAD_COMMAND <cmd>...`` + Overrides the command used for the download step + (:manual:`generator expressions <cmake-generator-expressions(7)>` are + supported). If this option is specified, all other download options will + be ignored. Providing an empty string for ``<cmd>`` effectively disables + the download step. + + *URL Download* + ``URL <url1> [<url2>...]`` + List of paths and/or URL(s) of the external project's source. When more + than one URL is given, they are tried in turn until one succeeds. A URL + may be an ordinary path in the local file system (in which case it + must be the only URL provided) or any downloadable URL supported by the + :command:`file(DOWNLOAD)` command. A local filesystem path may refer to + either an existing directory or to an archive file, whereas a URL is + expected to point to a file which can be treated as an archive. When an + archive is used, it will be unpacked automatically unless the + ``DOWNLOAD_NO_EXTRACT`` option is set to prevent it. The archive type + is determined by inspecting the actual content rather than using logic + based on the file extension. + + ``URL_HASH ALGO=<value>`` + Hash of the archive file to be downloaded. The ``<value>`` should be of + the form ``algo=hashValue`` where ``algo`` can be any of the hashing + algorithms supported by the :command:`file()` command. Specifying this + option is strongly recommended for URL downloads, as it ensures the + integrity of the downloaded content. It is also used as a check for a + previously downloaded file, allowing connection to the remote location + to be avoided altogether if the local directory already has a file from + an earlier download that matches the specified hash. + + ``URL_MD5 <md5>`` + Equivalent to ``URL_HASH MD5=<md5>``. + + ``DOWNLOAD_NAME <fname>`` + File name to use for the downloaded file. If not given, the end of the + URL is used to determine the file name. This option is rarely needed, + the default name is generally suitable and is not normally used outside + of code internal to the ``ExternalProject`` module. + + ``DOWNLOAD_NO_EXTRACT <bool>`` + Allows the extraction part of the download step to be disabled by + passing a boolean true value for this option. If this option is not + given, the downloaded contents will be unpacked automatically if + required. If extraction has been disabled, the full path to the + downloaded file is available as ``<DOWNLOADED_FILE>`` in subsequent + steps or as the property ``DOWNLOADED_FILE`` with the + :command:`ExternalProject_Get_Property` command. + + ``DOWNLOAD_NO_PROGRESS <bool>`` + Can be used to disable logging the download progress. If this option is + not given, download progress messages will be logged. + + ``TIMEOUT <seconds>`` + Maximum time allowed for file download operations. + + ``HTTP_USERNAME <username>`` + Username for the download operation if authentication is required. + + ``HTTP_PASSWORD <password>`` + Password for the download operation if authentication is required. + + ``HTTP_HEADER <header1> [<header2>...]`` + Provides an arbitrary list of HTTP headers for the download operation. + This can be useful for accessing content in systems like AWS, etc. + + ``TLS_VERIFY <bool>`` + Specifies whether certificate verification should be performed for + https URLs. If this option is not provided, the default behavior is + determined by the ``CMAKE_TLS_VERIFY`` variable (see + :command:`file(DOWNLOAD)`). If that is also not set, certificate + verification will not be performed. In situations where ``URL_HASH`` + cannot be provided, this option can be an alternative verification + measure. + + ``TLS_CAINFO <file>`` + Specify a custom certificate authority file to use if ``TLS_VERIFY`` + is enabled. If this option is not specified, the value of the + ``CMAKE_TLS_CAINFO`` variable will be used instead (see + :command:`file(DOWNLOAD)`) + + *Git* + NOTE: A git version of 1.6.5 or later is required if this download method + is used. + + ``GIT_REPOSITORY <url>`` + URL of the git repository. Any URL understood by the ``git`` command + may be used. + + ``GIT_TAG <tag>`` + Git branch name, tag or commit hash. Note that branch names and tags + should generally be specified as remote names (i.e. ``origin/myBranch`` + rather than simply ``myBranch``). This ensures that if the remote end + has its tag moved or branch rebased or history rewritten, the local + clone will still be updated correctly. In general, however, specifying + a commit hash should be preferred for a number of reasons: + + - If the local clone already has the commit corresponding to the hash, + no ``git fetch`` needs to be performed to check for changes each time + CMake is re-run. This can result in a significant speed up if many + external projects are being used. + - Using a specific git hash ensures that the main project's own history + is fully traceable to a specific point in the external project's + evolution. If a branch or tag name is used instead, then checking out + a specific commit of the main project doesn't necessarily pin the + whole build to a specific point in the life of the external project. + The lack of such deterministic behavior makes the main project lose + traceability and repeatability. + + ``GIT_REMOTE_NAME <name>`` + The optional name of the remote. If this option is not specified, it + defaults to ``origin``. + + ``GIT_SUBMODULES <module>...`` + Specific git submodules that should also be updated. If this option is + not provided, all git submodules will be updated. + + ``GIT_SHALLOW <bool>`` + When this option is enabled, the ``git clone`` operation will be given + the ``--depth 1`` option. This performs a shallow clone, which avoids + downloading the whole history and instead retrieves just the commit + denoted by the ``GIT_TAG`` option. + + ``GIT_PROGRESS <bool>`` + When enabled, this option instructs the ``git clone`` operation to + report its progress by passing it the ``--progress`` option. Without + this option, the clone step for large projects may appear to make the + build stall, since nothing will be logged until the clone operation + finishes. While this option can be used to provide progress to prevent + the appearance of the build having stalled, it may also make the build + overly noisy if lots of external projects are used. + + ``GIT_CONFIG <option1> [<option2>...]`` + Specify a list of config options to pass to ``git clone``. Each option + listed will be transformed into its own ``--config <option>`` on the + ``git clone`` command line, with each option required to be in the + form ``key=value``. + + *Subversion* + ``SVN_REPOSITORY <url>`` + URL of the Subversion repository. + + ``SVN_REVISION -r<rev>`` + Revision to checkout from the Subversion repository. + + ``SVN_USERNAME <username>`` + Username for the Subversion checkout and update. + + ``SVN_PASSWORD <password>`` + Password for the Subversion checkout and update. + + ``SVN_TRUST_CERT <bool>`` + Specifies whether to trust the Subversion server site certificate. If + enabled, the ``--trust-server-cert`` option is passed to the ``svn`` + checkout and update commands. + + *Mercurial* + ``HG_REPOSITORY <url>`` + URL of the mercurial repository. + + ``HG_TAG <tag>`` + Mercurial branch name, tag or commit id. + + *CVS* + ``CVS_REPOSITORY <cvsroot>`` + CVSROOT of the CVS repository. + + ``CVS_MODULE <mod>`` + Module to checkout from the CVS repository. + + ``CVS_TAG <tag>`` + Tag to checkout from the CVS repository. + + **Update/Patch Step Options:** + Whenever CMake is re-run, by default the external project's sources will be + updated if the download method supports updates (e.g. a git repository + would be checked if the ``GIT_TAG`` does not refer to a specific commit). + + ``UPDATE_COMMAND <cmd>...`` + Overrides the download method's update step with a custom command. + The command may use + :manual:`generator expressions <cmake-generator-expressions(7)>`. + + ``UPDATE_DISCONNECTED <bool>`` + When enabled, this option causes the update step to be skipped. It does + not, however, prevent the download step. The update step can still be + added as a step target (see :command:`ExternalProject_Add_StepTargets`) + and called manually. This is useful if you want to allow developers to + build the project when disconnected from the network (the network may + still be needed for the download step though). + + When this option is present, it is generally advisable to make the value + a cache variable under the developer's control rather than hard-coding + it. If this option is not present, the default value is taken from the + ``EP_UPDATE_DISCONNECTED`` directory property. If that is also not + defined, updates are performed as normal. The ``EP_UPDATE_DISCONNECTED`` + directory property is intended as a convenience for controlling the + ``UPDATE_DISCONNECTED`` behavior for an entire section of a project's + directory hierarchy and may be a more convenient method of giving + developers control over whether or not to perform updates (assuming the + project also provides a cache variable or some other convenient method + for setting the directory property). + + ``PATCH_COMMAND <cmd>...`` + Specifies a custom command to patch the sources after an update. By + default, no patch command is defined. Note that it can be quite difficult + to define an appropriate patch command that performs robustly, especially + for download methods such as git where changing the ``GIT_TAG`` will not + discard changes from a previous patch, but the patch command will be + called again after updating to the new tag. + + **Configure Step Options:** + The configure step is run after the download and update steps. By default, + the external project is assumed to be a CMake project, but this can be + overridden if required. + + ``CONFIGURE_COMMAND <cmd>...`` + The default configure command runs CMake with options based on the main + project. For non-CMake external projects, the ``CONFIGURE_COMMAND`` + option must be used to override this behavior + (:manual:`generator expressions <cmake-generator-expressions(7)>` are + supported). For projects that require no configure step, specify this + option with an empty string as the command to execute. + + ``CMAKE_COMMAND /.../cmake`` + Specify an alternative cmake executable for the configure step (use an + absolute path). This is generally not recommended, since it is + usually desirable to use the same CMake version throughout the whole + build. This option is ignored if a custom configure command has been + specified with ``CONFIGURE_COMMAND``. + + ``CMAKE_GENERATOR <gen>`` + Override the CMake generator used for the configure step. Without this + option, the same generator as the main build will be used. This option is + ignored if a custom configure command has been specified with the + ``CONFIGURE_COMMAND`` option. + + ``CMAKE_GENERATOR_PLATFORM <platform>`` + Pass a generator-specific platform name to the CMake command (see + :variable:`CMAKE_GENERATOR_PLATFORM`). It is an error to provide this + option without the ``CMAKE_GENERATOR`` option. + + ``CMAKE_GENERATOR_TOOLSET <toolset>`` + Pass a generator-specific toolset name to the CMake command (see + :variable:`CMAKE_GENERATOR_TOOLSET`). It is an error to provide this + option without the ``CMAKE_GENERATOR`` option. + + ``CMAKE_ARGS <arg>...`` + The specified arguments are passed to the ``cmake`` command line. They + can be any argument the ``cmake`` command understands, not just cache + values defined by ``-D...`` arguments (see also + :manual:`CMake Options <cmake(1)>`). In addition, arguments may use + :manual:`generator expressions <cmake-generator-expressions(7)>`. + + ``CMAKE_CACHE_ARGS <arg>...`` + This is an alternate way of specifying cache variables where command line + length issues may become a problem. The arguments are expected to be in + the form ``-Dvar:STRING=value``, which are then transformed into + CMake :command:`set` commands with the ``FORCE`` option used. These + ``set()`` commands are written to a pre-load script which is then applied + using the :manual:`cmake -C <cmake(1)>` command line option. Arguments + may use :manual:`generator expressions <cmake-generator-expressions(7)>`. + + ``CMAKE_CACHE_DEFAULT_ARGS <arg>...`` + This is the same as the ``CMAKE_CACHE_ARGS`` option except the ``set()`` + commands do not include the ``FORCE`` keyword. This means the values act + as initial defaults only and will not override any variables already set + from a previous run. Use this option with care, as it can lead to + different behavior depending on whether the build starts from a fresh + build directory or re-uses previous build contents. + + ``SOURCE_SUBDIR <dir>`` + When no ``CONFIGURE_COMMAND`` option is specified, the configure step + assumes the external project has a ``CMakeLists.txt`` file at the top of + its source tree (i.e. in ``SOURCE_DIR``). The ``SOURCE_SUBDIR`` option + can be used to point to an alternative directory within the source tree + to use as the top of the CMake source tree instead. This must be a + relative path and it will be interpreted as being relative to + ``SOURCE_DIR``. + + **Build Step Options:** + If the configure step assumed the external project uses CMake as its build + system, the build step will also. Otherwise, the build step will assume a + Makefile-based build and simply run ``make`` with no arguments as the + default build step. This can be overridden with custom build commands if + required. + + ``BUILD_COMMAND <cmd>...`` + Overrides the default build command + (:manual:`generator expressions <cmake-generator-expressions(7)>` are + supported). If this option is not given, the default build command will + be chosen to integrate with the main build in the most appropriate way + (e.g. using recursive ``make`` for Makefile generators or + ``cmake --build`` if the project uses a CMake build). This option can be + specified with an empty string as the command to make the build step do + nothing. + + ``BUILD_IN_SOURCE <bool>`` + When this option is enabled, the build will be done directly within the + external project's source tree. This should generally be avoided, the use + of a separate build directory is usually preferred, but it can be useful + when the external project assumes an in-source build. The ``BINARY_DIR`` + option should not be specified if building in-source. + + ``BUILD_ALWAYS <bool>`` + Enabling this option forces the build step to always be run. This can be + the easiest way to robustly ensure that the external project's own build + dependencies are evaluated rather than relying on the default + success timestamp-based method. This option is not normally needed unless + developers are expected to modify something the external project's build + depends on in a way that is not detectable via the step target + dependencies (e.g. ``SOURCE_DIR`` is used without a download method and + developers might modify the sources in ``SOURCE_DIR``). + + ``BUILD_BYPRODUCTS <file>...`` + Specifies files that will be generated by the build command but which + might or might not have their modification time updated by subsequent + builds. These ultimately get passed through as ``BYPRODUCTS`` to the + build step's own underlying call to :command:`add_custom_command`. + + **Install Step Options:** + If the configure step assumed the external project uses CMake as its build + system, the install step will also. Otherwise, the install step will assume + a Makefile-based build and simply run ``make install`` as the default build + step. This can be overridden with custom install commands if required. + + ``INSTALL_COMMAND <cmd>...`` + The external project's own install step is invoked as part of the main + project's *build*. It is done after the external project's build step + and may be before or after the external project's test step (see the + ``TEST_BEFORE_INSTALL`` option below). The external project's install + rules are not part of the main project's install rules, so if anything + from the external project should be installed as part of the main build, + these need to be specified in the main build as additional + :command:`install` commands. The default install step builds the + ``install`` target of the external project, but this can be overridden + with a custom command using this option + (:manual:`generator expressions <cmake-generator-expressions(7)>` are + supported). Passing an empty string as the ``<cmd>`` makes the install + step do nothing. + + **Test Step Options:** + The test step is only defined if at least one of the following ``TEST_...`` + options are provided. + + ``TEST_COMMAND <cmd>...`` + Overrides the default test command + (:manual:`generator expressions <cmake-generator-expressions(7)>` are + supported). If this option is not given, the default behavior of the test + step is to build the external project's own ``test`` target. This option + can be specified with ``<cmd>`` as an empty string, which allows the test + step to still be defined, but it will do nothing. Do not specify any of + the other ``TEST_...`` options if providing an empty string as the test + command, but prefer to omit all ``TEST_...`` options altogether if the + test step target is not needed. + + ``TEST_BEFORE_INSTALL <bool>`` + When this option is enabled, the test step will be executed before the + install step. The default behavior is for the test step to run after the + install step. + + ``TEST_AFTER_INSTALL <bool>`` + This option is mainly useful as a way to indicate that the test step is + desired but all default behavior is sufficient. Specifying this option + with a boolean true value ensures the test step is defined and that it + comes after the install step. If both ``TEST_BEFORE_INSTALL`` and + ``TEST_AFTER_INSTALL`` are enabled, the latter is silently ignored. + + ``TEST_EXCLUDE_FROM_MAIN <bool>`` + If enabled, the main build's default ALL target will not depend on the + test step. This can be a useful way of ensuring the test step is defined + but only gets invoked when manually requested. + + **Output Logging Options:** + Each of the following ``LOG_...`` options can be used to wrap the relevant + step in a script to capture its output to files. The log files will be + created in the ``STAMP_DIR`` directory with step-specific file names. + + ``LOG_DOWNLOAD <bool>`` + When enabled, the output of the download step is logged to files. + + ``LOG_UPDATE <bool>`` + When enabled, the output of the update step is logged to files. + + ``LOG_CONFIGURE <bool>`` + When enabled, the output of the configure step is logged to files. + + ``LOG_BUILD <bool>`` + When enabled, the output of the build step is logged to files. + + ``LOG_INSTALL <bool>`` + When enabled, the output of the install step is logged to files. + + ``LOG_TEST <bool>`` + When enabled, the output of the test step is logged to files. + + **Terminal Access Options:** + Steps can be given direct access to the terminal in some cases. Giving a + step access to the terminal may allow it to receive terminal input if + required, such as for authentication details not provided by other options. + With the :generator:`Ninja` generator, these options place the steps in the + ``console`` :prop_gbl:`job pool <JOB_POOLS>`. Each step can be given access + to the terminal individually via the following options: + + ``USES_TERMINAL_DOWNLOAD <bool>`` + Give the download step access to the terminal. + + ``USES_TERMINAL_UPDATE <bool>`` + Give the update step access to the terminal. + + ``USES_TERMINAL_CONFIGURE <bool>`` + Give the configure step access to the terminal. + + ``USES_TERMINAL_BUILD <bool>`` + Give the build step access to the terminal. + + ``USES_TERMINAL_INSTALL <bool>`` + Give the install step access to the terminal. + + ``USES_TERMINAL_TEST <bool>`` + Give the test step access to the terminal. + + **Target Options:** + ``DEPENDS <targets>...`` + Specify other targets on which the external project depends. The other + targets will be brought up to date before any of the external project's + steps are executed. Because the external project uses additional custom + targets internally for each step, the ``DEPENDS`` option is the most + convenient way to ensure all of those steps depend on the other targets. + Simply doing + :command:`add_dependencies(\<name\> \<targets\>) <add_dependencies>` will + not make any of the steps dependent on ``<targets>``. + + ``EXCLUDE_FROM_ALL <bool>`` + When enabled, this option excludes the external project from the default + ALL target of the main build. + + ``STEP_TARGETS <step-target>...`` + Generate custom targets for the specified steps. This is required if the + steps need to be triggered manually or if they need to be used as + dependencies of other targets. If this option is not specified, the + default value is taken from the ``EP_STEP_TARGETS`` directory property. + See :command:`ExternalProject_Add_Step` below for further discussion of + the effects of this option. + + ``INDEPENDENT_STEP_TARGETS <step-target>...`` + Generate custom targets for the specified steps and prevent these targets + from having the usual dependencies applied to them. If this option is not + specified, the default value is taken from the + ``EP_INDEPENDENT_STEP_TARGETS`` directory property. This option is mostly + useful for allowing individual steps to be driven independently, such as + for a CDash setup where each step should be initiated and reported + individually rather than as one whole build. See + :command:`ExternalProject_Add_Step` below for further discussion of the + effects of this option. + + **Miscellaneous Options:** + ``LIST_SEPARATOR <sep>`` + For any of the various ``..._COMMAND`` options, replace ``;`` with + ``<sep>`` in the specified command lines. This can be useful where list + variables may be given in commands where they should end up as + space-separated arguments (``<sep>`` would be a single space character + string in this case). + + ``COMMAND <cmd>...`` + Any of the other ``..._COMMAND`` options can have additional commands + appended to them by following them with as many ``COMMAND ...`` options + as needed + (:manual:`generator expressions <cmake-generator-expressions(7)>` are + supported). For example:: + + ExternalProject_Add(example + ... # Download options, etc. + BUILD_COMMAND ${CMAKE_COMMAND} -E echo "Starting $<CONFIG> build" + COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config $<CONFIG> + COMMAND ${CMAKE_COMMAND} -E echo "$<CONFIG> build complete" + ) + + It should also be noted that each build step is created via a call to + :command:`ExternalProject_Add_Step`. See that command's documentation for the + automatic substitutions that are supported for some options. + +Obtaining Project Properties +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. command:: ExternalProject_Get_Property + + The ``ExternalProject_Get_Property()`` function retrieves external project + target properties:: + + ExternalProject_Get_Property(<name> <prop1> [<prop2>...]) + + The function stores property values in variables of the same name. Property + names correspond to the keyword argument names of ``ExternalProject_Add()``. + For example, the source directory might be retrieved like so: + + .. code-block:: cmake + + ExternalProject_Get_property(myExtProj SOURCE_DIR) + message("Source dir of myExtProj = ${SOURCE_DIR}") + +Explicit Step Management +^^^^^^^^^^^^^^^^^^^^^^^^ + +The ``ExternalProject_Add()`` function on its own is often sufficient for +incorporating an external project into the main build. Certain scenarios +require additional work to implement desired behavior, such as adding in a +custom step or making steps available as manually triggerable targets. The +``ExternalProject_Add_Step()``, ``ExternalProject_Add_StepTargets()`` and +``ExternalProject_Add_StepDependencies`` functions provide the lower level +control needed to implement such step-level capabilities. .. command:: ExternalProject_Add_Step - The ``ExternalProject_Add_Step`` function adds a custom step to an - external project:: + The ``ExternalProject_Add_Step()`` function specifies an additional custom + step for an external project defined by an earlier call to + :command:`ExternalProject_Add`:: - ExternalProject_Add_Step(<name> <step> [<option>...]) + ExternalProject_Add_Step(<name> <step> [<option>...]) - Options are: + ``<name>`` is the same as the name passed to the original call to + :command:`ExternalProject_Add`. The specified ``<step>`` must not be one of + the pre-defined steps (``mkdir``, ``download``, ``update``, ``skip-update``, + ``patch``, ``configure``, ``build``, ``install`` or ``test``). The supported + options are: ``COMMAND <cmd>...`` - Command line invoked by this step + The command line to be executed by this custom step + (:manual:`generator expressions <cmake-generator-expressions(7)>` are + supported). This option can be repeated multiple times to specify multiple + commands to be executed in order. + ``COMMENT "<text>..."`` - Text printed when step executes + Text to be printed when the custom step executes. + ``DEPENDEES <step>...`` - Steps on which this step depends + Other steps (custom or pre-defined) on which this step depends. + ``DEPENDERS <step>...`` - Steps that depend on this step + Other steps (custom or pre-defined) that depend on this new custom step. + ``DEPENDS <file>...`` - Files on which this step depends + Files on which this custom step depends. + ``BYPRODUCTS <file>...`` - Files that will be generated by this step but may or may not - have their modification time updated by subsequent builds. - ``ALWAYS 1`` - No stamp file, step always runs - ``EXCLUDE_FROM_MAIN 1`` - Main target does not depend on this step + Files that will be generated by this custom step but which might or might + not have their modification time updated by subsequent builds. This list of + files will ultimately be passed through as the ``BYPRODUCTS`` option to the + :command:`add_custom_command` used to implement the custom step internally. + + ``ALWAYS <bool>`` + When enabled, this option specifies that the custom step should always be + run (i.e. that it is always considered out of date). + + ``EXCLUDE_FROM_MAIN <bool>`` + When enabled, this option specifies that the external project's main target + does not depend on the custom step. + ``WORKING_DIRECTORY <dir>`` - Working directory for command - ``LOG 1`` - Wrap step in script to log output - ``USES_TERMINAL 1`` - Give the step direct access to the terminal if possible. + Specifies the working directory to set before running the custom step's + command. If this option is not specified, the directory will be the value + of the :variable:`CMAKE_CURRENT_BINARY_DIR` at the point where + ``ExternalProject_Add_Step()`` was called. - The command line, comment, working directory, and byproducts of every - standard and custom step are processed to replace tokens ``<SOURCE_DIR>``, - ``<SOURCE_SUBDIR>``, ``<BINARY_DIR>``, ``<INSTALL_DIR>``, and ``<TMP_DIR>`` - with corresponding property values. + ``LOG <bool>`` + If set, this causes the output from the custom step to be captured to files + in the external project's ``STAMP_DIR``. -Any builtin step that specifies a ``<step>_COMMAND cmd...`` or custom -step that specifies a ``COMMAND cmd...`` may specify additional command -lines using the form ``COMMAND cmd...``. At build time the commands -will be executed in order and aborted if any one fails. For example:: + ``USES_TERMINAL <bool>`` + If enabled, this gives the custom step direct access to the terminal if + possible. - ... BUILD_COMMAND make COMMAND echo done ... + The command line, comment, working directory and byproducts of every + standard and custom step are processed to replace the tokens + ``<SOURCE_DIR>``, ``<SOURCE_SUBDIR>``, ``<BINARY_DIR>``, ``<INSTALL_DIR>`` + and ``<TMP_DIR>`` with their corresponding property values defined in the + original call to :command:`ExternalProject_Add`. -specifies to run ``make`` and then ``echo done`` during the build step. -Whether the current working directory is preserved between commands is -not defined. Behavior of shell operators like ``&&`` is not defined. +.. command:: ExternalProject_Add_StepTargets -Arguments to ``<step>_COMMAND`` or ``COMMAND`` options may use -:manual:`generator expressions <cmake-generator-expressions(7)>`. + The ``ExternalProject_Add_StepTargets()`` function generates targets for the + steps listed. The name of each created target will be of the form + ``<name>-<step>``:: + + ExternalProject_Add_StepTargets(<name> [NO_DEPENDS] <step1> [<step2>...]) + + Creating a target for a step allows it to be used as a dependency of another + target or to be triggered manually. Having targets for specific steps also + allows them to be driven independently of each other by specifying targets on + build command lines. For example, you may be submitting to a sub-project + based dashboard where you want to drive the configure portion of the build, + then submit to the dashboard, followed by the build portion, followed + by tests. If you invoke a custom target that depends on a step halfway + through the step dependency chain, then all the previous steps will also run + to ensure everything is up to date. + + If the ``NO_DEPENDS`` option is specified, the step target will not depend on + the dependencies of the external project (i.e. on any dependencies of the + ``<name>`` custom target created by :command:`ExternalProject_Add`). This is + usually safe for the ``download``, ``update`` and ``patch`` steps, since they + do not typically require that the dependencies are updated and built. Using + ``NO_DEPENDS`` for any of the other pre-defined steps, however, may break + parallel builds. Only use ``NO_DEPENDS`` where it is certain that the named + steps genuinely do not have dependencies. For custom steps, consider whether + or not the custom commands require the dependencies to be configured, built + and installed. + + Internally, :command:`ExternalProject_Add` calls + :command:`ExternalProject_Add_Step` to create each step. If any + ``STEP_TARGETS`` or ``INDEPENDENT_STEP_TARGETS`` were specified, then + ``ExternalProject_Add_StepTargets()`` will also be called after + :command:`ExternalProject_Add_Step`. ``INDEPENDENT_STEP_TARGETS`` have the + ``NO_DEPENDS`` option set, whereas ``STEP_TARGETS`` do not. Other than that, + the two options result in ``ExternalProject_Add_StepTargets()`` being called + in the same way. Even if a step is not mentioned in either of those two + options, ``ExternalProject_Add_StepTargets()`` can still be called later to + manually define a target for the step. + + The ``STEP_TARGETS`` and ``INDEPENDENT_STEP_TARGETS`` options for + :command:`ExternalProject_Add` are generally the easiest way to ensure + targets are created for specific steps of interest. For custom steps, + ``ExternalProject_Add_StepTargets()`` must be called explicitly if a target + should also be created for that custom step. An alternative to these two + options is to populate the ``EP_STEP_TARGETS`` and + ``EP_INDEPENDENT_STEP_TARGETS`` directory properties. These act as defaults + for the step target options and can save having to repeatedly specify the + same set of step targets when multiple external projects are being defined. -.. command:: ExternalProject_Get_Property +.. command:: ExternalProject_Add_StepDependencies - The ``ExternalProject_Get_Property`` function retrieves external project - target properties:: + The ``ExternalProject_Add_StepDependencies()`` function can be used to add + dependencies to a step. The dependencies added must be targets CMake already + knows about (these can be ordinary executable or library targets, custom + targets or even step targets of another external project):: - ExternalProject_Get_Property(<name> [prop1 [prop2 [...]]]) + ExternalProject_Add_StepDependencies(<name> <step> <target1> [<target2>...]) - It stores property values in variables of the same name. Property - names correspond to the keyword argument names of - ``ExternalProject_Add``. + This function takes care to set both target and file level dependencies and + will ensure that parallel builds will not break. It should be used instead of + :command:`add_dependencies` whenever adding a dependency for some of the step + targets generated by the ``ExternalProject`` module. -.. command:: ExternalProject_Add_StepTargets +Examples +^^^^^^^^ - The ``ExternalProject_Add_StepTargets`` function generates custom - targets for the steps listed:: - - ExternalProject_Add_StepTargets(<name> [NO_DEPENDS] [step1 [step2 [...]]]) - -If ``NO_DEPENDS`` is set, the target will not depend on the -dependencies of the complete project. This is usually safe to use for -the download, update, and patch steps that do not require that all the -dependencies are updated and built. Using ``NO_DEPENDS`` for other -of the default steps might break parallel builds, so you should avoid, -it. For custom steps, you should consider whether or not the custom -commands requires that the dependencies are configured, built and -installed. - -If ``STEP_TARGETS`` or ``INDEPENDENT_STEP_TARGETS`` is set then -``ExternalProject_Add_StepTargets`` is automatically called at the end -of matching calls to ``ExternalProject_Add_Step``. Pass -``STEP_TARGETS`` or ``INDEPENDENT_STEP_TARGETS`` explicitly to -individual ``ExternalProject_Add`` calls, or implicitly to all -``ExternalProject_Add`` calls by setting the directory properties -``EP_STEP_TARGETS`` and ``EP_INDEPENDENT_STEP_TARGETS``. The -``INDEPENDENT`` version of the argument and of the property will call -``ExternalProject_Add_StepTargets`` with the ``NO_DEPENDS`` argument. - -If ``STEP_TARGETS`` and ``INDEPENDENT_STEP_TARGETS`` are not set, -clients may still manually call ``ExternalProject_Add_StepTargets`` -after calling ``ExternalProject_Add`` or ``ExternalProject_Add_Step``. - -This functionality is provided to make it easy to drive the steps -independently of each other by specifying targets on build command -lines. For example, you may be submitting to a sub-project based -dashboard, where you want to drive the configure portion of the build, -then submit to the dashboard, followed by the build portion, followed -by tests. If you invoke a custom target that depends on a step -halfway through the step dependency chain, then all the previous steps -will also run to ensure everything is up to date. - -For example, to drive configure, build and test steps independently -for each ``ExternalProject_Add`` call in your project, write the following -line prior to any ``ExternalProject_Add`` calls in your ``CMakeLists.txt`` -file:: - - set_property(DIRECTORY PROPERTY EP_STEP_TARGETS configure build test) +The following example shows how to download and build a hypothetical project +called *FooBar* from github: -.. command:: ExternalProject_Add_StepDependencies +.. code-block:: cmake + + include(ExternalProject) + ExternalProject_Add(foobar + GIT_REPOSITORY git@github.com:FooCo/FooBar.git + GIT_TAG origin/release/1.2.3 + ) + +For the sake of the example, also define a second hypothetical external project +called *SecretSauce*, which is downloaded from a web server. Two URLs are given +to take advantage of a faster internal network if available, with a fallback to +a slower external server. The project is a typical ``Makefile`` project with no +configure step, so some of the default commands are overridden. The build is +only required to build the *sauce* target: + +.. code-block:: cmake + + find_program(MAKE_EXE NAMES gmake nmake make) + ExternalProject_Add(secretsauce + URL http://intranet.somecompany.com/artifacts/sauce-2.7.tgz + https://www.somecompany.com/downloads/sauce-2.7.zip + URL_HASH MD5=d41d8cd98f00b204e9800998ecf8427e + CONFIGURE_COMMAND "" + BUILD_COMMAND ${MAKE_EXE} sauce + ) + +Suppose the build step of ``secretsauce`` requires that ``foobar`` must already +be built. This could be enforced like so: + +.. code-block:: cmake + + ExternalProject_Add_StepDependencies(secretsauce build foobar) + +Another alternative would be to create a custom target for ``foobar``'s build +step and make ``secretsauce`` depend on that rather than the whole ``foobar`` +project. This would mean ``foobar`` only needs to be built, it doesn't need to +run its install or test steps before ``secretsauce`` can be built. The +dependency can also be defined along with the ``secretsauce`` project: + +.. code-block:: cmake + + ExternalProject_Add_StepTargets(foobar build) + ExternalProject_Add(secretsauce + URL http://intranet.somecompany.com/artifacts/sauce-2.7.tgz + https://www.somecompany.com/downloads/sauce-2.7.zip + URL_HASH MD5=d41d8cd98f00b204e9800998ecf8427e + CONFIGURE_COMMAND "" + BUILD_COMMAND ${MAKE_EXE} sauce + DEPENDS foobar-build + ) + +Instead of calling :command:`ExternalProject_Add_StepTargets`, the target could +be defined along with the ``foobar`` project itself: + +.. code-block:: cmake + + ExternalProject_Add(foobar + GIT_REPOSITORY git@github.com:FooCo/FooBar.git + GIT_TAG origin/release/1.2.3 + STEP_TARGETS build + ) + +If many external projects should have the same set of step targets, setting a +directory property may be more convenient. The ``build`` step target could be +created automatically by setting the ``EP_STEP_TARGETS`` directory property +before creating the external projects with :command:`ExternalProject_Add`: + +.. code-block:: cmake + + set_property(DIRECTORY PROPERTY EP_STEP_TARGETS build) + +Lastly, suppose that ``secretsauce`` provides a script called ``makedoc`` which +can be used to generate its own documentation. Further suppose that the script +expects the output directory to be provided as the only parameter and that it +should be run from the ``secretsauce`` source directory. A custom step and a +custom target to trigger the script can be defined like so: + +.. code-block:: cmake + + ExternalProject_Add_Step(secretsauce docs + COMMAND <SOURCE_DIR>/makedoc <BINARY_DIR> + WORKING_DIRECTORY <SOURCE_DIR> + COMMENT "Building secretsauce docs" + ALWAYS TRUE + EXCLUDE_FROM_MAIN TRUE + ) + ExternalProject_Add_StepTargets(secretsauce docs) - The ``ExternalProject_Add_StepDependencies`` function add some - dependencies for some external project step:: +The custom step could then be triggered from the main build like so:: - ExternalProject_Add_StepDependencies(<name> <step> [target1 [target2 [...]]]) + cmake --build . --target secretsauce-docs - This function takes care to set both target and file level - dependencies, and will ensure that parallel builds will not break. - It should be used instead of :command:`add_dependencies()` when adding - a dependency for some of the step targets generated by - ``ExternalProject``. #]=======================================================================] # Pre-compute a regex to match documented keywords for each command. -math(EXPR _ep_documentation_line_count "${CMAKE_CURRENT_LIST_LINE} - 16") +math(EXPR _ep_documentation_line_count "${CMAKE_CURRENT_LIST_LINE} - 4") file(STRINGS "${CMAKE_CURRENT_LIST_FILE}" lines LIMIT_COUNT ${_ep_documentation_line_count} - REGEX "^\\.\\. command:: [A-Za-z0-9_]+|^ ``[A-Z0-9_]+ .*``$") + REGEX "^\\.\\. command:: [A-Za-z0-9_]+|^ +``[A-Z0-9_]+ [^`]*``$") foreach(line IN LISTS lines) if("${line}" MATCHES "^\\.\\. command:: ([A-Za-z0-9_]+)") if(_ep_func) @@ -421,7 +868,7 @@ foreach(line IN LISTS lines) #message("function [${_ep_func}]") set(_ep_keywords_${_ep_func} "^(") set(_ep_keyword_sep) - elseif("${line}" MATCHES "^ ``([A-Z0-9_]+) .*``$") + elseif("${line}" MATCHES "^ +``([A-Z0-9_]+) [^`]*``$") set(_ep_key "${CMAKE_MATCH_1}") #message(" keyword [${_ep_key}]") string(APPEND _ep_keywords_${_ep_func} @@ -504,7 +951,7 @@ define_property(DIRECTORY PROPERTY "EP_STEP_TARGETS" INHERITED BRIEF_DOCS "List of ExternalProject steps that automatically get corresponding targets" FULL_DOCS - "These targets will be dependent on the main target dependencies" + "These targets will be dependent on the main target dependencies. " "See documentation of the ExternalProject_Add_StepTargets() function in the " "ExternalProject module." ) @@ -513,7 +960,7 @@ define_property(DIRECTORY PROPERTY "EP_INDEPENDENT_STEP_TARGETS" INHERITED BRIEF_DOCS "List of ExternalProject steps that automatically get corresponding targets" FULL_DOCS - "These targets will not be dependent on the main target dependencies" + "These targets will not be dependent on the main target dependencies. " "See documentation of the ExternalProject_Add_StepTargets() function in the " "ExternalProject module." ) @@ -2012,12 +2459,12 @@ function(_ep_add_download_command name) " ${source_dir}\n" "is not an existing non-empty directory. Please specify one of:\n" " * SOURCE_DIR with an existing non-empty directory\n" + " * DOWNLOAD_COMMAND\n" " * URL\n" " * GIT_REPOSITORY\n" + " * SVN_REPOSITORY\n" " * HG_REPOSITORY\n" - " * CVS_REPOSITORY and CVS_MODULE\n" - " * SVN_REVISION\n" - " * DOWNLOAD_COMMAND" + " * CVS_REPOSITORY and CVS_MODULE" ) endif() endif() diff --git a/Modules/FindCUDA.cmake b/Modules/FindCUDA.cmake index a4dca54..bd7d0c0 100644 --- a/Modules/FindCUDA.cmake +++ b/Modules/FindCUDA.cmake @@ -2,6 +2,20 @@ # FindCUDA # -------- # +# .. note:: +# +# The FindCUDA module has been superseded by first-class support +# for the CUDA language in CMake. It is no longer necessary to +# use this module or call ``find_package(CUDA)``. This module +# now exists only for compatibility with projects that have not +# been ported. +# +# Instead, list ``CUDA`` among the languages named in the top-level +# call to the :command:`project` command, or call the +# :command:`enable_language` command with ``CUDA``. +# Then one can add CUDA (``.cu``) sources to programs directly +# in calls to :command:`add_library` and :command:`add_executable`. +# # Tools for building CUDA C files: libraries and build dependencies. # # This script locates the NVIDIA CUDA C tools. It should work on linux, @@ -589,7 +603,6 @@ macro(cuda_unset_include_and_libraries) unset(CUDA_npps_LIBRARY CACHE) unset(CUDA_nvcuvenc_LIBRARY CACHE) unset(CUDA_nvcuvid_LIBRARY CACHE) - unset(CUDA_USE_STATIC_CUDA_RUNTIME CACHE) unset(CUDA_GPU_DETECT_OUTPUT CACHE) endmacro() @@ -679,7 +692,11 @@ if(CMAKE_CROSSCOMPILING) # add known CUDA targetr root path to the set of directories we search for programs, libraries and headers set( CMAKE_FIND_ROOT_PATH "${CUDA_TOOLKIT_TARGET_DIR};${CMAKE_FIND_ROOT_PATH}") macro( cuda_find_host_program ) - find_host_program( ${ARGN} ) + if (COMMAND find_host_program) + find_host_program( ${ARGN} ) + else() + find_program( ${ARGN} ) + endif() endmacro() else() # for non-cross-compile, find_host_program == find_program and CUDA_TOOLKIT_TARGET_DIR == CUDA_TOOLKIT_ROOT_DIR @@ -798,12 +815,17 @@ endif() if(CUDA_cudart_static_LIBRARY) # If static cudart available, use it by default, but provide a user-visible option to disable it. option(CUDA_USE_STATIC_CUDA_RUNTIME "Use the static version of the CUDA runtime library if available" ON) - set(CUDA_CUDART_LIBRARY_VAR CUDA_cudart_static_LIBRARY) else() # If not available, silently disable the option. set(CUDA_USE_STATIC_CUDA_RUNTIME OFF CACHE INTERNAL "") +endif() + +if(CUDA_USE_STATIC_CUDA_RUNTIME) + set(CUDA_CUDART_LIBRARY_VAR CUDA_cudart_static_LIBRARY) +else() set(CUDA_CUDART_LIBRARY_VAR CUDA_CUDART_LIBRARY) endif() + if(NOT CUDA_VERSION VERSION_LESS "5.0") cuda_find_library_local_first(CUDA_cudadevrt_LIBRARY cudadevrt "\"cudadevrt\" library") mark_as_advanced(CUDA_cudadevrt_LIBRARY) @@ -1698,6 +1720,7 @@ function(CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS output_file cuda_target options COMMAND ${CUDA_NVCC_EXECUTABLE} ${nvcc_flags} -dlink ${object_files} -o ${output_file} ${flags} COMMENT "Building NVCC intermediate link file ${output_file_relative_path}" + COMMAND_EXPAND_LISTS ${_verbatim} ) else() @@ -1708,6 +1731,7 @@ function(CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS output_file cuda_target options COMMAND ${CMAKE_COMMAND} -E echo "Building NVCC intermediate link file ${output_file_relative_path}" COMMAND ${CMAKE_COMMAND} -E make_directory "${output_file_dir}" COMMAND ${CUDA_NVCC_EXECUTABLE} ${nvcc_flags} ${flags} -dlink ${object_files} -o "${output_file}" + COMMAND_EXPAND_LISTS ${_verbatim} ) endif() diff --git a/Modules/FindCUDA/run_nvcc.cmake b/Modules/FindCUDA/run_nvcc.cmake index 28cc1e9..ec5a099 100644 --- a/Modules/FindCUDA/run_nvcc.cmake +++ b/Modules/FindCUDA/run_nvcc.cmake @@ -74,7 +74,7 @@ set(CUDA_NVCC_FLAGS @CUDA_NVCC_FLAGS@ ;; @CUDA_WRAP_OPTION_NVCC_FLAGS@) # list @CUDA_NVCC_FLAGS_CONFIG@ set(nvcc_flags @nvcc_flags@) # list set(CUDA_NVCC_INCLUDE_DIRS "@CUDA_NVCC_INCLUDE_DIRS@") # list (needs to be in quotes to handle spaces properly). -set(CUDA_NVCC_COMPILE_DEFINITIONS "@CUDA_NVCC_COMPILE_DEFINITIONS@") # list (needs to be in quotes to handle spaces properly). +set(CUDA_NVCC_COMPILE_DEFINITIONS [==[@CUDA_NVCC_COMPILE_DEFINITIONS@]==]) # list (needs to be in lua quotes see #16510 ). set(format_flag "@format_flag@") # string set(cuda_language_flag @cuda_language_flag@) # list diff --git a/Modules/FindCUDA/select_compute_arch.cmake b/Modules/FindCUDA/select_compute_arch.cmake index 8fb44d8..b604a17 100644 --- a/Modules/FindCUDA/select_compute_arch.cmake +++ b/Modules/FindCUDA/select_compute_arch.cmake @@ -30,12 +30,17 @@ endif () if (CUDA_VERSION VERSION_GREATER "7.5") list(APPEND CUDA_KNOWN_GPU_ARCHITECTURES "Pascal") - list(APPEND CUDA_COMMON_GPU_ARCHITECTURES "6.0" "6.1" "6.1+PTX") + list(APPEND CUDA_COMMON_GPU_ARCHITECTURES "6.0" "6.1") else() list(APPEND CUDA_COMMON_GPU_ARCHITECTURES "5.2+PTX") endif () - +if (CUDA_VERSION VERSION_GREATER "8.5") + list(APPEND CUDA_KNOWN_GPU_ARCHITECTURES "Volta") + list(APPEND CUDA_COMMON_GPU_ARCHITECTURES "7.0" "7.0+PTX") +else() + list(APPEND CUDA_COMMON_GPU_ARCHITECTURES "6.1+PTX") +endif() ################################################################################################ # A function for automatic detection of GPUs installed (if autodetection is enabled) @@ -141,6 +146,9 @@ function(CUDA_SELECT_NVCC_ARCH_FLAGS out_variable) elseif(${arch_name} STREQUAL "Pascal") set(arch_bin 6.0 6.1) set(arch_ptx 6.1) + elseif(${arch_name} STREQUAL "Volta") + set(arch_bin 7.0 7.0) + set(arch_ptx 7.0) else() message(SEND_ERROR "Unknown CUDA Architecture Name ${arch_name} in CUDA_SELECT_NVCC_ARCH_FLAGS") endif() diff --git a/Modules/FindCurses.cmake b/Modules/FindCurses.cmake index 4365e99..8d58d03 100644 --- a/Modules/FindCurses.cmake +++ b/Modules/FindCurses.cmake @@ -199,4 +199,5 @@ mark_as_advanced( CURSES_CURSES_LIBRARY CURSES_NCURSES_LIBRARY CURSES_EXTRA_LIBRARY + CURSES_FORM_LIBRARY ) diff --git a/Modules/FindCygwin.cmake b/Modules/FindCygwin.cmake index b2ed703..092a3bd 100644 --- a/Modules/FindCygwin.cmake +++ b/Modules/FindCygwin.cmake @@ -8,14 +8,19 @@ # this module looks for Cygwin if (WIN32) - find_program(CYGWIN_INSTALL_PATH - cygwin.bat - "C:/Cygwin" - "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Cygwin\\setup;rootdir]" - "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Cygnus Solutions\\Cygwin\\mounts v2\\/;native]" - ) - get_filename_component(CYGWIN_INSTALL_PATH "${CYGWIN_INSTALL_PATH}" DIRECTORY) - mark_as_advanced( - CYGWIN_INSTALL_PATH + if(CYGWIN_INSTALL_PATH) + set(CYGWIN_BAT "${CYGWIN_INSTALL_PATH}/cygwin.bat") + endif() + + find_program(CYGWIN_BAT + NAMES cygwin.bat + PATHS + "C:/Cygwin" + "C:/Cygwin64" + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Cygwin\\setup;rootdir]" + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Cygnus Solutions\\Cygwin\\mounts v2\\/;native]" ) + get_filename_component(CYGWIN_INSTALL_PATH "${CYGWIN_BAT}" DIRECTORY) + mark_as_advanced(CYGWIN_BAT) + endif () diff --git a/Modules/FindGTest.cmake b/Modules/FindGTest.cmake index c4b4535..cb71ef1 100644 --- a/Modules/FindGTest.cmake +++ b/Modules/FindGTest.cmake @@ -71,7 +71,7 @@ # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # # See :module:`GoogleTest` for information on the :command:`gtest_add_tests` -# command. +# and :command:`gtest_discover_tests` commands. include(${CMAKE_CURRENT_LIST_DIR}/GoogleTest.cmake) diff --git a/Modules/FindHDF5.cmake b/Modules/FindHDF5.cmake index 5962c5b..de20049 100644 --- a/Modules/FindHDF5.cmake +++ b/Modules/FindHDF5.cmake @@ -23,7 +23,7 @@ # Fortran_HL. If the COMPONENTS argument is not given, the module will # attempt to find only the C bindings. # -# On UNIX systems, this module will read the variable +# This module will read the variable # HDF5_USE_STATIC_LIBRARIES to determine whether or not to prefer a # static link to a dynamic link for HDF5 and all of it's dependencies. # To use this feature, make sure that the HDF5_USE_STATIC_LIBRARIES @@ -187,8 +187,16 @@ function(_HDF5_test_regular_compiler_C success version is_parallel) file(WRITE ${test_file} "#include <hdf5.h>\n" "#include <hdf5_hl.h>\n" - "int main(void) {\n" - " char const* info_ver = \"INFO\" \":\" H5_VERSION;\n" + "const char* info_ver = \"INFO\" \":\" H5_VERSION;\n" + "#ifdef H5_HAVE_PARALLEL\n" + "const char* info_parallel = \"INFO\" \":\" \"PARALLEL\";\n" + "#endif\n" + "int main(int argc, char **argv) {\n" + " int require = 0;\n" + " require += info_ver[argc];\n" + "#ifdef H5_HAVE_PARALLEL\n" + " require += info_parallel[argc];\n" + "#endif\n" " hid_t fid;\n" " fid = H5Fcreate(\"foo.h5\",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT);\n" " return 0;\n" @@ -198,11 +206,11 @@ function(_HDF5_test_regular_compiler_C success version is_parallel) ) endif() if(${success}) - file(STRINGS ${scratch_directory}/compiler_has_h5_c INFO_VER - REGEX "^INFO:([0-9]+\\.[0-9]+\\.[0-9]+)(-patch([0-9]+))?" + file(STRINGS ${scratch_directory}/compiler_has_h5_c INFO_STRINGS + REGEX "^INFO:" ) string(REGEX MATCH "^INFO:([0-9]+\\.[0-9]+\\.[0-9]+)(-patch([0-9]+))?" - INFO_VER "${INFO_VER}" + INFO_VER "${INFO_STRINGS}" ) set(${version} ${CMAKE_MATCH_1}) if(CMAKE_MATCH_3) @@ -210,12 +218,7 @@ function(_HDF5_test_regular_compiler_C success version is_parallel) endif() set(${version} ${${version}} PARENT_SCOPE) - execute_process(COMMAND ${CMAKE_C_COMPILER} -showconfig - OUTPUT_VARIABLE config_output - ERROR_VARIABLE config_error - RESULT_VARIABLE config_result - ) - if(config_output MATCHES "Parallel HDF5: yes") + if(INFO_STRINGS MATCHES "INFO:PARALLEL") set(${is_parallel} TRUE PARENT_SCOPE) else() set(${is_parallel} FALSE PARENT_SCOPE) @@ -233,8 +236,16 @@ function(_HDF5_test_regular_compiler_CXX success version is_parallel) "#ifndef H5_NO_NAMESPACE\n" "using namespace H5;\n" "#endif\n" + "const char* info_ver = \"INFO\" \":\" H5_VERSION;\n" + "#ifdef H5_HAVE_PARALLEL\n" + "const char* info_parallel = \"INFO\" \":\" \"PARALLEL\";\n" + "#endif\n" "int main(int argc, char **argv) {\n" - " char const* info_ver = \"INFO\" \":\" H5_VERSION;\n" + " int require = 0;\n" + " require += info_ver[argc];\n" + "#ifdef H5_HAVE_PARALLEL\n" + " require += info_parallel[argc];\n" + "#endif\n" " H5File file(\"foo.h5\", H5F_ACC_TRUNC);\n" " return 0;\n" "}") @@ -243,11 +254,11 @@ function(_HDF5_test_regular_compiler_CXX success version is_parallel) ) endif() if(${success}) - file(STRINGS ${scratch_directory}/compiler_has_h5_cxx INFO_VER - REGEX "^INFO:([0-9]+\\.[0-9]+\\.[0-9]+)(-patch([0-9]+))?" + file(STRINGS ${scratch_directory}/compiler_has_h5_cxx INFO_STRINGS + REGEX "^INFO:" ) string(REGEX MATCH "^INFO:([0-9]+\\.[0-9]+\\.[0-9]+)(-patch([0-9]+))?" - INFO_VER "${INFO_VER}" + INFO_VER "${INFO_STRINGS}" ) set(${version} ${CMAKE_MATCH_1}) if(CMAKE_MATCH_3) @@ -255,12 +266,7 @@ function(_HDF5_test_regular_compiler_CXX success version is_parallel) endif() set(${version} ${${version}} PARENT_SCOPE) - execute_process(COMMAND ${CMAKE_CXX_COMPILER} -showconfig - OUTPUT_VARIABLE config_output - ERROR_VARIABLE config_error - RESULT_VARIABLE config_result - ) - if(config_output MATCHES "Parallel HDF5: yes") + if(INFO_STRINGS MATCHES "INFO:PARALLEL") set(${is_parallel} TRUE PARENT_SCOPE) else() set(${is_parallel} FALSE PARENT_SCOPE) @@ -390,6 +396,45 @@ macro( _HDF5_parse_compile_line endforeach() endmacro() +# Select a preferred imported configuration from a target +function(_HDF5_select_imported_config target imported_conf) + # We will first assign the value to a local variable _imported_conf, then assign + # it to the function argument at the end. + get_target_property(_imported_conf ${target} MAP_IMPORTED_CONFIG_${CMAKE_BUILD_TYPE}) + if (NOT _imported_conf) + # Get available imported configurations by examining target properties + get_target_property(_imported_conf ${target} IMPORTED_CONFIGURATIONS) + if(HDF5_FIND_DEBUG) + message(STATUS "Found imported configurations: ${_imported_conf}") + endif() + # Find the imported configuration that we prefer. + # We do this by making list of configurations in order of preference, + # starting with ${CMAKE_BUILD_TYPE} and ending with the first imported_conf + set(_preferred_confs ${CMAKE_BUILD_TYPE}) + list(GET _imported_conf 0 _fallback_conf) + list(APPEND _preferred_confs RELWITHDEBINFO RELEASE DEBUG ${_fallback_conf}) + if(HDF5_FIND_DEBUG) + message(STATUS "Start search through imported configurations in the following order: ${_preferred_confs}") + endif() + # Now find the first of these that is present in imported_conf + cmake_policy(PUSH) + cmake_policy(SET CMP0057 NEW) # support IN_LISTS + foreach (_conf IN LISTS _preferred_confs) + if (${_conf} IN_LIST _imported_conf) + set(_imported_conf ${_conf}) + break() + endif() + endforeach() + cmake_policy(POP) + endif() + if(HDF5_FIND_DEBUG) + message(STATUS "Selected imported configuration: ${_imported_conf}") + endif() + # assign value to function argument + set(${imported_conf} ${_imported_conf} PARENT_SCOPE) +endfunction() + + if(NOT HDF5_ROOT) set(HDF5_ROOT $ENV{HDF5_ROOT}) endif() @@ -446,30 +491,39 @@ if(NOT HDF5_FOUND AND NOT HDF5_NO_FIND_PACKAGE_CONFIG_FILE) message(STATUS "Trying to get properties of target ${HDF5_${_lang}_TARGET}${_suffix}") endif() # Find library for this target. Complicated as on Windows with a DLL, we need to search for the import-lib. - get_target_property(_imported_conf ${HDF5_${_lang}_TARGET}${_suffix} IMPORTED_CONFIGURATIONS) - get_target_property(_lang_location ${HDF5_${_lang}_TARGET}${_suffix} IMPORTED_IMPLIB_${_imported_conf} ) - if (NOT _lang_location) + _HDF5_select_imported_config(${HDF5_${_lang}_TARGET}${_suffix} _hdf5_imported_conf) + get_target_property(_hdf5_lang_location ${HDF5_${_lang}_TARGET}${_suffix} IMPORTED_IMPLIB_${_hdf5_imported_conf} ) + if (NOT _hdf5_lang_location) # no import lib, just try LOCATION - get_target_property(_lang_location ${HDF5_${_lang}_TARGET}${_suffix} LOCATION) + get_target_property(_hdf5_lang_location ${HDF5_${_lang}_TARGET}${_suffix} LOCATION_${_hdf5_imported_conf}) + if (NOT _hdf5_lang_location) + get_target_property(_hdf5_lang_location ${HDF5_${_lang}_TARGET}${_suffix} LOCATION) + endif() endif() - if( _lang_location ) - set(HDF5_${_lang}_LIBRARY ${_lang_location}) + if( _hdf5_lang_location ) + set(HDF5_${_lang}_LIBRARY ${_hdf5_lang_location}) list(APPEND HDF5_LIBRARIES ${HDF5_${_lang}_TARGET}${_suffix}) set(HDF5_${_lang}_LIBRARIES ${HDF5_${_lang}_TARGET}${_suffix}) set(HDF5_${_lang}_FOUND True) endif() if(FIND_HL) - get_target_property(__lang_hl_location ${HDF5_${_lang}_HL_TARGET}${_suffix} IMPORTED_IMPLIB_${_imported_conf} ) - if (NOT _lang_hl_location) - get_target_property(_lang_hl_location ${HDF5_${_lang}_HL_TARGET}${_suffix} LOCATION) + get_target_property(__lang_hl_location ${HDF5_${_lang}_HL_TARGET}${_suffix} IMPORTED_IMPLIB_${_hdf5_imported_conf} ) + if (NOT _hdf5_lang_hl_location) + get_target_property(_hdf5_lang_hl_location ${HDF5_${_lang}_HL_TARGET}${_suffix} LOCATION_${_hdf5_imported_conf}) + if (NOT _hdf5_hl_lang_location) + get_target_property(_hdf5_hl_lang_location ${HDF5_${_lang}_HL_TARGET}${_suffix} LOCATION) + endif() endif() - if( _lang_hl_location ) - set(HDF5_${_lang}_HL_LIBRARY ${_lang_hl_location}) - list(APPEND HDF5_HL_LIBRARIES ${HDF5_${_lang}_TARGET}${_suffix}) - set(HDF5_${_lang}_HL_LIBRARIES ${HDF5_${_lang}_TARGET}${_suffix}) + if( _hdf5_lang_hl_location ) + set(HDF5_${_lang}_HL_LIBRARY ${_hdf5_lang_hl_location}) + list(APPEND HDF5_HL_LIBRARIES ${HDF5_${_lang}_HL_TARGET}${_suffix}) + set(HDF5_${_lang}_HL_LIBRARIES ${HDF5_${_lang}_HL_TARGET}${_suffix}) set(HDF5_HL_FOUND True) endif() + unset(_hdf5_lang_hl_location) endif() + unset(_hdf5_imported_conf) + unset(_hdf5_lang_location) endforeach() endif() endif() @@ -545,8 +599,12 @@ if(NOT HDF5_FOUND) if("x${L}" MATCHES "hdf5") # hdf5 library set(_HDF5_SEARCH_OPTS_LOCAL ${_HDF5_SEARCH_OPTS}) - if(UNIX AND HDF5_USE_STATIC_LIBRARIES) - set(_HDF5_SEARCH_NAMES_LOCAL lib${L}.a) + if(HDF5_USE_STATIC_LIBRARIES) + if(WIN32) + set(_HDF5_SEARCH_NAMES_LOCAL lib${L}) + else() + set(_HDF5_SEARCH_NAMES_LOCAL lib${L}.a) + endif() endif() else() # external library @@ -573,8 +631,12 @@ if(NOT HDF5_FOUND) if("x${L}" MATCHES "hdf5") # hdf5 library set(_HDF5_SEARCH_OPTS_LOCAL ${_HDF5_SEARCH_OPTS}) - if(UNIX AND HDF5_USE_STATIC_LIBRARIES) - set(_HDF5_SEARCH_NAMES_LOCAL lib${L}.a) + if(HDF5_USE_STATIC_LIBRARIES) + if(WIN32) + set(_HDF5_SEARCH_NAMES_LOCAL lib${L}) + else() + set(_HDF5_SEARCH_NAMES_LOCAL lib${L}.a) + endif() endif() else() # external library @@ -706,19 +768,22 @@ if( NOT HDF5_FOUND ) # find the HDF5 libraries foreach(LIB IN LISTS HDF5_${__lang}_LIBRARY_NAMES) - if(UNIX AND HDF5_USE_STATIC_LIBRARIES) + if(HDF5_USE_STATIC_LIBRARIES) # According to bug 1643 on the CMake bug tracker, this is the # preferred method for searching for a static library. # See https://gitlab.kitware.com/cmake/cmake/issues/1643. We search # first for the full static library name, but fall back to a # generic search on the name if the static search fails. set( THIS_LIBRARY_SEARCH_DEBUG - lib${LIB}d.a lib${LIB}_debug.a ${LIB}d ${LIB}_debug - lib${LIB}d-static.a lib${LIB}_debug-static.a ${LIB}d-static ${LIB}_debug-static ) - set( THIS_LIBRARY_SEARCH_RELEASE lib${LIB}.a ${LIB} lib${LIB}-static.a ${LIB}-static) + lib${LIB}d.a lib${LIB}_debug.a lib${LIB}d lib${LIB}_D lib${LIB}_debug + lib${LIB}d-static.a lib${LIB}_debug-static.a ${LIB}d-static ${LIB}_D-static ${LIB}_debug-static ) + set( THIS_LIBRARY_SEARCH_RELEASE lib${LIB}.a lib${LIB} lib${LIB}-static.a ${LIB}-static) else() - set( THIS_LIBRARY_SEARCH_DEBUG ${LIB}d ${LIB}_debug ${LIB}d-shared ${LIB}_debug-shared) + set( THIS_LIBRARY_SEARCH_DEBUG ${LIB}d ${LIB}_D ${LIB}_debug ${LIB}d-shared ${LIB}_D-shared ${LIB}_debug-shared) set( THIS_LIBRARY_SEARCH_RELEASE ${LIB} ${LIB}-shared) + if(WIN32) + list(APPEND HDF5_DEFINITIONS "-DH5_BUILT_AS_DYNAMIC_LIB") + endif() endif() find_library(HDF5_${LIB}_LIBRARY_DEBUG NAMES ${THIS_LIBRARY_SEARCH_DEBUG} @@ -743,18 +808,18 @@ if( NOT HDF5_FOUND ) if(FIND_HL) foreach(LIB IN LISTS HDF5_${__lang}_HL_LIBRARY_NAMES) - if(UNIX AND HDF5_USE_STATIC_LIBRARIES) + if(HDF5_USE_STATIC_LIBRARIES) # According to bug 1643 on the CMake bug tracker, this is the # preferred method for searching for a static library. # See https://gitlab.kitware.com/cmake/cmake/issues/1643. We search # first for the full static library name, but fall back to a # generic search on the name if the static search fails. set( THIS_LIBRARY_SEARCH_DEBUG - lib${LIB}d.a lib${LIB}_debug.a ${LIB}d ${LIB}_debug - lib${LIB}d-static.a lib${LIB}_debug-static.a ${LIB}d-static ${LIB}_debug-static ) - set( THIS_LIBRARY_SEARCH_RELEASE lib${LIB}.a ${LIB} lib${LIB}-static.a ${LIB}-static) + lib${LIB}d.a lib${LIB}_debug.a lib${LIB}d lib${LIB}_D lib${LIB}_debug + lib${LIB}d-static.a lib${LIB}_debug-static.a lib${LIB}d-static lib${LIB}_D-static lib${LIB}_debug-static ) + set( THIS_LIBRARY_SEARCH_RELEASE lib${LIB}.a ${LIB} lib${LIB}-static.a lib${LIB}-static) else() - set( THIS_LIBRARY_SEARCH_DEBUG ${LIB}d ${LIB}_debug ${LIB}d-shared ${LIB}_debug-shared) + set( THIS_LIBRARY_SEARCH_DEBUG ${LIB}d ${LIB}_D ${LIB}_debug ${LIB}d-shared ${LIB}_D-shared ${LIB}_debug-shared) set( THIS_LIBRARY_SEARCH_RELEASE ${LIB} ${LIB}-shared) endif() find_library(HDF5_${LIB}_LIBRARY_DEBUG @@ -780,6 +845,7 @@ if( NOT HDF5_FOUND ) set(HDF5_HL_FOUND True) endif() + _HDF5_remove_duplicates_from_beginning(HDF5_DEFINITIONS) _HDF5_remove_duplicates_from_beginning(HDF5_INCLUDE_DIRS) _HDF5_remove_duplicates_from_beginning(HDF5_LIBRARIES) _HDF5_remove_duplicates_from_beginning(HDF5_HL_LIBRARIES) @@ -855,11 +921,14 @@ if (HDF5_FIND_DEBUG) message(STATUS "HDF5_DEFINITIONS: ${HDF5_DEFINITIONS}") message(STATUS "HDF5_INCLUDE_DIRS: ${HDF5_INCLUDE_DIRS}") message(STATUS "HDF5_LIBRARIES: ${HDF5_LIBRARIES}") + message(STATUS "HDF5_HL_LIBRARIES: ${HDF5_HL_LIBRARIES}") foreach(__lang IN LISTS HDF5_LANGUAGE_BINDINGS) message(STATUS "HDF5_${__lang}_DEFINITIONS: ${HDF5_${__lang}_DEFINITIONS}") message(STATUS "HDF5_${__lang}_INCLUDE_DIR: ${HDF5_${__lang}_INCLUDE_DIR}") message(STATUS "HDF5_${__lang}_INCLUDE_DIRS: ${HDF5_${__lang}_INCLUDE_DIRS}") message(STATUS "HDF5_${__lang}_LIBRARY: ${HDF5_${__lang}_LIBRARY}") message(STATUS "HDF5_${__lang}_LIBRARIES: ${HDF5_${__lang}_LIBRARIES}") + message(STATUS "HDF5_${__lang}_HL_LIBRARY: ${HDF5_${__lang}_HL_LIBRARY}") + message(STATUS "HDF5_${__lang}_HL_LIBRARIES: ${HDF5_${__lang}_HL_LIBRARIES}") endforeach() endif() diff --git a/Modules/FindHTMLHelp.cmake b/Modules/FindHTMLHelp.cmake index 84e2458..6aab8a7 100644 --- a/Modules/FindHTMLHelp.cmake +++ b/Modules/FindHTMLHelp.cmake @@ -18,28 +18,28 @@ if(WIN32) find_program(HTML_HELP_COMPILER - hhc - "[HKEY_CURRENT_USER\\Software\\Microsoft\\HTML Help Workshop;InstallDir]" - "$ENV{ProgramFiles}/HTML Help Workshop" - "C:/Program Files/HTML Help Workshop" + NAMES hhc + PATHS + "[HKEY_CURRENT_USER\\Software\\Microsoft\\HTML Help Workshop;InstallDir]" + PATH_SUFFIXES "HTML Help Workshop" ) get_filename_component(HTML_HELP_COMPILER_PATH "${HTML_HELP_COMPILER}" PATH) find_path(HTML_HELP_INCLUDE_PATH - htmlhelp.h - "${HTML_HELP_COMPILER_PATH}/include" - "[HKEY_CURRENT_USER\\Software\\Microsoft\\HTML Help Workshop;InstallDir]/include" - "$ENV{ProgramFiles}/HTML Help Workshop/include" - "C:/Program Files/HTML Help Workshop/include" + NAMES htmlhelp.h + PATHS + "${HTML_HELP_COMPILER_PATH}/include" + "[HKEY_CURRENT_USER\\Software\\Microsoft\\HTML Help Workshop;InstallDir]/include" + PATH_SUFFIXES "HTML Help Workshop/include" ) find_library(HTML_HELP_LIBRARY - htmlhelp - "${HTML_HELP_COMPILER_PATH}/lib" - "[HKEY_CURRENT_USER\\Software\\Microsoft\\HTML Help Workshop;InstallDir]/lib" - "$ENV{ProgramFiles}/HTML Help Workshop/lib" - "C:/Program Files/HTML Help Workshop/lib" + NAMES htmlhelp + PATHS + "${HTML_HELP_COMPILER_PATH}/lib" + "[HKEY_CURRENT_USER\\Software\\Microsoft\\HTML Help Workshop;InstallDir]/lib" + PATH_SUFFIXES "HTML Help Workshop/lib" ) mark_as_advanced( diff --git a/Modules/FindICU.cmake b/Modules/FindICU.cmake index 5210f08..d9705d9 100644 --- a/Modules/FindICU.cmake +++ b/Modules/FindICU.cmake @@ -55,6 +55,11 @@ # ICU_<C>_FOUND - ON if component was found # ICU_<C>_LIBRARIES - libraries for component # +# ICU datafiles are reported in:: +# +# ICU_MAKEFILE_INC - Makefile.inc +# ICU_PKGDATA_INC - pkgdata.inc +# # Note that ``<C>`` is the uppercased name of the component. # # This module reads hints about search results from:: @@ -100,6 +105,10 @@ set(icu_programs icupkg gencmn) +set(icu_data + Makefile.inc + pkgdata.inc) + # The ICU checks are contained in a function due to the large number # of temporary variables needed. function(_ICU_FIND) @@ -116,6 +125,28 @@ function(_ICU_FIND) endif() endif() + # Find include directory + list(APPEND icu_include_suffixes "include") + find_path(ICU_INCLUDE_DIR + NAMES "unicode/utypes.h" + HINTS ${icu_roots} + PATH_SUFFIXES ${icu_include_suffixes} + DOC "ICU include directory") + set(ICU_INCLUDE_DIR "${ICU_INCLUDE_DIR}" PARENT_SCOPE) + + # Get version + if(ICU_INCLUDE_DIR AND EXISTS "${ICU_INCLUDE_DIR}/unicode/uvernum.h") + file(STRINGS "${ICU_INCLUDE_DIR}/unicode/uvernum.h" icu_header_str + REGEX "^#define[\t ]+U_ICU_VERSION[\t ]+\".*\".*") + + string(REGEX REPLACE "^#define[\t ]+U_ICU_VERSION[\t ]+\"([^ \\n]*)\".*" + "\\1" icu_version_string "${icu_header_str}") + set(ICU_VERSION "${icu_version_string}") + set(ICU_VERSION "${icu_version_string}" PARENT_SCOPE) + unset(icu_header_str) + unset(icu_version_string) + endif() + if(CMAKE_SIZEOF_VOID_P EQUAL 8) # 64-bit binary directory set(_bin64 "bin64") @@ -123,12 +154,9 @@ function(_ICU_FIND) set(_lib64 "lib64") endif() - # Generic 64-bit and 32-bit directories - list(APPEND icu_binary_suffixes "${_bin64}" "bin") - list(APPEND icu_library_suffixes "${_lib64}" "lib") - list(APPEND icu_include_suffixes "include") # Find all ICU programs + list(APPEND icu_binary_suffixes "${_bin64}" "bin") foreach(program ${icu_programs}) string(TOUPPER "${program}" program_upcase) set(cache_var "ICU_${program_upcase}_EXECUTABLE") @@ -141,27 +169,8 @@ function(_ICU_FIND) set("${program_var}" "${${cache_var}}" PARENT_SCOPE) endforeach() - # Find include directory - find_path(ICU_INCLUDE_DIR - NAMES "unicode/utypes.h" - HINTS ${icu_roots} - PATH_SUFFIXES ${icu_include_suffixes} - DOC "ICU include directory") - set(ICU_INCLUDE_DIR "${ICU_INCLUDE_DIR}" PARENT_SCOPE) - - # Get version - if(ICU_INCLUDE_DIR AND EXISTS "${ICU_INCLUDE_DIR}/unicode/uvernum.h") - file(STRINGS "${ICU_INCLUDE_DIR}/unicode/uvernum.h" icu_header_str - REGEX "^#define[\t ]+U_ICU_VERSION[\t ]+\".*\".*") - - string(REGEX REPLACE "^#define[\t ]+U_ICU_VERSION[\t ]+\"([^ \\n]*)\".*" - "\\1" icu_version_string "${icu_header_str}") - set(ICU_VERSION "${icu_version_string}" PARENT_SCOPE) - unset(icu_header_str) - unset(icu_version_string) - endif() - # Find all ICU libraries + list(APPEND icu_library_suffixes "${_lib64}" "lib") set(ICU_REQUIRED_LIBS_FOUND ON) foreach(component ${ICU_FIND_COMPONENTS}) string(TOUPPER "${component}" component_upcase) @@ -233,6 +242,32 @@ function(_ICU_FIND) set(_ICU_REQUIRED_LIBS_FOUND "${ICU_REQUIRED_LIBS_FOUND}" PARENT_SCOPE) set(ICU_LIBRARY "${ICU_LIBRARY}" PARENT_SCOPE) + # Find all ICU data files + if(CMAKE_LIBRARY_ARCHITECTURE) + list(APPEND icu_data_suffixes + "${_lib64}/${CMAKE_LIBRARY_ARCHITECTURE}/icu/${ICU_VERSION}" + "lib/${CMAKE_LIBRARY_ARCHITECTURE}/icu/${ICU_VERSION}" + "${_lib64}/${CMAKE_LIBRARY_ARCHITECTURE}/icu" + "lib/${CMAKE_LIBRARY_ARCHITECTURE}/icu") + endif() + list(APPEND icu_data_suffixes + "${_lib64}/icu/${ICU_VERSION}" + "lib/icu/${ICU_VERSION}" + "${_lib64}/icu" + "lib/icu") + foreach(data ${icu_data}) + string(TOUPPER "${data}" data_upcase) + string(REPLACE "." "_" data_upcase "${data_upcase}") + set(cache_var "ICU_${data_upcase}") + set(data_var "ICU_${data_upcase}") + find_file("${cache_var}" "${data}" + HINTS ${icu_roots} + PATH_SUFFIXES ${icu_data_suffixes} + DOC "ICU ${data} data file") + mark_as_advanced(cache_var) + set("${data_var}" "${${cache_var}}" PARENT_SCOPE) + endforeach() + if(NOT ICU_FIND_QUIETLY) if(ICU_LIBS_FOUND) message(STATUS "Found the following ICU libraries:") @@ -334,6 +369,15 @@ if(ICU_DEBUG) unset(program_lib) endforeach() + foreach(data IN LISTS icu_data) + string(TOUPPER "${data}" data_upcase) + string(REPLACE "." "_" data_upcase "${data_upcase}") + set(data_lib "ICU_${data_upcase}") + message(STATUS "${data} data: ${${data_lib}}") + unset(data_upcase) + unset(data_lib) + endforeach() + foreach(component IN LISTS ICU_FIND_COMPONENTS) string(TOUPPER "${component}" component_upcase) set(component_lib "ICU_${component_upcase}_LIBRARIES") diff --git a/Modules/FindIce.cmake b/Modules/FindIce.cmake index e0286ee..a8133da 100644 --- a/Modules/FindIce.cmake +++ b/Modules/FindIce.cmake @@ -10,8 +10,16 @@ # # This module supports multiple components. # Components can include any of: ``Freeze``, ``Glacier2``, ``Ice``, -# ``IceBox``, ``IceDB``, ``IceGrid``, ``IcePatch``, ``IceSSL``, -# ``IceStorm``, ``IceUtil``, ``IceXML``, or ``Slice``. +# ``IceBox``, ``IceDB``, ``IceDiscovery``, ``IceGrid``, +# ``IceLocatorDiscovery``, ``IcePatch``, ``IceSSL``, ``IceStorm``, +# ``IceUtil``, ``IceXML``, or ``Slice``. +# +# Ice 3.7 and later also include C++11-specific components: +# ``Glacier2++11``, ``Ice++11``, ``IceBox++11``, ``IceDiscovery++11`` +# ``IceGrid``, ``IceLocatorDiscovery++11``, ``IceSSL++11``, +# ``IceStorm++11`` +# +# Note that the set of supported components is Ice version-specific. # # This module reports information about the Ice installation in # several variables. General variables:: @@ -28,7 +36,7 @@ # Ice::<C> # # Where ``<C>`` is the name of an Ice component, for example -# ``Ice::Glacier2``. +# ``Ice::Glacier2`` or ``Ice++11``. # # Ice slice programs are reported in:: # @@ -39,6 +47,7 @@ # Ice_SLICE2HTML_EXECUTABLE - path to slice2html executable # Ice_SLICE2JAVA_EXECUTABLE - path to slice2java executable # Ice_SLICE2JS_EXECUTABLE - path to slice2js executable +# Ice_SLICE2OBJC_EXECUTABLE - path to slice2objc executable # Ice_SLICE2PHP_EXECUTABLE - path to slice2php executable # Ice_SLICE2PY_EXECUTABLE - path to slice2py executable # Ice_SLICE2RB_EXECUTABLE - path to slice2rb executable @@ -47,10 +56,13 @@ # # Ice_GLACIER2ROUTER_EXECUTABLE - path to glacier2router executable # Ice_ICEBOX_EXECUTABLE - path to icebox executable +# Ice_ICEBOXXX11_EXECUTABLE - path to icebox++11 executable # Ice_ICEBOXADMIN_EXECUTABLE - path to iceboxadmin executable # Ice_ICEBOXD_EXECUTABLE - path to iceboxd executable # Ice_ICEBOXNET_EXECUTABLE - path to iceboxnet executable +# Ice_ICEBRIDGE_EXECUTABLE - path to icebridge executable # Ice_ICEGRIDADMIN_EXECUTABLE - path to icegridadmin executable +# Ice_ICEGRIDDB_EXECUTABLE - path to icegriddb executable # Ice_ICEGRIDNODE_EXECUTABLE - path to icegridnode executable # Ice_ICEGRIDNODED_EXECUTABLE - path to icegridnoded executable # Ice_ICEGRIDREGISTRY_EXECUTABLE - path to icegridregistry executable @@ -60,6 +72,7 @@ # Ice_ICEPATCH2SERVER_EXECUTABLE - path to icepatch2server executable # Ice_ICESERVICEINSTALL_EXECUTABLE - path to iceserviceinstall executable # Ice_ICESTORMADMIN_EXECUTABLE - path to icestormadmin executable +# Ice_ICESTORMDB_EXECUTABLE - path to icestormdb executable # Ice_ICESTORMMIGRATE_EXECUTABLE - path to icestormmigrate executable # # Ice db programs (Windows only; standard system versions on all other @@ -95,6 +108,13 @@ # The environment variable ``ICE_HOME`` may also be used; the # Ice_HOME variable takes precedence. # +# .. note:: +# On Windows, Ice 3.7.0 and later provide libraries via the NuGet +# package manager. Appropriate NuGet packages will be searched for +# using ``CMAKE_PREFIX_PATH``, or alternatively ``Ice_HOME`` may be +# set to the location of a specific NuGet package to restrict the +# search. +# # The following cache variables may also be set:: # # Ice_<P>_EXECUTABLE - the path to executable <P> @@ -124,12 +144,67 @@ # Written by Roger Leigh <rleigh@codelibre.net> + set(_Ice_db_programs + db_archive + db_checkpoint + db_deadlock + db_dump + db_hotbackup + db_load + db_log_verify + db_printlog + db_recover + db_stat + db_tuner + db_upgrade + db_verify + dumpdb + transformdb) + + set(_Ice_programs + glacier2router + icebox + icebox++11 + iceboxadmin + iceboxd + iceboxnet + icebridge + icegridadmin + icegriddb + icegridnode + icegridnoded + icegridregistry + icegridregistryd + icepatch2calc + icepatch2client + icepatch2server + iceserviceinstall + icestormadmin + icestormdb + icestormmigrate) + + set(_Ice_slice_programs + slice2cpp + slice2cs + slice2freezej + slice2freeze + slice2html + slice2java + slice2js + slice2objc + slice2php + slice2py + slice2rb) + + # The Ice checks are contained in a function due to the large number # of temporary variables needed. function(_Ice_FIND) # Released versions of Ice, including generic short forms set(ice_versions 3 + 3.7 + 3.7.0 3.6 3.6.3 3.6.2 @@ -146,6 +221,14 @@ function(_Ice_FIND) 3.3.1 3.3.0) + foreach(ver ${ice_versions}) + string(REGEX MATCH "^([0-9]+)\\.([0-9]+)\$" two_digit_version_match "${ver}") + if(two_digit_version_match) + string(REGEX REPLACE "^([0-9]+)\\.([0-9]+)\$" "\\1\\2" two_digit_version "${ver}") + list(APPEND ice_suffix_versions "${two_digit_version}") + endif() + endforeach() + # Set up search paths, taking compiler into account. Search Ice_HOME, # with ICE_HOME in the environment as a fallback if unset. if(Ice_HOME) @@ -159,52 +242,77 @@ function(_Ice_FIND) endif() endif() + set(_bin "bin/Win32") + set(_lib "lib/Win32") if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(_bin "bin/x64") + set(_lib "lib/x64") # 64-bit path suffix set(_x64 "/x64") # 64-bit library directory set(_lib64 "lib64") endif() - if(MSVC_VERSION) - # VS 8.0 - if(NOT MSVC_VERSION VERSION_LESS 1400 AND MSVC_VERSION VERSION_LESS 1500) - set(vcver "vc80") - set(vcyear "2005") - # VS 9.0 - elseif(NOT MSVC_VERSION VERSION_LESS 1500 AND MSVC_VERSION VERSION_LESS 1600) - set(vcver "vc90") + unset(vcvers) + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.10) + set(vcvers "141;140") + elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19) + set(vcvers "140") + elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18) + set(vcvers "120") + elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 17) + set(vcvers "110") + elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16) + set(vcvers "100") + elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15) + set(vcvers "90") set(vcyear "2008") - # VS 10.0 - elseif(NOT MSVC_VERSION VERSION_LESS 1600 AND MSVC_VERSION VERSION_LESS 1700) - set(vcver "vc100") - # VS 11.0 - elseif(NOT MSVC_VERSION VERSION_LESS 1700 AND MSVC_VERSION VERSION_LESS 1800) - set(vcver "vc110") - # VS 12.0 - elseif(NOT MSVC_VERSION VERSION_LESS 1800 AND MSVC_VERSION VERSION_LESS 1900) - set(vcver "vc120") - # VS 14.0 - elseif(NOT MSVC_VERSION VERSION_LESS 1900 AND MSVC_VERSION VERSION_LESS 2000) - set(vcver "vc140") + elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 14) + set(vcvers "80") + set(vcyear "2005") + else() # Unknown version + set(vcvers Unknown) endif() endif() # For compatibility with ZeroC Windows builds. - if(vcver) - # Earlier Ice (3.3) builds don't use vcnnn subdirectories, but are harmless to check. - list(APPEND ice_binary_suffixes "bin/${vcver}${_x64}" "bin/${vcver}") - list(APPEND ice_library_suffixes "lib/${vcver}${_x64}" "lib/${vcver}") + if(vcvers) + list(APPEND ice_binary_suffixes "build/native/${_bin}/Release" "tools") + list(APPEND ice_debug_library_suffixes "build/native/${_lib}/Debug") + list(APPEND ice_release_library_suffixes "build/native/${_lib}/Release") + foreach(vcver IN LISTS vcvers) + # Earlier Ice (3.3) builds don't use vcnnn subdirectories, but are harmless to check. + list(APPEND ice_binary_suffixes "bin/vc${vcver}${_x64}" "bin/vc${vcver}") + list(APPEND ice_debug_library_suffixes "lib/vc${vcver}${_x64}" "lib/vc${vcver}") + list(APPEND ice_release_library_suffixes "lib/vc${vcver}${_x64}" "lib/vc${vcver}") + endforeach() endif() # Generic 64-bit and 32-bit directories list(APPEND ice_binary_suffixes "bin${_x64}" "bin") - list(APPEND ice_library_suffixes "libx32" "${_lib64}" "lib${_x64}" "lib") + list(APPEND ice_debug_library_suffixes "libx32" "${_lib64}" "lib${_x64}" "lib") + list(APPEND ice_release_library_suffixes "libx32" "${_lib64}" "lib${_x64}" "lib") + if(vcvers) + list(APPEND ice_include_suffixes "build/native/include") + endif() list(APPEND ice_include_suffixes "include") list(APPEND ice_slice_suffixes "slice") # On Windows, look in the registry for install locations. Different # versions of Ice install support different compiler versions. - if(vcver) + if(vcvers) + foreach(ice_version ${ice_versions}) + foreach(vcver IN LISTS vcvers) + list(APPEND ice_nuget_dirs "zeroc.ice.v${vcver}.${ice_version}") + endforeach() + endforeach() + find_path(Ice_NUGET_DIR + NAMES "tools/slice2cpp.exe" + PATH_SUFFIXES ${ice_nuget_dirs} + DOC "Ice NuGet directory") + if(Ice_NUGET_DIR) + list(APPEND ice_roots "${Ice_NUGET_DIR}") + endif() foreach(ice_version ${ice_versions}) # Ice 3.3 releases use a Visual Studio year suffix and value is # enclosed in double quotes, though only the leading quote is @@ -239,55 +347,8 @@ function(_Ice_FIND) endforeach() endif() - set(db_programs - db_archive - db_checkpoint - db_deadlock - db_dump - db_hotbackup - db_load - db_log_verify - db_printlog - db_recover - db_stat - db_tuner - db_upgrade - db_verify - dumpdb - transformdb) - - set(ice_programs - glacier2router - icebox - iceboxadmin - iceboxd - iceboxnet - icegridadmin - icegridnode - icegridnoded - icegridregistry - icegridregistryd - icepatch2calc - icepatch2client - icepatch2server - iceserviceinstall - icestormadmin - icestormmigrate) - - set(slice_programs - slice2cpp - slice2cs - slice2freezej - slice2freeze - slice2html - slice2java - slice2js - slice2php - slice2py - slice2rb) - # Find all Ice programs - foreach(program ${db_programs} ${ice_programs} ${slice_programs}) + foreach(program ${_Ice_db_programs} ${_Ice_programs} ${_Ice_slice_programs}) string(TOUPPER "${program}" program_upcase) set(cache_var "Ice_${program_upcase}_EXECUTABLE") set(program_var "Ice_${program_upcase}_EXECUTABLE") @@ -336,6 +397,7 @@ function(_Ice_FIND) list(APPEND ice_slice_suffixes "Ice-${Ice_VERSION_SLICE2CPP_FULL}/slice" "Ice-${Ice_VERSION_SLICE2CPP_SHORT}/slice" + "ice/slice" Ice) # Find slice directory @@ -356,13 +418,39 @@ function(_Ice_FIND) set(component_cache_release "${component_cache}_RELEASE") set(component_cache_debug "${component_cache}_DEBUG") set(component_found "${component_upcase}_FOUND") - find_library("${component_cache_release}" "${component}" + set(component_library "${component}") + unset(component_library_release_names) + unset(component_library_debug_names) + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + string(REGEX MATCH ".+\\+\\+11$" component_library_cpp11 "${component_library}") + if(component_library_cpp11) + string(REGEX REPLACE "^(.+)(\\+\\+11)$" "\\1" component_library "${component_library}") + endif() + foreach(suffix_ver ${ice_suffix_versions}) + set(_name "${component_library}${suffix_ver}") + if(component_library_cpp11) + string(APPEND _name "++11") + endif() + list(APPEND component_library_debug_names "${_name}d") + list(APPEND component_library_release_names "${_name}") + endforeach() + set(_name "${component_library}") + if(component_library_cpp11) + string(APPEND _name "++11") + endif() + list(APPEND component_library_debug_names "${_name}d") + list(APPEND component_library_release_names "${_name}") + else() + list(APPEND component_library_debug_names "${component_library}d") + list(APPEND component_library_release_names "${component_library}") + endif() + find_library("${component_cache_release}" ${component_library_release_names} HINTS ${ice_roots} - PATH_SUFFIXES ${ice_library_suffixes} + PATH_SUFFIXES ${ice_release_library_suffixes} DOC "Ice ${component} library (release)") - find_library("${component_cache_debug}" "${component}d" + find_library("${component_cache_debug}" ${component_library_debug_names} HINTS ${ice_roots} - PATH_SUFFIXES ${ice_library_suffixes} + PATH_SUFFIXES ${ice_debug_library_suffixes} DOC "Ice ${component} library (debug)") include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake) select_library_configurations(Ice_${component_upcase}) @@ -410,9 +498,14 @@ function(_Ice_FIND) if(Ice_DEBUG) message(STATUS "--------FindIce.cmake search debug--------") message(STATUS "ICE binary path search order: ${ice_roots}") + message(STATUS "ICE binary suffixes: ${ice_binary_suffixes}") message(STATUS "ICE include path search order: ${ice_roots}") + message(STATUS "ICE include suffixes: ${ice_include_suffixes}") message(STATUS "ICE slice path search order: ${ice_roots} ${ice_slice_paths}") + message(STATUS "ICE slice suffixes: ${ice_slice_suffixes}") message(STATUS "ICE library path search order: ${ice_roots}") + message(STATUS "ICE debug library suffixes: ${ice_debug_library_suffixes}") + message(STATUS "ICE release library suffixes: ${ice_release_library_suffixes}") message(STATUS "----------------") endif() endfunction() @@ -489,49 +582,10 @@ if(Ice_DEBUG) message(STATUS "Ice_SLICE_DIR directory: ${Ice_SLICE_DIR}") message(STATUS "Ice_LIBRARIES: ${Ice_LIBRARIES}") - message(STATUS "slice2cpp executable: ${Ice_SLICE2CPP_EXECUTABLE}") - message(STATUS "slice2cs executable: ${Ice_SLICE2CS_EXECUTABLE}") - message(STATUS "slice2freezej executable: ${Ice_SLICE2FREEZEJ_EXECUTABLE}") - message(STATUS "slice2freeze executable: ${Ice_SLICE2FREEZE_EXECUTABLE}") - message(STATUS "slice2html executable: ${Ice_SLICE2HTML_EXECUTABLE}") - message(STATUS "slice2java executable: ${Ice_SLICE2JAVA_EXECUTABLE}") - message(STATUS "slice2js executable: ${Ice_SLICE2JS_EXECUTABLE}") - message(STATUS "slice2php executable: ${Ice_SLICE2PHP_EXECUTABLE}") - message(STATUS "slice2py executable: ${Ice_SLICE2PY_EXECUTABLE}") - message(STATUS "slice2rb executable: ${Ice_SLICE2RB_EXECUTABLE}") - message(STATUS "glacier2router executable: ${Ice_GLACIER2ROUTER_EXECUTABLE}") - - message(STATUS "icebox executable: ${Ice_ICEBOX_EXECUTABLE}") - message(STATUS "iceboxadmin executable: ${Ice_ICEBOXADMIN_EXECUTABLE}") - message(STATUS "iceboxd executable: ${Ice_ICEBOXD_EXECUTABLE}") - message(STATUS "iceboxnet executable: ${Ice_ICEBOXNET_EXECUTABLE}") - message(STATUS "icegridadmin executable: ${Ice_ICEGRIDADMIN_EXECUTABLE}") - message(STATUS "icegridnode executable: ${Ice_ICEGRIDNODE_EXECUTABLE}") - message(STATUS "icegridnoded executable: ${Ice_ICEGRIDNODED_EXECUTABLE}") - message(STATUS "icegridregistry executable: ${Ice_ICEGRIDREGISTRY_EXECUTABLE}") - message(STATUS "icegridregistryd executable: ${Ice_ICEGRIDREGISTRYD_EXECUTABLE}") - message(STATUS "icepatch2calc executable: ${Ice_ICEPATCH2CALC_EXECUTABLE}") - message(STATUS "icepatch2client executable: ${Ice_ICEPATCH2CLIENT_EXECUTABLE}") - message(STATUS "icepatch2server executable: ${Ice_ICEPATCH2SERVER_EXECUTABLE}") - message(STATUS "iceserviceinstall executable: ${Ice_ICESERVICEINSTALL_EXECUTABLE}") - message(STATUS "icestormadmin executable: ${Ice_ICESTORMADMIN_EXECUTABLE}") - message(STATUS "icestormmigrate executable: ${Ice_ICESTORMMIGRATE_EXECUTABLE}") - - message(STATUS "db_archive executable: ${Ice_DB_ARCHIVE_EXECUTABLE}") - message(STATUS "db_checkpoint executable: ${Ice_DB_CHECKPOINT_EXECUTABLE}") - message(STATUS "db_deadlock executable: ${Ice_DB_DEADLOCK_EXECUTABLE}") - message(STATUS "db_dump executable: ${Ice_DB_DUMP_EXECUTABLE}") - message(STATUS "db_hotbackup executable: ${Ice_DB_HOTBACKUP_EXECUTABLE}") - message(STATUS "db_load executable: ${Ice_DB_LOAD_EXECUTABLE}") - message(STATUS "db_log_verify executable: ${Ice_DB_LOG_VERIFY_EXECUTABLE}") - message(STATUS "db_printlog executable: ${Ice_DB_PRINTLOG_EXECUTABLE}") - message(STATUS "db_recover executable: ${Ice_DB_RECOVER_EXECUTABLE}") - message(STATUS "db_stat executable: ${Ice_DB_STAT_EXECUTABLE}") - message(STATUS "db_tuner executable: ${Ice_DB_TUNER_EXECUTABLE}") - message(STATUS "db_upgrade executable: ${Ice_DB_UPGRADE_EXECUTABLE}") - message(STATUS "db_verify executable: ${Ice_DB_VERIFY_EXECUTABLE}") - message(STATUS "dumpdb executable: ${Ice_DUMPDB_EXECUTABLE}") - message(STATUS "transformdb executable: ${Ice_TRANSFORMDB_EXECUTABLE}") + foreach(program ${_Ice_db_programs} ${_Ice_programs} ${_Ice_slice_programs}) + string(TOUPPER "${program}" program_upcase) + message(STATUS "${program} executable: ${Ice_${program_upcase}_EXECUTABLE}") + endforeach() foreach(component ${Ice_FIND_COMPONENTS}) string(TOUPPER "${component}" component_upcase) @@ -542,3 +596,7 @@ if(Ice_DEBUG) endforeach() message(STATUS "----------------") endif() + +unset(_Ice_db_programs) +unset(_Ice_programs) +unset(_Ice_slice_programs) diff --git a/Modules/FindLibXml2.cmake b/Modules/FindLibXml2.cmake index 613f927..8ac2980 100644 --- a/Modules/FindLibXml2.cmake +++ b/Modules/FindLibXml2.cmake @@ -5,18 +5,37 @@ # FindLibXml2 # ----------- # -# Try to find the LibXml2 xml processing library +# Find the XML processing library (libxml2). # -# Once done this will define +# Result variables +# ^^^^^^^^^^^^^^^^ # -# :: +# This module will set the following variables in your project: # -# LIBXML2_FOUND - System has LibXml2 -# LIBXML2_INCLUDE_DIR - The LibXml2 include directory -# LIBXML2_LIBRARIES - The libraries needed to use LibXml2 -# LIBXML2_DEFINITIONS - Compiler switches required for using LibXml2 -# LIBXML2_XMLLINT_EXECUTABLE - The XML checking tool xmllint coming with LibXml2 -# LIBXML2_VERSION_STRING - the version of LibXml2 found (since CMake 2.8.8) +# ``LIBXML2_FOUND`` +# true if libxml2 headers and libraries were found +# ``LIBXML2_INCLUDE_DIR`` +# the directory containing LibXml2 headers +# ``LIBXML2_INCLUDE_DIRS`` +# list of the include directories needed to use LibXml2 +# ``LIBXML2_LIBRARIES`` +# LibXml2 libraries to be linked +# ``LIBXML2_DEFINITIONS`` +# the compiler switches required for using LibXml2 +# ``LIBXML2_XMLLINT_EXECUTABLE`` +# path to the XML checking tool xmllint coming with LibXml2 +# ``LIBXML2_VERSION_STRING`` +# the version of LibXml2 found (since CMake 2.8.8) +# +# Cache variables +# ^^^^^^^^^^^^^^^ +# +# The following cache variables may also be set: +# +# ``LIBXML2_INCLUDE_DIR`` +# the directory containing LibXml2 headers +# ``LIBXML2_LIBRARY`` +# path to the LibXml2 library # use pkg-config to get the directories and then use these values # in the find_path() and find_library() calls @@ -31,7 +50,14 @@ find_path(LIBXML2_INCLUDE_DIR NAMES libxml/xpath.h PATH_SUFFIXES libxml2 ) -find_library(LIBXML2_LIBRARIES NAMES xml2 libxml2 +# CMake 3.9 and below used 'LIBXML2_LIBRARIES' as the name of +# the cache entry storing the find_library result. Use the +# value if it was set by the project or user. +if(DEFINED LIBXML2_LIBRARIES AND NOT DEFINED LIBXML2_LIBRARY) + set(LIBXML2_LIBRARY ${LIBXML2_LIBRARIES}) +endif() + +find_library(LIBXML2_LIBRARY NAMES xml2 libxml2 HINTS ${PC_LIBXML_LIBDIR} ${PC_LIBXML_LIBRARY_DIRS} @@ -52,9 +78,12 @@ elseif(LIBXML2_INCLUDE_DIR AND EXISTS "${LIBXML2_INCLUDE_DIR}/libxml/xmlversion. unset(libxml2_version_str) endif() +set(LIBXML2_INCLUDE_DIRS ${LIBXML2_INCLUDE_DIR} ${PC_LIBXML_INCLUDE_DIRS}) +set(LIBXML2_LIBRARIES ${LIBXML2_LIBRARY}) + include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibXml2 - REQUIRED_VARS LIBXML2_LIBRARIES LIBXML2_INCLUDE_DIR + REQUIRED_VARS LIBXML2_LIBRARY LIBXML2_INCLUDE_DIR VERSION_VAR LIBXML2_VERSION_STRING) -mark_as_advanced(LIBXML2_INCLUDE_DIR LIBXML2_LIBRARIES LIBXML2_XMLLINT_EXECUTABLE) +mark_as_advanced(LIBXML2_INCLUDE_DIR LIBXML2_LIBRARY LIBXML2_XMLLINT_EXECUTABLE) diff --git a/Modules/FindMFC.cmake b/Modules/FindMFC.cmake index 5c2dbbf..3baaf32 100644 --- a/Modules/FindMFC.cmake +++ b/Modules/FindMFC.cmake @@ -31,6 +31,7 @@ if(MFC_ATTEMPT_TRY_COMPILE) configure_file(${CMAKE_ROOT}/Modules/CheckIncludeFile.cxx.in ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.cxx) message(STATUS "Looking for MFC") + # Try both shared and static as the root project may have set the /MT flag try_compile(MFC_HAVE_MFC ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.cxx @@ -38,6 +39,16 @@ if(MFC_ATTEMPT_TRY_COMPILE) -DCMAKE_MFC_FLAG:STRING=2 -DCOMPILE_DEFINITIONS:STRING=-D_AFXDLL OUTPUT_VARIABLE OUTPUT) + if(NOT MFC_HAVE_MFC) + configure_file(${CMAKE_ROOT}/Modules/CheckIncludeFile.cxx.in + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.cxx) + try_compile(MFC_HAVE_MFC + ${CMAKE_BINARY_DIR} + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.cxx + CMAKE_FLAGS + -DCMAKE_MFC_FLAG:STRING=1 + OUTPUT_VARIABLE OUTPUT) + endif() if(MFC_HAVE_MFC) message(STATUS "Looking for MFC - found") set(MFC_HAVE_MFC 1 CACHE INTERNAL "Have MFC?") diff --git a/Modules/FindMatlab.cmake b/Modules/FindMatlab.cmake index 80bcda3..cd8246d 100644 --- a/Modules/FindMatlab.cmake +++ b/Modules/FindMatlab.cmake @@ -721,7 +721,7 @@ endfunction() # matlab_add_unit_test( # NAME <name> # UNITTEST_FILE matlab_file_containing_unittest.m -# [CUSTOM_MATLAB_COMMAND matlab_command_to_run_as_test] +# [CUSTOM_TEST_COMMAND matlab_command_to_run_as_test] # [UNITTEST_PRECOMMAND matlab_command_to_run] # [TIMEOUT timeout] # [ADDITIONAL_PATH path1 [path2 ...]] @@ -737,7 +737,7 @@ endfunction() # ``UNITTEST_FILE`` # the matlab unittest file. Its path will be automatically # added to the Matlab path. -# ``CUSTOM_MATLAB_COMMAND`` +# ``CUSTOM_TEST_COMMAND`` # Matlab script command to run as the test. # If this is not set, then the following is run: # ``runtests('matlab_file_name'), exit(max([ans(1,:).Failed]))`` diff --git a/Modules/FindPkgConfig.cmake b/Modules/FindPkgConfig.cmake index a5357fa..76afa8a 100644 --- a/Modules/FindPkgConfig.cmake +++ b/Modules/FindPkgConfig.cmake @@ -323,6 +323,9 @@ macro(_pkg_check_modules_internal _is_required _is_silent _no_cmake_path _no_cma endif() endif() endif() + if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" AND NOT CMAKE_CROSSCOMPILING) + list(APPEND _lib_dirs "libdata/pkgconfig") + endif() list(APPEND _lib_dirs "lib/pkgconfig") list(APPEND _lib_dirs "share/pkgconfig") @@ -584,7 +587,9 @@ endmacro() macro(pkg_check_modules _prefix _module0) _pkgconfig_parse_options(_pkg_modules _pkg_is_required _pkg_is_silent _no_cmake_path _no_cmake_environment_path _imp_target "${_module0}" ${ARGN}) # check cached value - if (NOT DEFINED __pkg_config_checked_${_prefix} OR __pkg_config_checked_${_prefix} LESS ${PKG_CONFIG_VERSION} OR NOT ${_prefix}_FOUND OR NOT "${__pkg_config_arguments_${_prefix}}" STREQUAL "${_module0};${ARGN}") + if (NOT DEFINED __pkg_config_checked_${_prefix} OR __pkg_config_checked_${_prefix} LESS ${PKG_CONFIG_VERSION} OR NOT ${_prefix}_FOUND OR + (NOT "${ARGN}" STREQUAL "" AND NOT "${__pkg_config_arguments_${_prefix}}" STREQUAL "${_module0};${ARGN}") OR + ( "${ARGN}" STREQUAL "" AND NOT "${__pkg_config_arguments_${_prefix}}" STREQUAL "${_module0}")) _pkg_check_modules_internal("${_pkg_is_required}" "${_pkg_is_silent}" ${_no_cmake_path} ${_no_cmake_environment_path} ${_imp_target} "${_prefix}" ${_pkg_modules}) _pkgconfig_set(__pkg_config_checked_${_prefix} ${PKG_CONFIG_VERSION}) diff --git a/Modules/FindProtobuf.cmake b/Modules/FindProtobuf.cmake index 33262f3..90f7a2e 100644 --- a/Modules/FindProtobuf.cmake +++ b/Modules/FindProtobuf.cmake @@ -48,6 +48,8 @@ # The protobuf lite library. # ``protobuf::libprotoc`` # The protoc library. +# ``protobuf::protoc`` +# The protoc compiler. # # The following cache variables are also available to set or use: # @@ -172,9 +174,9 @@ function(PROTOBUF_GENERATE_CPP SRCS HDRS) add_custom_command( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc" "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h" - COMMAND ${Protobuf_PROTOC_EXECUTABLE} + COMMAND protobuf::protoc ARGS "--cpp_out=${DLL_EXPORT_DECL}${CMAKE_CURRENT_BINARY_DIR}" ${_protobuf_include_path} ${ABS_FIL} - DEPENDS ${ABS_FIL} ${Protobuf_PROTOC_EXECUTABLE} + DEPENDS ${ABS_FIL} protobuf::protoc COMMENT "Running C++ protocol buffer compiler on ${FIL}" VERBATIM ) endforeach() @@ -232,8 +234,8 @@ function(PROTOBUF_GENERATE_PYTHON SRCS) list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}_pb2.py") add_custom_command( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}_pb2.py" - COMMAND ${Protobuf_PROTOC_EXECUTABLE} --python_out ${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${ABS_FIL} - DEPENDS ${ABS_FIL} ${Protobuf_PROTOC_EXECUTABLE} + COMMAND protobuf::protoc --python_out ${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${ABS_FIL} + DEPENDS ${ABS_FIL} protobuf::protoc COMMENT "Running Python protocol buffer compiler on ${FIL}" VERBATIM ) endforeach() @@ -501,6 +503,16 @@ if(Protobuf_INCLUDE_DIR) endif() endif() endif() + + if(Protobuf_PROTOC_EXECUTABLE) + if(NOT TARGET protobuf::protoc) + add_executable(protobuf::protoc IMPORTED) + if(EXISTS "${Protobuf_PROTOC_EXECUTABLE}") + set_target_properties(protobuf::protoc PROPERTIES + IMPORTED_LOCATION "${Protobuf_PROTOC_EXECUTABLE}") + endif() + endif() + endif() endif() include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) diff --git a/Modules/FindXCTest.cmake b/Modules/FindXCTest.cmake index ffdf677..8497336 100644 --- a/Modules/FindXCTest.cmake +++ b/Modules/FindXCTest.cmake @@ -136,7 +136,7 @@ function(xctest_add_bundle target testee) XCODE_ATTRIBUTE_TEST_HOST "$<TARGET_FILE:${testee}>") if(NOT XCODE_VERSION VERSION_LESS 7.3) set_target_properties(${target} PROPERTIES - LIBRARY_OUTPUT_DIRECTORY "$<TARGET_FILE_DIR:${testee}>/../PlugIns") + LIBRARY_OUTPUT_DIRECTORY "$<TARGET_BUNDLE_CONTENT_DIR:${testee}>/PlugIns") endif() else(XCODE) target_link_libraries(${target} @@ -183,7 +183,7 @@ function(xctest_add_test name bundle) add_test( NAME ${name} - COMMAND ${XCTest_EXECUTABLE} $<TARGET_LINKER_FILE_DIR:${bundle}>/../..) + COMMAND ${XCTest_EXECUTABLE} $<TARGET_BUNDLE_DIR:${bundle}>) # point loader to testee in case rpath is disabled diff --git a/Modules/FindwxWidgets.cmake b/Modules/FindwxWidgets.cmake index af4daf0..63f2c60 100644 --- a/Modules/FindwxWidgets.cmake +++ b/Modules/FindwxWidgets.cmake @@ -778,28 +778,24 @@ else() ) if(RET EQUAL 0) string(STRIP "${wxWidgets_CXX_FLAGS}" wxWidgets_CXX_FLAGS) - separate_arguments(wxWidgets_CXX_FLAGS) + separate_arguments(wxWidgets_CXX_FLAGS_LIST NATIVE_COMMAND "${wxWidgets_CXX_FLAGS}") DBG_MSG_V("wxWidgets_CXX_FLAGS=${wxWidgets_CXX_FLAGS}") - # parse definitions from cxxflags; - # drop -D* from CXXFLAGS and the -D prefix - string(REGEX MATCHALL "-D[^;]+" - wxWidgets_DEFINITIONS "${wxWidgets_CXX_FLAGS}") - string(REGEX REPLACE "-D[^;]+(;|$)" "" - wxWidgets_CXX_FLAGS "${wxWidgets_CXX_FLAGS}") - string(REGEX REPLACE ";$" "" - wxWidgets_CXX_FLAGS "${wxWidgets_CXX_FLAGS}") - string(REPLACE "-D" "" - wxWidgets_DEFINITIONS "${wxWidgets_DEFINITIONS}") - - # parse include dirs from cxxflags; drop -I prefix - string(REGEX MATCHALL "-I[^;]+" - wxWidgets_INCLUDE_DIRS "${wxWidgets_CXX_FLAGS}") - string(REGEX REPLACE "-I[^;]+;" "" - wxWidgets_CXX_FLAGS "${wxWidgets_CXX_FLAGS}") - string(REPLACE "-I" "" - wxWidgets_INCLUDE_DIRS "${wxWidgets_INCLUDE_DIRS}") + # parse definitions and include dirs from cxxflags + # drop the -D and -I prefixes + set(wxWidgets_CXX_FLAGS) + foreach(arg IN LISTS wxWidgets_CXX_FLAGS_LIST) + if("${arg}" MATCHES "^-I(.*)$") + # include directory + list(APPEND wxWidgets_INCLUDE_DIRS "${CMAKE_MATCH_1}") + elseif("${arg}" MATCHES "^-D(.*)$") + # compile definition + list(APPEND wxWidgets_DEFINITIONS "${CMAKE_MATCH_1}") + else() + list(APPEND wxWidgets_CXX_FLAGS "${arg}") + endif() + endforeach() DBG_MSG_V("wxWidgets_DEFINITIONS=${wxWidgets_DEFINITIONS}") DBG_MSG_V("wxWidgets_INCLUDE_DIRS=${wxWidgets_INCLUDE_DIRS}") diff --git a/Modules/GoogleTest.cmake b/Modules/GoogleTest.cmake index 7415e06..41bd1dc 100644 --- a/Modules/GoogleTest.cmake +++ b/Modules/GoogleTest.cmake @@ -5,7 +5,33 @@ GoogleTest ---------- -This module defines functions to help use the Google Test infrastructure. +This module defines functions to help use the Google Test infrastructure. Two +mechanisms for adding tests are provided. :command:`gtest_add_tests` has been +around for some time, originally via ``find_package(GTest)``. +:command:`gtest_discover_tests` was introduced in CMake 3.10. + +The (older) :command:`gtest_add_tests` scans source files to identify tests. +This is usually effective, with some caveats, including in cross-compiling +environments, and makes setting additional properties on tests more convenient. +However, its handling of parameterized tests is less comprehensive, and it +requires re-running CMake to detect changes to the list of tests. + +The (newer) :command:`gtest_discover_tests` discovers tests by asking the +compiled test executable to enumerate its tests. This is more robust and +provides better handling of parameterized tests, and does not require CMake +to be re-run when tests change. However, it may not work in a cross-compiling +environment, and setting test properties is less convenient. + +More details can be found in the documentation of the respective functions. + +Both commands are intended to replace use of :command:`add_test` to register +tests, and will create a separate CTest test for each Google Test test case. +Note that this is in some cases less efficient, as common set-up and tear-down +logic cannot be shared by multiple test cases executing in the same instance. +However, it provides more fine-grained pass/fail information to CTest, which is +usually considered as more beneficial. By default, the CTest test name is the +same as the Google Test name (i.e. ``suite.testcase``); see also +``TEST_PREFIX`` and ``TEST_SUFFIX``. .. command:: gtest_add_tests @@ -22,12 +48,25 @@ This module defines functions to help use the Google Test infrastructure. [TEST_LIST outVar] ) + ``gtest_add_tests`` attempts to identify tests by scanning source files. + Although this is generally effective, it uses only a basic regular expression + match, which can be defeated by atypical test declarations, and is unable to + fully "split" parameterized tests. Additionally, it requires that CMake be + re-run to discover any newly added, removed or renamed tests (by default, + this means that CMake is re-run when any test source file is changed, but see + ``SKIP_DEPENDENCY``). However, it has the advantage of declaring tests at + CMake time, which somewhat simplifies setting additional properties on tests, + and always works in a cross-compiling environment. + + The options are: + ``TARGET target`` - This must be a known CMake target. CMake will substitute the location of - the built executable when running the test. + Specifies the Google Test executable, which must be a known CMake + executable target. CMake will substitute the location of the built + executable when running the test. ``SOURCES src1...`` - When provided, only the listed files will be scanned for test cases. If + When provided, only the listed files will be scanned for test cases. If this option is not given, the :prop_tgt:`SOURCES` property of the specified ``target`` will be used to obtain the list of sources. @@ -35,31 +74,30 @@ This module defines functions to help use the Google Test infrastructure. Any extra arguments to pass on the command line to each test case. ``WORKING_DIRECTORY dir`` - Specifies the directory in which to run the discovered test cases. If this + Specifies the directory in which to run the discovered test cases. If this option is not provided, the current binary directory is used. ``TEST_PREFIX prefix`` - Allows the specified ``prefix`` to be prepended to the name of each - discovered test case. This can be useful when the same source files are - being used in multiple calls to ``gtest_add_test()`` but with different - ``EXTRA_ARGS``. + Specifies a ``prefix`` to be prepended to the name of each discovered test + case. This can be useful when the same source files are being used in + multiple calls to ``gtest_add_test()`` but with different ``EXTRA_ARGS``. ``TEST_SUFFIX suffix`` Similar to ``TEST_PREFIX`` except the ``suffix`` is appended to the name of - every discovered test case. Both ``TEST_PREFIX`` and ``TEST_SUFFIX`` can be - specified. + every discovered test case. Both ``TEST_PREFIX`` and ``TEST_SUFFIX`` may + be specified. ``SKIP_DEPENDENCY`` Normally, the function creates a dependency which will cause CMake to be - re-run if any of the sources being scanned are changed. This is to ensure - that the list of discovered tests is updated. If this behavior is not + re-run if any of the sources being scanned are changed. This is to ensure + that the list of discovered tests is updated. If this behavior is not desired (as may be the case while actually writing the test cases), this option can be used to prevent the dependency from being added. ``TEST_LIST outVar`` The variable named by ``outVar`` will be populated in the calling scope - with the list of discovered test cases. This allows the caller to do things - like manipulate test properties of the discovered tests. + with the list of discovered test cases. This allows the caller to do + things like manipulate test properties of the discovered tests. .. code-block:: cmake @@ -77,7 +115,7 @@ This module defines functions to help use the Google Test infrastructure. set_tests_properties(${noArgsTests} PROPERTIES TIMEOUT 10) set_tests_properties(${withArgsTests} PROPERTIES TIMEOUT 20) - For backward compatibility reasons, the following form is also supported:: + For backward compatibility, the following form is also supported:: gtest_add_tests(exe args files...) @@ -99,8 +137,89 @@ This module defines functions to help use the Google Test infrastructure. add_executable(FooTest FooUnitTest.cxx) gtest_add_tests(FooTest "${FooTestArgs}" AUTO) +.. command:: gtest_discover_tests + + Automatically add tests with CTest by querying the compiled test executable + for available tests:: + + gtest_discover_tests(target + [EXTRA_ARGS arg1...] + [WORKING_DIRECTORY dir] + [TEST_PREFIX prefix] + [TEST_SUFFIX suffix] + [NO_PRETTY_TYPES] [NO_PRETTY_VALUES] + [PROPERTIES name1 value1...] + [TEST_LIST var] + ) + + ``gtest_discover_tests`` sets up a post-build command on the test executable + that generates the list of tests by parsing the output from running the test + with the ``--gtest_list_tests`` argument. Compared to the source parsing + approach of :command:`gtest_add_tests`, this ensures that the full list of + tests, including instantiations of parameterized tests, is obtained. Since + test discovery occurs at build time, it is not necessary to re-run CMake when + the list of tests changes. + However, it requires that :prop_tgt:`CROSSCOMPILING_EMULATOR` is properly set + in order to function in a cross-compiling environment. + + Additionally, setting properties on tests is somewhat less convenient, since + the tests are not available at CMake time. Additional test properties may be + assigned to the set of tests as a whole using the ``PROPERTIES`` option. If + more fine-grained test control is needed, custom content may be provided + through an external CTest script using the :prop_dir:`TEST_INCLUDE_FILES` + directory property. The set of discovered tests is made accessible to such a + script via the ``<target>_TESTS`` variable. + + The options are: + + ``target`` + Specifies the Google Test executable, which must be a known CMake + executable target. CMake will substitute the location of the built + executable when running the test. + + ``EXTRA_ARGS arg1...`` + Any extra arguments to pass on the command line to each test case. + + ``WORKING_DIRECTORY dir`` + Specifies the directory in which to run the discovered test cases. If this + option is not provided, the current binary directory is used. + + ``TEST_PREFIX prefix`` + Specifies a ``prefix`` to be prepended to the name of each discovered test + case. This can be useful when the same test executable is being used in + multiple calls to ``gtest_discover_tests()`` but with different + ``EXTRA_ARGS``. + + ``TEST_SUFFIX suffix`` + Similar to ``TEST_PREFIX`` except the ``suffix`` is appended to the name of + every discovered test case. Both ``TEST_PREFIX`` and ``TEST_SUFFIX`` may + be specified. + + ``NO_PRETTY_TYPES`` + By default, the type index of type-parameterized tests is replaced by the + actual type name in the CTest test name. If this behavior is undesirable + (e.g. because the type names are unwieldy), this option will suppress this + behavior. + + ``NO_PRETTY_VALUES`` + By default, the value index of value-parameterized tests is replaced by the + actual value in the CTest test name. If this behavior is undesirable + (e.g. because the value strings are unwieldy), this option will suppress + this behavior. + + ``PROPERTIES name1 value1...`` + Specifies additional properties to be set on all tests discovered by this + invocation of ``gtest_discover_tests``. + + ``TEST_LIST var`` + Make the list of tests available in the variable ``var``, rather than the + default ``<target>_TESTS``. This can be useful when the same test + executable is being used in multiple calls to ``gtest_discover_tests()``. + Note that this variable is only available in CTest. + #]=======================================================================] +#------------------------------------------------------------------------------ function(gtest_add_tests) if (ARGC LESS 1) @@ -224,3 +343,68 @@ function(gtest_add_tests) endif() endfunction() + +#------------------------------------------------------------------------------ +function(gtest_discover_tests TARGET) + cmake_parse_arguments( + "" + "NO_PRETTY_TYPES;NO_PRETTY_VALUES" + "TEST_PREFIX;TEST_SUFFIX;WORKING_DIRECTORY;TEST_LIST" + "EXTRA_ARGS;PROPERTIES" + ${ARGN} + ) + + if(NOT _WORKING_DIRECTORY) + set(_WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") + endif() + if(NOT _TEST_LIST) + set(_TEST_LIST ${TARGET}_TESTS) + endif() + + # Define rule to generate test list for aforementioned test executable + set(ctest_include_file "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_include.cmake") + set(ctest_tests_file "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_tests.cmake") + get_property(crosscompiling_emulator + TARGET ${TARGET} + PROPERTY CROSSCOMPILING_EMULATOR + ) + add_custom_command( + TARGET ${TARGET} POST_BUILD + BYPRODUCTS "${ctest_tests_file}" + COMMAND "${CMAKE_COMMAND}" + -D "TEST_TARGET=${TARGET}" + -D "TEST_EXECUTABLE=$<TARGET_FILE:${TARGET}>" + -D "TEST_EXECUTOR=${crosscompiling_emulator}" + -D "TEST_WORKING_DIR=${_WORKING_DIRECTORY}" + -D "TEST_EXTRA_ARGS=${_EXTRA_ARGS}" + -D "TEST_PROPERTIES=${_PROPERTIES}" + -D "TEST_PREFIX=${_TEST_PREFIX}" + -D "TEST_SUFFIX=${_TEST_SUFFIX}" + -D "NO_PRETTY_TYPES=${_NO_PRETTY_TYPES}" + -D "NO_PRETTY_VALUES=${_NO_PRETTY_VALUES}" + -D "TEST_LIST=${_TEST_LIST}" + -D "CTEST_FILE=${ctest_tests_file}" + -P "${_GOOGLETEST_DISCOVER_TESTS_SCRIPT}" + VERBATIM + ) + + file(WRITE "${ctest_include_file}" + "if(EXISTS \"${ctest_tests_file}\")\n" + " include(\"${ctest_tests_file}\")\n" + "else()\n" + " add_test(${TARGET}_NOT_BUILT ${TARGET}_NOT_BUILT)\n" + "endif()\n" + ) + + # Add discovered tests to directory TEST_INCLUDE_FILES + set_property(DIRECTORY + APPEND PROPERTY TEST_INCLUDE_FILES "${ctest_include_file}" + ) + +endfunction() + +############################################################################### + +set(_GOOGLETEST_DISCOVER_TESTS_SCRIPT + ${CMAKE_CURRENT_LIST_DIR}/GoogleTestAddTests.cmake +) diff --git a/Modules/GoogleTestAddTests.cmake b/Modules/GoogleTestAddTests.cmake new file mode 100644 index 0000000..7d0d909 --- /dev/null +++ b/Modules/GoogleTestAddTests.cmake @@ -0,0 +1,100 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +set(prefix "${TEST_PREFIX}") +set(suffix "${TEST_SUFFIX}") +set(extra_args ${TEST_EXTRA_ARGS}) +set(properties ${TEST_PROPERTIES}) +set(script) +set(suite) +set(tests) + +function(add_command NAME) + set(_args "") + foreach(_arg ${ARGN}) + if(_arg MATCHES "[^-./:a-zA-Z0-9_]") + set(_args "${_args} [==[${_arg}]==]") + else() + set(_args "${_args} ${_arg}") + endif() + endforeach() + set(script "${script}${NAME}(${_args})\n" PARENT_SCOPE) +endfunction() + +# Run test executable to get list of available tests +if(NOT EXISTS "${TEST_EXECUTABLE}") + message(FATAL_ERROR + "Specified test executable '${TEST_EXECUTABLE}' does not exist" + ) +endif() +execute_process( + COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" --gtest_list_tests + OUTPUT_VARIABLE output + RESULT_VARIABLE result +) +if(NOT ${result} EQUAL 0) + message(FATAL_ERROR + "Error running test executable '${TEST_EXECUTABLE}':\n" + " Result: ${result}\n" + " Output: ${output}\n" + ) +endif() + +string(REPLACE "\n" ";" output "${output}") + +# Parse output +foreach(line ${output}) + # Skip header + if(NOT line MATCHES "gtest_main\\.cc") + # Do we have a module name or a test name? + if(NOT line MATCHES "^ ") + # Module; remove trailing '.' to get just the name... + string(REGEX REPLACE "\\.( *#.*)?" "" suite "${line}") + if(line MATCHES "#" AND NOT NO_PRETTY_TYPES) + string(REGEX REPLACE "/[0-9]\\.+ +#.*= +" "/" pretty_suite "${line}") + else() + set(pretty_suite "${suite}") + endif() + string(REGEX REPLACE "^DISABLED_" "" pretty_suite "${pretty_suite}") + else() + # Test name; strip spaces and comments to get just the name... + string(REGEX REPLACE " +" "" test "${line}") + if(test MATCHES "#" AND NOT NO_PRETTY_VALUES) + string(REGEX REPLACE "/[0-9]+#GetParam..=" "/" pretty_test "${test}") + else() + string(REGEX REPLACE "#.*" "" pretty_test "${test}") + endif() + string(REGEX REPLACE "^DISABLED_" "" pretty_test "${pretty_test}") + string(REGEX REPLACE "#.*" "" test "${test}") + # ...and add to script + add_command(add_test + "${prefix}${pretty_suite}.${pretty_test}${suffix}" + ${TEST_EXECUTOR} + "${TEST_EXECUTABLE}" + "--gtest_filter=${suite}.${test}" + "--gtest_also_run_disabled_tests" + ${extra_args} + ) + if(suite MATCHES "^DISABLED" OR test MATCHES "^DISABLED") + add_command(set_tests_properties + "${prefix}${pretty_suite}.${pretty_test}${suffix}" + PROPERTIES DISABLED TRUE + ) + endif() + add_command(set_tests_properties + "${prefix}${pretty_suite}.${pretty_test}${suffix}" + PROPERTIES + WORKING_DIRECTORY "${TEST_WORKING_DIR}" + ${properties} + ) + list(APPEND tests "${prefix}${pretty_suite}.${pretty_test}${suffix}") + endif() + endif() +endforeach() + +# Create a list of all discovered tests, which users may use to e.g. set +# properties on the tests +add_command(set ${TEST_LIST} ${tests}) + +# Write CTest script +file(WRITE "${CTEST_FILE}" "${script}") diff --git a/Modules/MacOSXBundleInfo.plist.in b/Modules/MacOSXBundleInfo.plist.in index e06b17e..a4009bc 100644 --- a/Modules/MacOSXBundleInfo.plist.in +++ b/Modules/MacOSXBundleInfo.plist.in @@ -30,9 +30,5 @@ <true/> <key>NSHumanReadableCopyright</key> <string>${MACOSX_BUNDLE_COPYRIGHT}</string> - <key>NSPrincipalClass</key> - <string>NSApplication</string> - <key>NSHighResolutionCapable</key> - <string>True</string> </dict> </plist> diff --git a/Modules/Platform/GHS-MULTI-Initialize.cmake b/Modules/Platform/GHS-MULTI-Initialize.cmake index fcda6f6..bf61d7b 100644 --- a/Modules/Platform/GHS-MULTI-Initialize.cmake +++ b/Modules/Platform/GHS-MULTI-Initialize.cmake @@ -10,7 +10,7 @@ if (NOT GHS_INT_DIRECTORY) if (EXISTS ${GHS_EXPECTED_ROOT}) FILE(GLOB GHS_CANDIDATE_INT_DIRS RELATIVE ${GHS_EXPECTED_ROOT} ${GHS_EXPECTED_ROOT}/*) - string(REGEX MATCHALL "int[0-9][0-9][0-9][0-9]" GHS_CANDIDATE_INT_DIRS + string(REGEX MATCHALL "int[0-9][0-9][0-9][0-9a-z]" GHS_CANDIDATE_INT_DIRS ${GHS_CANDIDATE_INT_DIRS}) if (GHS_CANDIDATE_INT_DIRS) list(SORT GHS_CANDIDATE_INT_DIRS) diff --git a/Modules/Platform/Generic-SDCC-C.cmake b/Modules/Platform/Generic-SDCC-C.cmake index bbefe19..4b3912a 100644 --- a/Modules/Platform/Generic-SDCC-C.cmake +++ b/Modules/Platform/Generic-SDCC-C.cmake @@ -41,7 +41,7 @@ endif() set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>") # link object files to an executable -set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <FLAGS> <OBJECTS> --out-fmt-ihx -o <TARGET> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES>") +set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <FLAGS> <OBJECTS> -o <TARGET> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES>") # needs sdcc 2.7.0 + sddclib from cvs set(CMAKE_C_CREATE_STATIC_LIBRARY diff --git a/Modules/UseSWIG.cmake b/Modules/UseSWIG.cmake index fc815dd..c8b1cd7 100644 --- a/Modules/UseSWIG.cmake +++ b/Modules/UseSWIG.cmake @@ -82,10 +82,6 @@ macro(SWIG_MODULE_INITIALIZE name language) set(SWIG_MODULE_${name}_REAL_NAME "_${name}") elseif("x${SWIG_MODULE_${name}_LANGUAGE}" STREQUAL "xPERL") set(SWIG_MODULE_${name}_EXTRA_FLAGS "-shadow") - elseif("x${SWIG_MODULE_${name}_LANGUAGE}" STREQUAL "xCSHARP") - # This makes sure that the name used in the generated DllImport - # matches the library name created by CMake - set(SWIG_MODULE_${name}_EXTRA_FLAGS "-dllimport;${name}") endif() endmacro() @@ -194,6 +190,13 @@ macro(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile) if(swig_source_file_cplusplus) set(swig_special_flags ${swig_special_flags} "-c++") endif() + if("x${SWIG_MODULE_${name}_LANGUAGE}" STREQUAL "xCSHARP") + if(NOT ";${swig_source_file_flags};${CMAKE_SWIG_FLAGS};" MATCHES ";-dllimport;") + # This makes sure that the name used in the generated DllImport + # matches the library name created by CMake + set(SWIG_MODULE_${name}_EXTRA_FLAGS "-dllimport;${name}") + endif() + endif() set(swig_extra_flags) if(SWIG_MODULE_${name}_EXTRA_FLAGS) set(swig_extra_flags ${swig_extra_flags} ${SWIG_MODULE_${name}_EXTRA_FLAGS}) @@ -36,7 +36,7 @@ Supported Platforms * FreeBSD * OpenBSD * Solaris -* HP-UX +* AIX Other UNIX-like operating systems may work too out of the box, if not it should not be a major problem to port CMake to this platform. @@ -51,7 +51,7 @@ Building CMake from Scratch UNIX/Mac OSX/MinGW/MSYS/Cygwin ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -You need to have a compiler and a make installed. +You need to have a C++ compiler (supporting C++11) and a ``make`` installed. Run the ``bootstrap`` script you find in the source directory of CMake. You can use the ``--help`` option to see the supported options. You may use the ``--prefix=<install_prefix>`` option to specify a custom diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 40403ca..d35b7fb 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -469,6 +469,8 @@ set(SRCS cmIncludeDirectoryCommand.h cmIncludeExternalMSProjectCommand.cxx cmIncludeExternalMSProjectCommand.h + cmIncludeGuardCommand.cxx + cmIncludeGuardCommand.h cmIncludeRegularExpressionCommand.cxx cmIncludeRegularExpressionCommand.h cmInstallCommand.cxx @@ -874,6 +876,7 @@ set(CPACK_SRCS CPack/cmCPackTarCompressGenerator.cxx CPack/cmCPackZIPGenerator.cxx CPack/cmCPack7zGenerator.cxx + CPack/cmCPackDebGenerator.cxx ) # CPack IFW generator set(CPACK_SRCS ${CPACK_SRCS} @@ -896,11 +899,39 @@ if(CYGWIN) ) endif() +option(CPACK_ENABLE_FREEBSD_PKG "Add FreeBSD pkg(8) generator to CPack." OFF) + if(UNIX) set(CPACK_SRCS ${CPACK_SRCS} - CPack/cmCPackDebGenerator.cxx CPack/cmCPackRPMGenerator.cxx ) + + # Optionally, try to use pkg(8) + if(CPACK_ENABLE_FREEBSD_PKG) + # On UNIX, you may find FreeBSD's pkg(8) and attendant + # library -- it can be used on FreeBSD, Dragonfly, NetBSD, + # OpenBSD and also Linux and OSX. Look for the header and + # the library; it's a warning on FreeBSD if they're not + # found, and informational on other platforms. + find_path(FREEBSD_PKG_INCLUDE_DIRS "pkg.h" PATHS /usr/local) + if(FREEBSD_PKG_INCLUDE_DIRS) + find_library(FREEBSD_PKG_LIBRARIES + pkg + DOC "FreeBSD pkg(8) library") + if(FREEBSD_PKG_LIBRARIES) + set(CPACK_SRCS ${CPACK_SRCS} + CPack/cmCPackFreeBSDGenerator.cxx + ) + endif() + endif() + + if (NOT FREEBSD_PKG_INCLUDE_DIRS OR NOT FREEBSD_PKG_LIBRARIES) + message(FATAL_ERROR "CPack needs libpkg(3) to produce FreeBSD packages natively.") + endif() + else() + set(FREEBSD_PKG_INCLUDE_DIRS NOTFOUND) + set(FREEBSD_PKG_LIBRARIES NOTFOUND) + endif() endif() if(WIN32) @@ -958,6 +989,11 @@ if(APPLE) "See CMakeFiles/CMakeError.log for details of the failure.") endif() endif() +if(CPACK_ENABLE_FREEBSD_PKG AND FREEBSD_PKG_INCLUDE_DIRS AND FREEBSD_PKG_LIBRARIES) + target_link_libraries(CPackLib ${FREEBSD_PKG_LIBRARIES}) + include_directories(${FREEBSD_PKG_INCLUDE_DIRS}) + add_definitions(-DHAVE_FREEBSD_PKG) +endif() if(APPLE) add_executable(cmakexbuild cmakexbuild.cxx) @@ -976,7 +1012,9 @@ target_link_libraries(cmake CMakeLib) if(CMake_ENABLE_SERVER_MODE) add_library(CMakeServerLib + cmConnection.h cmConnection.cxx cmFileMonitor.cxx cmFileMonitor.h + cmPipeConnection.cxx cmPipeConnection.h cmServer.cxx cmServer.h cmServerConnection.cxx cmServerConnection.h cmServerProtocol.cxx cmServerProtocol.h diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 8b9cbbd..3403b61 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 9) -set(CMake_VERSION_PATCH 1) -#set(CMake_VERSION_RC 0) +set(CMake_VERSION_PATCH 20170822) +#set(CMake_VERSION_RC 1) diff --git a/Source/CPack/IFW/cmCPackIFWGenerator.cxx b/Source/CPack/IFW/cmCPackIFWGenerator.cxx index 226ea0a..6861623 100644 --- a/Source/CPack/IFW/cmCPackIFWGenerator.cxx +++ b/Source/CPack/IFW/cmCPackIFWGenerator.cxx @@ -164,6 +164,7 @@ int cmCPackIFWGenerator::PackageFiles() ifwCmd += " " + this->packageFileNames[0]; } else { ifwCmd += " installer"; + ifwCmd += this->OutputExtension; } cmCPackIFWLogger(VERBOSE, "Execute: " << ifwCmd << std::endl); std::string output; @@ -205,7 +206,7 @@ const char* cmCPackIFWGenerator::GetPackagingInstallPrefix() const char* cmCPackIFWGenerator::GetOutputExtension() { - return this->ExecutableSuffix.c_str(); + return this->OutputExtension.c_str(); } int cmCPackIFWGenerator::InitializeInternal() @@ -305,16 +306,29 @@ int cmCPackIFWGenerator::InitializeInternal() } // Executable suffix - if (const char* optExeSuffix = this->GetOption("CMAKE_EXECUTABLE_SUFFIX")) { - this->ExecutableSuffix = optExeSuffix; - if (this->ExecutableSuffix.empty()) { - std::string sysName(this->GetOption("CMAKE_SYSTEM_NAME")); - if (sysName == "Linux") { - this->ExecutableSuffix = ".run"; - } - } + std::string exeSuffix(this->GetOption("CMAKE_EXECUTABLE_SUFFIX")); + std::string sysName(this->GetOption("CMAKE_SYSTEM_NAME")); + if (sysName == "Linux") { + this->ExecutableSuffix = ".run"; + } else if (sysName == "Windows") { + this->ExecutableSuffix = ".exe"; + } else if (sysName == "Darwin") { + this->ExecutableSuffix = ".app"; + } else { + this->ExecutableSuffix = exeSuffix; + } + + // Output extension + if (const char* optOutExt = + this->GetOption("CPACK_IFW_PACKAGE_FILE_EXTENSION")) { + this->OutputExtension = optOutExt; + } else if (sysName == "Darwin") { + this->OutputExtension = ".dmg"; } else { - this->ExecutableSuffix = this->cmCPackGenerator::GetOutputExtension(); + this->OutputExtension = this->ExecutableSuffix; + } + if (this->OutputExtension.empty()) { + this->OutputExtension = this->cmCPackGenerator::GetOutputExtension(); } return this->Superclass::InitializeInternal(); diff --git a/Source/CPack/IFW/cmCPackIFWGenerator.h b/Source/CPack/IFW/cmCPackIFWGenerator.h index 8348cee..9d635f8 100644 --- a/Source/CPack/IFW/cmCPackIFWGenerator.h +++ b/Source/CPack/IFW/cmCPackIFWGenerator.h @@ -61,8 +61,8 @@ protected: const char* GetPackagingInstallPrefix() CM_OVERRIDE; /** - * @brief Extension of binary installer - * @return Executable suffix or value from default implementation + * @brief Target binary extension + * @return Executable suffix or disk image format */ const char* GetOutputExtension() CM_OVERRIDE; @@ -143,6 +143,7 @@ private: std::string BinCreator; std::string FrameworkVersion; std::string ExecutableSuffix; + std::string OutputExtension; bool OnlineOnly; bool ResolveDuplicateNames; diff --git a/Source/CPack/cmCPackBundleGenerator.h b/Source/CPack/cmCPackBundleGenerator.h index 861fe4b..a127e7b 100644 --- a/Source/CPack/cmCPackBundleGenerator.h +++ b/Source/CPack/cmCPackBundleGenerator.h @@ -21,7 +21,7 @@ public: cmCPackTypeMacro(cmCPackBundleGenerator, cmCPackDragNDropGenerator); cmCPackBundleGenerator(); - virtual ~cmCPackBundleGenerator(); + ~cmCPackBundleGenerator() CM_OVERRIDE; protected: int InitializeInternal() CM_OVERRIDE; diff --git a/Source/CPack/cmCPackCygwinBinaryGenerator.h b/Source/CPack/cmCPackCygwinBinaryGenerator.h index 58e80bd..b5a0531 100644 --- a/Source/CPack/cmCPackCygwinBinaryGenerator.h +++ b/Source/CPack/cmCPackCygwinBinaryGenerator.h @@ -17,7 +17,7 @@ public: * Construct generator */ cmCPackCygwinBinaryGenerator(); - virtual ~cmCPackCygwinBinaryGenerator(); + ~cmCPackCygwinBinaryGenerator() CM_OVERRIDE; protected: virtual int InitializeInternal(); diff --git a/Source/CPack/cmCPackCygwinSourceGenerator.h b/Source/CPack/cmCPackCygwinSourceGenerator.h index 896de1d..d19f87c 100644 --- a/Source/CPack/cmCPackCygwinSourceGenerator.h +++ b/Source/CPack/cmCPackCygwinSourceGenerator.h @@ -17,7 +17,7 @@ public: * Construct generator */ cmCPackCygwinSourceGenerator(); - virtual ~cmCPackCygwinSourceGenerator(); + ~cmCPackCygwinSourceGenerator() CM_OVERRIDE; protected: const char* GetPackagingInstallPrefix(); diff --git a/Source/CPack/cmCPackDebGenerator.cxx b/Source/CPack/cmCPackDebGenerator.cxx index af54fce..0705460 100644 --- a/Source/CPack/cmCPackDebGenerator.cxx +++ b/Source/CPack/cmCPackDebGenerator.cxx @@ -6,6 +6,7 @@ #include "cmCPackComponentGroup.h" #include "cmCPackGenerator.h" #include "cmCPackLog.h" +#include "cmCryptoHash.h" #include "cmGeneratedFileStream.h" #include "cmSystemTools.h" #include "cm_sys_stat.h" @@ -479,6 +480,25 @@ int cmCPackDebGenerator::createDeb() cmCPackLogger(cmCPackLog::LOG_DEBUG, "RELATIVEDIR: \"" << relativeDir << "\"" << std::endl); +#ifdef WIN32 + std::string mode_t_adt_filename = *fileIt + ":cmake_mode_t"; + cmsys::ifstream permissionStream(mode_t_adt_filename.c_str()); + + mode_t permissions = 0; + + if (permissionStream) { + permissionStream >> std::oct >> permissions; + } + + if (permissions != 0) { + data_tar.SetPermissions(permissions); + } else if (cmSystemTools::FileIsDirectory(*fileIt)) { + data_tar.SetPermissions(0755); + } else { + data_tar.ClearPermissions(); + } +#endif + // do not recurse because the loop will do it if (!data_tar.Add(*fileIt, topLevelLength, ".", false)) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem adding file to tar:" @@ -508,15 +528,13 @@ int cmCPackDebGenerator::createDeb() continue; } - char md5sum[33]; - if (!cmSystemTools::ComputeFileMD5(*fileIt, md5sum)) { + std::string output = + cmSystemTools::ComputeFileHash(*fileIt, cmCryptoHash::AlgoMD5); + if (output.empty()) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem computing the md5 of " << *fileIt << std::endl); } - md5sum[32] = 0; - - std::string output(md5sum); output += " " + *fileIt + "\n"; // debian md5sums entries are like this: // 014f3604694729f3bf19263bac599765 usr/bin/ccmake @@ -553,8 +571,8 @@ int cmCPackDebGenerator::createDeb() and https://lintian.debian.org/tags/control-file-has-bad-permissions.html */ - const mode_t permission644 = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; - const mode_t permissionExecute = S_IXUSR | S_IXGRP | S_IXOTH; + const mode_t permission644 = 0644; + const mode_t permissionExecute = 0111; const mode_t permission755 = permission644 | permissionExecute; // for md5sum and control (that we have generated here), we use 644 @@ -831,7 +849,7 @@ static int copy_ar(CF* cfp, off_t size) ? static_cast<size_t>(sz) : sizeof(buf), from)) > 0) { - sz -= nr; + sz -= static_cast<off_t>(nr); for (size_t off = 0; off < nr; nr -= off, off += nw) { if ((nw = fwrite(buf + off, 1, nr, to)) < nr) { return -1; @@ -854,7 +872,6 @@ static int copy_ar(CF* cfp, off_t size) static int put_arobj(CF* cfp, struct stat* sb) { int result = 0; - struct ar_hdr* hdr; /* If passed an sb structure, reading a file from disk. Get stat(2) * information, build a name and construct a header. (Files are named @@ -873,7 +890,7 @@ static int put_arobj(CF* cfp, struct stat* sb) if (gid > USHRT_MAX) { gid = USHRT_MAX; } - if (lname > sizeof(hdr->ar_name) || strchr(name, ' ')) { + if (lname > sizeof(ar_hdr().ar_name) || strchr(name, ' ')) { (void)sprintf(ar_hb, HDR1, AR_EFMT1, (int)lname, (long int)sb->st_mtime, (unsigned)uid, (unsigned)gid, (unsigned)sb->st_mode, (long long)sb->st_size + lname, ARFMAG); diff --git a/Source/CPack/cmCPackDragNDropGenerator.cxx b/Source/CPack/cmCPackDragNDropGenerator.cxx index 9864cf3..d4d2fdb 100644 --- a/Source/CPack/cmCPackDragNDropGenerator.cxx +++ b/Source/CPack/cmCPackDragNDropGenerator.cxx @@ -447,6 +447,8 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir, cmsys::RegularExpression mountpoint_regex(".*(/Volumes/[^\n]+)\n.*"); mountpoint_regex.find(attach_output.c_str()); std::string const temp_mount = mountpoint_regex.match(1); + std::string const temp_mount_name = + temp_mount.substr(sizeof("/Volumes/") - 1); // Remove dummy padding file so we have enough space on RW image ... std::ostringstream dummy_padding; @@ -480,7 +482,7 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir, std::ostringstream setup_script_command; setup_script_command << "osascript" << " \"" << cpack_dmg_ds_store_setup_script << "\"" - << " \"" << cpack_dmg_volume_name << "\""; + << " \"" << temp_mount_name << "\""; std::string error; if (!this->RunCommand(setup_script_command, &error)) { cmCPackLogger(cmCPackLog::LOG_ERROR, diff --git a/Source/CPack/cmCPackDragNDropGenerator.h b/Source/CPack/cmCPackDragNDropGenerator.h index ae2cc17..ffa9015 100644 --- a/Source/CPack/cmCPackDragNDropGenerator.h +++ b/Source/CPack/cmCPackDragNDropGenerator.h @@ -23,7 +23,7 @@ public: cmCPackTypeMacro(cmCPackDragNDropGenerator, cmCPackGenerator); cmCPackDragNDropGenerator(); - virtual ~cmCPackDragNDropGenerator(); + ~cmCPackDragNDropGenerator() CM_OVERRIDE; protected: int InitializeInternal() CM_OVERRIDE; @@ -40,8 +40,6 @@ protected: int CreateDMG(const std::string& src_dir, const std::string& output_file); - std::string InstallPrefix; - private: std::string slaDirectory; bool singleLicense; diff --git a/Source/CPack/cmCPackFreeBSDGenerator.cxx b/Source/CPack/cmCPackFreeBSDGenerator.cxx new file mode 100644 index 0000000..ae17b79 --- /dev/null +++ b/Source/CPack/cmCPackFreeBSDGenerator.cxx @@ -0,0 +1,359 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmCPackFreeBSDGenerator.h" + +#include "cmArchiveWrite.h" +#include "cmCPackArchiveGenerator.h" +#include "cmCPackLog.h" +#include "cmGeneratedFileStream.h" +#include "cmSystemTools.h" + +// Needed for ::open() and ::stat() +#include <fcntl.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> + +#include <pkg.h> + +#include <algorithm> + +cmCPackFreeBSDGenerator::cmCPackFreeBSDGenerator() + : cmCPackArchiveGenerator(cmArchiveWrite::CompressXZ, "paxr") +{ +} + +int cmCPackFreeBSDGenerator::InitializeInternal() +{ + this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/usr/local"); + this->SetOption("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "0"); + return this->Superclass::InitializeInternal(); +} + +cmCPackFreeBSDGenerator::~cmCPackFreeBSDGenerator() +{ +} + +// This is a wrapper, for use only in stream-based output, +// that will output a string in UCL escaped fashion (in particular, +// quotes and backslashes are escaped). The list of characters +// to escape is taken from https://github.com/vstakhov/libucl +// (which is the reference implementation pkg(8) refers to). +class EscapeQuotes +{ +public: + const std::string& value; + + EscapeQuotes(const std::string& s) + : value(s) + { + } +}; + +// Output a string as "string" with escaping applied. +cmGeneratedFileStream& operator<<(cmGeneratedFileStream& s, + const EscapeQuotes& v) +{ + s << '"'; + for (std::string::size_type i = 0; i < v.value.length(); ++i) { + char c = v.value[i]; + switch (c) { + case '\n': + s << "\\n"; + break; + case '\r': + s << "\\r"; + break; + case '\b': + s << "\\b"; + break; + case '\t': + s << "\\t"; + break; + case '\f': + s << "\\f"; + break; + case '\\': + s << "\\\\"; + break; + case '"': + s << "\\\""; + break; + default: + s << c; + break; + } + } + s << '"'; + return s; +} + +// The following classes are all helpers for writing out the UCL +// manifest file (it also looks like JSON). ManifestKey just has +// a (string-valued) key; subclasses add a specific kind of +// value-type to the key, and implement write_value() to output +// the corresponding UCL. +class ManifestKey +{ +public: + std::string key; + + ManifestKey(const std::string& k) + : key(k) + { + } + + virtual ~ManifestKey() {} + + // Output the value associated with this key to the stream @p s. + // Format is to be decided by subclasses. + virtual void write_value(cmGeneratedFileStream& s) const = 0; +}; + +// Basic string-value (e.g. "name": "cmake") +class ManifestKeyValue : public ManifestKey +{ +public: + std::string value; + + ManifestKeyValue(const std::string& k, const std::string& v) + : ManifestKey(k) + , value(v) + { + } + + void write_value(cmGeneratedFileStream& s) const CM_OVERRIDE + { + s << EscapeQuotes(value); + } +}; + +// List-of-strings values (e.g. "licenses": ["GPLv2", "LGPLv2"]) +class ManifestKeyListValue : public ManifestKey +{ +public: + typedef std::vector<std::string> VList; + VList value; + + ManifestKeyListValue(const std::string& k) + : ManifestKey(k) + { + } + + ManifestKeyListValue& operator<<(const std::string& v) + { + value.push_back(v); + return *this; + } + + ManifestKeyListValue& operator<<(const std::vector<std::string>& v) + { + for (VList::const_iterator it = v.begin(); it != v.end(); ++it) { + (*this) << (*it); + } + return *this; + } + + void write_value(cmGeneratedFileStream& s) const CM_OVERRIDE + { + bool with_comma = false; + + s << '['; + for (VList::const_iterator it = value.begin(); it != value.end(); ++it) { + s << (with_comma ? ',' : ' '); + s << EscapeQuotes(*it); + with_comma = true; + } + s << " ]"; + } +}; + +// Deps: actually a dictionary, but we'll treat it as a +// list so we only name the deps, and produce dictionary- +// like output via write_value() +class ManifestKeyDepsValue : public ManifestKeyListValue +{ +public: + ManifestKeyDepsValue(const std::string& k) + : ManifestKeyListValue(k) + { + } + + void write_value(cmGeneratedFileStream& s) const CM_OVERRIDE + { + s << "{\n"; + for (VList::const_iterator it = value.begin(); it != value.end(); ++it) { + s << " \"" << *it << "\": {\"origin\": \"" << *it << "\"},\n"; + } + s << '}'; + } +}; + +// Write one of the key-value classes (above) to the stream @p s +cmGeneratedFileStream& operator<<(cmGeneratedFileStream& s, + const ManifestKey& v) +{ + s << '"' << v.key << "\": "; + v.write_value(s); + s << ",\n"; + return s; +} + +// Look up variable; if no value is set, returns an empty string; +// basically a wrapper that handles the NULL-ptr return from GetOption(). +std::string cmCPackFreeBSDGenerator::var_lookup(const char* var_name) +{ + const char* pv = this->GetOption(var_name); + if (!pv) { + return std::string(); + } else { + return pv; + } +} + +// Produce UCL in the given @p manifest file for the common +// manifest fields (common to the compact and regular formats), +// by reading the CPACK_FREEBSD_* variables. +void cmCPackFreeBSDGenerator::write_manifest_fields( + cmGeneratedFileStream& manifest) +{ + manifest << ManifestKeyValue("name", + var_lookup("CPACK_FREEBSD_PACKAGE_NAME")); + manifest << ManifestKeyValue("origin", + var_lookup("CPACK_FREEBSD_PACKAGE_ORIGIN")); + manifest << ManifestKeyValue("version", + var_lookup("CPACK_FREEBSD_PACKAGE_VERSION")); + manifest << ManifestKeyValue("maintainer", + var_lookup("CPACK_FREEBSD_PACKAGE_MAINTAINER")); + manifest << ManifestKeyValue("comment", + var_lookup("CPACK_FREEBSD_PACKAGE_COMMENT")); + manifest << ManifestKeyValue( + "desc", var_lookup("CPACK_FREEBSD_PACKAGE_DESCRIPTION")); + manifest << ManifestKeyValue("www", var_lookup("CPACK_FREEBSD_PACKAGE_WWW")); + std::vector<std::string> licenses; + cmSystemTools::ExpandListArgument( + var_lookup("CPACK_FREEBSD_PACKAGE_LICENSE"), licenses); + std::string licenselogic("single"); + if (licenses.size() < 1) { + cmSystemTools::SetFatalErrorOccured(); + } else if (licenses.size() > 1) { + licenselogic = var_lookup("CPACK_FREEBSD_PACKAGE_LICENSE_LOGIC"); + } + manifest << ManifestKeyValue("licenselogic", licenselogic); + manifest << (ManifestKeyListValue("licenses") << licenses); + std::vector<std::string> categories; + cmSystemTools::ExpandListArgument( + var_lookup("CPACK_FREEBSD_PACKAGE_CATEGORIES"), categories); + manifest << (ManifestKeyListValue("categories") << categories); + manifest << ManifestKeyValue("prefix", var_lookup("CMAKE_INSTALL_PREFIX")); + std::vector<std::string> deps; + cmSystemTools::ExpandListArgument(var_lookup("CPACK_FREEBSD_PACKAGE_DEPS"), + deps); + if (deps.size() > 0) { + manifest << (ManifestKeyDepsValue("deps") << deps); + } +} + +// Package only actual files; others are ignored (in particular, +// intermediate subdirectories are ignored). +static bool ignore_file(const std::string& filename) +{ + struct stat statbuf; + + if (!((stat(filename.c_str(), &statbuf) >= 0) && + ((statbuf.st_mode & S_IFMT) == S_IFREG))) { + return true; + } + // May be other reasons to return false + return false; +} + +// Write the given list of @p files to the manifest stream @p s, +// as the UCL field "files" (which is dictionary-valued, to +// associate filenames with hashes). All the files are transformed +// to paths relative to @p toplevel, with a leading / (since the paths +// in FreeBSD package files are supposed to be absolute). +void write_manifest_files(cmGeneratedFileStream& s, + const std::string& toplevel, + const std::vector<std::string>& files) +{ + const char* c_toplevel = toplevel.c_str(); + std::vector<std::string>::const_iterator it; + + s << "\"files\": {\n"; + for (it = files.begin(); it != files.end(); ++it) { + s << " \"/" << cmSystemTools::RelativePath(c_toplevel, it->c_str()) + << "\": \"" + << "<sha256>" + << "\",\n"; + } + s << " },\n"; +} + +static bool has_suffix(const std::string& str, const std::string& suffix) +{ + return str.size() >= suffix.size() && + str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; +} + +int cmCPackFreeBSDGenerator::PackageFiles() +{ + if (!this->ReadListFile("CPackFreeBSD.cmake")) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Error while execution CPackFreeBSD.cmake" << std::endl); + return 0; + } + + std::vector<std::string>::const_iterator fileIt; + std::string dir = cmSystemTools::GetCurrentWorkingDirectory(); + cmSystemTools::ChangeDirectory(toplevel); + + files.erase(std::remove_if(files.begin(), files.end(), ignore_file), + files.end()); + + std::string manifestname = toplevel + "/+MANIFEST"; + { + cmGeneratedFileStream manifest(manifestname.c_str()); + manifest << "{\n"; + write_manifest_fields(manifest); + write_manifest_files(manifest, toplevel, files); + manifest << "}\n"; + } + + cmCPackLogger(cmCPackLog::LOG_DEBUG, "Toplevel: " << toplevel << std::endl); + + if (WantsComponentInstallation()) { + // CASE 1 : COMPONENT ALL-IN-ONE package + // If ALL COMPONENTS in ONE package has been requested + // then the package file is unique and should be open here. + if (componentPackageMethod == ONE_PACKAGE) { + return PackageComponentsAllInOne(); + } + // CASE 2 : COMPONENT CLASSICAL package(s) (i.e. not all-in-one) + // There will be 1 package for each component group + // however one may require to ignore component group and + // in this case you'll get 1 package for each component. + return PackageComponents(componentPackageMethod == + ONE_PACKAGE_PER_COMPONENT); + } + + std::string output_dir = + cmSystemTools::CollapseCombinedPath(toplevel, "../"); + pkg_create_from_manifest(output_dir.c_str(), ::TXZ, toplevel.c_str(), + manifestname.c_str(), NULL); + + std::string broken_suffix = std::string("-") + + var_lookup("CPACK_TOPLEVEL_TAG") + std::string(GetOutputExtension()); + for (std::vector<std::string>::iterator it = packageFileNames.begin(); + it != packageFileNames.end(); ++it) { + cmCPackLogger(cmCPackLog::LOG_DEBUG, "Packagefile " << *it << std::endl); + if (has_suffix(*it, broken_suffix)) { + it->replace(it->size() - broken_suffix.size(), std::string::npos, + GetOutputExtension()); + break; + } + } + + cmSystemTools::ChangeDirectory(dir); + return 1; +} diff --git a/Source/CPack/cmCPackFreeBSDGenerator.h b/Source/CPack/cmCPackFreeBSDGenerator.h new file mode 100644 index 0000000..230f728 --- /dev/null +++ b/Source/CPack/cmCPackFreeBSDGenerator.h @@ -0,0 +1,37 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmCPackFreeBSDGenerator_h +#define cmCPackFreeBSDGenerator_h + +#include <cmConfigure.h> + +#include "cmCPackArchiveGenerator.h" +#include "cmCPackGenerator.h" + +class cmGeneratedFileStream; + +/** \class cmCPackFreeBSDGenerator + * \brief A generator for FreeBSD package files (TXZ with a manifest) + * + */ +class cmCPackFreeBSDGenerator : public cmCPackArchiveGenerator +{ +public: + cmCPackTypeMacro(cmCPackFreeBSDGenerator, cmCPackArchiveGenerator); + /** + * Construct generator + */ + cmCPackFreeBSDGenerator(); + ~cmCPackFreeBSDGenerator() CM_OVERRIDE; + + int InitializeInternal() CM_OVERRIDE; + int PackageFiles() CM_OVERRIDE; + +protected: + const char* GetOutputExtension() CM_OVERRIDE { return ".txz"; } + + std::string var_lookup(const char* var_name); + void write_manifest_fields(cmGeneratedFileStream&); +}; + +#endif diff --git a/Source/CPack/cmCPackGeneratorFactory.cxx b/Source/CPack/cmCPackGeneratorFactory.cxx index 31f48c7..834913d 100644 --- a/Source/CPack/cmCPackGeneratorFactory.cxx +++ b/Source/CPack/cmCPackGeneratorFactory.cxx @@ -9,6 +9,10 @@ #include "IFW/cmCPackIFWGenerator.h" #include "cmAlgorithms.h" #include "cmCPack7zGenerator.h" +#ifdef HAVE_FREEBSD_PKG +#include "cmCPackFreeBSDGenerator.h" +#endif +#include "cmCPackDebGenerator.h" #include "cmCPackGenerator.h" #include "cmCPackLog.h" #include "cmCPackNSISGenerator.h" @@ -34,7 +38,6 @@ #if !defined(_WIN32) && !defined(__QNXNTO__) && !defined(__BEOS__) && \ !defined(__HAIKU__) -#include "cmCPackDebGenerator.h" #include "cmCPackRPMGenerator.h" #endif @@ -99,6 +102,10 @@ cmCPackGeneratorFactory::cmCPackGeneratorFactory() this->RegisterGenerator("TZ", "Tar Compress compression", cmCPackTarCompressGenerator::CreateGenerator); } + if (cmCPackDebGenerator::CanGenerate()) { + this->RegisterGenerator("DEB", "Debian packages", + cmCPackDebGenerator::CreateGenerator); + } #ifdef __APPLE__ if (cmCPackDragNDropGenerator::CanGenerate()) { this->RegisterGenerator("DragNDrop", "Mac OSX Drag And Drop", @@ -123,15 +130,17 @@ cmCPackGeneratorFactory::cmCPackGeneratorFactory() #endif #if !defined(_WIN32) && !defined(__QNXNTO__) && !defined(__BEOS__) && \ !defined(__HAIKU__) - if (cmCPackDebGenerator::CanGenerate()) { - this->RegisterGenerator("DEB", "Debian packages", - cmCPackDebGenerator::CreateGenerator); - } if (cmCPackRPMGenerator::CanGenerate()) { this->RegisterGenerator("RPM", "RPM packages", cmCPackRPMGenerator::CreateGenerator); } #endif +#ifdef HAVE_FREEBSD_PKG + if (cmCPackFreeBSDGenerator::CanGenerate()) { + this->RegisterGenerator("FREEBSD", "FreeBSD pkg(8) packages", + cmCPackFreeBSDGenerator::CreateGenerator); + } +#endif } cmCPackGeneratorFactory::~cmCPackGeneratorFactory() diff --git a/Source/CPack/cmCPackOSXX11Generator.h b/Source/CPack/cmCPackOSXX11Generator.h index 0eebc6d..0a1770c 100644 --- a/Source/CPack/cmCPackOSXX11Generator.h +++ b/Source/CPack/cmCPackOSXX11Generator.h @@ -23,7 +23,7 @@ public: * Construct generator */ cmCPackOSXX11Generator(); - virtual ~cmCPackOSXX11Generator(); + ~cmCPackOSXX11Generator() CM_OVERRIDE; protected: virtual int InitializeInternal() CM_OVERRIDE; diff --git a/Source/CPack/cmCPackPKGGenerator.h b/Source/CPack/cmCPackPKGGenerator.h index f873c59..d9461ee 100644 --- a/Source/CPack/cmCPackPKGGenerator.h +++ b/Source/CPack/cmCPackPKGGenerator.h @@ -27,7 +27,7 @@ public: * Construct generator */ cmCPackPKGGenerator(); - virtual ~cmCPackPKGGenerator(); + ~cmCPackPKGGenerator() CM_OVERRIDE; bool SupportsComponentInstallation() const CM_OVERRIDE; diff --git a/Source/CPack/cmCPackPackageMakerGenerator.h b/Source/CPack/cmCPackPackageMakerGenerator.h index 6274515..770f434 100644 --- a/Source/CPack/cmCPackPackageMakerGenerator.h +++ b/Source/CPack/cmCPackPackageMakerGenerator.h @@ -25,7 +25,7 @@ public: * Construct generator */ cmCPackPackageMakerGenerator(); - virtual ~cmCPackPackageMakerGenerator(); + ~cmCPackPackageMakerGenerator() CM_OVERRIDE; bool SupportsComponentInstallation() const CM_OVERRIDE; protected: diff --git a/Source/CPack/cmCPackProductBuildGenerator.h b/Source/CPack/cmCPackProductBuildGenerator.h index 12093a0..3435641 100644 --- a/Source/CPack/cmCPackProductBuildGenerator.h +++ b/Source/CPack/cmCPackProductBuildGenerator.h @@ -25,7 +25,7 @@ public: * Construct generator */ cmCPackProductBuildGenerator(); - virtual ~cmCPackProductBuildGenerator(); + ~cmCPackProductBuildGenerator() CM_OVERRIDE; protected: int InitializeInternal() CM_OVERRIDE; diff --git a/Source/CTest/cmCTestBuildCommand.cxx b/Source/CTest/cmCTestBuildCommand.cxx index 4c82760..64ef8de 100644 --- a/Source/CTest/cmCTestBuildCommand.cxx +++ b/Source/CTest/cmCTestBuildCommand.cxx @@ -153,6 +153,12 @@ cmCTestGenericHandler* cmCTestBuildCommand::InitializeHandler() this->Quiet); } + if (const char* labelsForSubprojects = + this->Makefile->GetDefinition("CTEST_LABELS_FOR_SUBPROJECTS")) { + this->CTest->SetCTestConfiguration("LabelsForSubprojects", + labelsForSubprojects, this->Quiet); + } + handler->SetQuiet(this->Quiet); return handler; } diff --git a/Source/CTest/cmCTestBuildHandler.cxx b/Source/CTest/cmCTestBuildHandler.cxx index 18ef05c..f9116e3 100644 --- a/Source/CTest/cmCTestBuildHandler.cxx +++ b/Source/CTest/cmCTestBuildHandler.cxx @@ -488,6 +488,7 @@ int cmCTestBuildHandler::ProcessHandler() void cmCTestBuildHandler::GenerateXMLHeader(cmXMLWriter& xml) { this->CTest->StartXML(xml, this->AppendXML); + this->CTest->GenerateSubprojectsOutput(xml); xml.StartElement("Build"); xml.Element("StartDateTime", this->StartBuild); xml.Element("StartBuildTime", diff --git a/Source/CTest/cmCTestConfigureCommand.cxx b/Source/CTest/cmCTestConfigureCommand.cxx index 73e893d..aca5bd3 100644 --- a/Source/CTest/cmCTestConfigureCommand.cxx +++ b/Source/CTest/cmCTestConfigureCommand.cxx @@ -141,6 +141,12 @@ cmCTestGenericHandler* cmCTestConfigureCommand::InitializeHandler() } } + if (const char* labelsForSubprojects = + this->Makefile->GetDefinition("CTEST_LABELS_FOR_SUBPROJECTS")) { + this->CTest->SetCTestConfiguration("LabelsForSubprojects", + labelsForSubprojects, this->Quiet); + } + cmCTestGenericHandler* handler = this->CTest->GetInitializedHandler("configure"); if (!handler) { diff --git a/Source/CTest/cmCTestConfigureHandler.cxx b/Source/CTest/cmCTestConfigureHandler.cxx index 5d87f3f..56a038e 100644 --- a/Source/CTest/cmCTestConfigureHandler.cxx +++ b/Source/CTest/cmCTestConfigureHandler.cxx @@ -73,6 +73,7 @@ int cmCTestConfigureHandler::ProcessHandler() if (os) { cmXMLWriter xml(os); this->CTest->StartXML(xml, this->AppendXML); + this->CTest->GenerateSubprojectsOutput(xml); xml.StartElement("Configure"); xml.Element("StartDateTime", start_time); xml.Element("StartConfigureTime", start_time_time); diff --git a/Source/CTest/cmCTestLaunch.cxx b/Source/CTest/cmCTestLaunch.cxx index 5b21351..9be8696 100644 --- a/Source/CTest/cmCTestLaunch.cxx +++ b/Source/CTest/cmCTestLaunch.cxx @@ -508,7 +508,11 @@ void cmCTestLaunch::DumpFileToXML(cmXMLWriter& xml, std::string const& fname) if (MatchesFilterPrefix(line)) { continue; } - + if (this->Match(line, this->RegexWarningSuppress)) { + line = "[CTest: warning suppressed] " + line; + } else if (this->Match(line, this->RegexWarning)) { + line = "[CTest: warning matched] " + line; + } xml.Content(sep); xml.Content(line); sep = "\n"; diff --git a/Source/CTest/cmCTestMemCheckHandler.cxx b/Source/CTest/cmCTestMemCheckHandler.cxx index c35f0bc..6026a2a 100644 --- a/Source/CTest/cmCTestMemCheckHandler.cxx +++ b/Source/CTest/cmCTestMemCheckHandler.cxx @@ -291,6 +291,7 @@ void cmCTestMemCheckHandler::GenerateDartOutput(cmXMLWriter& xml) return; } this->CTest->StartXML(xml, this->AppendXML); + this->CTest->GenerateSubprojectsOutput(xml); xml.StartElement("DynamicAnalysis"); switch (this->MemoryTesterStyle) { case cmCTestMemCheckHandler::VALGRIND: diff --git a/Source/CTest/cmCTestRunTest.cxx b/Source/CTest/cmCTestRunTest.cxx index 0c4269e..9274c01 100644 --- a/Source/CTest/cmCTestRunTest.cxx +++ b/Source/CTest/cmCTestRunTest.cxx @@ -237,6 +237,8 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started) } else if (res == cmsysProcess_State_Exception) { outputTestErrorsToConsole = this->CTest->OutputTestOutputOnTestFailure; cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Exception: "); + this->TestResult.ExceptionStatus = + this->TestProcess->GetExitExceptionString(); switch (this->TestProcess->GetExitException()) { case cmsysProcess_Exception_Fault: cmCTestLog(this->CTest, HANDLER_OUTPUT, "SegFault"); @@ -255,7 +257,8 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started) this->TestResult.Status = cmCTestTestHandler::NUMERICAL; break; default: - cmCTestLog(this->CTest, HANDLER_OUTPUT, "Other"); + cmCTestLog(this->CTest, HANDLER_OUTPUT, + this->TestResult.ExceptionStatus); this->TestResult.Status = cmCTestTestHandler::OTHER_FAULT; } } else if ("Disabled" == this->TestResult.CompletionStatus) { diff --git a/Source/CTest/cmCTestScriptHandler.cxx b/Source/CTest/cmCTestScriptHandler.cxx index 1d29dfa..c566c5c 100644 --- a/Source/CTest/cmCTestScriptHandler.cxx +++ b/Source/CTest/cmCTestScriptHandler.cxx @@ -394,7 +394,7 @@ int cmCTestScriptHandler::ReadInScript(const std::string& total_script_arg) return 0; } -// extract variabels from the script to set ivars +// extract variables from the script to set ivars int cmCTestScriptHandler::ExtractVariables() { // Temporary variables diff --git a/Source/CTest/cmCTestSubmitHandler.cxx b/Source/CTest/cmCTestSubmitHandler.cxx index 8d62fa1..689668d 100644 --- a/Source/CTest/cmCTestSubmitHandler.cxx +++ b/Source/CTest/cmCTestSubmitHandler.cxx @@ -13,6 +13,7 @@ #include "cmCTest.h" #include "cmCTestCurl.h" #include "cmCTestScriptHandler.h" +#include "cmCryptoHash.h" #include "cmCurl.h" #include "cmGeneratedFileStream.h" #include "cmProcessOutput.h" @@ -428,10 +429,8 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(const std::string& localprefix, if (cmSystemTools::IsOn(this->GetOption("InternalTest"))) { upload_as += "bad_md5sum"; } else { - char md5[33]; - cmSystemTools::ComputeFileMD5(local_file, md5); - md5[32] = 0; - upload_as += md5; + upload_as += + cmSystemTools::ComputeFileHash(local_file, cmCryptoHash::AlgoMD5); } if (!cmSystemTools::FileExists(local_file.c_str())) { @@ -1058,9 +1057,8 @@ int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file, } } - char md5sum[33]; - md5sum[32] = 0; - cmSystemTools::ComputeFileMD5(file, md5sum); + std::string md5sum = + cmSystemTools::ComputeFileHash(file, cmCryptoHash::AlgoMD5); // 1. request the buildid and check to see if the file // has already been uploaded // TODO I added support for subproject. You would need to add diff --git a/Source/CTest/cmCTestTestCommand.cxx b/Source/CTest/cmCTestTestCommand.cxx index 075b140..3346d86 100644 --- a/Source/CTest/cmCTestTestCommand.cxx +++ b/Source/CTest/cmCTestTestCommand.cxx @@ -124,6 +124,12 @@ cmCTestGenericHandler* cmCTestTestCommand::InitializeHandler() } handler->SetTestLoad(testLoad); + if (const char* labelsForSubprojects = + this->Makefile->GetDefinition("CTEST_LABELS_FOR_SUBPROJECTS")) { + this->CTest->SetCTestConfiguration("LabelsForSubprojects", + labelsForSubprojects, this->Quiet); + } + handler->SetQuiet(this->Quiet); return handler; } diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index 674be60..ef0fac8 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -1,12 +1,10 @@ /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCTestTestHandler.h" - -#include "cmsys/Base64.h" -#include "cmsys/Directory.hxx" -#include "cmsys/FStream.hxx" -#include "cmsys/RegularExpression.hxx" #include <algorithm> +#include <cmsys/Base64.h> +#include <cmsys/Directory.hxx> +#include <cmsys/RegularExpression.hxx> #include <functional> #include <iomanip> #include <iterator> @@ -33,6 +31,7 @@ #include "cm_auto_ptr.hxx" #include "cm_utf8.h" #include "cmake.h" +#include "cmsys/FStream.hxx" class cmExecutionStatus; @@ -238,6 +237,36 @@ bool cmCTestSetTestsPropertiesCommand::InitialPass( return this->TestHandler->SetTestsProperties(args); } +class cmCTestSetDirectoryPropertiesCommand : public cmCommand +{ +public: + /** + * This is a virtual constructor for the command. + */ + cmCommand* Clone() CM_OVERRIDE + { + cmCTestSetDirectoryPropertiesCommand* c = + new cmCTestSetDirectoryPropertiesCommand; + c->TestHandler = this->TestHandler; + return c; + } + + /** + * This is called when the command is first encountered in + * the CMakeLists.txt file. + */ + bool InitialPass(std::vector<std::string> const& /*unused*/, + cmExecutionStatus& /*unused*/) CM_OVERRIDE; + + cmCTestTestHandler* TestHandler; +}; + +bool cmCTestSetDirectoryPropertiesCommand::InitialPass( + std::vector<std::string> const& args, cmExecutionStatus&) +{ + return this->TestHandler->SetDirectoryProperties(args); +} + // get the next number in a string with numbers separated by , // pos is the start of the search and pos2 is the end of the search // pos becomes pos2 after a call to GetNextNumber. @@ -506,9 +535,14 @@ int cmCTestTestHandler::ProcessHandler() << static_cast<int>(percent + .5f) << "% tests passed, " << failed.size() << " tests failed out of " << total << std::endl); - if (this->CTest->GetLabelSummary()) { + + if (!this->CTest->GetLabelsForSubprojects().empty() && + this->CTest->GetSubprojectSummary()) { + this->PrintSubprojectSummary(); + } else if (this->CTest->GetLabelSummary()) { this->PrintLabelSummary(); } + char realBuf[1024]; sprintf(realBuf, "%6.2f sec", (double)(clock_finish - clock_start)); cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, @@ -549,10 +583,10 @@ int cmCTestTestHandler::ProcessHandler() !cmHasLiteralPrefix(ftit->CompletionStatus, "SKIP_RETURN_CODE=") && ftit->CompletionStatus != "Disabled") { ofs << ftit->TestCount << ":" << ftit->Name << std::endl; - cmCTestLog( - this->CTest, HANDLER_OUTPUT, "\t" - << std::setw(3) << ftit->TestCount << " - " << ftit->Name << " (" - << this->GetTestStatus(ftit->Status) << ")" << std::endl); + cmCTestLog(this->CTest, HANDLER_OUTPUT, "\t" + << std::setw(3) << ftit->TestCount << " - " + << ftit->Name << " (" << this->GetTestStatus(&*ftit) + << ")" << std::endl); } } } @@ -658,6 +692,84 @@ void cmCTestTestHandler::PrintLabelSummary() } } +void cmCTestTestHandler::PrintSubprojectSummary() +{ + std::vector<std::string> subprojects = + this->CTest->GetLabelsForSubprojects(); + + cmCTestTestHandler::ListOfTests::iterator it = this->TestList.begin(); + std::map<std::string, double> labelTimes; + std::map<std::string, int> labelCounts; + std::set<std::string> labels; + // initialize maps + std::string::size_type maxlen = 0; + for (; it != this->TestList.end(); ++it) { + cmCTestTestProperties& p = *it; + for (std::vector<std::string>::iterator l = p.Labels.begin(); + l != p.Labels.end(); ++l) { + std::vector<std::string>::iterator subproject = + std::find(subprojects.begin(), subprojects.end(), *l); + if (subproject != subprojects.end()) { + if ((*l).size() > maxlen) { + maxlen = (*l).size(); + } + labels.insert(*l); + labelTimes[*l] = 0; + labelCounts[*l] = 0; + } + } + } + cmCTestTestHandler::TestResultsVector::iterator ri = + this->TestResults.begin(); + // fill maps + for (; ri != this->TestResults.end(); ++ri) { + cmCTestTestResult& result = *ri; + cmCTestTestProperties& p = *result.Properties; + for (std::vector<std::string>::iterator l = p.Labels.begin(); + l != p.Labels.end(); ++l) { + std::vector<std::string>::iterator subproject = + std::find(subprojects.begin(), subprojects.end(), *l); + if (subproject != subprojects.end()) { + labelTimes[*l] += result.ExecutionTime; + ++labelCounts[*l]; + } + } + } + // now print times + if (!labels.empty()) { + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, + "\nSubproject Time Summary:", this->Quiet); + } + for (std::set<std::string>::const_iterator i = labels.begin(); + i != labels.end(); ++i) { + std::string label = *i; + label.resize(maxlen + 3, ' '); + + char buf[1024]; + sprintf(buf, "%6.2f sec", labelTimes[*i]); + + std::ostringstream labelCountStr; + labelCountStr << "(" << labelCounts[*i] << " test"; + if (labelCounts[*i] > 1) { + labelCountStr << "s"; + } + labelCountStr << ")"; + + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "\n" + << label << " = " << buf << " " + << labelCountStr.str(), + this->Quiet); + if (this->LogFile) { + *this->LogFile << "\n" << *i << " = " << buf << "\n"; + } + } + if (!labels.empty()) { + if (this->LogFile) { + *this->LogFile << "\n"; + } + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "\n", this->Quiet); + } +} void cmCTestTestHandler::CheckLabelFilterInclude(cmCTestTestProperties& it) { // if not using Labels to filter then return @@ -1277,6 +1389,7 @@ void cmCTestTestHandler::GenerateDartOutput(cmXMLWriter& xml) } this->CTest->StartXML(xml, this->AppendXML); + this->CTest->GenerateSubprojectsOutput(xml); xml.StartElement("Testing"); xml.Element("StartDateTime", this->StartTest); xml.Element("StartTestTime", this->StartTestTime); @@ -1299,7 +1412,7 @@ void cmCTestTestHandler::GenerateDartOutput(cmXMLWriter& xml) xml.StartElement("NamedMeasurement"); xml.Attribute("type", "text/string"); xml.Attribute("name", "Exit Code"); - xml.Element("Value", this->GetTestStatus(result->Status)); + xml.Element("Value", this->GetTestStatus(result)); xml.EndElement(); // NamedMeasurement xml.StartElement("NamedMeasurement"); @@ -1328,6 +1441,12 @@ void cmCTestTestHandler::GenerateDartOutput(cmXMLWriter& xml) } xml.StartElement("NamedMeasurement"); + xml.Attribute("type", "numeric/double"); + xml.Attribute("name", "Processors"); + xml.Element("Value", result->Properties->Processors); + xml.EndElement(); // NamedMeasurement + + xml.StartElement("NamedMeasurement"); xml.Attribute("type", "text/string"); xml.Attribute("name", "Completion Status"); xml.Element("Value", result->CompletionStatus); @@ -1660,6 +1779,12 @@ void cmCTestTestHandler::GetListOfTests() newCom4->TestHandler = this; cm.GetState()->AddBuiltinCommand("set_tests_properties", newCom4); + // Add handler for SET_DIRECTORY_PROPERTIES + cmCTestSetDirectoryPropertiesCommand* newCom5 = + new cmCTestSetDirectoryPropertiesCommand; + newCom5->TestHandler = this; + cm.GetState()->AddBuiltinCommand("set_directory_properties", newCom5); + const char* testFilename; if (cmSystemTools::FileExists("CTestTestfile.cmake")) { // does the CTestTestfile.cmake exist ? @@ -1693,17 +1818,20 @@ void cmCTestTestHandler::UseExcludeRegExp() this->UseExcludeRegExpFirst = !this->UseIncludeRegExpFlag; } -const char* cmCTestTestHandler::GetTestStatus(int status) +const char* cmCTestTestHandler::GetTestStatus(const cmCTestTestResult* result) { static const char* statuses[] = { "Not Run", "Timeout", "SEGFAULT", "ILLEGAL", "INTERRUPT", "NUMERICAL", "OTHER_FAULT", "Failed", "BAD_COMMAND", "Completed" }; - + int status = result->Status; if (status < cmCTestTestHandler::NOT_RUN || status > cmCTestTestHandler::COMPLETED) { return "No Status"; } + if (status == cmCTestTestHandler::OTHER_FAULT) { + return result->ExceptionStatus.c_str(); + } return statuses[status]; } @@ -2171,7 +2299,16 @@ bool cmCTestTestHandler::SetTestsProperties( cmSystemTools::ExpandListArgument(val, rtit->Environment); } if (key == "LABELS") { - cmSystemTools::ExpandListArgument(val, rtit->Labels); + std::vector<std::string> Labels; + cmSystemTools::ExpandListArgument(val, Labels); + rtit->Labels.insert(rtit->Labels.end(), Labels.begin(), + Labels.end()); + // sort the array + std::sort(rtit->Labels.begin(), rtit->Labels.end()); + // remove duplicates + std::vector<std::string>::iterator new_end = + std::unique(rtit->Labels.begin(), rtit->Labels.end()); + rtit->Labels.erase(new_end, rtit->Labels.end()); } if (key == "MEASUREMENT") { size_t pos = val.find_first_of('='); @@ -2224,6 +2361,54 @@ bool cmCTestTestHandler::SetTestsProperties( return true; } +bool cmCTestTestHandler::SetDirectoryProperties( + const std::vector<std::string>& args) +{ + std::vector<std::string>::const_iterator it; + std::vector<std::string> tests; + bool found = false; + for (it = args.begin(); it != args.end(); ++it) { + if (*it == "PROPERTIES") { + found = true; + break; + } + tests.push_back(*it); + } + + if (!found) { + return false; + } + ++it; // skip PROPERTIES + for (; it != args.end(); ++it) { + std::string key = *it; + ++it; + if (it == args.end()) { + break; + } + std::string val = *it; + cmCTestTestHandler::ListOfTests::iterator rtit; + for (rtit = this->TestList.begin(); rtit != this->TestList.end(); ++rtit) { + std::string cwd = cmSystemTools::GetCurrentWorkingDirectory(); + if (cwd == rtit->Directory) { + if (key == "LABELS") { + std::vector<std::string> DirectoryLabels; + cmSystemTools::ExpandListArgument(val, DirectoryLabels); + rtit->Labels.insert(rtit->Labels.end(), DirectoryLabels.begin(), + DirectoryLabels.end()); + + // sort the array + std::sort(rtit->Labels.begin(), rtit->Labels.end()); + // remove duplicates + std::vector<std::string>::iterator new_end = + std::unique(rtit->Labels.begin(), rtit->Labels.end()); + rtit->Labels.erase(new_end, rtit->Labels.end()); + } + } + } + } + return true; +} + bool cmCTestTestHandler::AddTest(const std::vector<std::string>& args) { const std::string& testname = args[0]; diff --git a/Source/CTest/cmCTestTestHandler.h b/Source/CTest/cmCTestTestHandler.h index 0edcb14..6dbbcf8 100644 --- a/Source/CTest/cmCTestTestHandler.h +++ b/Source/CTest/cmCTestTestHandler.h @@ -90,6 +90,11 @@ public: */ bool SetTestsProperties(const std::vector<std::string>& args); + /** + * Set directory properties + */ + bool SetDirectoryProperties(const std::vector<std::string>& args); + void Initialize() CM_OVERRIDE; // NOTE: This struct is Saved/Restored @@ -144,6 +149,7 @@ public: double ExecutionTime; int ReturnValue; int Status; + std::string ExceptionStatus; bool CompressOutput; std::string CompletionStatus; std::string Output; @@ -227,6 +233,8 @@ private: virtual void GenerateDartOutput(cmXMLWriter& xml); void PrintLabelSummary(); + void PrintSubprojectSummary(); + /** * Run the tests for a directory and any subdirectories */ @@ -262,7 +270,7 @@ private: */ std::string FindTheExecutable(const char* exe); - const char* GetTestStatus(int status); + const char* GetTestStatus(const cmCTestTestResult*); void ExpandTestsToRunInformation(size_t numPossibleTests); void ExpandTestsToRunInformationForRerunFailed(); diff --git a/Source/CTest/cmProcess.cxx b/Source/CTest/cmProcess.cxx index f4ec6da..9680a69 100644 --- a/Source/CTest/cmProcess.cxx +++ b/Source/CTest/cmProcess.cxx @@ -240,3 +240,8 @@ int cmProcess::GetExitException() { return cmsysProcess_GetExitException(this->Process); } + +std::string cmProcess::GetExitExceptionString() +{ + return cmsysProcess_GetExceptionString(this->Process); +} diff --git a/Source/CTest/cmProcess.h b/Source/CTest/cmProcess.h index 86e905a..dfb02fe 100644 --- a/Source/CTest/cmProcess.h +++ b/Source/CTest/cmProcess.h @@ -38,6 +38,7 @@ public: int GetExitValue() { return this->ExitValue; } double GetTotalTime() { return this->TotalTime; } int GetExitException(); + std::string GetExitExceptionString(); /** * Read one line of output but block for no more than timeout. * Returns: diff --git a/Source/CursesDialog/CMakeLists.txt b/Source/CursesDialog/CMakeLists.txt index c5ac1f1..6023c83 100644 --- a/Source/CursesDialog/CMakeLists.txt +++ b/Source/CursesDialog/CMakeLists.txt @@ -17,10 +17,6 @@ set( CURSES_SRCS CursesDialog/ccmake ) -if( NOT CMAKE_USE_SYSTEM_FORM ) - include_directories(${CMake_SOURCE_DIR}/Source/CursesDialog/form - ${CMake_BINARY_DIR}/Source/CursesDialog/form) -endif() include_directories(${CURSES_INCLUDE_PATH}) diff --git a/Source/CursesDialog/form/CMakeLists.txt b/Source/CursesDialog/form/CMakeLists.txt index 0677043..b468f5b 100644 --- a/Source/CursesDialog/form/CMakeLists.txt +++ b/Source/CursesDialog/form/CMakeLists.txt @@ -3,12 +3,9 @@ project(CMAKE_FORM) -include_regular_expression("^.*$") -include_directories(${CURSES_INCLUDE_PATH} "${CMAKE_CURRENT_BINARY_DIR}") - configure_file(cmFormConfigure.h.in "${CMAKE_CURRENT_BINARY_DIR}/cmFormConfigure.h") -set( FORM_SRCS +add_library(cmForm fld_arg.c fld_attr.c fld_current.c @@ -49,10 +46,16 @@ set( FORM_SRCS fty_num.c fty_regex.c ) - -include_directories(${CMAKE_FORM_SOURCE_DIR}) -add_library(cmForm ${FORM_SRCS} ) + +target_include_directories(cmForm + PUBLIC + ${CURSES_INCLUDE_PATH} + ${CMAKE_FORM_BINARY_DIR} + ${CMAKE_FORM_SOURCE_DIR} + ) + target_link_libraries(cmForm ${CURSES_LIBRARY}) + if(CURSES_EXTRA_LIBRARY) target_link_libraries(cmForm ${CURSES_EXTRA_LIBRARY}) endif() diff --git a/Source/QtDialog/CMakeSetupDialog.cxx b/Source/QtDialog/CMakeSetupDialog.cxx index 57f8e10..5290afe 100644 --- a/Source/QtDialog/CMakeSetupDialog.cxx +++ b/Source/QtDialog/CMakeSetupDialog.cxx @@ -1195,7 +1195,7 @@ void CMakeSetupDialog::setSearchFilter(const QString& str) this->CacheValues->setSearchFilter(str); } -void CMakeSetupDialog::doOutputContextMenu(const QPoint& pt) +void CMakeSetupDialog::doOutputContextMenu(QPoint pt) { QMenu* menu = this->Output->createStandardContextMenu(); diff --git a/Source/QtDialog/CMakeSetupDialog.h b/Source/QtDialog/CMakeSetupDialog.h index 1abdb46..0da28d8 100644 --- a/Source/QtDialog/CMakeSetupDialog.h +++ b/Source/QtDialog/CMakeSetupDialog.h @@ -70,7 +70,7 @@ protected slots: bool doConfigureInternal(); bool doGenerateInternal(); void exitLoop(int); - void doOutputContextMenu(const QPoint&); + void doOutputContextMenu(QPoint pt); void doOutputFindDialog(); void doOutputFindNext(bool directionForward = true); void doOutputFindPrev(); diff --git a/Source/QtDialog/FirstConfigure.cxx b/Source/QtDialog/FirstConfigure.cxx index b193a27..88ce7cb 100644 --- a/Source/QtDialog/FirstConfigure.cxx +++ b/Source/QtDialog/FirstConfigure.cxx @@ -301,7 +301,7 @@ QString CrossCompilerSetup::getFindRoot() const void CrossCompilerSetup::setFindRoot(const QString& t) { - return this->crossFindRoot->setText(t); + this->crossFindRoot->setText(t); } int CrossCompilerSetup::getProgramMode() const diff --git a/Source/cmCMakeHostSystemInformationCommand.cxx b/Source/cmCMakeHostSystemInformationCommand.cxx index 4475c5a..5106f52 100644 --- a/Source/cmCMakeHostSystemInformationCommand.cxx +++ b/Source/cmCMakeHostSystemInformationCommand.cxx @@ -76,6 +76,55 @@ bool cmCMakeHostSystemInformationCommand::GetValue( value = this->ValueToString(info.GetTotalPhysicalMemory()); } else if (key == "AVAILABLE_PHYSICAL_MEMORY") { value = this->ValueToString(info.GetAvailablePhysicalMemory()); + } else if (key == "IS_64BIT") { + value = this->ValueToString(info.Is64Bits()); + } else if (key == "HAS_FPU") { + value = this->ValueToString( + info.DoesCPUSupportFeature(cmsys::SystemInformation::CPU_FEATURE_FPU)); + } else if (key == "HAS_MMX") { + value = this->ValueToString( + info.DoesCPUSupportFeature(cmsys::SystemInformation::CPU_FEATURE_MMX)); + } else if (key == "HAS_MMX_PLUS") { + value = this->ValueToString(info.DoesCPUSupportFeature( + cmsys::SystemInformation::CPU_FEATURE_MMX_PLUS)); + } else if (key == "HAS_SSE") { + value = this->ValueToString( + info.DoesCPUSupportFeature(cmsys::SystemInformation::CPU_FEATURE_SSE)); + } else if (key == "HAS_SSE2") { + value = this->ValueToString( + info.DoesCPUSupportFeature(cmsys::SystemInformation::CPU_FEATURE_SSE2)); + } else if (key == "HAS_SSE_FP") { + value = this->ValueToString(info.DoesCPUSupportFeature( + cmsys::SystemInformation::CPU_FEATURE_SSE_FP)); + } else if (key == "HAS_SSE_MMX") { + value = this->ValueToString(info.DoesCPUSupportFeature( + cmsys::SystemInformation::CPU_FEATURE_SSE_MMX)); + } else if (key == "HAS_AMD_3DNOW") { + value = this->ValueToString(info.DoesCPUSupportFeature( + cmsys::SystemInformation::CPU_FEATURE_AMD_3DNOW)); + } else if (key == "HAS_AMD_3DNOW_PLUS") { + value = this->ValueToString(info.DoesCPUSupportFeature( + cmsys::SystemInformation::CPU_FEATURE_AMD_3DNOW_PLUS)); + } else if (key == "HAS_IA64") { + value = this->ValueToString( + info.DoesCPUSupportFeature(cmsys::SystemInformation::CPU_FEATURE_IA64)); + } else if (key == "HAS_SERIAL_NUMBER") { + value = this->ValueToString(info.DoesCPUSupportFeature( + cmsys::SystemInformation::CPU_FEATURE_SERIALNUMBER)); + } else if (key == "PROCESSOR_NAME") { + value = this->ValueToString(info.GetExtendedProcessorName()); + } else if (key == "PROCESSOR_DESCRIPTION") { + value = info.GetCPUDescription(); + } else if (key == "PROCESSOR_SERIAL_NUMBER") { + value = this->ValueToString(info.GetProcessorSerialNumber()); + } else if (key == "OS_NAME") { + value = this->ValueToString(info.GetOSName()); + } else if (key == "OS_RELEASE") { + value = this->ValueToString(info.GetOSRelease()); + } else if (key == "OS_VERSION") { + value = this->ValueToString(info.GetOSVersion()); + } else if (key == "OS_PLATFORM") { + value = this->ValueToString(info.GetOSPlatform()); #ifdef HAVE_VS_SETUP_HELPER } else if (key == "VS_15_DIR") { cmVSSetupAPIHelper vsSetupAPIHelper; diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index e260556..dfb1398 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -11,6 +11,7 @@ #include "cmsys/Process.h" #include "cmsys/String.hxx" #include "cmsys/SystemInformation.hxx" +#include <algorithm> #include <ctype.h> #include <iostream> #include <map> @@ -190,7 +191,8 @@ int cmCTest::HTTPRequest(std::string url, HTTPMethod method, ::curl_easy_setopt(curl, CURLOPT_PUT, 1); file = cmsys::SystemTools::Fopen(putFile, "rb"); ::curl_easy_setopt(curl, CURLOPT_INFILE, file); - // fall through to append GET fields + // fall through to append GET fields + CM_FALLTHROUGH; case cmCTest::HTTP_GET: if (!fields.empty()) { url += "?" + fields; @@ -252,6 +254,7 @@ std::string cmCTest::DecodeURL(const std::string& in) cmCTest::cmCTest() { this->LabelSummary = true; + this->SubprojectSummary = true; this->ParallelLevel = 1; this->ParallelLevelSetInCli = false; this->TestLoad = 0; @@ -1363,6 +1366,35 @@ void cmCTest::AddSiteProperties(cmXMLWriter& xml) } } +void cmCTest::GenerateSubprojectsOutput(cmXMLWriter& xml) +{ + std::vector<std::string> subprojects = this->GetLabelsForSubprojects(); + std::vector<std::string>::const_iterator i; + for (i = subprojects.begin(); i != subprojects.end(); ++i) { + xml.StartElement("Subproject"); + xml.Attribute("name", *i); + xml.Element("Label", *i); + xml.EndElement(); // Subproject + } +} + +std::vector<std::string> cmCTest::GetLabelsForSubprojects() +{ + std::string labelsForSubprojects = + this->GetCTestConfiguration("LabelsForSubprojects"); + std::vector<std::string> subprojects; + cmSystemTools::ExpandListArgument(labelsForSubprojects, subprojects); + + // sort the array + std::sort(subprojects.begin(), subprojects.end()); + // remove duplicates + std::vector<std::string>::iterator new_end = + std::unique(subprojects.begin(), subprojects.end()); + subprojects.erase(new_end, subprojects.end()); + + return subprojects; +} + void cmCTest::EndXML(cmXMLWriter& xml) { xml.EndElement(); // Site @@ -1764,6 +1796,9 @@ bool cmCTest::HandleCommandLineArguments(size_t& i, if (this->CheckArgument(arg, "--no-label-summary")) { this->LabelSummary = false; } + if (this->CheckArgument(arg, "--no-subproject-summary")) { + this->SubprojectSummary = false; + } if (this->CheckArgument(arg, "-Q", "--quiet")) { this->Quiet = true; } diff --git a/Source/cmCTest.h b/Source/cmCTest.h index 60f3295..0d2a903 100644 --- a/Source/cmCTest.h +++ b/Source/cmCTest.h @@ -438,7 +438,9 @@ public: this->StreamErr = err; } void AddSiteProperties(cmXMLWriter& xml); + bool GetLabelSummary() { return this->LabelSummary; } + bool GetSubprojectSummary() { return this->SubprojectSummary; } std::string GetCostDataFile(); @@ -453,6 +455,9 @@ public: /** Return true if test should run until fail */ bool GetRepeatUntilFail() { return this->RepeatUntilFail; } + void GenerateSubprojectsOutput(cmXMLWriter& xml); + std::vector<std::string> GetLabelsForSubprojects(); + private: int RepeatTests; bool RepeatUntilFail; @@ -464,6 +469,7 @@ private: bool ExtraVerbose; bool ProduceXML; bool LabelSummary; + bool SubprojectSummary; bool UseHTTP10; bool PrintLabels; bool Failover; diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx index e1d8ef1..8a7d9bd 100644 --- a/Source/cmCommands.cxx +++ b/Source/cmCommands.cxx @@ -42,6 +42,7 @@ #include "cmIfCommand.h" #include "cmIncludeCommand.h" #include "cmIncludeDirectoryCommand.h" +#include "cmIncludeGuardCommand.h" #include "cmIncludeRegularExpressionCommand.h" #include "cmInstallCommand.h" #include "cmInstallFilesCommand.h" @@ -67,7 +68,12 @@ #include "cmSiteNameCommand.h" #include "cmStringCommand.h" #include "cmSubdirCommand.h" +#include "cmTargetCompileDefinitionsCommand.h" +#include "cmTargetCompileFeaturesCommand.h" +#include "cmTargetCompileOptionsCommand.h" +#include "cmTargetIncludeDirectoriesCommand.h" #include "cmTargetLinkLibrariesCommand.h" +#include "cmTargetSourcesCommand.h" #include "cmTryCompileCommand.h" #include "cmTryRunCommand.h" #include "cmUnsetCommand.h" @@ -93,11 +99,6 @@ #include "cmRemoveDefinitionsCommand.h" #include "cmSourceGroupCommand.h" #include "cmSubdirDependsCommand.h" -#include "cmTargetCompileDefinitionsCommand.h" -#include "cmTargetCompileFeaturesCommand.h" -#include "cmTargetCompileOptionsCommand.h" -#include "cmTargetIncludeDirectoriesCommand.h" -#include "cmTargetSourcesCommand.h" #include "cmUseMangledMesaCommand.h" #include "cmUtilitySourceCommand.h" #include "cmVariableRequiresCommand.h" @@ -132,6 +133,7 @@ void GetScriptingCommands(cmState* state) state->AddBuiltinCommand("get_property", new cmGetPropertyCommand); state->AddBuiltinCommand("if", new cmIfCommand); state->AddBuiltinCommand("include", new cmIncludeCommand); + state->AddBuiltinCommand("include_guard", new cmIncludeGuardCommand); state->AddBuiltinCommand("list", new cmListCommand); state->AddBuiltinCommand("macro", new cmMacroCommand); state->AddBuiltinCommand("make_directory", new cmMakeDirectoryCommand); @@ -145,8 +147,6 @@ void GetScriptingCommands(cmState* state) state->AddBuiltinCommand("separate_arguments", new cmSeparateArgumentsCommand); state->AddBuiltinCommand("set", new cmSetCommand); - state->AddBuiltinCommand("set_directory_properties", - new cmSetDirectoryPropertiesCommand); state->AddBuiltinCommand("set_property", new cmSetPropertyCommand); state->AddBuiltinCommand("site_name", new cmSiteNameCommand); state->AddBuiltinCommand("string", new cmStringCommand); @@ -229,6 +229,8 @@ void GetProjectCommands(cmState* state) state->AddBuiltinCommand("install_targets", new cmInstallTargetsCommand); state->AddBuiltinCommand("link_directories", new cmLinkDirectoriesCommand); state->AddBuiltinCommand("project", new cmProjectCommand); + state->AddBuiltinCommand("set_directory_properties", + new cmSetDirectoryPropertiesCommand); state->AddBuiltinCommand("set_source_files_properties", new cmSetSourceFilesPropertiesCommand); state->AddBuiltinCommand("set_target_properties", @@ -236,8 +238,17 @@ void GetProjectCommands(cmState* state) state->AddBuiltinCommand("set_tests_properties", new cmSetTestsPropertiesCommand); state->AddBuiltinCommand("subdirs", new cmSubdirCommand); + state->AddBuiltinCommand("target_compile_definitions", + new cmTargetCompileDefinitionsCommand); + state->AddBuiltinCommand("target_compile_features", + new cmTargetCompileFeaturesCommand); + state->AddBuiltinCommand("target_compile_options", + new cmTargetCompileOptionsCommand); + state->AddBuiltinCommand("target_include_directories", + new cmTargetIncludeDirectoriesCommand); state->AddBuiltinCommand("target_link_libraries", new cmTargetLinkLibrariesCommand); + state->AddBuiltinCommand("target_sources", new cmTargetSourcesCommand); state->AddBuiltinCommand("try_compile", new cmTryCompileCommand); state->AddBuiltinCommand("try_run", new cmTryRunCommand); @@ -258,15 +269,6 @@ void GetProjectCommands(cmState* state) state->AddBuiltinCommand("remove_definitions", new cmRemoveDefinitionsCommand); state->AddBuiltinCommand("source_group", new cmSourceGroupCommand); - state->AddBuiltinCommand("target_compile_definitions", - new cmTargetCompileDefinitionsCommand); - state->AddBuiltinCommand("target_compile_features", - new cmTargetCompileFeaturesCommand); - state->AddBuiltinCommand("target_compile_options", - new cmTargetCompileOptionsCommand); - state->AddBuiltinCommand("target_include_directories", - new cmTargetIncludeDirectoriesCommand); - state->AddBuiltinCommand("target_sources", new cmTargetSourcesCommand); state->AddDisallowedCommand( "export_library_dependencies", new cmExportLibraryDependenciesCommand, diff --git a/Source/cmCommonTargetGenerator.cxx b/Source/cmCommonTargetGenerator.cxx index 391d65c..6a007c8 100644 --- a/Source/cmCommonTargetGenerator.cxx +++ b/Source/cmCommonTargetGenerator.cxx @@ -22,10 +22,11 @@ cmCommonTargetGenerator::cmCommonTargetGenerator(cmGeneratorTarget* gt) : GeneratorTarget(gt) , Makefile(gt->Makefile) - , LocalGenerator(static_cast<cmLocalCommonGenerator*>(gt->LocalGenerator)) - , GlobalGenerator(static_cast<cmGlobalCommonGenerator*>( + , LocalCommonGenerator( + static_cast<cmLocalCommonGenerator*>(gt->LocalGenerator)) + , GlobalCommonGenerator(static_cast<cmGlobalCommonGenerator*>( gt->LocalGenerator->GetGlobalGenerator())) - , ConfigName(LocalGenerator->GetConfigName()) + , ConfigName(LocalCommonGenerator->GetConfigName()) { } @@ -62,10 +63,10 @@ void cmCommonTargetGenerator::AddModuleDefinitionFlag( // Append the flag and value. Use ConvertToLinkReference to help // vs6's "cl -link" pass it to the linker. std::string flag = defFileFlag; - flag += this->LocalGenerator->ConvertToOutputFormat( + flag += this->LocalCommonGenerator->ConvertToOutputFormat( linkLineComputer->ConvertToLinkReference(mdi->DefFile), cmOutputConverter::SHELL); - this->LocalGenerator->AppendFlags(flags, flag); + this->LocalCommonGenerator->AppendFlags(flags, flag); } void cmCommonTargetGenerator::AppendFortranFormatFlags( @@ -90,8 +91,8 @@ void cmCommonTargetGenerator::AppendFortranFormatFlags( break; } if (var) { - this->LocalGenerator->AppendFlags(flags, - this->Makefile->GetDefinition(var)); + this->LocalCommonGenerator->AppendFlags( + flags, this->Makefile->GetDefinition(var)); } } @@ -101,8 +102,8 @@ std::string cmCommonTargetGenerator::GetFlags(const std::string& l) if (i == this->FlagsByLanguage.end()) { std::string flags; - this->LocalGenerator->GetTargetCompileFlags(this->GeneratorTarget, - this->ConfigName, l, flags); + this->LocalCommonGenerator->GetTargetCompileFlags( + this->GeneratorTarget, this->ConfigName, l, flags); ByLanguageMap::value_type entry(l, flags); i = this->FlagsByLanguage.insert(entry).first; @@ -115,11 +116,11 @@ std::string cmCommonTargetGenerator::GetDefines(const std::string& l) ByLanguageMap::iterator i = this->DefinesByLanguage.find(l); if (i == this->DefinesByLanguage.end()) { std::set<std::string> defines; - this->LocalGenerator->GetTargetDefines(this->GeneratorTarget, - this->ConfigName, l, defines); + this->LocalCommonGenerator->GetTargetDefines(this->GeneratorTarget, + this->ConfigName, l, defines); std::string definesString; - this->LocalGenerator->JoinDefines(defines, definesString, l); + this->LocalCommonGenerator->JoinDefines(defines, definesString, l); ByLanguageMap::value_type entry(l, definesString); i = this->DefinesByLanguage.insert(entry).first; @@ -198,9 +199,10 @@ std::string cmCommonTargetGenerator::GetManifests() std::vector<std::string> manifests; for (std::vector<cmSourceFile const*>::iterator mi = manifest_srcs.begin(); mi != manifest_srcs.end(); ++mi) { - manifests.push_back(this->LocalGenerator->ConvertToOutputFormat( - this->LocalGenerator->ConvertToRelativePath( - this->LocalGenerator->GetWorkingDirectory(), (*mi)->GetFullPath()), + manifests.push_back(this->LocalCommonGenerator->ConvertToOutputFormat( + this->LocalCommonGenerator->ConvertToRelativePath( + this->LocalCommonGenerator->GetWorkingDirectory(), + (*mi)->GetFullPath()), cmOutputConverter::SHELL)); } @@ -233,6 +235,6 @@ void cmCommonTargetGenerator::AppendOSXVerFlag(std::string& flags, // Append the flag since a non-zero version is specified. std::ostringstream vflag; vflag << flag << major << "." << minor << "." << patch; - this->LocalGenerator->AppendFlags(flags, vflag.str()); + this->LocalCommonGenerator->AppendFlags(flags, vflag.str()); } } diff --git a/Source/cmCommonTargetGenerator.h b/Source/cmCommonTargetGenerator.h index c36145f..6b0f74e 100644 --- a/Source/cmCommonTargetGenerator.h +++ b/Source/cmCommonTargetGenerator.h @@ -37,8 +37,8 @@ protected: cmGeneratorTarget* GeneratorTarget; cmMakefile* Makefile; - cmLocalCommonGenerator* LocalGenerator; - cmGlobalCommonGenerator* GlobalGenerator; + cmLocalCommonGenerator* LocalCommonGenerator; + cmGlobalCommonGenerator* GlobalCommonGenerator; std::string ConfigName; void AppendFortranFormatFlags(std::string& flags, diff --git a/Source/cmComputeTargetDepends.cxx b/Source/cmComputeTargetDepends.cxx index ff19eac..8a3a671 100644 --- a/Source/cmComputeTargetDepends.cxx +++ b/Source/cmComputeTargetDepends.cxx @@ -161,7 +161,7 @@ void cmComputeTargetDepends::CollectTargets() std::vector<cmLocalGenerator*> const& lgens = this->GlobalGenerator->GetLocalGenerators(); for (unsigned int i = 0; i < lgens.size(); ++i) { - const std::vector<cmGeneratorTarget*> targets = + const std::vector<cmGeneratorTarget*>& targets = lgens[i]->GetGeneratorTargets(); for (std::vector<cmGeneratorTarget*>::const_iterator ti = targets.begin(); ti != targets.end(); ++ti) { diff --git a/Source/cmConfigure.cmake.h.in b/Source/cmConfigure.cmake.h.in index 524fdf8..302000a 100644 --- a/Source/cmConfigure.cmake.h.in +++ b/Source/cmConfigure.cmake.h.in @@ -19,7 +19,6 @@ #cmakedefine HAVE_UNSETENV #cmakedefine CMAKE_USE_ELF_PARSER #cmakedefine CMAKE_USE_MACH_PARSER -#cmakedefine CMAKE_USE_LIBUV #cmakedefine CMake_HAVE_CXX_AUTO_PTR #cmakedefine CMake_HAVE_CXX_EQ_DELETE #cmakedefine CMake_HAVE_CXX_FALLTHROUGH diff --git a/Source/cmConnection.cxx b/Source/cmConnection.cxx new file mode 100644 index 0000000..00cf283 --- /dev/null +++ b/Source/cmConnection.cxx @@ -0,0 +1,158 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmConnection.h" + +#include "cmServer.h" +#include "cm_uv.h" + +#include <cassert> +#include <cstring> + +struct write_req_t +{ + uv_write_t req; + uv_buf_t buf; +}; + +void cmEventBasedConnection::on_alloc_buffer(uv_handle_t* handle, + size_t suggested_size, + uv_buf_t* buf) +{ + (void)(handle); + char* rawBuffer = new char[suggested_size]; + *buf = uv_buf_init(rawBuffer, static_cast<unsigned int>(suggested_size)); +} + +void cmEventBasedConnection::on_read(uv_stream_t* stream, ssize_t nread, + const uv_buf_t* buf) +{ + auto conn = reinterpret_cast<cmEventBasedConnection*>(stream->data); + if (conn) { + if (nread >= 0) { + conn->ReadData(std::string(buf->base, buf->base + nread)); + } else { + conn->OnDisconnect((int)nread); + } + } + + delete[](buf->base); +} + +void cmEventBasedConnection::on_close_delete(uv_handle_t* handle) +{ + delete handle; +} + +void cmEventBasedConnection::on_close(uv_handle_t* /*handle*/) +{ +} + +void cmEventBasedConnection::on_write(uv_write_t* req, int status) +{ + (void)(status); + + // Free req and buffer + write_req_t* wr = reinterpret_cast<write_req_t*>(req); + delete[](wr->buf.base); + delete wr; +} + +void cmEventBasedConnection::on_new_connection(uv_stream_t* stream, int status) +{ + (void)(status); + auto conn = reinterpret_cast<cmEventBasedConnection*>(stream->data); + + if (conn) { + conn->Connect(stream); + } +} + +bool cmEventBasedConnection::IsOpen() const +{ + return this->WriteStream != CM_NULLPTR; +} + +void cmEventBasedConnection::WriteData(const std::string& data) +{ + assert(this->WriteStream); + + auto ds = data.size(); + + write_req_t* req = new write_req_t; + req->req.data = this; + req->buf = uv_buf_init(new char[ds], static_cast<unsigned int>(ds)); + memcpy(req->buf.base, data.c_str(), ds); + uv_write(reinterpret_cast<uv_write_t*>(req), + static_cast<uv_stream_t*>(this->WriteStream), &req->buf, 1, + on_write); +} + +void cmEventBasedConnection::ReadData(const std::string& data) +{ + this->RawReadBuffer += data; + if (BufferStrategy) { + std::string packet = BufferStrategy->BufferMessage(this->RawReadBuffer); + do { + ProcessRequest(packet); + packet = BufferStrategy->BufferMessage(this->RawReadBuffer); + } while (!packet.empty()); + + } else { + ProcessRequest(this->RawReadBuffer); + this->RawReadBuffer.clear(); + } +} + +cmEventBasedConnection::cmEventBasedConnection( + cmConnectionBufferStrategy* bufferStrategy) + : BufferStrategy(bufferStrategy) +{ +} + +void cmEventBasedConnection::Connect(uv_stream_t* server) +{ + (void)server; + Server->OnConnected(nullptr); +} + +void cmEventBasedConnection::OnDisconnect(int onerror) +{ + (void)onerror; + this->OnConnectionShuttingDown(); + this->Server->OnDisconnect(this); +} + +cmConnection::~cmConnection() +{ +} + +bool cmConnection::OnConnectionShuttingDown() +{ + return true; +} + +void cmConnection::SetServer(cmServerBase* s) +{ + Server = s; +} + +void cmConnection::ProcessRequest(const std::string& request) +{ + Server->ProcessRequest(this, request); +} + +bool cmConnection::OnServeStart(std::string* errString) +{ + (void)errString; + return true; +} + +bool cmEventBasedConnection::OnConnectionShuttingDown() +{ + this->WriteStream->data = nullptr; + this->ReadStream->data = nullptr; + + this->ReadStream = nullptr; + this->WriteStream = nullptr; + return true; +} diff --git a/Source/cmConnection.h b/Source/cmConnection.h new file mode 100644 index 0000000..4b8fcb3 --- /dev/null +++ b/Source/cmConnection.h @@ -0,0 +1,118 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ + +#pragma once + +#include "cmConfigure.h" + +#include "cm_uv.h" + +#include <cstddef> +#include <memory> +#include <string> + +class cmServerBase; + +/*** + * Given a sequence of bytes with any kind of buffering, instances of this + * class arrange logical chunks according to whatever the use case is for + * the connection. + */ +class cmConnectionBufferStrategy +{ +public: + virtual ~cmConnectionBufferStrategy(); + + /*** + * Called whenever with an active raw buffer. If a logical chunk + * becomes available, that chunk is returned and that portion is + * removed from the rawBuffer + * + * @param rawBuffer in/out parameter. Receive buffer; the buffer strategy is + * free to manipulate this buffer anyway it needs to. + * + * @return Next chunk from the stream. Returns the empty string if a chunk + * isn't ready yet. Users of this interface should repeatedly call this + * function until an empty string is returned since its entirely possible + * multiple chunks come in a single raw buffer. + */ + virtual std::string BufferMessage(std::string& rawBuffer) = 0; + + /*** + * Resets the internal state of the buffering + */ + virtual void clear(); + + // TODO: There should be a callback / flag set for errors +}; + +class cmConnection +{ + CM_DISABLE_COPY(cmConnection) + +public: + cmConnection() {} + + virtual void WriteData(const std::string& data) = 0; + + virtual ~cmConnection(); + + virtual bool OnConnectionShuttingDown(); + + virtual bool IsOpen() const = 0; + + virtual void SetServer(cmServerBase* s); + + virtual void ProcessRequest(const std::string& request); + + virtual bool OnServeStart(std::string* pString); + +protected: + cmServerBase* Server = nullptr; +}; + +/*** + * Abstraction of a connection; ties in event callbacks from libuv and notifies + * the server when appropriate + */ +class cmEventBasedConnection : public cmConnection +{ + +public: + /*** + * @param bufferStrategy If no strategy is given, it will process the raw + * chunks as they come in. The connection + * owns the pointer given. + */ + cmEventBasedConnection(cmConnectionBufferStrategy* bufferStrategy = nullptr); + + virtual void Connect(uv_stream_t* server); + + virtual void ReadData(const std::string& data); + + bool IsOpen() const override; + + void WriteData(const std::string& data) override; + bool OnConnectionShuttingDown() override; + + virtual void OnDisconnect(int errorCode); + uv_stream_t* ReadStream = nullptr; + uv_stream_t* WriteStream = nullptr; + + static void on_close(uv_handle_t* handle); + static void on_close_delete(uv_handle_t* handle); + +protected: + std::string RawReadBuffer; + + std::unique_ptr<cmConnectionBufferStrategy> BufferStrategy; + + static void on_read(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf); + + static void on_write(uv_write_t* req, int status); + + static void on_new_connection(uv_stream_t* stream, int status); + + static void on_alloc_buffer(uv_handle_t* handle, size_t suggested_size, + uv_buf_t* buf); +}; diff --git a/Source/cmExecuteProcessCommand.cxx b/Source/cmExecuteProcessCommand.cxx index 8c10dbe..435adca 100644 --- a/Source/cmExecuteProcessCommand.cxx +++ b/Source/cmExecuteProcessCommand.cxx @@ -7,6 +7,7 @@ #include <sstream> #include <stdio.h> +#include "cmAlgorithms.h" #include "cmMakefile.h" #include "cmProcessOutput.h" #include "cmSystemTools.h" @@ -46,6 +47,7 @@ bool cmExecuteProcessCommand::InitialPass(std::vector<std::string> const& args, std::string output_variable; std::string error_variable; std::string result_variable; + std::string results_variable; std::string working_directory; cmProcessOutput::Encoding encoding = cmProcessOutput::None; for (size_t i = 0; i < args.size(); ++i) { @@ -77,6 +79,14 @@ bool cmExecuteProcessCommand::InitialPass(std::vector<std::string> const& args, this->SetError(" called with no value for RESULT_VARIABLE."); return false; } + } else if (args[i] == "RESULTS_VARIABLE") { + doing_command = false; + if (++i < args.size()) { + results_variable = args[i]; + } else { + this->SetError(" called with no value for RESULTS_VARIABLE."); + return false; + } } else if (args[i] == "WORKING_DIRECTORY") { doing_command = false; if (++i < args.size()) { @@ -287,7 +297,7 @@ bool cmExecuteProcessCommand::InitialPass(std::vector<std::string> const& args, switch (cmsysProcess_GetState(cp)) { case cmsysProcess_State_Exited: { int v = cmsysProcess_GetExitValue(cp); - char buf[100]; + char buf[16]; sprintf(buf, "%d", v); this->Makefile->AddDefinition(result_variable, buf); } break; @@ -305,6 +315,47 @@ bool cmExecuteProcessCommand::InitialPass(std::vector<std::string> const& args, break; } } + // Store the result of running the processes. + if (!results_variable.empty()) { + switch (cmsysProcess_GetState(cp)) { + case cmsysProcess_State_Exited: { + std::vector<std::string> res; + for (size_t i = 0; i < cmds.size(); ++i) { + switch (cmsysProcess_GetStateByIndex(cp, static_cast<int>(i))) { + case kwsysProcess_StateByIndex_Exited: { + int exitCode = + cmsysProcess_GetExitValueByIndex(cp, static_cast<int>(i)); + char buf[16]; + sprintf(buf, "%d", exitCode); + res.push_back(buf); + } break; + case kwsysProcess_StateByIndex_Exception: + res.push_back(cmsysProcess_GetExceptionStringByIndex( + cp, static_cast<int>(i))); + break; + case kwsysProcess_StateByIndex_Error: + default: + res.push_back("Error getting the child return code"); + break; + } + } + this->Makefile->AddDefinition(results_variable, + cmJoin(res, ";").c_str()); + } break; + case cmsysProcess_State_Exception: + this->Makefile->AddDefinition(results_variable, + cmsysProcess_GetExceptionString(cp)); + break; + case cmsysProcess_State_Error: + this->Makefile->AddDefinition(results_variable, + cmsysProcess_GetErrorString(cp)); + break; + case cmsysProcess_State_Expired: + this->Makefile->AddDefinition(results_variable, + "Process terminated due to timeout"); + break; + } + } // Delete the process instance. cmsysProcess_Delete(cp); diff --git a/Source/cmExtraCodeBlocksGenerator.cxx b/Source/cmExtraCodeBlocksGenerator.cxx index 5b7b827..e7a8975 100644 --- a/Source/cmExtraCodeBlocksGenerator.cxx +++ b/Source/cmExtraCodeBlocksGenerator.cxx @@ -296,8 +296,9 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile( // and UTILITY targets for (std::vector<cmLocalGenerator*>::const_iterator lg = lgs.begin(); lg != lgs.end(); lg++) { - std::vector<cmGeneratorTarget*> targets = (*lg)->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin(); + const std::vector<cmGeneratorTarget*>& targets = + (*lg)->GetGeneratorTargets(); + for (std::vector<cmGeneratorTarget*>::const_iterator ti = targets.begin(); ti != targets.end(); ti++) { std::string targetName = (*ti)->GetName(); switch ((*ti)->GetType()) { @@ -359,8 +360,9 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile( for (std::vector<cmLocalGenerator*>::const_iterator lg = lgs.begin(); lg != lgs.end(); lg++) { cmMakefile* makefile = (*lg)->GetMakefile(); - std::vector<cmGeneratorTarget*> targets = (*lg)->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin(); + const std::vector<cmGeneratorTarget*>& targets = + (*lg)->GetGeneratorTargets(); + for (std::vector<cmGeneratorTarget*>::const_iterator ti = targets.begin(); ti != targets.end(); ti++) { switch ((*ti)->GetType()) { case cmStateEnums::EXECUTABLE: diff --git a/Source/cmExtraCodeLiteGenerator.cxx b/Source/cmExtraCodeLiteGenerator.cxx index b478f34..96502d5 100644 --- a/Source/cmExtraCodeLiteGenerator.cxx +++ b/Source/cmExtraCodeLiteGenerator.cxx @@ -292,8 +292,9 @@ void cmExtraCodeLiteGenerator::CreateNewProjectFile( for (std::vector<cmLocalGenerator*>::const_iterator lg = lgs.begin(); lg != lgs.end(); lg++) { cmMakefile* makefile = (*lg)->GetMakefile(); - std::vector<cmGeneratorTarget*> targets = (*lg)->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin(); + const std::vector<cmGeneratorTarget*>& targets = + (*lg)->GetGeneratorTargets(); + for (std::vector<cmGeneratorTarget*>::const_iterator ti = targets.begin(); ti != targets.end(); ti++) { projectType = CollectSourceFiles(makefile, *ti, cFiles, otherFiles); } diff --git a/Source/cmExtraEclipseCDT4Generator.cxx b/Source/cmExtraEclipseCDT4Generator.cxx index 2a6ce98..473af37 100644 --- a/Source/cmExtraEclipseCDT4Generator.cxx +++ b/Source/cmExtraEclipseCDT4Generator.cxx @@ -475,7 +475,7 @@ void cmExtraEclipseCDT4Generator::CreateLinksForTargets(cmXMLWriter& xml) this->GlobalGenerator->GetLocalGenerators().begin(); lgIt != this->GlobalGenerator->GetLocalGenerators().end(); ++lgIt) { cmMakefile* makefile = (*lgIt)->GetMakefile(); - const std::vector<cmGeneratorTarget*> targets = + const std::vector<cmGeneratorTarget*>& targets = (*lgIt)->GetGeneratorTargets(); for (std::vector<cmGeneratorTarget*>::const_iterator ti = targets.begin(); @@ -853,8 +853,9 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const for (std::vector<cmLocalGenerator*>::const_iterator it = this->GlobalGenerator->GetLocalGenerators().begin(); it != this->GlobalGenerator->GetLocalGenerators().end(); ++it) { - std::vector<cmGeneratorTarget*> targets = (*it)->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::iterator l = targets.begin(); + const std::vector<cmGeneratorTarget*>& targets = + (*it)->GetGeneratorTargets(); + for (std::vector<cmGeneratorTarget*>::const_iterator l = targets.begin(); l != targets.end(); ++l) { std::vector<std::string> includeDirs; std::string config = mf->GetSafeDefinition("CMAKE_BUILD_TYPE"); @@ -910,7 +911,7 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const for (std::vector<cmLocalGenerator*>::const_iterator it = this->GlobalGenerator->GetLocalGenerators().begin(); it != this->GlobalGenerator->GetLocalGenerators().end(); ++it) { - const std::vector<cmGeneratorTarget*> targets = + const std::vector<cmGeneratorTarget*>& targets = (*it)->GetGeneratorTargets(); std::string subdir = (*it)->ConvertToRelativePath( this->HomeOutputDirectory, (*it)->GetCurrentBinaryDirectory()); diff --git a/Source/cmExtraKateGenerator.cxx b/Source/cmExtraKateGenerator.cxx index 3730433..e366774 100644 --- a/Source/cmExtraKateGenerator.cxx +++ b/Source/cmExtraKateGenerator.cxx @@ -115,7 +115,7 @@ void cmExtraKateGenerator::WriteTargets(const cmLocalGenerator* lg, for (std::vector<cmLocalGenerator*>::const_iterator it = this->GlobalGenerator->GetLocalGenerators().begin(); it != this->GlobalGenerator->GetLocalGenerators().end(); ++it) { - const std::vector<cmGeneratorTarget*> targets = + const std::vector<cmGeneratorTarget*>& targets = (*it)->GetGeneratorTargets(); std::string currentDir = (*it)->GetCurrentBinaryDirectory(); bool topLevel = (currentDir == (*it)->GetBinaryDirectory()); diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx index 1fd1418..a62a546 100644 --- a/Source/cmExtraSublimeTextGenerator.cxx +++ b/Source/cmExtraSublimeTextGenerator.cxx @@ -185,8 +185,9 @@ void cmExtraSublimeTextGenerator::AppendAllTargets( for (std::vector<cmLocalGenerator*>::const_iterator lg = lgs.begin(); lg != lgs.end(); lg++) { cmMakefile* makefile = (*lg)->GetMakefile(); - std::vector<cmGeneratorTarget*> targets = (*lg)->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin(); + const std::vector<cmGeneratorTarget*>& targets = + (*lg)->GetGeneratorTargets(); + for (std::vector<cmGeneratorTarget*>::const_iterator ti = targets.begin(); ti != targets.end(); ti++) { std::string targetName = (*ti)->GetName(); switch ((*ti)->GetType()) { diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 5777fb2..b769a56 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -55,14 +55,14 @@ class cmSystemToolsFileTime; static mode_t mode_owner_read = S_IREAD; static mode_t mode_owner_write = S_IWRITE; static mode_t mode_owner_execute = S_IEXEC; -static mode_t mode_group_read = 0; -static mode_t mode_group_write = 0; -static mode_t mode_group_execute = 0; -static mode_t mode_world_read = 0; -static mode_t mode_world_write = 0; -static mode_t mode_world_execute = 0; -static mode_t mode_setuid = 0; -static mode_t mode_setgid = 0; +static mode_t mode_group_read = 040; +static mode_t mode_group_write = 020; +static mode_t mode_group_execute = 010; +static mode_t mode_world_read = 04; +static mode_t mode_world_write = 02; +static mode_t mode_world_execute = 01; +static mode_t mode_setuid = 04000; +static mode_t mode_setgid = 02000; #else static mode_t mode_owner_read = S_IRUSR; static mode_t mode_owner_write = S_IWUSR; @@ -1076,11 +1076,26 @@ protected: bool SetPermissions(const char* toFile, mode_t permissions) { - if (permissions && !cmSystemTools::SetPermissions(toFile, permissions)) { - std::ostringstream e; - e << this->Name << " cannot set permissions on \"" << toFile << "\""; - this->FileCommand->SetError(e.str()); - return false; + if (permissions) { +#ifdef WIN32 + if (Makefile->IsOn("CMAKE_CROSSCOMPILING")) { + std::string mode_t_adt_filename = + std::string(toFile) + ":cmake_mode_t"; + + cmsys::ofstream permissionStream(mode_t_adt_filename.c_str()); + + if (permissionStream) { + permissionStream << std::oct << permissions << std::endl; + } + } +#endif + + if (!cmSystemTools::SetPermissions(toFile, permissions)) { + std::ostringstream e; + e << this->Name << " cannot set permissions on \"" << toFile << "\""; + this->FileCommand->SetError(e.str()); + return false; + } } return true; } diff --git a/Source/cmFileLockResult.cxx b/Source/cmFileLockResult.cxx index a040705..9ca5d8a 100644 --- a/Source/cmFileLockResult.cxx +++ b/Source/cmFileLockResult.cxx @@ -5,6 +5,7 @@ #include <errno.h> #include <string.h> +#define WINMSG_BUF_LEN (1024) cmFileLockResult cmFileLockResult::MakeOk() { return cmFileLockResult(OK, 0); @@ -53,18 +54,12 @@ std::string cmFileLockResult::GetOutputMessage() const case SYSTEM: #if defined(_WIN32) { - char* errorText = NULL; - - // http://stackoverflow.com/a/455533/2288008 - DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS; - ::FormatMessageA(flags, NULL, this->ErrorValue, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPSTR)&errorText, 0, NULL); - - if (errorText != NULL) { - const std::string message = errorText; - ::LocalFree(errorText); + char winmsg[WINMSG_BUF_LEN]; + DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS; + if (FormatMessageA(flags, NULL, this->ErrorValue, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPSTR)winmsg, WINMSG_BUF_LEN, NULL)) { + const std::string message = winmsg; return message; } else { return "Internal error (FormatMessageA failed)"; diff --git a/Source/cmFileMonitor.cxx b/Source/cmFileMonitor.cxx index 8027535..c0401d7 100644 --- a/Source/cmFileMonitor.cxx +++ b/Source/cmFileMonitor.cxx @@ -171,7 +171,9 @@ public: { if (this->Handle) { uv_fs_event_stop(this->Handle); - uv_close(reinterpret_cast<uv_handle_t*>(this->Handle), &on_fs_close); + if (!uv_is_closing(reinterpret_cast<uv_handle_t*>(this->Handle))) { + uv_close(reinterpret_cast<uv_handle_t*>(this->Handle), &on_fs_close); + } this->Handle = nullptr; } cmVirtualDirectoryWatcher::StopWatching(); diff --git a/Source/cmGeneratorExpressionEvaluationFile.cxx b/Source/cmGeneratorExpressionEvaluationFile.cxx index 1526454..5003e8d 100644 --- a/Source/cmGeneratorExpressionEvaluationFile.cxx +++ b/Source/cmGeneratorExpressionEvaluationFile.cxx @@ -20,11 +20,13 @@ cmGeneratorExpressionEvaluationFile::cmGeneratorExpressionEvaluationFile( const std::string& input, CM_AUTO_PTR<cmCompiledGeneratorExpression> outputFileExpr, - CM_AUTO_PTR<cmCompiledGeneratorExpression> condition, bool inputIsContent) + CM_AUTO_PTR<cmCompiledGeneratorExpression> condition, bool inputIsContent, + cmPolicies::PolicyStatus policyStatusCMP0070) : Input(input) , OutputFileExpr(outputFileExpr) , Condition(condition) , InputIsContent(inputIsContent) + , PolicyStatusCMP0070(policyStatusCMP0070) { } @@ -51,11 +53,17 @@ void cmGeneratorExpressionEvaluationFile::Generate( } } - const std::string outputFileName = this->OutputFileExpr->Evaluate( + std::string outputFileName = this->OutputFileExpr->Evaluate( lg, config, false, CM_NULLPTR, CM_NULLPTR, CM_NULLPTR, lang); const std::string outputContent = inputExpression->Evaluate( lg, config, false, CM_NULLPTR, CM_NULLPTR, CM_NULLPTR, lang); + if (cmSystemTools::FileIsFullPath(outputFileName)) { + outputFileName = cmSystemTools::CollapseFullPath(outputFileName); + } else { + outputFileName = this->FixRelativePath(outputFileName, PathForOutput, lg); + } + std::map<std::string, std::string>::iterator it = outputFiles.find(outputFileName); @@ -111,12 +119,18 @@ void cmGeneratorExpressionEvaluationFile::Generate(cmLocalGenerator* lg) if (this->InputIsContent) { inputContent = this->Input; } else { - lg->GetMakefile()->AddCMakeDependFile(this->Input); - cmSystemTools::GetPermissions(this->Input.c_str(), perm); - cmsys::ifstream fin(this->Input.c_str()); + std::string inputFileName = this->Input; + if (cmSystemTools::FileIsFullPath(inputFileName)) { + inputFileName = cmSystemTools::CollapseFullPath(inputFileName); + } else { + inputFileName = this->FixRelativePath(inputFileName, PathForInput, lg); + } + lg->GetMakefile()->AddCMakeDependFile(inputFileName); + cmSystemTools::GetPermissions(inputFileName.c_str(), perm); + cmsys::ifstream fin(inputFileName.c_str()); if (!fin) { std::ostringstream e; - e << "Evaluation file \"" << this->Input << "\" cannot be read."; + e << "Evaluation file \"" << inputFileName << "\" cannot be read."; lg->IssueMessage(cmake::FATAL_ERROR, e.str()); return; } @@ -159,3 +173,57 @@ void cmGeneratorExpressionEvaluationFile::Generate(cmLocalGenerator* lg) } } } + +std::string cmGeneratorExpressionEvaluationFile::FixRelativePath( + std::string const& relativePath, PathRole role, cmLocalGenerator* lg) +{ + std::string resultPath; + switch (this->PolicyStatusCMP0070) { + case cmPolicies::WARN: { + std::string arg; + switch (role) { + case PathForInput: + arg = "INPUT"; + break; + case PathForOutput: + arg = "OUTPUT"; + break; + } + std::ostringstream w; + /* clang-format off */ + w << + cmPolicies::GetPolicyWarning(cmPolicies::CMP0070) << "\n" + "file(GENERATE) given relative " << arg << " path:\n" + " " << relativePath << "\n" + "This is not defined behavior unless CMP0070 is set to NEW. " + "For compatibility with older versions of CMake, the previous " + "undefined behavior will be used." + ; + /* clang-format on */ + lg->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + } + CM_FALLTHROUGH; + case cmPolicies::OLD: + // OLD behavior is to use the relative path unchanged, + // which ends up being used relative to the working dir. + resultPath = relativePath; + break; + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::REQUIRED_ALWAYS: + case cmPolicies::NEW: + // NEW behavior is to interpret the relative path with respect + // to the current source or binary directory. + switch (role) { + case PathForInput: + resultPath = cmSystemTools::CollapseFullPath( + relativePath, lg->GetCurrentSourceDirectory()); + break; + case PathForOutput: + resultPath = cmSystemTools::CollapseFullPath( + relativePath, lg->GetCurrentBinaryDirectory()); + break; + } + break; + } + return resultPath; +} diff --git a/Source/cmGeneratorExpressionEvaluationFile.h b/Source/cmGeneratorExpressionEvaluationFile.h index 9872746..ecf919d 100644 --- a/Source/cmGeneratorExpressionEvaluationFile.h +++ b/Source/cmGeneratorExpressionEvaluationFile.h @@ -10,6 +10,7 @@ #include <vector> #include "cmGeneratorExpression.h" +#include "cmPolicies.h" #include "cm_auto_ptr.hxx" #include "cm_sys_stat.h" @@ -21,7 +22,8 @@ public: cmGeneratorExpressionEvaluationFile( const std::string& input, CM_AUTO_PTR<cmCompiledGeneratorExpression> outputFileExpr, - CM_AUTO_PTR<cmCompiledGeneratorExpression> condition, bool inputIsContent); + CM_AUTO_PTR<cmCompiledGeneratorExpression> condition, bool inputIsContent, + cmPolicies::PolicyStatus policyStatusCMP0070); void Generate(cmLocalGenerator* lg); @@ -35,12 +37,21 @@ private: cmCompiledGeneratorExpression* inputExpression, std::map<std::string, std::string>& outputFiles, mode_t perm); + enum PathRole + { + PathForInput, + PathForOutput + }; + std::string FixRelativePath(std::string const& filePath, PathRole role, + cmLocalGenerator* lg); + private: const std::string Input; const CM_AUTO_PTR<cmCompiledGeneratorExpression> OutputFileExpr; const CM_AUTO_PTR<cmCompiledGeneratorExpression> Condition; std::vector<std::string> Files; const bool InputIsContent; + cmPolicies::PolicyStatus PolicyStatusCMP0070; }; #endif diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index a57d2a0..4d2e5c7 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -813,7 +813,7 @@ static const struct CompileLanguageNode : public cmGeneratorExpressionNode reportError( context, content->GetOriginalExpression(), "$<COMPILE_LANGUAGE:...> may only be used to specify include " - "directories compile definitions, compile options and to evaluate " + "directories, compile definitions, compile options, and to evaluate " "components of the file(GENERATE) command."); return std::string(); } diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 329c7a9..95f4543 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -326,6 +326,13 @@ std::string cmGeneratorTarget::GetOutputName( return i->second; } +void cmGeneratorTarget::ClearSourcesCache() +{ + this->KindedSourcesMap.clear(); + this->LinkImplementationLanguageIsContextDependent = true; + this->Objects.clear(); +} + void cmGeneratorTarget::AddSourceCommon(const std::string& src) { cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); @@ -333,8 +340,7 @@ void cmGeneratorTarget::AddSourceCommon(const std::string& src) CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(src); cge->SetEvaluateForBuildsystem(true); this->SourceEntries.push_back(new TargetPropertyEntry(cge)); - this->KindedSourcesMap.clear(); - this->LinkImplementationLanguageIsContextDependent = true; + this->ClearSourcesCache(); } void cmGeneratorTarget::AddSource(const std::string& src) diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 52147e3..b5f7f6e 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -491,6 +491,11 @@ public: std::string GetOutputName(const std::string& config, cmStateEnums::ArtifactType artifact) const; + /** Clears cached meta data for local and external source files. + * The meta data will be recomputed on demand. + */ + void ClearSourcesCache(); + void AddSource(const std::string& src); void AddTracedSources(std::vector<std::string> const& srcs); diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 099f705..85ba5ee 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -90,7 +90,7 @@ cmGlobalGenerator::cmGlobalGenerator(cmake* cm) this->TryCompileTimeout = 0; this->ExtraGenerator = CM_NULLPTR; - this->CurrentMakefile = CM_NULLPTR; + this->CurrentConfigureMakefile = CM_NULLPTR; this->TryCompileOuterMakefile = CM_NULLPTR; this->ConfigureDoneCMP0026AndCMP0024 = false; @@ -490,7 +490,6 @@ void cmGlobalGenerator::EnableLanguage( windowsVersionString << osviex.dwMajorVersion << "." << osviex.dwMinorVersion << "." << osviex.dwBuildNumber; - windowsVersionString.str(); mf->AddDefinition("CMAKE_HOST_SYSTEM_VERSION", windowsVersionString.str().c_str()); #endif @@ -1075,7 +1074,7 @@ bool cmGlobalGenerator::GetLanguageEnabled(const std::string& l) const void cmGlobalGenerator::ClearEnabledLanguages() { - return this->CMakeInstance->GetState()->ClearEnabledLanguages(); + this->CMakeInstance->GetState()->ClearEnabledLanguages(); } void cmGlobalGenerator::CreateLocalGenerators() @@ -1434,31 +1433,36 @@ cmGlobalGenerator::CreateQtAutoGeneratorsTargets() std::vector<const cmGeneratorTarget*> autogenTargets; #ifdef CMAKE_BUILD_WITH_CMAKE - for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) { - std::vector<cmGeneratorTarget*> targets = - this->LocalGenerators[i]->GetGeneratorTargets(); + for (std::vector<cmLocalGenerator*>::const_iterator lgit = + this->LocalGenerators.begin(); + lgit != this->LocalGenerators.end(); ++lgit) { + cmLocalGenerator* localGen = *lgit; + const std::vector<cmGeneratorTarget*>& targets = + localGen->GetGeneratorTargets(); + // Find targets that require AUTOGEN processing std::vector<cmGeneratorTarget*> filteredTargets; filteredTargets.reserve(targets.size()); - for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin(); + for (std::vector<cmGeneratorTarget*>::const_iterator ti = targets.begin(); ti != targets.end(); ++ti) { - if ((*ti)->GetType() == cmStateEnums::GLOBAL_TARGET) { + cmGeneratorTarget* target = *ti; + if (target->GetType() == cmStateEnums::GLOBAL_TARGET) { continue; } - if ((*ti)->GetType() != cmStateEnums::EXECUTABLE && - (*ti)->GetType() != cmStateEnums::STATIC_LIBRARY && - (*ti)->GetType() != cmStateEnums::SHARED_LIBRARY && - (*ti)->GetType() != cmStateEnums::MODULE_LIBRARY && - (*ti)->GetType() != cmStateEnums::OBJECT_LIBRARY) { + if (target->GetType() != cmStateEnums::EXECUTABLE && + target->GetType() != cmStateEnums::STATIC_LIBRARY && + target->GetType() != cmStateEnums::SHARED_LIBRARY && + target->GetType() != cmStateEnums::MODULE_LIBRARY && + target->GetType() != cmStateEnums::OBJECT_LIBRARY) { continue; } - if ((!(*ti)->GetPropertyAsBool("AUTOMOC") && - !(*ti)->GetPropertyAsBool("AUTOUIC") && - !(*ti)->GetPropertyAsBool("AUTORCC")) || - (*ti)->IsImported()) { + if ((!target->GetPropertyAsBool("AUTOMOC") && + !target->GetPropertyAsBool("AUTOUIC") && + !target->GetPropertyAsBool("AUTORCC")) || + target->IsImported()) { continue; } - // don't do anything if there is no Qt4 or Qt5Core (which contains moc): - cmMakefile* mf = (*ti)->Target->GetMakefile(); + // don't do anything if there is no Qt4 or Qt5Core (which contains moc) + cmMakefile* mf = target->Target->GetMakefile(); std::string qtMajorVersion = mf->GetSafeDefinition("QT_VERSION_MAJOR"); if (qtMajorVersion == "") { qtMajorVersion = mf->GetSafeDefinition("Qt5Core_VERSION_MAJOR"); @@ -1466,17 +1470,13 @@ cmGlobalGenerator::CreateQtAutoGeneratorsTargets() if (qtMajorVersion != "4" && qtMajorVersion != "5") { continue; } - - cmGeneratorTarget* gt = *ti; - - cmQtAutoGeneratorInitializer::InitializeAutogenSources(gt); - filteredTargets.push_back(gt); + filteredTargets.push_back(target); } + // Initialize AUTOGEN targets for (std::vector<cmGeneratorTarget*>::iterator ti = filteredTargets.begin(); ti != filteredTargets.end(); ++ti) { - cmQtAutoGeneratorInitializer::InitializeAutogenTarget( - this->LocalGenerators[i], *ti); + cmQtAutoGeneratorInitializer::InitializeAutogenTarget(localGen, *ti); autogenTargets.push_back(*ti); } } @@ -2594,9 +2594,9 @@ void cmGlobalGenerator::GetTargetSets(TargetDependSet& projectTargets, continue; } // Get the targets in the makefile - std::vector<cmGeneratorTarget*> tgts = (*i)->GetGeneratorTargets(); + const std::vector<cmGeneratorTarget*>& tgts = (*i)->GetGeneratorTargets(); // loop over all the targets - for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin(); + for (std::vector<cmGeneratorTarget*>::const_iterator l = tgts.begin(); l != tgts.end(); ++l) { cmGeneratorTarget* target = *l; if (this->IsRootOnlyTarget(target) && @@ -2789,9 +2789,9 @@ void cmGlobalGenerator::WriteSummary() cmGeneratedFileStream fout(fname.c_str()); for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) { - std::vector<cmGeneratorTarget*> tgts = + const std::vector<cmGeneratorTarget*>& tgts = this->LocalGenerators[i]->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::iterator it = tgts.begin(); + for (std::vector<cmGeneratorTarget*>::const_iterator it = tgts.begin(); it != tgts.end(); ++it) { if ((*it)->GetType() == cmStateEnums::INTERFACE_LIBRARY) { continue; @@ -2812,7 +2812,12 @@ void cmGlobalGenerator::WriteSummary(cmGeneratorTarget* target) #ifdef CMAKE_BUILD_WITH_CMAKE // Check whether labels are enabled for this target. - if (const char* value = target->GetProperty("LABELS")) { + const char* targetLabels = target->GetProperty("LABELS"); + const char* directoryLabels = + target->Target->GetMakefile()->GetProperty("LABELS"); + const char* cmakeDirectoryLabels = + target->Target->GetMakefile()->GetDefinition("CMAKE_DIRECTORY_LABELS"); + if (targetLabels || directoryLabels || cmakeDirectoryLabels) { Json::Value lj_root(Json::objectValue); Json::Value& lj_target = lj_root["target"] = Json::objectValue; lj_target["name"] = target->GetName(); @@ -2822,19 +2827,53 @@ void cmGlobalGenerator::WriteSummary(cmGeneratorTarget* target) cmSystemTools::MakeDirectory(dir.c_str()); cmGeneratedFileStream fout(file.c_str()); + std::vector<std::string> labels; + // List the target-wide labels. All sources in the target get // these labels. - std::vector<std::string> labels; - cmSystemTools::ExpandListArgument(value, labels); - if (!labels.empty()) { - fout << "# Target labels\n"; - for (std::vector<std::string>::const_iterator li = labels.begin(); - li != labels.end(); ++li) { - fout << " " << *li << "\n"; - lj_target_labels.append(*li); + if (targetLabels) { + cmSystemTools::ExpandListArgument(targetLabels, labels); + if (!labels.empty()) { + fout << "# Target labels\n"; + for (std::vector<std::string>::const_iterator li = labels.begin(); + li != labels.end(); ++li) { + fout << " " << *li << "\n"; + lj_target_labels.append(*li); + } } } + // List directory labels + std::vector<std::string> directoryLabelsList; + std::vector<std::string> cmakeDirectoryLabelsList; + + if (directoryLabels) { + cmSystemTools::ExpandListArgument(directoryLabels, directoryLabelsList); + } + + if (cmakeDirectoryLabels) { + cmSystemTools::ExpandListArgument(cmakeDirectoryLabels, + cmakeDirectoryLabelsList); + } + + if (!directoryLabelsList.empty() || !cmakeDirectoryLabelsList.empty()) { + fout << "# Directory labels\n"; + } + + for (std::vector<std::string>::const_iterator li = + directoryLabelsList.begin(); + li != directoryLabelsList.end(); ++li) { + fout << " " << *li << "\n"; + lj_target_labels.append(*li); + } + + for (std::vector<std::string>::const_iterator li = + cmakeDirectoryLabelsList.begin(); + li != cmakeDirectoryLabelsList.end(); ++li) { + fout << " " << *li << "\n"; + lj_target_labels.append(*li); + } + // List the source files with any per-source labels. fout << "# Source files and their labels\n"; std::vector<cmSourceFile*> sources; diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 871178b..23c6218 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -187,9 +187,15 @@ public: return this->LocalGenerators; } - cmMakefile* GetCurrentMakefile() const { return this->CurrentMakefile; } + cmMakefile* GetCurrentMakefile() const + { + return this->CurrentConfigureMakefile; + } - void SetCurrentMakefile(cmMakefile* mf) { this->CurrentMakefile = mf; } + void SetCurrentMakefile(cmMakefile* mf) + { + this->CurrentConfigureMakefile = mf; + } void AddMakefile(cmMakefile* mf); @@ -460,7 +466,7 @@ protected: cmake* CMakeInstance; std::vector<cmMakefile*> Makefiles; std::vector<cmLocalGenerator*> LocalGenerators; - cmMakefile* CurrentMakefile; + cmMakefile* CurrentConfigureMakefile; // map from project name to vector of local generators in that project std::map<std::string, std::vector<cmLocalGenerator*> > ProjectMap; diff --git a/Source/cmGlobalGhsMultiGenerator.cxx b/Source/cmGlobalGhsMultiGenerator.cxx index 42ab4d9..788a179 100644 --- a/Source/cmGlobalGhsMultiGenerator.cxx +++ b/Source/cmGlobalGhsMultiGenerator.cxx @@ -260,7 +260,7 @@ void cmGlobalGhsMultiGenerator::Generate() for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) { cmLocalGhsMultiGenerator* lg = static_cast<cmLocalGhsMultiGenerator*>(this->LocalGenerators[i]); - std::vector<cmGeneratorTarget*> tgts = lg->GetGeneratorTargets(); + const std::vector<cmGeneratorTarget*>& tgts = lg->GetGeneratorTargets(); this->UpdateBuildFiles(tgts); } } @@ -436,9 +436,9 @@ std::string cmGlobalGhsMultiGenerator::GetFileNameFromPath( } void cmGlobalGhsMultiGenerator::UpdateBuildFiles( - std::vector<cmGeneratorTarget*> tgts) + const std::vector<cmGeneratorTarget*>& tgts) { - for (std::vector<cmGeneratorTarget*>::iterator tgtsI = tgts.begin(); + for (std::vector<cmGeneratorTarget*>::const_iterator tgtsI = tgts.begin(); tgtsI != tgts.end(); ++tgtsI) { const cmGeneratorTarget* tgt = *tgtsI; if (IsTgtForBuild(tgt)) { diff --git a/Source/cmGlobalGhsMultiGenerator.h b/Source/cmGlobalGhsMultiGenerator.h index 7b3eebb..05a3a3c 100644 --- a/Source/cmGlobalGhsMultiGenerator.h +++ b/Source/cmGlobalGhsMultiGenerator.h @@ -116,7 +116,7 @@ private: std::vector<cmsys::String>::const_iterator end, GhsMultiGpj::Types projType); static std::string GetFileNameFromPath(std::string const& path); - void UpdateBuildFiles(std::vector<cmGeneratorTarget*> tgts); + void UpdateBuildFiles(const std::vector<cmGeneratorTarget*>& tgts); bool IsTgtForBuild(const cmGeneratorTarget* tgt); std::vector<cmGeneratedFileStream*> TargetSubProjects; diff --git a/Source/cmGlobalKdevelopGenerator.cxx b/Source/cmGlobalKdevelopGenerator.cxx index e72c6e3..85a1417 100644 --- a/Source/cmGlobalKdevelopGenerator.cxx +++ b/Source/cmGlobalKdevelopGenerator.cxx @@ -128,8 +128,9 @@ bool cmGlobalKdevelopGenerator::CreateFilelistFile( } // get all sources - std::vector<cmGeneratorTarget*> targets = (*it)->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin(); + const std::vector<cmGeneratorTarget*>& targets = + (*it)->GetGeneratorTargets(); + for (std::vector<cmGeneratorTarget*>::const_iterator ti = targets.begin(); ti != targets.end(); ti++) { std::vector<cmSourceFile*> sources; cmGeneratorTarget* gt = *ti; diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index 23b3718..e42bf20 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -382,8 +382,8 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefileLanguageRules( for (unsigned int i = 0; i < lGenerators.size(); ++i) { lg = static_cast<cmLocalUnixMakefileGenerator3*>(lGenerators[i]); // for all of out targets - std::vector<cmGeneratorTarget*> tgts = lg->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin(); + const std::vector<cmGeneratorTarget*>& tgts = lg->GetGeneratorTargets(); + for (std::vector<cmGeneratorTarget*>::const_iterator l = tgts.begin(); l != tgts.end(); l++) { if (((*l)->GetType() == cmStateEnums::EXECUTABLE) || ((*l)->GetType() == cmStateEnums::STATIC_LIBRARY) || @@ -414,8 +414,8 @@ void cmGlobalUnixMakefileGenerator3::WriteDirectoryRule2( // The directory-level rule should depend on the target-level rules // for all targets in the directory. std::vector<std::string> depends; - std::vector<cmGeneratorTarget*> targets = lg->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::iterator l = targets.begin(); + const std::vector<cmGeneratorTarget*>& targets = lg->GetGeneratorTargets(); + for (std::vector<cmGeneratorTarget*>::const_iterator l = targets.begin(); l != targets.end(); ++l) { cmGeneratorTarget* gtarget = *l; int type = gtarget->GetType(); @@ -547,8 +547,8 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules( for (i = 0; i < this->LocalGenerators.size(); ++i) { lg = static_cast<cmLocalUnixMakefileGenerator3*>(this->LocalGenerators[i]); // for each target Generate the rule files for each target. - std::vector<cmGeneratorTarget*> targets = lg->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin(); + const std::vector<cmGeneratorTarget*>& targets = lg->GetGeneratorTargets(); + for (std::vector<cmGeneratorTarget*>::const_iterator t = targets.begin(); t != targets.end(); ++t) { cmGeneratorTarget* gtarget = *t; // Don't emit the same rule twice (e.g. two targets with the same @@ -629,8 +629,8 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2( depends.push_back("cmake_check_build_system"); // for each target Generate the rule files for each target. - std::vector<cmGeneratorTarget*> targets = lg->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin(); + const std::vector<cmGeneratorTarget*>& targets = lg->GetGeneratorTargets(); + for (std::vector<cmGeneratorTarget*>::const_iterator t = targets.begin(); t != targets.end(); ++t) { cmGeneratorTarget* gtarget = *t; int type = gtarget->GetType(); @@ -807,7 +807,7 @@ void cmGlobalUnixMakefileGenerator3::InitializeProgressMarks() this->LocalGenerators.begin(); lgi != this->LocalGenerators.end(); ++lgi) { cmLocalGenerator* lg = *lgi; - std::vector<cmGeneratorTarget*> targets = lg->GetGeneratorTargets(); + const std::vector<cmGeneratorTarget*>& targets = lg->GetGeneratorTargets(); for (std::vector<cmGeneratorTarget*>::const_iterator t = targets.begin(); t != targets.end(); ++t) { cmGeneratorTarget* gt = *t; @@ -952,8 +952,9 @@ void cmGlobalUnixMakefileGenerator3::WriteHelpRule( // the targets if (lg2 == lg || lg->IsRootMakefile()) { // for each target Generate the rule files for each target. - std::vector<cmGeneratorTarget*> targets = lg2->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin(); + const std::vector<cmGeneratorTarget*>& targets = + lg2->GetGeneratorTargets(); + for (std::vector<cmGeneratorTarget*>::const_iterator t = targets.begin(); t != targets.end(); ++t) { cmGeneratorTarget* target = *t; cmStateEnums::TargetType type = target->GetType(); diff --git a/Source/cmGlobalVisualStudio14Generator.cxx b/Source/cmGlobalVisualStudio14Generator.cxx index c8cf02c..e2120b8 100644 --- a/Source/cmGlobalVisualStudio14Generator.cxx +++ b/Source/cmGlobalVisualStudio14Generator.cxx @@ -151,6 +151,13 @@ bool cmGlobalVisualStudio14Generator::SelectWindows10SDK(cmMakefile* mf, mf->IssueMessage(cmake::FATAL_ERROR, e.str()); return false; } + if (!cmSystemTools::VersionCompareEqual(this->WindowsTargetPlatformVersion, + this->SystemVersion)) { + std::ostringstream e; + e << "Selecting Windows SDK version " << this->WindowsTargetPlatformVersion + << " to target Windows " << this->SystemVersion << "."; + mf->DisplayStatus(e.str().c_str(), -1); + } mf->AddDefinition("CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION", this->WindowsTargetPlatformVersion.c_str()); return true; diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx index 7a42b72..ed1ef1b 100644 --- a/Source/cmGlobalVisualStudio8Generator.cxx +++ b/Source/cmGlobalVisualStudio8Generator.cxx @@ -320,10 +320,10 @@ void cmGlobalVisualStudio8Generator::AddExtraIDETargets() cmGlobalVisualStudio7Generator::AddExtraIDETargets(); if (this->AddCheckTarget()) { for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) { - std::vector<cmGeneratorTarget*> tgts = + const std::vector<cmGeneratorTarget*>& tgts = this->LocalGenerators[i]->GetGeneratorTargets(); // All targets depend on the build-system check target. - for (std::vector<cmGeneratorTarget*>::iterator ti = tgts.begin(); + for (std::vector<cmGeneratorTarget*>::const_iterator ti = tgts.begin(); ti != tgts.end(); ++ti) { if ((*ti)->GetName() != CMAKE_CHECK_BUILD_SYSTEM_TARGET) { (*ti)->Target->AddUtility(CMAKE_CHECK_BUILD_SYSTEM_TARGET); diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index 87a22d1..f85e409 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -82,8 +82,10 @@ void cmGlobalVisualStudioGenerator::AddExtraIDETargets() // Now make all targets depend on the ALL_BUILD target for (std::vector<cmLocalGenerator*>::iterator i = gen.begin(); i != gen.end(); ++i) { - std::vector<cmGeneratorTarget*> targets = (*i)->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin(); + const std::vector<cmGeneratorTarget*>& targets = + (*i)->GetGeneratorTargets(); + for (std::vector<cmGeneratorTarget*>::const_iterator t = + targets.begin(); t != targets.end(); ++t) { cmGeneratorTarget* tgt = *t; if (tgt->GetType() == cmStateEnums::GLOBAL_TARGET || @@ -298,8 +300,10 @@ bool cmGlobalVisualStudioGenerator::ComputeTargetDepends() std::vector<cmLocalGenerator*>& gen = it->second; for (std::vector<cmLocalGenerator*>::iterator i = gen.begin(); i != gen.end(); ++i) { - std::vector<cmGeneratorTarget*> targets = (*i)->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin(); + const std::vector<cmGeneratorTarget*>& targets = + (*i)->GetGeneratorTargets(); + for (std::vector<cmGeneratorTarget*>::const_iterator ti = + targets.begin(); ti != targets.end(); ++ti) { this->ComputeVSTargetDepends(*ti); } diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 3cd14e1..8f260ec 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -440,8 +440,8 @@ void cmGlobalXCodeGenerator::AddExtraTargets( continue; } - std::vector<cmGeneratorTarget*> tgts = lg->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin(); + const std::vector<cmGeneratorTarget*>& tgts = lg->GetGeneratorTargets(); + for (std::vector<cmGeneratorTarget*>::const_iterator l = tgts.begin(); l != tgts.end(); l++) { cmGeneratorTarget* target = *l; @@ -925,12 +925,12 @@ bool cmGlobalXCodeGenerator::CreateXCodeTargets( cmLocalGenerator* gen, std::vector<cmXCodeObject*>& targets) { this->SetCurrentLocalGenerator(gen); - std::vector<cmGeneratorTarget*> tgts = + const std::vector<cmGeneratorTarget*>& tgts = this->CurrentLocalGenerator->GetGeneratorTargets(); typedef std::map<std::string, cmGeneratorTarget*, cmCompareTargets> cmSortedTargets; cmSortedTargets sortedTargets; - for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin(); + for (std::vector<cmGeneratorTarget*>::const_iterator l = tgts.begin(); l != tgts.end(); l++) { sortedTargets[(*l)->GetName()] = *l; } @@ -1210,7 +1210,7 @@ bool cmGlobalXCodeGenerator::CreateXCodeTargets( void cmGlobalXCodeGenerator::ForceLinkerLanguages() { for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) { - std::vector<cmGeneratorTarget*> tgts = + const std::vector<cmGeneratorTarget*>& tgts = this->LocalGenerators[i]->GetGeneratorTargets(); // All targets depend on the build-system check target. for (std::vector<cmGeneratorTarget*>::const_iterator ti = tgts.begin(); @@ -2706,8 +2706,8 @@ bool cmGlobalXCodeGenerator::CreateGroups( i != generators.end(); ++i) { cmMakefile* mf = (*i)->GetMakefile(); std::vector<cmSourceGroup> sourceGroups = mf->GetSourceGroups(); - std::vector<cmGeneratorTarget*> tgts = (*i)->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin(); + const std::vector<cmGeneratorTarget*>& tgts = (*i)->GetGeneratorTargets(); + for (std::vector<cmGeneratorTarget*>::const_iterator l = tgts.begin(); l != tgts.end(); l++) { cmGeneratorTarget* gtgt = *l; @@ -3309,6 +3309,31 @@ void cmGlobalXCodeGenerator::OutputXCodeProject( void cmGlobalXCodeGenerator::OutputXCodeSharedSchemes( const std::string& xcProjDir) { + // collect all tests for the targets + std::map<std::string, cmXCodeScheme::TestObjects> testables; + + for (std::vector<cmXCodeObject*>::const_iterator i = + this->XCodeObjects.begin(); + i != this->XCodeObjects.end(); ++i) { + cmXCodeObject* obj = *i; + if (obj->GetType() != cmXCodeObject::OBJECT || + obj->GetIsA() != cmXCodeObject::PBXNativeTarget) { + continue; + } + + if (!obj->GetTarget()->IsXCTestOnApple()) { + continue; + } + + const char* testee = obj->GetTarget()->GetProperty("XCTEST_TESTEE"); + if (!testee) { + continue; + } + + testables[testee].push_back(obj); + } + + // generate scheme for (std::vector<cmXCodeObject*>::const_iterator i = this->XCodeObjects.begin(); i != this->XCodeObjects.end(); ++i) { @@ -3316,8 +3341,9 @@ void cmGlobalXCodeGenerator::OutputXCodeSharedSchemes( if (obj->GetType() == cmXCodeObject::OBJECT && (obj->GetIsA() == cmXCodeObject::PBXNativeTarget || obj->GetIsA() == cmXCodeObject::PBXAggregateTarget)) { - cmXCodeScheme schm(obj, this->CurrentConfigurationTypes, - this->XcodeVersion); + const std::string& targetName = obj->GetTarget()->GetName(); + cmXCodeScheme schm(obj, testables[targetName], + this->CurrentConfigurationTypes, this->XcodeVersion); schm.WriteXCodeSharedScheme(xcProjDir, this->RelativeToSource(xcProjDir.c_str())); } diff --git a/Source/cmGraphVizWriter.cxx b/Source/cmGraphVizWriter.cxx index 7e953ce..015f887 100644 --- a/Source/cmGraphVizWriter.cxx +++ b/Source/cmGraphVizWriter.cxx @@ -420,7 +420,8 @@ int cmGraphVizWriter::CollectAllTargets() for (std::vector<cmLocalGenerator*>::const_iterator lit = this->LocalGenerators.begin(); lit != this->LocalGenerators.end(); ++lit) { - std::vector<cmGeneratorTarget*> targets = (*lit)->GetGeneratorTargets(); + const std::vector<cmGeneratorTarget*>& targets = + (*lit)->GetGeneratorTargets(); for (std::vector<cmGeneratorTarget*>::const_iterator it = targets.begin(); it != targets.end(); ++it) { const char* realTargetName = (*it)->GetName().c_str(); @@ -445,7 +446,8 @@ int cmGraphVizWriter::CollectAllExternalLibs(int cnt) for (std::vector<cmLocalGenerator*>::const_iterator lit = this->LocalGenerators.begin(); lit != this->LocalGenerators.end(); ++lit) { - std::vector<cmGeneratorTarget*> targets = (*lit)->GetGeneratorTargets(); + const std::vector<cmGeneratorTarget*>& targets = + (*lit)->GetGeneratorTargets(); for (std::vector<cmGeneratorTarget*>::const_iterator it = targets.begin(); it != targets.end(); ++it) { const char* realTargetName = (*it)->GetName().c_str(); diff --git a/Source/cmIncludeGuardCommand.cxx b/Source/cmIncludeGuardCommand.cxx new file mode 100644 index 0000000..505b07c --- /dev/null +++ b/Source/cmIncludeGuardCommand.cxx @@ -0,0 +1,108 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmIncludeGuardCommand.h" + +#include "cmExecutionStatus.h" +#include "cmMakefile.h" +#include "cmStateDirectory.h" +#include "cmStateSnapshot.h" +#include "cmSystemTools.h" +#include "cmake.h" + +namespace { + +enum IncludeGuardScope +{ + VARIABLE, + DIRECTORY, + GLOBAL +}; + +std::string GetIncludeGuardVariableName(std::string const& filePath) +{ + std::string result = "__INCGUARD_"; +#ifdef CMAKE_BUILD_WITH_CMAKE + result += cmSystemTools::ComputeStringMD5(filePath); +#else + result += cmSystemTools::MakeCidentifier(filePath); +#endif + result += "__"; + return result; +} + +bool CheckIncludeGuardIsSet(cmMakefile* mf, std::string const& includeGuardVar) +{ + if (mf->GetProperty(includeGuardVar)) { + return true; + } + cmStateSnapshot dirSnapshot = + mf->GetStateSnapshot().GetBuildsystemDirectoryParent(); + while (dirSnapshot.GetState()) { + cmStateDirectory stateDir = dirSnapshot.GetDirectory(); + if (stateDir.GetProperty(includeGuardVar)) { + return true; + } + dirSnapshot = dirSnapshot.GetBuildsystemDirectoryParent(); + } + return false; +} + +} // anonymous namespace + +// cmIncludeGuardCommand +bool cmIncludeGuardCommand::InitialPass(std::vector<std::string> const& args, + cmExecutionStatus& status) +{ + if (args.size() > 1) { + this->SetError( + "given an invalid number of arguments. The command takes at " + "most 1 argument."); + return false; + } + + IncludeGuardScope scope = VARIABLE; + + if (!args.empty()) { + std::string const& arg = args[0]; + if (arg == "DIRECTORY") { + scope = DIRECTORY; + } else if (arg == "GLOBAL") { + scope = GLOBAL; + } else { + this->SetError("given an invalid scope: " + arg); + return false; + } + } + + std::string includeGuardVar = GetIncludeGuardVariableName( + this->Makefile->GetDefinition("CMAKE_CURRENT_LIST_FILE")); + + cmMakefile* const mf = this->Makefile; + + switch (scope) { + case VARIABLE: + if (mf->IsDefinitionSet(includeGuardVar)) { + status.SetReturnInvoked(); + return true; + } + mf->AddDefinition(includeGuardVar, true); + break; + case DIRECTORY: + if (CheckIncludeGuardIsSet(mf, includeGuardVar)) { + status.SetReturnInvoked(); + return true; + } + mf->SetProperty(includeGuardVar, "TRUE"); + break; + case GLOBAL: + cmake* const cm = mf->GetCMakeInstance(); + if (cm->GetProperty(includeGuardVar)) { + status.SetReturnInvoked(); + return true; + } + cm->SetProperty(includeGuardVar, "TRUE"); + break; + } + + return true; +} diff --git a/Source/cmIncludeGuardCommand.h b/Source/cmIncludeGuardCommand.h new file mode 100644 index 0000000..140c04f --- /dev/null +++ b/Source/cmIncludeGuardCommand.h @@ -0,0 +1,37 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmIncludeGuardCommand_h +#define cmIncludeGuardCommand_h + +#include "cmConfigure.h" + +#include <string> +#include <vector> + +#include "cmCommand.h" + +class cmExecutionStatus; + +/** \class cmIncludeGuardCommand + * \brief cmIncludeGuardCommand identical to C++ #pragma_once command + * Can work in 3 modes: GLOBAL (works on global properties), + * DIRECTORY(use directory property), VARIABLE(unnamed overload without + * arguments) define an ordinary variable to be used as include guard checker + */ +class cmIncludeGuardCommand : public cmCommand +{ +public: + /** + * This is a virtual constructor for the command. + */ + cmCommand* Clone() CM_OVERRIDE { return new cmIncludeGuardCommand; } + + /** + * This is called when the command is first encountered in + * the CMakeLists.txt file. + */ + bool InitialPass(std::vector<std::string> const& args, + cmExecutionStatus& status) CM_OVERRIDE; +}; + +#endif diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 6ce31c5..2c8157e 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -214,8 +214,8 @@ void cmLocalGenerator::TraceDependencies() this->GlobalGenerator->CreateEvaluationSourceFiles(*ci); } // Generate the rule files for each target. - std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin(); + const std::vector<cmGeneratorTarget*>& targets = this->GetGeneratorTargets(); + for (std::vector<cmGeneratorTarget*>::const_iterator t = targets.begin(); t != targets.end(); ++t) { if ((*t)->GetType() == cmStateEnums::INTERFACE_LIBRARY) { continue; @@ -259,6 +259,17 @@ void cmLocalGenerator::GenerateTestFiles() fout << "include(\"" << testIncludeFile << "\")" << std::endl; } + const char* testIncludeFiles = + this->Makefile->GetProperty("TEST_INCLUDE_FILES"); + if (testIncludeFiles) { + std::vector<std::string> includesList; + cmSystemTools::ExpandListArgument(testIncludeFiles, includesList); + for (std::vector<std::string>::const_iterator i = includesList.begin(); + i != includesList.end(); ++i) { + fout << "include(\"" << *i << "\")" << std::endl; + } + } + // Ask each test generator to write its code. std::vector<cmTestGenerator*> const& testers = this->Makefile->GetTestGenerators(); @@ -277,6 +288,25 @@ void cmLocalGenerator::GenerateTestFiles() outP = cmOutputConverter::EscapeForCMake(outP); fout << "subdirs(" << outP << ")" << std::endl; } + + // Add directory labels property + const char* directoryLabels = + this->Makefile->GetDefinition("CMAKE_DIRECTORY_LABELS"); + const char* labels = this->Makefile->GetProperty("LABELS"); + + if (labels || directoryLabels) { + fout << "set_directory_properties(PROPERTIES LABELS "; + if (labels) { + fout << cmOutputConverter::EscapeForCMake(labels); + } + if (labels && directoryLabels) { + fout << ";"; + } + if (directoryLabels) { + fout << cmOutputConverter::EscapeForCMake(directoryLabels); + } + fout << ")" << std::endl; + } } void cmLocalGenerator::CreateEvaluationFileOutputs(std::string const& config) @@ -327,6 +357,7 @@ void cmLocalGenerator::GenerateInstallRules() { // Compute the install prefix. const char* prefix = this->Makefile->GetDefinition("CMAKE_INSTALL_PREFIX"); + #if defined(_WIN32) && !defined(__CYGWIN__) std::string prefix_win32; if (!prefix) { @@ -451,6 +482,19 @@ void cmLocalGenerator::GenerateInstallRules() /* clang-format on */ } + // Copy cmake cross compile state to install code. + if (const char* crosscompiling = + this->Makefile->GetDefinition("CMAKE_CROSSCOMPILING")) { + /* clang-format off */ + fout << + "# Is this installation the result of a crosscompile?\n" + "if(NOT DEFINED CMAKE_CROSSCOMPILING)\n" + " set(CMAKE_CROSSCOMPILING \"" << crosscompiling << "\")\n" + "endif()\n" + "\n"; + /* clang-format on */ + } + // Ask each install generator to write its code. std::vector<cmInstallGenerator*> const& installers = this->Makefile->GetInstallGenerators(); @@ -504,6 +548,8 @@ void cmLocalGenerator::GenerateInstallRules() void cmLocalGenerator::AddGeneratorTarget(cmGeneratorTarget* gt) { this->GeneratorTargets.push_back(gt); + this->GeneratorTargetSearchIndex.insert( + std::pair<std::string, cmGeneratorTarget*>(gt->GetName(), gt)); this->GlobalGenerator->IndexGeneratorTarget(gt); } @@ -537,11 +583,10 @@ private: cmGeneratorTarget* cmLocalGenerator::FindLocalNonAliasGeneratorTarget( const std::string& name) const { - std::vector<cmGeneratorTarget*>::const_iterator ti = - std::find_if(this->GeneratorTargets.begin(), this->GeneratorTargets.end(), - NamedGeneratorTargetFinder(name)); - if (ti != this->GeneratorTargets.end()) { - return *ti; + GeneratorTargetMap::const_iterator ti = + this->GeneratorTargetSearchIndex.find(name); + if (ti != this->GeneratorTargetSearchIndex.end()) { + return ti->second; } return CM_NULLPTR; } @@ -556,8 +601,8 @@ void cmLocalGenerator::ComputeTargetManifest() } // Add our targets to the manifest for each configuration. - std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin(); + const std::vector<cmGeneratorTarget*>& targets = this->GetGeneratorTargets(); + for (std::vector<cmGeneratorTarget*>::const_iterator t = targets.begin(); t != targets.end(); ++t) { cmGeneratorTarget* target = *t; if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) { @@ -581,8 +626,8 @@ bool cmLocalGenerator::ComputeTargetCompileFeatures() } // Process compile features of all targets. - std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin(); + const std::vector<cmGeneratorTarget*>& targets = this->GetGeneratorTargets(); + for (std::vector<cmGeneratorTarget*>::const_iterator t = targets.begin(); t != targets.end(); ++t) { cmGeneratorTarget* target = *t; for (std::vector<std::string>::iterator ci = configNames.begin(); @@ -1502,20 +1547,34 @@ void cmLocalGenerator::AddCompilerRequirementFlag( // This compiler has no notion of language standard levels. return; } - std::string stdProp = lang + "_STANDARD"; - const char* standardProp = target->GetProperty(stdProp); - if (!standardProp) { - return; - } std::string extProp = lang + "_EXTENSIONS"; - std::string type = "EXTENSION"; bool ext = true; if (const char* extPropValue = target->GetProperty(extProp)) { if (cmSystemTools::IsOff(extPropValue)) { ext = false; - type = "STANDARD"; } } + std::string stdProp = lang + "_STANDARD"; + const char* standardProp = target->GetProperty(stdProp); + if (!standardProp) { + if (ext) { + // No language standard is specified and extensions are not disabled. + // Check if this compiler needs a flag to enable extensions. + std::string const option_flag = + "CMAKE_" + lang + "_EXTENSION_COMPILE_OPTION"; + if (const char* opt = + target->Target->GetMakefile()->GetDefinition(option_flag)) { + std::vector<std::string> optVec; + cmSystemTools::ExpandListArgument(opt, optVec); + for (size_t i = 0; i < optVec.size(); ++i) { + this->AppendFlagEscape(flags, optVec[i]); + } + } + } + return; + } + + std::string const type = ext ? "EXTENSION" : "STANDARD"; if (target->GetPropertyAsBool(lang + "_STANDARD_REQUIRED")) { std::string option_flag = @@ -1583,8 +1642,10 @@ void cmLocalGenerator::AddCompilerRequirementFlag( return; } - // Greater or equal because the standards are stored in - // backward chronological order. + // If the standard requested is older than the compiler's default + // then we need to use a flag to change it. The comparison is + // greater-or-equal because the standards are stored in backward + // chronological order. if (stdIt >= defaultStdIt) { std::string option_flag = "CMAKE_" + lang + *stdIt + "_" + type + "_COMPILE_OPTION"; @@ -1599,6 +1660,9 @@ void cmLocalGenerator::AddCompilerRequirementFlag( return; } + // The standard requested is at least as new as the compiler's default, + // and the standard request is not required. Decay to the newest standard + // for which a flag is defined. for (; stdIt < defaultStdIt; ++stdIt) { std::string option_flag = "CMAKE_" + lang + *stdIt + "_" + type + "_COMPILE_OPTION"; @@ -2058,8 +2122,8 @@ void cmLocalGenerator::GenerateTargetInstallRules( { // Convert the old-style install specification from each target to // an install generator and run it. - std::vector<cmGeneratorTarget*> tgts = this->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin(); + const std::vector<cmGeneratorTarget*>& tgts = this->GetGeneratorTargets(); + for (std::vector<cmGeneratorTarget*>::const_iterator l = tgts.begin(); l != tgts.end(); ++l) { if ((*l)->GetType() == cmStateEnums::INTERFACE_LIBRARY) { continue; diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 9f78be4..9083c83 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -16,6 +16,7 @@ #include "cmOutputConverter.h" #include "cmPolicies.h" #include "cmStateSnapshot.h" +#include "cm_unordered_map.hxx" #include "cmake.h" class cmComputeLinkInformation; @@ -353,8 +354,11 @@ protected: std::string::size_type ObjectPathMax; std::set<std::string> ObjectMaxPathViolations; - std::set<cmGeneratorTarget const*> WarnCMP0063; + typedef CM_UNORDERED_MAP<std::string, cmGeneratorTarget*> GeneratorTargetMap; + GeneratorTargetMap GeneratorTargetSearchIndex; std::vector<cmGeneratorTarget*> GeneratorTargets; + + std::set<cmGeneratorTarget const*> WarnCMP0063; std::vector<cmGeneratorTarget*> ImportedGeneratorTargets; std::vector<cmGeneratorTarget*> OwnedImportedGeneratorTargets; std::map<std::string, std::string> AliasTargets; diff --git a/Source/cmLocalGhsMultiGenerator.cxx b/Source/cmLocalGhsMultiGenerator.cxx index 5f37af5..ab6774e 100644 --- a/Source/cmLocalGhsMultiGenerator.cxx +++ b/Source/cmLocalGhsMultiGenerator.cxx @@ -20,9 +20,9 @@ cmLocalGhsMultiGenerator::~cmLocalGhsMultiGenerator() void cmLocalGhsMultiGenerator::Generate() { - std::vector<cmGeneratorTarget*> tgts = this->GetGeneratorTargets(); + const std::vector<cmGeneratorTarget*>& tgts = this->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin(); + for (std::vector<cmGeneratorTarget*>::const_iterator l = tgts.begin(); l != tgts.end(); ++l) { if ((*l)->GetType() == cmStateEnums::INTERFACE_LIBRARY) { continue; diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index 266710c..9fa3ca5 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -79,8 +79,8 @@ void cmLocalNinjaGenerator::Generate() } } - std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin(); + const std::vector<cmGeneratorTarget*>& targets = this->GetGeneratorTargets(); + for (std::vector<cmGeneratorTarget*>::const_iterator t = targets.begin(); t != targets.end(); ++t) { if ((*t)->GetType() == cmStateEnums::INTERFACE_LIBRARY) { continue; diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index 9b9d22c..2d10021 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -116,10 +116,10 @@ void cmLocalUnixMakefileGenerator3::Generate() this->Makefile->IsOn("CMAKE_SKIP_ASSEMBLY_SOURCE_RULES"); // Generate the rule files for each target. - std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets(); + const std::vector<cmGeneratorTarget*>& targets = this->GetGeneratorTargets(); cmGlobalUnixMakefileGenerator3* gg = static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator); - for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin(); + for (std::vector<cmGeneratorTarget*>::const_iterator t = targets.begin(); t != targets.end(); ++t) { if ((*t)->GetType() == cmStateEnums::INTERFACE_LIBRARY) { continue; @@ -172,8 +172,8 @@ void cmLocalUnixMakefileGenerator3::ComputeObjectFilenames( void cmLocalUnixMakefileGenerator3::GetLocalObjectFiles( std::map<std::string, LocalObjectInfo>& localObjectFiles) { - std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin(); + const std::vector<cmGeneratorTarget*>& targets = this->GetGeneratorTargets(); + for (std::vector<cmGeneratorTarget*>::const_iterator ti = targets.begin(); ti != targets.end(); ++ti) { cmGeneratorTarget* gt = *ti; if (gt->GetType() == cmStateEnums::INTERFACE_LIBRARY) { @@ -382,9 +382,9 @@ void cmLocalUnixMakefileGenerator3::WriteLocalMakefileTargets( // for each target we just provide a rule to cd up to the top and do a make // on the target - std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets(); + const std::vector<cmGeneratorTarget*>& targets = this->GetGeneratorTargets(); std::string localName; - for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin(); + for (std::vector<cmGeneratorTarget*>::const_iterator t = targets.begin(); t != targets.end(); ++t) { if (((*t)->GetType() == cmStateEnums::EXECUTABLE) || ((*t)->GetType() == cmStateEnums::STATIC_LIBRARY) || @@ -1562,8 +1562,8 @@ void cmLocalUnixMakefileGenerator3::WriteLocalAllRules( this->WriteDivider(ruleFileStream); ruleFileStream << "# Targets provided globally by CMake.\n" << "\n"; - std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets(); - std::vector<cmGeneratorTarget*>::iterator glIt; + const std::vector<cmGeneratorTarget*>& targets = this->GetGeneratorTargets(); + std::vector<cmGeneratorTarget*>::const_iterator glIt; for (glIt = targets.begin(); glIt != targets.end(); ++glIt) { if ((*glIt)->GetType() == cmStateEnums::GLOBAL_TARGET) { std::string targetString = diff --git a/Source/cmLocalVisualStudio10Generator.cxx b/Source/cmLocalVisualStudio10Generator.cxx index 85d4a73..db1776a 100644 --- a/Source/cmLocalVisualStudio10Generator.cxx +++ b/Source/cmLocalVisualStudio10Generator.cxx @@ -60,8 +60,8 @@ cmLocalVisualStudio10Generator::~cmLocalVisualStudio10Generator() void cmLocalVisualStudio10Generator::Generate() { - std::vector<cmGeneratorTarget*> tgts = this->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin(); + const std::vector<cmGeneratorTarget*>& tgts = this->GetGeneratorTargets(); + for (std::vector<cmGeneratorTarget*>::const_iterator l = tgts.begin(); l != tgts.end(); ++l) { if ((*l)->GetType() == cmStateEnums::INTERFACE_LIBRARY) { continue; diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index dd08e5b..857ce46 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -62,8 +62,8 @@ cmLocalVisualStudio7Generator::~cmLocalVisualStudio7Generator() void cmLocalVisualStudio7Generator::AddHelperCommands() { // Now create GUIDs for targets - std::vector<cmGeneratorTarget*> tgts = this->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin(); + const std::vector<cmGeneratorTarget*>& tgts = this->GetGeneratorTargets(); + for (std::vector<cmGeneratorTarget*>::const_iterator l = tgts.begin(); l != tgts.end(); ++l) { if ((*l)->GetType() == cmStateEnums::INTERFACE_LIBRARY) { continue; @@ -91,8 +91,9 @@ void cmLocalVisualStudio7Generator::AddCMakeListsRules() // specification source changes. if (cmSourceFile* sf = this->CreateVCProjBuildRule()) { // Add the rule to targets that need it. - std::vector<cmGeneratorTarget*> tgts = this->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin(); + const std::vector<cmGeneratorTarget*>& tgts = + this->GetGeneratorTargets(); + for (std::vector<cmGeneratorTarget*>::const_iterator l = tgts.begin(); l != tgts.end(); ++l) { if ((*l)->GetType() == cmStateEnums::GLOBAL_TARGET) { continue; @@ -110,8 +111,8 @@ void cmLocalVisualStudio7Generator::FixGlobalTargets() // Visual Studio .NET 2003 Service Pack 1 will not run post-build // commands for targets in which no sources are built. Add dummy // rules to force these targets to build. - std::vector<cmGeneratorTarget*> tgts = this->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin(); + const std::vector<cmGeneratorTarget*>& tgts = this->GetGeneratorTargets(); + for (std::vector<cmGeneratorTarget*>::const_iterator l = tgts.begin(); l != tgts.end(); l++) { if ((*l)->GetType() == cmStateEnums::GLOBAL_TARGET) { std::vector<std::string> no_depends; @@ -150,10 +151,10 @@ void cmLocalVisualStudio7Generator::WriteProjectFiles() } // Get the set of targets in this directory. - std::vector<cmGeneratorTarget*> tgts = this->GetGeneratorTargets(); + const std::vector<cmGeneratorTarget*>& tgts = this->GetGeneratorTargets(); // Create the project file for each target. - for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin(); + for (std::vector<cmGeneratorTarget*>::const_iterator l = tgts.begin(); l != tgts.end(); l++) { if ((*l)->GetType() == cmStateEnums::INTERFACE_LIBRARY) { continue; diff --git a/Source/cmLocalXCodeGenerator.cxx b/Source/cmLocalXCodeGenerator.cxx index 739ef43..355c394 100644 --- a/Source/cmLocalXCodeGenerator.cxx +++ b/Source/cmLocalXCodeGenerator.cxx @@ -42,8 +42,8 @@ void cmLocalXCodeGenerator::Generate() { cmLocalGenerator::Generate(); - std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::iterator iter = targets.begin(); + const std::vector<cmGeneratorTarget*>& targets = this->GetGeneratorTargets(); + for (std::vector<cmGeneratorTarget*>::const_iterator iter = targets.begin(); iter != targets.end(); ++iter) { (*iter)->HasMacOSXRpathInstallNameDir(""); } @@ -53,8 +53,8 @@ void cmLocalXCodeGenerator::GenerateInstallRules() { cmLocalGenerator::GenerateInstallRules(); - std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets(); - for (std::vector<cmGeneratorTarget*>::iterator iter = targets.begin(); + const std::vector<cmGeneratorTarget*>& targets = this->GetGeneratorTargets(); + for (std::vector<cmGeneratorTarget*>::const_iterator iter = targets.begin(); iter != targets.end(); ++iter) { (*iter)->HasMacOSXRpathInstallNameDir(""); } diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 608b18a..cb6cf2d 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -66,8 +66,8 @@ cmMakefile::cmMakefile(cmGlobalGenerator* globalGenerator, this->DefineFlags = " "; - this->cmDefineRegex.compile("#cmakedefine[ \t]+([A-Za-z_0-9]*)"); - this->cmDefine01Regex.compile("#cmakedefine01[ \t]+([A-Za-z_0-9]*)"); + this->cmDefineRegex.compile("#([ \t]*)cmakedefine[ \t]+([A-Za-z_0-9]*)"); + this->cmDefine01Regex.compile("#([ \t]*)cmakedefine01[ \t]+([A-Za-z_0-9]*)"); this->cmAtVarRegex.compile("(@[A-Za-z_0-9/.+-]+@)"); this->cmNamedCurly.compile("^[A-Za-z0-9/_.+-]+{"); @@ -87,12 +87,10 @@ cmMakefile::cmMakefile(cmGlobalGenerator* globalGenerator, #if defined(CMAKE_BUILD_WITH_CMAKE) this->AddSourceGroup("", "^.*$"); - this->AddSourceGroup("Source Files", - "\\.(C|M|c|c\\+\\+|cc|cpp|cxx|f|f90|for|fpp" - "|ftn|m|mm|rc|def|r|odl|idl|hpj|bat)$"); + this->AddSourceGroup("Source Files", CM_SOURCE_REGEX); this->AddSourceGroup("Header Files", CM_HEADER_REGEX); this->AddSourceGroup("CMake Rules", "\\.rule$"); - this->AddSourceGroup("Resources", "\\.plist$"); + this->AddSourceGroup("Resources", CM_RESOURCE_REGEX); this->AddSourceGroup("Object Files", "\\.(lo|o|obj)$"); this->ObjectLibrariesSourceGroupIndex = this->SourceGroups.size(); @@ -592,7 +590,8 @@ void cmMakefile::AddEvaluationFile( CM_AUTO_PTR<cmCompiledGeneratorExpression> condition, bool inputIsContent) { this->EvaluationFiles.push_back(new cmGeneratorExpressionEvaluationFile( - inputFile, outputName, condition, inputIsContent)); + inputFile, outputName, condition, inputIsContent, + this->GetPolicyStatus(cmPolicies::CMP0070))); } std::vector<cmGeneratorExpressionEvaluationFile*> @@ -1236,6 +1235,9 @@ void cmMakefile::InitializeFromParent(cmMakefile* parent) } } + // labels + this->SetProperty("LABELS", parent->GetProperty("LABELS")); + // link libraries this->SetProperty("LINK_LIBRARIES", parent->GetProperty("LINK_LIBRARIES")); @@ -3432,18 +3434,22 @@ void cmMakefile::ConfigureString(const std::string& input, std::string& output, // Replace #cmakedefine instances. if (this->cmDefineRegex.find(line)) { - const char* def = this->GetDefinition(this->cmDefineRegex.match(1)); + const char* def = this->GetDefinition(this->cmDefineRegex.match(2)); if (!cmSystemTools::IsOff(def)) { - cmSystemTools::ReplaceString(line, "#cmakedefine", "#define"); + const std::string indentation = this->cmDefineRegex.match(1); + cmSystemTools::ReplaceString(line, "#" + indentation + "cmakedefine", + "#" + indentation + "define"); output += line; } else { output += "/* #undef "; - output += this->cmDefineRegex.match(1); + output += this->cmDefineRegex.match(2); output += " */"; } } else if (this->cmDefine01Regex.find(line)) { - const char* def = this->GetDefinition(this->cmDefine01Regex.match(1)); - cmSystemTools::ReplaceString(line, "#cmakedefine01", "#define"); + const std::string indentation = this->cmDefine01Regex.match(1); + const char* def = this->GetDefinition(this->cmDefine01Regex.match(2)); + cmSystemTools::ReplaceString(line, "#" + indentation + "cmakedefine01", + "#" + indentation + "define"); output += line; if (!cmSystemTools::IsOff(def)) { output += " 1"; @@ -4375,6 +4381,18 @@ bool cmMakefile::HaveCxxStandardAvailable(cmTarget const* target, cmStrCmp(existingCxxStandard)) : cmArrayEnd(CXX_STANDARDS); + if (needCxx17 && + existingCxxIt < std::find_if(cmArrayBegin(CXX_STANDARDS), + cmArrayEnd(CXX_STANDARDS), + cmStrCmp("17"))) { + return false; + } + if (needCxx14 && + existingCxxIt < std::find_if(cmArrayBegin(CXX_STANDARDS), + cmArrayEnd(CXX_STANDARDS), + cmStrCmp("14"))) { + return false; + } if (needCxx11 && existingCxxIt < std::find_if(cmArrayBegin(CXX_STANDARDS), cmArrayEnd(CXX_STANDARDS), diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index a4511b6..7938683 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -657,7 +657,8 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile( } // Maybe insert a compiler launcher like ccache or distcc - if (!compileCommands.empty() && (lang == "C" || lang == "CXX")) { + if (!compileCommands.empty() && + (lang == "C" || lang == "CXX" || lang == "CUDA")) { std::string const clauncher_prop = lang + "_COMPILER_LAUNCHER"; const char* clauncher = this->GeneratorTarget->GetProperty(clauncher_prop); diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 14a4ef8..1e0bf8d 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -409,10 +409,14 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile) this->GetLocalGenerator()->ConvertToOutputFormat( cmSystemTools::GetCMakeCommand(), cmOutputConverter::SHELL); if (targetType == cmStateEnums::EXECUTABLE) { + std::vector<std::string> commandLines; + commandLines.push_back(cmakeCommand + + " -E cmake_symlink_executable $in $out"); + commandLines.push_back("$POST_BUILD"); + this->GetGlobalGenerator()->AddRule( "CMAKE_SYMLINK_EXECUTABLE", - cmakeCommand + " -E cmake_symlink_executable" - " $in $out && $POST_BUILD", + this->GetLocalGenerator()->BuildCommandLine(commandLines), "Creating executable symlink $out", "Rule for creating " "executable symlink.", /*depfile*/ "", @@ -422,10 +426,14 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile) /*restat*/ "", /*generator*/ false); } else { + std::vector<std::string> commandLines; + commandLines.push_back(cmakeCommand + + " -E cmake_symlink_library $in $SONAME $out"); + commandLines.push_back("$POST_BUILD"); + this->GetGlobalGenerator()->AddRule( "CMAKE_SYMLINK_LIBRARY", - cmakeCommand + " -E cmake_symlink_library" - " $in $SONAME $out && $POST_BUILD", + this->GetLocalGenerator()->BuildCommandLine(commandLines), "Creating library symlink $out", "Rule for creating " "library symlink.", /*depfile*/ "", diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index d38dbcb..7cc6ede 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -557,17 +557,11 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang) // Write the rule for ninja dyndep file generation. std::vector<std::string> ddCmds; -#ifdef _WIN32 - // Windows command line length is limited -> use response file for dyndep - // rules + // Command line length is almost always limited -> use response file for + // dyndep rules std::string ddRspFile = "$out.rsp"; std::string ddRspContent = "$in"; std::string ddInput = "@" + ddRspFile; -#else - std::string ddRspFile; - std::string ddRspContent; - std::string ddInput = "$in"; -#endif // Run CMake dependency scanner on preprocessed output. std::string const cmake = this->GetLocalGenerator()->ConvertToOutputFormat( @@ -648,7 +642,8 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang) } // Maybe insert a compiler launcher like ccache or distcc - if (!compileCmds.empty() && (lang == "C" || lang == "CXX")) { + if (!compileCmds.empty() && + (lang == "C" || lang == "CXX" || lang == "CUDA")) { std::string const clauncher_prop = lang + "_COMPILER_LAUNCHER"; const char* clauncher = this->GeneratorTarget->GetProperty(clauncher_prop); if (clauncher && *clauncher) { diff --git a/Source/cmPipeConnection.cxx b/Source/cmPipeConnection.cxx new file mode 100644 index 0000000..cc82438 --- /dev/null +++ b/Source/cmPipeConnection.cxx @@ -0,0 +1,80 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmPipeConnection.h" + +#include "cmConfigure.h" +#include "cmServer.h" + +cmPipeConnection::cmPipeConnection(const std::string& name, + cmConnectionBufferStrategy* bufferStrategy) + : cmEventBasedConnection(bufferStrategy) + , PipeName(name) +{ +} + +void cmPipeConnection::Connect(uv_stream_t* server) +{ + if (this->ClientPipe) { + // Accept and close all pipes but the first: + uv_pipe_t* rejectPipe = new uv_pipe_t(); + + uv_pipe_init(this->Server->GetLoop(), rejectPipe, 0); + uv_accept(server, reinterpret_cast<uv_stream_t*>(rejectPipe)); + uv_close(reinterpret_cast<uv_handle_t*>(rejectPipe), &on_close_delete); + return; + } + + this->ClientPipe = new uv_pipe_t(); + uv_pipe_init(this->Server->GetLoop(), this->ClientPipe, 0); + this->ClientPipe->data = static_cast<cmEventBasedConnection*>(this); + auto client = reinterpret_cast<uv_stream_t*>(this->ClientPipe); + if (uv_accept(server, client) != 0) { + uv_close(reinterpret_cast<uv_handle_t*>(client), &on_close_delete); + this->ClientPipe = CM_NULLPTR; + return; + } + this->ReadStream = client; + this->WriteStream = client; + + uv_read_start(this->ReadStream, on_alloc_buffer, on_read); + Server->OnConnected(this); +} + +bool cmPipeConnection::OnServeStart(std::string* errorMessage) +{ + this->ServerPipe = new uv_pipe_t(); + uv_pipe_init(this->Server->GetLoop(), this->ServerPipe, 0); + this->ServerPipe->data = static_cast<cmEventBasedConnection*>(this); + + int r; + if ((r = uv_pipe_bind(this->ServerPipe, this->PipeName.c_str())) != 0) { + *errorMessage = std::string("Internal Error with ") + this->PipeName + + ": " + uv_err_name(r); + return false; + } + auto serverStream = reinterpret_cast<uv_stream_t*>(this->ServerPipe); + if ((r = uv_listen(serverStream, 1, on_new_connection)) != 0) { + *errorMessage = std::string("Internal Error listening on ") + + this->PipeName + ": " + uv_err_name(r); + return false; + } + + return cmConnection::OnServeStart(errorMessage); +} + +bool cmPipeConnection::OnConnectionShuttingDown() +{ + if (this->ClientPipe) { + uv_close(reinterpret_cast<uv_handle_t*>(this->ClientPipe), + &on_close_delete); + this->WriteStream->data = nullptr; + } + uv_close(reinterpret_cast<uv_handle_t*>(this->ServerPipe), &on_close_delete); + + this->ClientPipe = nullptr; + this->ServerPipe = nullptr; + this->WriteStream = nullptr; + this->ReadStream = nullptr; + + return cmConnection::OnConnectionShuttingDown(); +} diff --git a/Source/cmPipeConnection.h b/Source/cmPipeConnection.h new file mode 100644 index 0000000..fea85b5 --- /dev/null +++ b/Source/cmPipeConnection.h @@ -0,0 +1,28 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ + +#pragma once + +#include "cmConnection.h" + +#include "cm_uv.h" + +#include <string> + +class cmPipeConnection : public cmEventBasedConnection +{ +public: + cmPipeConnection(const std::string& name, + cmConnectionBufferStrategy* bufferStrategy = nullptr); + + bool OnServeStart(std::string* pString) override; + + bool OnConnectionShuttingDown() override; + + void Connect(uv_stream_t* server) override; + +private: + const std::string PipeName; + uv_pipe_t* ServerPipe = nullptr; + uv_pipe_t* ClientPipe = nullptr; +}; diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index 69cbc18..354011a 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -206,7 +206,12 @@ class cmMakefile; cmPolicies::WARN) \ SELECT(POLICY, CMP0069, \ "INTERPROCEDURAL_OPTIMIZATION is enforced when enabled.", 3, 9, 0, \ - cmPolicies::WARN) + cmPolicies::WARN) \ + SELECT(POLICY, CMP0070, \ + "Define file(GENERATE) behavior for relative paths.", 3, 10, 0, \ + cmPolicies::WARN) \ + SELECT(POLICY, CMP0071, "Let AUTOMOC and AUTOUIC process GENERATED files.", \ + 3, 10, 0, cmPolicies::WARN) #define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1) #define CM_FOR_EACH_POLICY_ID(POLICY) \ diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index cecf165..6ae101f 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -11,6 +11,7 @@ #include "cmLocalGenerator.h" #include "cmMakefile.h" #include "cmOutputConverter.h" +#include "cmPolicies.h" #include "cmSourceFile.h" #include "cmSourceGroup.h" #include "cmState.h" @@ -28,6 +29,7 @@ #include <algorithm> #include <map> #include <set> +#include <sstream> #include <string> #include <utility> #include <vector> @@ -156,16 +158,6 @@ static void GetCompileDefinitionsAndDirectories( static bool IsMultiConfig(cmGlobalGenerator* globalGen) { - // FIXME: Xcode does not support per-config sources, yet. - // (EXCLUDED_SOURCE_FILE_NAMES) - // Treat it as a single configuration generator meanwhile. - if (globalGen->GetName().find("Xcode") != std::string::npos) { - return false; - } - // FIXME: Visual Studio does not fully support per-config sources yet. - if (globalGen->GetName().find("Visual Studio") != std::string::npos) { - return false; - } return globalGen->IsMultiConfig(); } @@ -271,13 +263,17 @@ static bool AddToSourceGroup(cmMakefile* makefile, const std::string& fileName, return true; } -static void AddGeneratedSource(cmMakefile* makefile, +static void AddGeneratedSource(cmGeneratorTarget* target, const std::string& filename, cmQtAutoGeneratorCommon::GeneratorType genType) { - cmSourceFile* gFile = makefile->GetOrCreateSource(filename, true); - gFile->SetProperty("GENERATED", "1"); - gFile->SetProperty("SKIP_AUTOGEN", "On"); + cmMakefile* makefile = target->Target->GetMakefile(); + { + cmSourceFile* gFile = makefile->GetOrCreateSource(filename, true); + gFile->SetProperty("GENERATED", "1"); + gFile->SetProperty("SKIP_AUTOGEN", "On"); + } + target->AddSource(filename); AddToSourceGroup(makefile, filename, genType); } @@ -290,6 +286,8 @@ static void AcquireScanFiles(cmGeneratorTarget const* target, { const bool mocTarget = target->GetPropertyAsBool("AUTOMOC"); const bool uicTarget = target->GetPropertyAsBool("AUTOUIC"); + const cmPolicies::PolicyStatus CMP0071_status = + target->Makefile->GetPolicyStatus(cmPolicies::CMP0071); std::vector<cmSourceFile*> srcFiles; target->GetConfigCommonSourceFiles(srcFiles); @@ -298,24 +296,46 @@ static void AcquireScanFiles(cmGeneratorTarget const* target, cmSourceFile* sf = *fileIt; const cmSystemTools::FileFormat fileType = cmSystemTools::GetFileFormat(sf->GetExtension().c_str()); - if (!(fileType == cmSystemTools::CXX_FILE_FORMAT) && !(fileType == cmSystemTools::HEADER_FILE_FORMAT)) { continue; } - if (PropertyEnabled(sf, "GENERATED") && - !target->GetPropertyAsBool("__UNDOCUMENTED_AUTOGEN_GENERATED_FILES")) { - // FIXME: Add a policy whose NEW behavior allows generated files. - // The implementation already works. We disable it here to avoid - // changing behavior for existing projects that do not expect it. - continue; - } + const std::string absFile = cmsys::SystemTools::GetRealPath(sf->GetFullPath()); // Skip flags const bool skipAll = PropertyEnabled(sf, "SKIP_AUTOGEN"); const bool mocSkip = skipAll || PropertyEnabled(sf, "SKIP_AUTOMOC"); const bool uicSkip = skipAll || PropertyEnabled(sf, "SKIP_AUTOUIC"); + const bool accept = (mocTarget && !mocSkip) || (uicTarget && !uicSkip); + + // For GENERATED files check status of policy CMP0071 + if (accept && PropertyEnabled(sf, "GENERATED")) { + bool policyAccept = false; + switch (CMP0071_status) { + case cmPolicies::WARN: { + std::ostringstream ost; + ost << cmPolicies::GetPolicyWarning(cmPolicies::CMP0071) << "\n"; + ost << "AUTOMOC/AUTOUIC: Ignoring GENERATED source file:\n"; + ost << " " << cmQtAutoGeneratorCommon::Quoted(absFile) << "\n"; + target->Makefile->IssueMessage(cmake::AUTHOR_WARNING, ost.str()); + } + CM_FALLTHROUGH; + case cmPolicies::OLD: + // Ignore GENERATED file + break; + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::REQUIRED_ALWAYS: + case cmPolicies::NEW: + // Process GENERATED file + policyAccept = true; + break; + } + if (!policyAccept) { + continue; + } + } + // Add file name to skip lists. // Do this even when the file is not added to the sources/headers lists // because the file name may be extracted from an other file when @@ -327,7 +347,7 @@ static void AcquireScanFiles(cmGeneratorTarget const* target, uicSkipList.push_back(absFile); } - if ((mocTarget && !mocSkip) || (uicTarget && !uicSkip)) { + if (accept) { // Add file name to sources or headers list switch (fileType) { case cmSystemTools::CXX_FILE_FORMAT: @@ -360,6 +380,8 @@ static void MocSetupAutoTarget( AddDefinitionEscaped(makefile, "_moc_relaxed_mode", makefile->IsOn("CMAKE_AUTOMOC_RELAXED_MODE") ? "TRUE" : "FALSE"); + AddDefinitionEscaped(makefile, "_moc_macro_names", + GetSafeProperty(target, "AUTOMOC_MACRO_NAMES")); AddDefinitionEscaped(makefile, "_moc_depend_filters", GetSafeProperty(target, "AUTOMOC_DEPEND_FILTERS")); @@ -676,32 +698,6 @@ static void RccSetupAutoTarget(cmGeneratorTarget const* target, AddDefinitionEscaped(makefile, "_rcc_options_options", rccFileOptions); } -void cmQtAutoGeneratorInitializer::InitializeAutogenSources( - cmGeneratorTarget* target) -{ - if (target->GetPropertyAsBool("AUTOMOC")) { - cmMakefile* makefile = target->Target->GetMakefile(); - const std::vector<std::string> suffixes = - GetConfigurationSuffixes(makefile); - // Get build directory - const std::string autogenBuildDir = GetAutogenTargetBuildDir(target); - // Register all compilation files as generated - for (std::vector<std::string>::const_iterator it = suffixes.begin(); - it != suffixes.end(); ++it) { - std::string mcFile = autogenBuildDir + "/mocs_compilation"; - mcFile += *it; - mcFile += ".cpp"; - AddGeneratedSource(makefile, mcFile, cmQtAutoGeneratorCommon::MOC); - } - // Mocs compilation file - if (IsMultiConfig(target->GetGlobalGenerator())) { - target->AddSource(autogenBuildDir + "/mocs_compilation_$<CONFIG>.cpp"); - } else { - target->AddSource(autogenBuildDir + "/mocs_compilation.cpp"); - } - } -} - void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( cmLocalGenerator* lg, cmGeneratorTarget* target) { @@ -719,7 +715,7 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( const std::string qtMajorVersion = GetQtMajorVersion(target); const std::string rccCommand = RccGetExecutable(target, qtMajorVersion); const std::vector<std::string> suffixes = GetConfigurationSuffixes(makefile); - std::vector<std::string> autogenDepends; + std::set<std::string> autogenDependsSet; std::vector<std::string> autogenProvides; // Remove build directories on cleanup @@ -777,24 +773,18 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( // Add moc compilation to generated files list if (mocEnabled) { - for (std::vector<std::string>::const_iterator it = suffixes.begin(); - it != suffixes.end(); ++it) { - std::string mcFile = autogenBuildDir + "/mocs_compilation"; - mcFile += *it; - mcFile += ".cpp"; - autogenProvides.push_back(mcFile); - } + const std::string mocsComp = autogenBuildDir + "/mocs_compilation.cpp"; + AddGeneratedSource(target, mocsComp, cmQtAutoGeneratorCommon::MOC); + autogenProvides.push_back(mocsComp); } // Add autogen includes directory to the origin target INCLUDE_DIRECTORIES if (mocEnabled || uicEnabled) { + std::string includeDir = autogenBuildDir + "/include"; if (multiConfig) { - target->AddIncludeDirectory(autogenBuildDir + "/include_$<CONFIG>", - true); - - } else { - target->AddIncludeDirectory(autogenBuildDir + "/include", true); + includeDir += "_$<CONFIG>"; } + target->AddIncludeDirectory(includeDir, true); } #if defined(_WIN32) && !defined(__CYGWIN__) @@ -811,7 +801,20 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( // Initialize autogen target dependencies if (const char* deps = target->GetProperty("AUTOGEN_TARGET_DEPENDS")) { - cmSystemTools::ExpandListArgument(deps, autogenDepends); + std::vector<std::string> extraDepends; + cmSystemTools::ExpandListArgument(deps, extraDepends); + autogenDependsSet.insert(extraDepends.begin(), extraDepends.end()); + } + // Add other target dependencies autogen dependencies + { + const std::set<std::string>& utils = target->Target->GetUtilities(); + for (std::set<std::string>::const_iterator it = utils.begin(); + it != utils.end(); ++it) { + const std::string& targetName = *it; + if (makefile->FindTargetToUse(targetName) != CM_NULLPTR) { + autogenDependsSet.insert(targetName); + } + } } // Add link library targets to the autogen dependencies { @@ -821,7 +824,7 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( it != libVec.end(); ++it) { const std::string& libName = it->first; if (makefile->FindTargetToUse(libName) != CM_NULLPTR) { - autogenDepends.push_back(libName); + autogenDependsSet.insert(libName); } } } @@ -845,7 +848,7 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( if (PropertyEnabled(sf, "GENERATED")) { if ((mocEnabled && !PropertyEnabled(sf, "SKIP_AUTOMOC")) || (uicEnabled && !PropertyEnabled(sf, "SKIP_AUTOUIC"))) { - autogenDepends.push_back( + autogenDependsSet.insert( cmsys::SystemTools::GetRealPath(sf->GetFullPath())); #if defined(_WIN32) && !defined(__CYGWIN__) // Cannot use PRE_BUILD with generated files @@ -863,44 +866,38 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( // Compose rcc output file name { - std::string rccOutBase = autogenBuildDir + "/"; - rccOutBase += fpathCheckSum.getPart(absFile); - rccOutBase += "/qrc_"; - rccOutBase += + std::string rccBuildFile = autogenBuildDir + "/"; + rccBuildFile += fpathCheckSum.getPart(absFile); + rccBuildFile += "/qrc_"; + rccBuildFile += cmsys::SystemTools::GetFilenameWithoutLastExtension(absFile); + rccBuildFile += ".cpp"; // Register rcc ouput file as generated - for (std::vector<std::string>::const_iterator it = - suffixes.begin(); - it != suffixes.end(); ++it) { - std::string rccOutCfg = rccOutBase; - rccOutCfg += *it; - rccOutCfg += ".cpp"; - AddGeneratedSource(makefile, rccOutCfg, - cmQtAutoGeneratorCommon::RCC); - autogenProvides.push_back(rccOutCfg); - } - // Add rcc output file to origin target sources - if (multiConfig) { - target->AddSource(rccOutBase + "_$<CONFIG>.cpp"); - } else { - target->AddSource(rccOutBase + ".cpp"); - } + AddGeneratedSource(target, rccBuildFile, + cmQtAutoGeneratorCommon::RCC); + // Register rcc ouput file as generated by the _autogen target + autogenProvides.push_back(rccBuildFile); } if (PropertyEnabled(sf, "GENERATED")) { // Add generated qrc file to the dependencies - autogenDepends.push_back(absFile); + autogenDependsSet.insert(absFile); } else { // Run cmake again when .qrc file changes makefile->AddCMakeDependFile(absFile); - // Add the qrc input files to the dependencies - std::string error; - if (!cmQtAutoGeneratorCommon::RccListInputs( - qtMajorVersion, rccCommand, absFile, autogenDepends, - &error)) { - cmSystemTools::Error(error.c_str()); + { + std::string error; + std::vector<std::string> extraDepends; + if (cmQtAutoGeneratorCommon::RccListInputs( + qtMajorVersion, rccCommand, absFile, extraDepends, + &error)) { + autogenDependsSet.insert(extraDepends.begin(), + extraDepends.end()); + } else { + cmSystemTools::Error(error.c_str()); + } } } #if defined(_WIN32) && !defined(__CYGWIN__) @@ -914,10 +911,19 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( } } + // cmGeneratorTarget::GetConfigCommonSourceFiles computes the target's + // sources meta data cache. Clear it so that OBJECT library targets that + // are AUTOGEN initialized after this target get their added + // mocs_compilation.cpp source acknowledged by this target. + target->ClearSourcesCache(); + + // Convert std::set to std::vector + const std::vector<std::string> autogenDepends(autogenDependsSet.begin(), + autogenDependsSet.end()); #if defined(_WIN32) && !defined(__CYGWIN__) if (usePRE_BUILD) { // If the autogen target depends on an other target don't use PRE_BUILD - for (std::vector<std::string>::iterator it = autogenDepends.begin(); + for (std::vector<std::string>::const_iterator it = autogenDepends.begin(); it != autogenDepends.end(); ++it) { if (makefile->FindTargetToUse(*it) != CM_NULLPTR) { usePRE_BUILD = false; @@ -988,7 +994,7 @@ void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget( if (IsMultiConfig(target->GetGlobalGenerator())) { for (std::vector<std::string>::const_iterator it = configs.begin(); it != configs.end(); ++it) { - configSuffix[*it] = "_" + *it; + configSuffix[*it] = cmOutputConverter::EscapeForCMake("_" + *it); } } diff --git a/Source/cmQtAutoGeneratorInitializer.h b/Source/cmQtAutoGeneratorInitializer.h index ca806f5..11f6e1e 100644 --- a/Source/cmQtAutoGeneratorInitializer.h +++ b/Source/cmQtAutoGeneratorInitializer.h @@ -11,7 +11,6 @@ class cmLocalGenerator; class cmQtAutoGeneratorInitializer { public: - static void InitializeAutogenSources(cmGeneratorTarget* target); static void InitializeAutogenTarget(cmLocalGenerator* lg, cmGeneratorTarget* target); static void SetupAutoGenerateTarget(cmGeneratorTarget const* target); diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index c79f66d..65ea048 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -280,10 +280,10 @@ cmQtAutoGenerators::cmQtAutoGenerators() } // Moc macro filters - this->MocMacroFilters[0].first = "Q_OBJECT"; - this->MocMacroFilters[0].second.compile("[\n][ \t]*Q_OBJECT[^a-zA-Z0-9_]"); - this->MocMacroFilters[1].first = "Q_GADGET"; - this->MocMacroFilters[1].second.compile("[\n][ \t]*Q_GADGET[^a-zA-Z0-9_]"); + this->MocMacroFilters.push_back( + MocMacroFilter("Q_OBJECT", "[\n][ \t]*{?[ \t]*Q_OBJECT[^a-zA-Z0-9_]")); + this->MocMacroFilters.push_back( + MocMacroFilter("Q_GADGET", "[\n][ \t]*{?[ \t]*Q_GADGET[^a-zA-Z0-9_]")); // Precompile regular expressions this->MocRegExpInclude.compile( @@ -364,6 +364,9 @@ bool cmQtAutoGenerators::ReadAutogenInfoFile( return false; } + // -- Meta + InfoGetConfig(makefile, "AM_CONFIG_SUFFIX", config, this->ConfigSuffix); + // - Old settings file { this->SettingsFile = cmSystemTools::CollapseFullPath(targetDirectory); @@ -373,9 +376,6 @@ bool cmQtAutoGenerators::ReadAutogenInfoFile( this->SettingsFile += ".cmake"; } - // -- Meta - InfoGetConfig(makefile, "AM_CONFIG_SUFFIX", config, this->ConfigSuffix); - // - Files and directories InfoGet(makefile, "AM_CMAKE_SOURCE_DIR", this->ProjectSourceDir); InfoGet(makefile, "AM_CMAKE_BINARY_DIR", this->ProjectBinaryDir); @@ -400,7 +400,6 @@ bool cmQtAutoGenerators::ReadAutogenInfoFile( InfoGet(makefile, "AM_QT_UIC_EXECUTABLE", this->UicExecutable); InfoGet(makefile, "AM_QT_RCC_EXECUTABLE", this->RccExecutable); - InfoGet(makefile, "AM_MOC_PREDEFS_CMD", this->MocPredefsCmd); // Check Qt version if ((this->QtMajorVersion != "4") && (this->QtMajorVersion != "5")) { this->LogError("AutoGen: Error: Unsupported Qt version: " + @@ -425,6 +424,16 @@ bool cmQtAutoGenerators::ReadAutogenInfoFile( InfoGet(makefile, "AM_MOC_OPTIONS", this->MocOptions); InfoGet(makefile, "AM_MOC_RELAXED_MODE", this->MocRelaxedMode); { + std::vector<std::string> MocMacroNames; + InfoGet(makefile, "AM_MOC_MACRO_NAMES", MocMacroNames); + for (std::vector<std::string>::const_iterator dit = + MocMacroNames.begin(); + dit != MocMacroNames.end(); ++dit) { + this->MocMacroFilters.push_back( + MocMacroFilter(*dit, "[^a-zA-Z0-9_]" + *dit + "[^a-zA-Z0-9_]")); + } + } + { std::vector<std::string> mocDependFilters; InfoGet(makefile, "AM_MOC_DEPEND_FILTERS", mocDependFilters); // Insert Q_PLUGIN_METADATA dependency filter @@ -450,6 +459,7 @@ bool cmQtAutoGenerators::ReadAutogenInfoFile( return false; } } + InfoGet(makefile, "AM_MOC_PREDEFS_CMD", this->MocPredefsCmd); } // - Uic @@ -634,9 +644,7 @@ bool cmQtAutoGenerators::SettingsFileWrite() void cmQtAutoGenerators::Init(cmMakefile* makefile) { // Mocs compilation file - this->MocCompFileRel = "mocs_compilation"; - this->MocCompFileRel += this->ConfigSuffix; - this->MocCompFileRel += ".cpp"; + this->MocCompFileRel = "mocs_compilation.cpp"; this->MocCompFileAbs = cmSystemTools::CollapseCombinedPath( this->AutogenBuildDir, this->MocCompFileRel); @@ -647,7 +655,9 @@ void cmQtAutoGenerators::Init(cmMakefile* makefile) // Moc predefs file if (!this->MocPredefsCmd.empty()) { - this->MocPredefsFileRel = "moc_predefs.h"; + this->MocPredefsFileRel = "moc_predefs"; + this->MocPredefsFileRel += this->ConfigSuffix; + this->MocPredefsFileRel += ".h"; this->MocPredefsFileAbs = cmSystemTools::CollapseCombinedPath( this->AutogenBuildDir, this->MocPredefsFileRel); } @@ -722,10 +732,10 @@ bool cmQtAutoGenerators::RunAutogen() // the program goes through all .cpp files to see which moc files are // included. It is not really interesting how the moc file is named, but // what file the moc is created from. Once a moc is included the same moc - // may not be included in the mocs_compilation_$<CONFIG>.cpp file anymore. + // may not be included in the mocs_compilation.cpp file anymore. // OTOH if there's a header containing Q_OBJECT where no corresponding // moc file is included anywhere a moc_<filename>.cpp file is created and - // included in the mocs_compilation_$<CONFIG>.cpp file. + // included in the mocs_compilation.cpp file. // Create AUTOGEN include directory { @@ -798,8 +808,10 @@ bool cmQtAutoGenerators::RunAutogen() bool cmQtAutoGenerators::MocRequired(const std::string& contentText, std::string* macroName) { - for (unsigned int ii = 0; ii != cmArraySize(this->MocMacroFilters); ++ii) { - MocMacroFilter& filter = this->MocMacroFilters[ii]; + for (std::vector<MocMacroFilter>::iterator fit = + this->MocMacroFilters.begin(); + fit != this->MocMacroFilters.end(); ++fit) { + MocMacroFilter& filter = *fit; // Run a simple find string operation before the expensive // regular expression check if (contentText.find(filter.first) != std::string::npos) { @@ -1253,7 +1265,9 @@ bool cmQtAutoGenerators::MocGenerateAll( if (!this->MocPredefsCmd.empty()) { if (this->MocSettingsChanged || FileAbsentOrOlder(this->MocPredefsFileAbs, this->SettingsFile)) { - this->LogBold("Generating MOC predefs " + this->MocPredefsFileRel); + if (this->Verbose) { + this->LogBold("Generating MOC predefs " + this->MocPredefsFileRel); + } std::string output; { @@ -1340,7 +1354,9 @@ bool cmQtAutoGenerators::MocGenerateAll( if (this->FileDiffers(this->MocCompFileAbs, automocSource)) { // Actually write mocs compilation file - this->LogBold("Generating MOC compilation " + this->MocCompFileRel); + if (this->Verbose) { + this->LogBold("Generating MOC compilation " + this->MocCompFileRel); + } if (!this->FileWrite("AutoMoc", this->MocCompFileAbs, automocSource)) { return false; } @@ -1391,7 +1407,9 @@ bool cmQtAutoGenerators::MocGenerateFile( } if (generateMoc) { // Log - this->LogBold("Generating MOC source " + mocFileRel); + if (this->Verbose) { + this->LogBold("Generating MOC source " + mocFileRel); + } // Make sure the parent directory exists if (this->MakeParentDirectory("AutoMoc", mocFileAbs)) { @@ -1446,31 +1464,62 @@ bool cmQtAutoGenerators::MocGenerateFile( bool cmQtAutoGenerators::UicFindIncludedFile(std::string& absFile, const std::string& sourceFile, - const std::string& includeString) + const std::string& searchPath, + const std::string& searchFile) { bool success = false; - // Search in vicinity of the source + std::vector<std::string> testFiles; + // Collect search paths list { - std::string testPath = SubDirPrefix(sourceFile); - testPath += includeString; - if (cmsys::SystemTools::FileExists(testPath.c_str())) { - absFile = cmsys::SystemTools::GetRealPath(testPath); + const std::string searchFileFull = searchPath + searchFile; + // Vicinity of the source + { + const std::string sourcePath = SubDirPrefix(sourceFile); + testFiles.push_back(sourcePath + searchFile); + if (!searchPath.empty()) { + testFiles.push_back(sourcePath + searchFileFull); + } + } + // AUTOUIC search paths + if (!this->UicSearchPaths.empty()) { + for (std::vector<std::string>::const_iterator iit = + this->UicSearchPaths.begin(); + iit != this->UicSearchPaths.end(); ++iit) { + testFiles.push_back(*iit + "/" + searchFile); + } + if (!searchPath.empty()) { + for (std::vector<std::string>::const_iterator iit = + this->UicSearchPaths.begin(); + iit != this->UicSearchPaths.end(); ++iit) { + testFiles.push_back(*iit + "/" + searchFileFull); + } + } + } + } + + // Search for the .ui file! + for (std::vector<std::string>::const_iterator iit = testFiles.begin(); + iit != testFiles.end(); ++iit) { + const std::string& testFile = *iit; + if (cmsys::SystemTools::FileExists(testFile.c_str())) { + absFile = cmsys::SystemTools::GetRealPath(testFile); success = true; + break; } } - // Search in include directories + + // Log error if (!success) { - for (std::vector<std::string>::const_iterator iit = - this->UicSearchPaths.begin(); - iit != this->UicSearchPaths.end(); ++iit) { - const std::string fullPath = ((*iit) + '/' + includeString); - if (cmsys::SystemTools::FileExists(fullPath.c_str())) { - absFile = cmsys::SystemTools::GetRealPath(fullPath); - success = true; - break; - } + std::ostringstream ost; + ost << "AutoUic: Error: " << Quoted(sourceFile) << "\n"; + ost << "Could not find " << Quoted(searchFile) << " in\n"; + for (std::vector<std::string>::const_iterator iit = testFiles.begin(); + iit != testFiles.end(); ++iit) { + ost << " " << Quoted(*iit) << "\n"; } + this->LogError(ost.str()); } + return success; } @@ -1500,16 +1549,14 @@ bool cmQtAutoGenerators::UicGenerateAll( const std::string uiBasePath = SubDirPrefix(*uit); const std::string uiBaseName = cmsys::SystemTools::GetFilenameWithoutLastExtension(*uit).substr(3); - const std::string searchFileName = uiBasePath + uiBaseName + ".ui"; + const std::string uiFileName = uiBaseName + ".ui"; std::string uiInputFile; - if (UicFindIncludedFile(uiInputFile, source, searchFileName)) { + if (UicFindIncludedFile(uiInputFile, source, uiBasePath, uiFileName)) { std::string uiOutputFile = uiBasePath + "ui_" + uiBaseName + ".h"; cmSystemTools::ReplaceString(uiOutputFile, "..", "__"); uiGenMap[uiInputFile] = uiOutputFile; testMap[uiInputFile] = uiOutputFile; } else { - this->LogError("AutoUic: Error: " + Quoted(sit->first) + - "\nCould not find " + Quoted(searchFileName)); return false; } } @@ -1567,7 +1614,9 @@ bool cmQtAutoGenerators::UicGenerateFile(const std::string& realName, } if (generateUic) { // Log - this->LogBold("Generating UIC header " + uicFileRel); + if (this->Verbose) { + this->LogBold("Generating UIC header " + uicFileRel); + } // Make sure the parent directory exists if (this->MakeParentDirectory("AutoUic", uicFileAbs)) { @@ -1673,10 +1722,10 @@ bool cmQtAutoGenerators::RccGenerateFile(const std::string& rccInputFile, { bool rccGenerated = false; bool generateRcc = this->RccSettingsChanged; - const std::string rccBuildFile = cmSystemTools::CollapseCombinedPath(this->AutogenBuildDir, rccOutputFile); + // Check if regeneration is required if (!generateRcc) { // Test if the resources list file is newer than build file generateRcc = FileAbsentOrOlder(rccBuildFile, rccInputFile); @@ -1709,9 +1758,12 @@ bool cmQtAutoGenerators::RccGenerateFile(const std::string& rccInputFile, } } } + // Regenerate on demand if (generateRcc) { // Log - this->LogBold("Generating RCC source " + rccOutputFile); + if (this->Verbose) { + this->LogBold("Generating RCC source " + rccOutputFile); + } // Make sure the parent directory exists if (this->MakeParentDirectory("AutoRcc", rccBuildFile)) { @@ -1764,6 +1816,41 @@ bool cmQtAutoGenerators::RccGenerateFile(const std::string& rccInputFile, this->RccRunFailed = true; } } + // For a multi configuration generator generate a wrapper file + if (!this->ConfigSuffix.empty() && !this->RccRunFailed) { + // Wrapper file name + const std::string cppSuffix = ".cpp"; + const size_t suffixLength = this->ConfigSuffix.size() + cppSuffix.size(); + const std::string wrapperFileRel = + rccOutputFile.substr(0, rccOutputFile.size() - suffixLength) + cppSuffix; + const std::string wrapperFileAbs = cmSystemTools::CollapseCombinedPath( + this->AutogenBuildDir, wrapperFileRel); + // Wrapper file content + std::string content = + "// This is an autogenerated configuration wrapper file. Do not edit.\n" + "#include \""; + content += cmsys::SystemTools::GetFilenameName(rccBuildFile); + content += "\"\n"; + // Write content to file + if (this->FileDiffers(wrapperFileAbs, content)) { + // Write new wrapper file if the content differs + if (this->Verbose) { + this->LogBold("Generating RCC wrapper " + wrapperFileRel); + } + if (!this->FileWrite("AutoRcc", wrapperFileAbs, content)) { + // Error + rccGenerated = false; + this->RccRunFailed = true; + } + } else if (rccGenerated) { + // Only touch wrapper file if the content matches + if (this->Verbose) { + this->LogInfo("Touching RCC wrapper " + wrapperFileRel); + } + cmSystemTools::Touch(wrapperFileAbs, false); + } + } + return rccGenerated; } diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index b525364..ce5db4a 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -112,7 +112,8 @@ private: // -- Uic file generation bool UicFindIncludedFile(std::string& absFile, const std::string& sourceFile, - const std::string& includeString); + const std::string& searchPath, + const std::string& searchFile); bool UicGenerateAll( const std::map<std::string, std::vector<std::string> >& includedUis); bool UicGenerateFile(const std::string& realName, @@ -200,7 +201,7 @@ private: std::vector<std::string> MocOptions; std::vector<std::string> MocPredefsCmd; std::vector<MocDependFilter> MocDependFilters; - MocMacroFilter MocMacroFilters[2]; + std::vector<MocMacroFilter> MocMacroFilters; cmsys::RegularExpression MocRegExpInclude; // -- Uic bool UicSettingsChanged; diff --git a/Source/cmServer.cxx b/Source/cmServer.cxx index 7fc6ed7..ccb9af6 100644 --- a/Source/cmServer.cxx +++ b/Source/cmServer.cxx @@ -2,7 +2,8 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmServer.h" -#include "cmServerConnection.h" +#include "cmConnection.h" +#include "cmFileMonitor.h" #include "cmServerDictionary.h" #include "cmServerProtocol.h" #include "cmSystemTools.h" @@ -14,8 +15,23 @@ #include <algorithm> #include <cassert> #include <cstdint> +#include <memory> #include <utility> +void on_signal(uv_signal_t* signal, int signum) +{ + auto conn = reinterpret_cast<cmServerBase*>(signal->data); + conn->OnSignal(signum); +} + +static void on_walk_to_shutdown(uv_handle_t* handle, void* arg) +{ + (void)arg; + if (!uv_is_closing(handle)) { + uv_close(handle, &cmEventBasedConnection::on_close); + } +} + class cmServer::DebugInfo { public: @@ -30,13 +46,12 @@ public: uint64_t StartTime; }; -cmServer::cmServer(cmServerConnection* conn, bool supportExperimental) - : Connection(conn) +cmServer::cmServer(cmConnection* conn, bool supportExperimental) + : cmServerBase(conn) , SupportExperimental(supportExperimental) { - this->Connection->SetServer(this); // Register supported protocols: - this->RegisterProtocol(new cmServerProtocol1_0); + this->RegisterProtocol(new cmServerProtocol1); } cmServer::~cmServer() @@ -48,23 +63,15 @@ cmServer::~cmServer() for (cmServerProtocol* p : this->SupportedProtocols) { delete p; } - - delete this->Connection; } -void cmServer::PopOne() +void cmServer::ProcessRequest(cmConnection* connection, + const std::string& input) { - if (this->Queue.empty()) { - return; - } - Json::Reader reader; Json::Value value; - const std::string input = this->Queue.front(); - this->Queue.erase(this->Queue.begin()); - if (!reader.parse(input, value)) { - this->WriteParseError("Failed to parse JSON input."); + this->WriteParseError(connection, "Failed to parse JSON input."); return; } @@ -76,13 +83,13 @@ void cmServer::PopOne() debug->PrintStatistics = debugValue["showStats"].asBool(); } - const cmServerRequest request(this, value[kTYPE_KEY].asString(), + const cmServerRequest request(this, connection, value[kTYPE_KEY].asString(), value[kCOOKIE_KEY].asString(), value); if (request.Type == "") { cmServerResponse response(request); response.SetError("No type given in request."); - this->WriteResponse(response, nullptr); + this->WriteResponse(connection, response, nullptr); return; } @@ -91,9 +98,11 @@ void cmServer::PopOne() if (this->Protocol) { this->Protocol->CMakeInstance()->SetProgressCallback( reportProgress, const_cast<cmServerRequest*>(&request)); - this->WriteResponse(this->Protocol->Process(request), debug.get()); + this->WriteResponse(connection, this->Protocol->Process(request), + debug.get()); } else { - this->WriteResponse(this->SetProtocolVersion(request), debug.get()); + this->WriteResponse(connection, this->SetProtocolVersion(request), + debug.get()); } } @@ -115,7 +124,7 @@ void cmServer::RegisterProtocol(cmServerProtocol* protocol) } } -void cmServer::PrintHello() const +void cmServer::PrintHello(cmConnection* connection) const { Json::Value hello = Json::objectValue; hello[kTYPE_KEY] = "hello"; @@ -134,13 +143,7 @@ void cmServer::PrintHello() const protocolVersions.append(tmp); } - this->WriteJsonObject(hello, nullptr); -} - -void cmServer::QueueRequest(const std::string& request) -{ - this->Queue.push_back(request); - this->PopOne(); + this->WriteJsonObject(connection, hello, nullptr); } void cmServer::reportProgress(const char* msg, float progress, void* data) @@ -232,17 +235,26 @@ bool cmServer::Serve(std::string* errorMessage) } assert(!this->Protocol); - return Connection->ProcessEvents(errorMessage); + return cmServerBase::Serve(errorMessage); } cmFileMonitor* cmServer::FileMonitor() const { - return Connection->FileMonitor(); + return fileMonitor.get(); } void cmServer::WriteJsonObject(const Json::Value& jsonValue, const DebugInfo* debug) const { + for (auto& connection : this->Connections) { + WriteJsonObject(connection.get(), jsonValue, debug); + } +} + +void cmServer::WriteJsonObject(cmConnection* connection, + const Json::Value& jsonValue, + const DebugInfo* debug) const +{ Json::FastWriter writer; auto beforeJson = uv_hrtime(); @@ -272,7 +284,7 @@ void cmServer::WriteJsonObject(const Json::Value& jsonValue, } } - Connection->WriteData(std::string("\n") + kSTART_MAGIC + std::string("\n") + + connection->WriteData(std::string("\n") + kSTART_MAGIC + std::string("\n") + result + kEND_MAGIC + std::string("\n")); } @@ -311,7 +323,7 @@ void cmServer::WriteProgress(const cmServerRequest& request, int min, obj[kPROGRESS_MAXIMUM_KEY] = max; obj[kPROGRESS_CURRENT_KEY] = current; - this->WriteJsonObject(obj, nullptr); + this->WriteJsonObject(request.Connection, obj, nullptr); } void cmServer::WriteMessage(const cmServerRequest& request, @@ -331,10 +343,11 @@ void cmServer::WriteMessage(const cmServerRequest& request, obj[kTITLE_KEY] = title; } - WriteJsonObject(obj, nullptr); + WriteJsonObject(request.Connection, obj, nullptr); } -void cmServer::WriteParseError(const std::string& message) const +void cmServer::WriteParseError(cmConnection* connection, + const std::string& message) const { Json::Value obj = Json::objectValue; obj[kTYPE_KEY] = kERROR_TYPE; @@ -342,7 +355,7 @@ void cmServer::WriteParseError(const std::string& message) const obj[kREPLY_TO_KEY] = ""; obj[kCOOKIE_KEY] = ""; - this->WriteJsonObject(obj, nullptr); + this->WriteJsonObject(connection, obj, nullptr); } void cmServer::WriteSignal(const std::string& name, @@ -358,7 +371,8 @@ void cmServer::WriteSignal(const std::string& name, WriteJsonObject(obj, nullptr); } -void cmServer::WriteResponse(const cmServerResponse& response, +void cmServer::WriteResponse(cmConnection* connection, + const cmServerResponse& response, const DebugInfo* debug) const { assert(response.IsComplete()); @@ -371,5 +385,161 @@ void cmServer::WriteResponse(const cmServerResponse& response, obj[kERROR_MESSAGE_KEY] = response.ErrorMessage(); } - this->WriteJsonObject(obj, debug); + this->WriteJsonObject(connection, obj, debug); +} + +void cmServer::OnConnected(cmConnection* connection) +{ + PrintHello(connection); +} + +void cmServer::OnServeStart() +{ + cmServerBase::OnServeStart(); + fileMonitor = std::make_shared<cmFileMonitor>(GetLoop()); +} + +void cmServer::StartShutDown() +{ + if (fileMonitor) { + fileMonitor->StopMonitoring(); + fileMonitor.reset(); + } + cmServerBase::StartShutDown(); +} + +static void __start_thread(void* arg) +{ + auto server = reinterpret_cast<cmServerBase*>(arg); + std::string error; + server->Serve(&error); +} + +bool cmServerBase::StartServeThread() +{ + ServeThreadRunning = true; + uv_thread_create(&ServeThread, __start_thread, this); + return true; +} + +bool cmServerBase::Serve(std::string* errorMessage) +{ + errorMessage->clear(); + + uv_signal_init(&Loop, &this->SIGINTHandler); + uv_signal_init(&Loop, &this->SIGHUPHandler); + + this->SIGINTHandler.data = this; + this->SIGHUPHandler.data = this; + + uv_signal_start(&this->SIGINTHandler, &on_signal, SIGINT); + uv_signal_start(&this->SIGHUPHandler, &on_signal, SIGHUP); + + OnServeStart(); + + for (auto& connection : Connections) { + if (!connection->OnServeStart(errorMessage)) { + return false; + } + } + + if (uv_run(&Loop, UV_RUN_DEFAULT) != 0) { + *errorMessage = "Internal Error: Event loop stopped in unclean state."; + StartShutDown(); + return false; + } + + ServeThreadRunning = false; + return true; +} + +void cmServerBase::OnConnected(cmConnection*) +{ +} + +void cmServerBase::OnDisconnect() +{ +} + +void cmServerBase::OnServeStart() +{ + uv_signal_start(&this->SIGINTHandler, &on_signal, SIGINT); + uv_signal_start(&this->SIGHUPHandler, &on_signal, SIGHUP); +} + +void cmServerBase::StartShutDown() +{ + if (!uv_is_closing((const uv_handle_t*)&this->SIGINTHandler)) { + uv_signal_stop(&this->SIGINTHandler); + } + + if (!uv_is_closing((const uv_handle_t*)&this->SIGHUPHandler)) { + uv_signal_stop(&this->SIGHUPHandler); + } + + for (auto& connection : Connections) { + connection->OnConnectionShuttingDown(); + } + Connections.clear(); + + uv_stop(&Loop); + + uv_walk(&Loop, on_walk_to_shutdown, CM_NULLPTR); + + uv_run(&Loop, UV_RUN_DEFAULT); +} + +bool cmServerBase::OnSignal(int signum) +{ + (void)signum; + StartShutDown(); + return true; +} + +cmServerBase::cmServerBase(cmConnection* connection) +{ + uv_loop_init(&Loop); + + uv_signal_init(&Loop, &this->SIGINTHandler); + uv_signal_init(&Loop, &this->SIGHUPHandler); + + this->SIGINTHandler.data = this; + this->SIGHUPHandler.data = this; + + AddNewConnection(connection); +} + +cmServerBase::~cmServerBase() +{ + + if (ServeThreadRunning) { + StartShutDown(); + uv_thread_join(&ServeThread); + } + + uv_loop_close(&Loop); +} + +void cmServerBase::AddNewConnection(cmConnection* ownedConnection) +{ + Connections.emplace_back(ownedConnection); + ownedConnection->SetServer(this); +} + +uv_loop_t* cmServerBase::GetLoop() +{ + return &Loop; +} + +void cmServerBase::OnDisconnect(cmConnection* pConnection) +{ + auto pred = [pConnection](const std::unique_ptr<cmConnection>& m) { + return m.get() == pConnection; + }; + Connections.erase( + std::remove_if(Connections.begin(), Connections.end(), pred), + Connections.end()); + if (Connections.empty()) { + StartShutDown(); + } } diff --git a/Source/cmServer.h b/Source/cmServer.h index b814050..0000704 100644 --- a/Source/cmServer.h +++ b/Source/cmServer.h @@ -7,26 +7,83 @@ #include "cm_jsoncpp_value.h" #include "cm_uv.h" +#include <memory> // IWYU pragma: keep #include <string> #include <vector> +class cmConnection; class cmFileMonitor; -class cmServerConnection; class cmServerProtocol; class cmServerRequest; class cmServerResponse; -class cmServer +/*** + * This essentially hold and manages a libuv event queue and responds to + * messages + * on any of its connections. + */ +class cmServerBase +{ +public: + cmServerBase(cmConnection* connection); + virtual ~cmServerBase(); + + virtual void AddNewConnection(cmConnection* ownedConnection); + + /*** + * The main override responsible for tailoring behavior towards + * whatever the given server is supposed to do + * + * This should almost always be called by the given connections + * directly. + * + * @param connection The connectiont the request was received on + * @param request The actual request + */ + virtual void ProcessRequest(cmConnection* connection, + const std::string& request) = 0; + virtual void OnConnected(cmConnection* connection); + virtual void OnDisconnect(); + + /*** + * Start a dedicated thread. If this is used to start the server, it will + * join on the + * servers dtor. + */ + virtual bool StartServeThread(); + virtual bool Serve(std::string* errorMessage); + + virtual void OnServeStart(); + virtual void StartShutDown(); + + virtual bool OnSignal(int signum); + uv_loop_t* GetLoop(); + + void OnDisconnect(cmConnection* pConnection); + +protected: + std::vector<std::unique_ptr<cmConnection> > Connections; + + bool ServeThreadRunning = false; + uv_thread_t ServeThread; + + uv_loop_t Loop; + + uv_signal_t SIGINTHandler; + uv_signal_t SIGHUPHandler; +}; + +class cmServer : public cmServerBase { CM_DISABLE_COPY(cmServer) public: class DebugInfo; - cmServer(cmServerConnection* conn, bool supportExperimental); - ~cmServer(); + cmServer(cmConnection* conn, bool supportExperimental); + ~cmServer() override; - bool Serve(std::string* errorMessage); + bool Serve(std::string* errorMessage) override; cmFileMonitor* FileMonitor() const; @@ -34,9 +91,20 @@ private: void RegisterProtocol(cmServerProtocol* protocol); // Callbacks from cmServerConnection: - void PopOne(); - void QueueRequest(const std::string& request); + void ProcessRequest(cmConnection* connection, + const std::string& request) override; + std::shared_ptr<cmFileMonitor> fileMonitor; + +public: + void OnServeStart() override; + + void StartShutDown() override; + +public: + void OnConnected(cmConnection* connection) override; + +private: static void reportProgress(const char* msg, float progress, void* data); static void reportMessage(const char* msg, const char* title, bool& cancel, void* data); @@ -44,36 +112,37 @@ private: // Handle requests: cmServerResponse SetProtocolVersion(const cmServerRequest& request); - void PrintHello() const; + void PrintHello(cmConnection* connection) const; // Write responses: void WriteProgress(const cmServerRequest& request, int min, int current, int max, const std::string& message) const; void WriteMessage(const cmServerRequest& request, const std::string& message, const std::string& title) const; - void WriteResponse(const cmServerResponse& response, + void WriteResponse(cmConnection* connection, + const cmServerResponse& response, const DebugInfo* debug) const; - void WriteParseError(const std::string& message) const; + void WriteParseError(cmConnection* connection, + const std::string& message) const; void WriteSignal(const std::string& name, const Json::Value& obj) const; void WriteJsonObject(Json::Value const& jsonValue, const DebugInfo* debug) const; + void WriteJsonObject(cmConnection* connection, Json::Value const& jsonValue, + const DebugInfo* debug) const; + static cmServerProtocol* FindMatchingProtocol( const std::vector<cmServerProtocol*>& protocols, int major, int minor); - cmServerConnection* Connection = nullptr; const bool SupportExperimental; cmServerProtocol* Protocol = nullptr; std::vector<cmServerProtocol*> SupportedProtocols; - std::vector<std::string> Queue; std::string DataBuffer; std::string JsonData; - uv_loop_t* Loop = nullptr; - typedef union { uv_tty_t tty; @@ -87,7 +156,6 @@ private: mutable bool Writing = false; - friend class cmServerConnection; friend class cmServerProtocol; friend class cmServerRequest; }; diff --git a/Source/cmServerConnection.cxx b/Source/cmServerConnection.cxx index 36312ed..4891131 100644 --- a/Source/cmServerConnection.cxx +++ b/Source/cmServerConnection.cxx @@ -2,376 +2,123 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmServerConnection.h" -#include "cmFileMonitor.h" #include "cmServer.h" #include "cmServerDictionary.h" -#include <assert.h> -#include <string.h> - -namespace { - -struct write_req_t +cmStdIoConnection::cmStdIoConnection( + cmConnectionBufferStrategy* bufferStrategy) + : cmEventBasedConnection(bufferStrategy) + , Input() + , Output() { - uv_write_t req; - uv_buf_t buf; -}; - -void on_alloc_buffer(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) -{ - (void)(handle); - char* rawBuffer = new char[suggested_size]; - *buf = uv_buf_init(rawBuffer, static_cast<unsigned int>(suggested_size)); -} - -void on_read(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) -{ - auto conn = reinterpret_cast<cmServerConnection*>(stream->data); - if (nread >= 0) { - conn->ReadData(std::string(buf->base, buf->base + nread)); - } else { - conn->TriggerShutdown(); - } - - delete[](buf->base); } -void on_write(uv_write_t* req, int status) +void cmStdIoConnection::SetServer(cmServerBase* s) { - (void)(status); - auto conn = reinterpret_cast<cmServerConnection*>(req->data); - - // Free req and buffer - write_req_t* wr = reinterpret_cast<write_req_t*>(req); - delete[](wr->buf.base); - delete wr; + cmConnection::SetServer(s); - conn->ProcessNextRequest(); -} + if (uv_guess_handle(1) == UV_TTY) { + usesTty = true; -void on_new_connection(uv_stream_t* stream, int status) -{ - (void)(status); - auto conn = reinterpret_cast<cmServerConnection*>(stream->data); - conn->Connect(stream); -} + this->Input.tty = new uv_tty_t(); + uv_tty_init(this->Server->GetLoop(), this->Input.tty, 0, 1); + uv_tty_set_mode(this->Input.tty, UV_TTY_MODE_NORMAL); + this->Input.tty->data = static_cast<cmEventBasedConnection*>(this); + this->ReadStream = reinterpret_cast<uv_stream_t*>(this->Input.tty); -void on_signal(uv_signal_t* signal, int signum) -{ - auto conn = reinterpret_cast<cmServerConnection*>(signal->data); - (void)(signum); - conn->TriggerShutdown(); -} + this->Output.tty = new uv_tty_t(); + uv_tty_init(this->Server->GetLoop(), this->Output.tty, 1, 0); + uv_tty_set_mode(this->Output.tty, UV_TTY_MODE_NORMAL); + this->Output.tty->data = static_cast<cmEventBasedConnection*>(this); + this->WriteStream = reinterpret_cast<uv_stream_t*>(this->Output.tty); + } else { + usesTty = false; -void on_signal_close(uv_handle_t* handle) -{ - delete reinterpret_cast<uv_signal_t*>(handle); -} + this->Input.pipe = new uv_pipe_t(); + uv_pipe_init(this->Server->GetLoop(), this->Input.pipe, 0); + uv_pipe_open(this->Input.pipe, 0); + this->Input.pipe->data = static_cast<cmEventBasedConnection*>(this); + this->ReadStream = reinterpret_cast<uv_stream_t*>(this->Input.pipe); -void on_pipe_close(uv_handle_t* handle) -{ - delete reinterpret_cast<uv_pipe_t*>(handle); + this->Output.pipe = new uv_pipe_t(); + uv_pipe_init(this->Server->GetLoop(), this->Output.pipe, 0); + uv_pipe_open(this->Output.pipe, 1); + this->Output.pipe->data = static_cast<cmEventBasedConnection*>(this); + this->WriteStream = reinterpret_cast<uv_stream_t*>(this->Output.pipe); + } } -void on_tty_close(uv_handle_t* handle) +bool cmStdIoConnection::OnServeStart(std::string* pString) { - delete reinterpret_cast<uv_tty_t*>(handle); + uv_read_start(this->ReadStream, on_alloc_buffer, on_read); + Server->OnConnected(this); + return cmConnection::OnServeStart(pString); } -} // namespace - -class LoopGuard +bool cmStdIoConnection::OnConnectionShuttingDown() { -public: - LoopGuard(cmServerConnection* connection) - : Connection(connection) - { - this->Connection->mLoop = uv_default_loop(); - if (!this->Connection->mLoop) { - return; - } - this->Connection->mFileMonitor = - new cmFileMonitor(this->Connection->mLoop); - } - - ~LoopGuard() - { - if (!this->Connection->mLoop) { - return; - } + cmEventBasedConnection::OnConnectionShuttingDown(); - if (this->Connection->mFileMonitor) { - delete this->Connection->mFileMonitor; - } - uv_loop_close(this->Connection->mLoop); - this->Connection->mLoop = nullptr; + if (usesTty) { + uv_read_stop(reinterpret_cast<uv_stream_t*>(this->Input.tty)); + uv_close(reinterpret_cast<uv_handle_t*>(this->Input.tty), + &on_close_delete); + uv_close(reinterpret_cast<uv_handle_t*>(this->Output.tty), + &on_close_delete); + } else { + uv_close(reinterpret_cast<uv_handle_t*>(this->Input.pipe), + &on_close_delete); + uv_close(reinterpret_cast<uv_handle_t*>(this->Output.pipe), + &on_close_delete); } -private: - cmServerConnection* Connection; -}; + return true; +} -cmServerConnection::cmServerConnection() +cmServerPipeConnection::cmServerPipeConnection(const std::string& name) + : cmPipeConnection(name, new cmServerBufferStrategy) { } -cmServerConnection::~cmServerConnection() +cmServerStdIoConnection::cmServerStdIoConnection() + : cmStdIoConnection(new cmServerBufferStrategy) { } -void cmServerConnection::SetServer(cmServer* s) +cmConnectionBufferStrategy::~cmConnectionBufferStrategy() { - this->Server = s; } -bool cmServerConnection::ProcessEvents(std::string* errorMessage) +void cmConnectionBufferStrategy::clear() { - assert(this->Server); - errorMessage->clear(); - - this->RawReadBuffer.clear(); - this->RequestBuffer.clear(); - - LoopGuard guard(this); - (void)(guard); - if (!this->mLoop) { - *errorMessage = "Internal Error: Failed to create event loop."; - return false; - } - - this->SIGINTHandler = new uv_signal_t; - uv_signal_init(this->mLoop, this->SIGINTHandler); - this->SIGINTHandler->data = static_cast<void*>(this); - uv_signal_start(this->SIGINTHandler, &on_signal, SIGINT); - - this->SIGHUPHandler = new uv_signal_t; - uv_signal_init(this->mLoop, this->SIGHUPHandler); - this->SIGHUPHandler->data = static_cast<void*>(this); - uv_signal_start(this->SIGHUPHandler, &on_signal, SIGHUP); - - if (!DoSetup(errorMessage)) { - return false; - } - - if (uv_run(this->mLoop, UV_RUN_DEFAULT) != 0) { - *errorMessage = "Internal Error: Event loop stopped in unclean state."; - return false; - } - - // These need to be cleaned up by now: - assert(!this->ReadStream); - assert(!this->WriteStream); - - this->RawReadBuffer.clear(); - this->RequestBuffer.clear(); - - return true; } -void cmServerConnection::ReadData(const std::string& data) +std::string cmServerBufferStrategy::BufferMessage(std::string& RawReadBuffer) { - this->RawReadBuffer += data; - for (;;) { - auto needle = this->RawReadBuffer.find('\n'); + auto needle = RawReadBuffer.find('\n'); if (needle == std::string::npos) { - return; + return ""; } - std::string line = this->RawReadBuffer.substr(0, needle); + std::string line = RawReadBuffer.substr(0, needle); const auto ls = line.size(); if (ls > 1 && line.at(ls - 1) == '\r') { line.erase(ls - 1, 1); } - this->RawReadBuffer.erase(this->RawReadBuffer.begin(), - this->RawReadBuffer.begin() + - static_cast<long>(needle) + 1); + RawReadBuffer.erase(RawReadBuffer.begin(), + RawReadBuffer.begin() + static_cast<long>(needle) + 1); if (line == kSTART_MAGIC) { - this->RequestBuffer.clear(); + RequestBuffer.clear(); continue; } if (line == kEND_MAGIC) { - this->Server->QueueRequest(this->RequestBuffer); - this->RequestBuffer.clear(); - } else { - this->RequestBuffer += line; - this->RequestBuffer += "\n"; + std::string rtn; + rtn.swap(this->RequestBuffer); + return rtn; } - } -} -void cmServerConnection::TriggerShutdown() -{ - this->FileMonitor()->StopMonitoring(); - - uv_signal_stop(this->SIGINTHandler); - uv_signal_stop(this->SIGHUPHandler); - - uv_close(reinterpret_cast<uv_handle_t*>(this->SIGINTHandler), - &on_signal_close); // delete handle - uv_close(reinterpret_cast<uv_handle_t*>(this->SIGHUPHandler), - &on_signal_close); // delete handle - - this->SIGINTHandler = nullptr; - this->SIGHUPHandler = nullptr; - - this->TearDown(); -} - -void cmServerConnection::WriteData(const std::string& data) -{ - assert(this->WriteStream); - - auto ds = data.size(); - - write_req_t* req = new write_req_t; - req->req.data = this; - req->buf = uv_buf_init(new char[ds], static_cast<unsigned int>(ds)); - memcpy(req->buf.base, data.c_str(), ds); - - uv_write(reinterpret_cast<uv_write_t*>(req), - static_cast<uv_stream_t*>(this->WriteStream), &req->buf, 1, - on_write); -} - -void cmServerConnection::ProcessNextRequest() -{ - Server->PopOne(); -} - -void cmServerConnection::SendGreetings() -{ - Server->PrintHello(); -} - -cmServerStdIoConnection::cmServerStdIoConnection() -{ - this->Input.tty = nullptr; - this->Output.tty = nullptr; -} - -bool cmServerStdIoConnection::DoSetup(std::string* errorMessage) -{ - (void)(errorMessage); - - if (uv_guess_handle(1) == UV_TTY) { - usesTty = true; - this->Input.tty = new uv_tty_t; - uv_tty_init(this->Loop(), this->Input.tty, 0, 1); - uv_tty_set_mode(this->Input.tty, UV_TTY_MODE_NORMAL); - Input.tty->data = this; - this->ReadStream = reinterpret_cast<uv_stream_t*>(this->Input.tty); - - this->Output.tty = new uv_tty_t; - uv_tty_init(this->Loop(), this->Output.tty, 1, 0); - uv_tty_set_mode(this->Output.tty, UV_TTY_MODE_NORMAL); - Output.tty->data = this; - this->WriteStream = reinterpret_cast<uv_stream_t*>(this->Output.tty); - } else { - usesTty = false; - this->Input.pipe = new uv_pipe_t; - uv_pipe_init(this->Loop(), this->Input.pipe, 0); - uv_pipe_open(this->Input.pipe, 0); - Input.pipe->data = this; - this->ReadStream = reinterpret_cast<uv_stream_t*>(this->Input.pipe); - - this->Output.pipe = new uv_pipe_t; - uv_pipe_init(this->Loop(), this->Output.pipe, 0); - uv_pipe_open(this->Output.pipe, 1); - Output.pipe->data = this; - this->WriteStream = reinterpret_cast<uv_stream_t*>(this->Output.pipe); + this->RequestBuffer += line; + this->RequestBuffer += "\n"; } - - SendGreetings(); - uv_read_start(this->ReadStream, on_alloc_buffer, on_read); - - return true; -} - -void cmServerStdIoConnection::TearDown() -{ - if (usesTty) { - uv_close(reinterpret_cast<uv_handle_t*>(this->Input.tty), &on_tty_close); - uv_close(reinterpret_cast<uv_handle_t*>(this->Output.tty), &on_tty_close); - this->Input.tty = nullptr; - this->Output.tty = nullptr; - } else { - uv_close(reinterpret_cast<uv_handle_t*>(this->Input.pipe), &on_pipe_close); - uv_close(reinterpret_cast<uv_handle_t*>(this->Output.pipe), - &on_pipe_close); - this->Input.pipe = nullptr; - this->Input.pipe = nullptr; - } - this->ReadStream = nullptr; - this->WriteStream = nullptr; -} - -cmServerPipeConnection::cmServerPipeConnection(const std::string& name) - : PipeName(name) -{ -} - -bool cmServerPipeConnection::DoSetup(std::string* errorMessage) -{ - this->ServerPipe = new uv_pipe_t; - uv_pipe_init(this->Loop(), this->ServerPipe, 0); - this->ServerPipe->data = this; - - int r; - if ((r = uv_pipe_bind(this->ServerPipe, this->PipeName.c_str())) != 0) { - *errorMessage = std::string("Internal Error with ") + this->PipeName + - ": " + uv_err_name(r); - return false; - } - auto serverStream = reinterpret_cast<uv_stream_t*>(this->ServerPipe); - if ((r = uv_listen(serverStream, 1, on_new_connection)) != 0) { - *errorMessage = std::string("Internal Error listening on ") + - this->PipeName + ": " + uv_err_name(r); - return false; - } - - return true; -} - -void cmServerPipeConnection::TearDown() -{ - if (this->ClientPipe) { - uv_close(reinterpret_cast<uv_handle_t*>(this->ClientPipe), &on_pipe_close); - this->WriteStream->data = nullptr; - } - uv_close(reinterpret_cast<uv_handle_t*>(this->ServerPipe), &on_pipe_close); - - this->ClientPipe = nullptr; - this->ServerPipe = nullptr; - this->WriteStream = nullptr; - this->ReadStream = nullptr; -} - -void cmServerPipeConnection::Connect(uv_stream_t* server) -{ - if (this->ClientPipe) { - // Accept and close all pipes but the first: - uv_pipe_t* rejectPipe = new uv_pipe_t; - - uv_pipe_init(this->Loop(), rejectPipe, 0); - auto rejecter = reinterpret_cast<uv_stream_t*>(rejectPipe); - uv_accept(server, rejecter); - uv_close(reinterpret_cast<uv_handle_t*>(rejecter), &on_pipe_close); - return; - } - - this->ClientPipe = new uv_pipe_t; - uv_pipe_init(this->Loop(), this->ClientPipe, 0); - this->ClientPipe->data = this; - auto client = reinterpret_cast<uv_stream_t*>(this->ClientPipe); - if (uv_accept(server, client) != 0) { - uv_close(reinterpret_cast<uv_handle_t*>(client), nullptr); - return; - } - this->ReadStream = client; - this->WriteStream = client; - - uv_read_start(this->ReadStream, on_alloc_buffer, on_read); - - this->SendGreetings(); } diff --git a/Source/cmServerConnection.h b/Source/cmServerConnection.h index b96bf3c..0804f0e 100644 --- a/Source/cmServerConnection.h +++ b/Source/cmServerConnection.h @@ -2,68 +2,46 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #pragma once -#include "cmConfigure.h" +#include "cmConnection.h" +#include "cmPipeConnection.h" #include "cm_uv.h" #include <string> -class cmFileMonitor; -class cmServer; +class cmServerBase; -class cmServerConnection +/*** + * This connection buffer strategy accepts messages in the form of + * [== "CMake Server" ==[ +{ + ... some JSON message ... +} +]== "CMake Server" ==] + * and only passes on the core json; it discards the envelope. + */ +class cmServerBufferStrategy : public cmConnectionBufferStrategy { - CM_DISABLE_COPY(cmServerConnection) - public: - cmServerConnection(); - virtual ~cmServerConnection(); - - void SetServer(cmServer* s); - - bool ProcessEvents(std::string* errorMessage); - - void ReadData(const std::string& data); - void TriggerShutdown(); - void WriteData(const std::string& data); - void ProcessNextRequest(); - - virtual void Connect(uv_stream_t* server) { (void)(server); } - - cmFileMonitor* FileMonitor() const { return this->mFileMonitor; } - -protected: - virtual bool DoSetup(std::string* errorMessage) = 0; - virtual void TearDown() = 0; - - void SendGreetings(); - - uv_loop_t* Loop() const { return mLoop; } - -protected: - std::string RawReadBuffer; - std::string RequestBuffer; - - uv_stream_t* ReadStream = nullptr; - uv_stream_t* WriteStream = nullptr; + std::string BufferMessage(std::string& rawBuffer) override; private: - uv_loop_t* mLoop = nullptr; - cmFileMonitor* mFileMonitor = nullptr; - cmServer* Server = nullptr; - uv_signal_t* SIGINTHandler = nullptr; - uv_signal_t* SIGHUPHandler = nullptr; - - friend class LoopGuard; + std::string RequestBuffer; }; -class cmServerStdIoConnection : public cmServerConnection +/*** + * Generic connection over std io interfaces -- tty + */ +class cmStdIoConnection : public cmEventBasedConnection { public: - cmServerStdIoConnection(); - bool DoSetup(std::string* errorMessage) override; + cmStdIoConnection(cmConnectionBufferStrategy* bufferStrategy); + + void SetServer(cmServerBase* s) override; + + bool OnConnectionShuttingDown() override; - void TearDown() override; + bool OnServeStart(std::string* pString) override; private: typedef union @@ -78,18 +56,18 @@ private: InOutUnion Output; }; -class cmServerPipeConnection : public cmServerConnection +/*** + * These specific connections use the cmake server + * buffering strategy. + */ +class cmServerStdIoConnection : public cmStdIoConnection { public: - cmServerPipeConnection(const std::string& name); - bool DoSetup(std::string* errorMessage) override; - - void TearDown() override; - - void Connect(uv_stream_t* server) override; + cmServerStdIoConnection(); +}; -private: - const std::string PipeName; - uv_pipe_t* ServerPipe = nullptr; - uv_pipe_t* ClientPipe = nullptr; +class cmServerPipeConnection : public cmPipeConnection +{ +public: + cmServerPipeConnection(const std::string& name); }; diff --git a/Source/cmServerDictionary.h b/Source/cmServerDictionary.h index e6a7ae6..405ff6b 100644 --- a/Source/cmServerDictionary.h +++ b/Source/cmServerDictionary.h @@ -89,6 +89,11 @@ static const std::string kWARN_UNUSED_KEY = "warnUnused"; static const std::string kWATCHED_DIRECTORIES_KEY = "watchedDirectories"; static const std::string kWATCHED_FILES_KEY = "watchedFiles"; +static const std::string kTARGET_CROSS_REFERENCES_KEY = "crossReferences"; +static const std::string kLINE_NUMBER_KEY = "line"; +static const std::string kBACKTRACE_KEY = "backtrace"; +static const std::string kRELATED_STATEMENTS_KEY = "relatedStatements"; + static const std::string kSTART_MAGIC = "[== \"CMake Server\" ==["; static const std::string kEND_MAGIC = "]== \"CMake Server\" ==]"; diff --git a/Source/cmServerProtocol.cxx b/Source/cmServerProtocol.cxx index c5b7f60..2063c82 100644 --- a/Source/cmServerProtocol.cxx +++ b/Source/cmServerProtocol.cxx @@ -2,12 +2,14 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmServerProtocol.h" +#include "cmAlgorithms.h" #include "cmExternalMakefileProjectGenerator.h" #include "cmFileMonitor.h" #include "cmGeneratorExpression.h" #include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" #include "cmLinkLineComputer.h" +#include "cmListFileCache.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" #include "cmServer.h" @@ -18,6 +20,7 @@ #include "cmStateSnapshot.h" #include "cmStateTypes.h" #include "cmSystemTools.h" +#include "cmTarget.h" #include "cm_uv.h" #include "cmake.h" @@ -125,11 +128,13 @@ void getCMakeInputs(const cmGlobalGenerator* gg, const std::string& sourceDir, } // namespace -cmServerRequest::cmServerRequest(cmServer* server, const std::string& t, - const std::string& c, const Json::Value& d) +cmServerRequest::cmServerRequest(cmServer* server, cmConnection* connection, + const std::string& t, const std::string& c, + const Json::Value& d) : Type(t) , Cookie(c) , Data(d) + , Connection(connection) , m_Server(server) { } @@ -247,9 +252,9 @@ bool cmServerProtocol::DoActivate(const cmServerRequest& /*request*/, return true; } -std::pair<int, int> cmServerProtocol1_0::ProtocolVersion() const +std::pair<int, int> cmServerProtocol1::ProtocolVersion() const { - return std::make_pair(1, 0); + return std::make_pair(1, 1); } static void setErrorMessage(std::string* errorMessage, const std::string& text) @@ -264,6 +269,10 @@ static bool testHomeDirectory(cmState* state, std::string& value, { const std::string cachedValue = std::string(state->GetCacheEntryValue("CMAKE_HOME_DIRECTORY")); + if (value.empty()) { + value = cachedValue; + return true; + } const std::string suffix = "/CMakeLists.txt"; const std::string cachedValueCML = cachedValue + suffix; const std::string valueCML = value + suffix; @@ -274,9 +283,6 @@ static bool testHomeDirectory(cmState* state, std::string& value, "source directory value.")); return false; } - if (value.empty()) { - value = cachedValue; - } return true; } @@ -287,20 +293,20 @@ static bool testValue(cmState* state, const std::string& key, const char* entry = state->GetCacheEntryValue(key); const std::string cachedValue = entry == nullptr ? std::string() : std::string(entry); - if (!cachedValue.empty() && !value.empty() && cachedValue != value) { + if (value.empty()) { + value = cachedValue; + } + if (!cachedValue.empty() && cachedValue != value) { setErrorMessage(errorMessage, std::string("\"") + key + "\" is set but incompatible with configured " + keyDescription + " value."); return false; } - if (value.empty()) { - value = cachedValue; - } return true; } -bool cmServerProtocol1_0::DoActivate(const cmServerRequest& request, - std::string* errorMessage) +bool cmServerProtocol1::DoActivate(const cmServerRequest& request, + std::string* errorMessage) { std::string sourceDirectory = request.Data[kSOURCE_DIRECTORY_KEY].asString(); const std::string buildDirectory = @@ -419,8 +425,8 @@ bool cmServerProtocol1_0::DoActivate(const cmServerRequest& request, return true; } -void cmServerProtocol1_0::HandleCMakeFileChanges(const std::string& path, - int event, int status) +void cmServerProtocol1::HandleCMakeFileChanges(const std::string& path, + int event, int status) { assert(status == 0); static_cast<void>(status); @@ -443,7 +449,7 @@ void cmServerProtocol1_0::HandleCMakeFileChanges(const std::string& path, SendSignal(kFILE_CHANGE_SIGNAL, obj); } -const cmServerResponse cmServerProtocol1_0::Process( +const cmServerResponse cmServerProtocol1::Process( const cmServerRequest& request) { assert(this->m_State >= STATE_ACTIVE); @@ -476,18 +482,14 @@ const cmServerResponse cmServerProtocol1_0::Process( return request.ReportError("Unknown command!"); } -bool cmServerProtocol1_0::IsExperimental() const +bool cmServerProtocol1::IsExperimental() const { return true; } -cmServerResponse cmServerProtocol1_0::ProcessCache( +cmServerResponse cmServerProtocol1::ProcessCache( const cmServerRequest& request) { - if (this->m_State < STATE_CONFIGURED) { - return request.ReportError("This project was not configured yet."); - } - cmState* state = this->CMakeInstance()->GetState(); Json::Value result = Json::objectValue; @@ -530,7 +532,7 @@ cmServerResponse cmServerProtocol1_0::ProcessCache( return request.Reply(result); } -cmServerResponse cmServerProtocol1_0::ProcessCMakeInputs( +cmServerResponse cmServerProtocol1::ProcessCMakeInputs( const cmServerRequest& request) { if (this->m_State < STATE_CONFIGURED) { @@ -731,6 +733,37 @@ static Json::Value DumpSourceFilesList( return result; } +static Json::Value DumpBacktrace(const cmListFileBacktrace& backtrace) +{ + Json::Value result = Json::arrayValue; + + cmListFileBacktrace backtraceCopy = backtrace; + while (!backtraceCopy.Top().FilePath.empty()) { + Json::Value entry = Json::objectValue; + entry[kPATH_KEY] = backtraceCopy.Top().FilePath; + if (backtraceCopy.Top().Line) { + entry[kLINE_NUMBER_KEY] = (int)backtraceCopy.Top().Line; + } + if (!backtraceCopy.Top().Name.empty()) { + entry[kNAME_KEY] = backtraceCopy.Top().Name; + } + result.append(entry); + backtraceCopy = backtraceCopy.Pop(); + } + return result; +} + +static void DumpBacktraceRange(Json::Value& result, const std::string& type, + cmBacktraceRange range) +{ + for (const auto& bt : range) { + Json::Value obj = Json::objectValue; + obj[kTYPE_KEY] = type; + obj[kBACKTRACE_KEY] = DumpBacktrace(bt); + result.append(obj); + } +} + static Json::Value DumpTarget(cmGeneratorTarget* target, const std::string& config) { @@ -765,6 +798,22 @@ static Json::Value DumpTarget(cmGeneratorTarget* target, result[kFULL_NAME_KEY] = target->GetFullName(config); + Json::Value crossRefs = Json::objectValue; + crossRefs[kBACKTRACE_KEY] = DumpBacktrace(target->Target->GetBacktrace()); + + Json::Value statements = Json::arrayValue; + DumpBacktraceRange(statements, "target_compile_definitions", + target->Target->GetCompileDefinitionsBacktraces()); + DumpBacktraceRange(statements, "target_include_directories", + target->Target->GetIncludeDirectoriesBacktraces()); + DumpBacktraceRange(statements, "target_compile_options", + target->Target->GetCompileOptionsBacktraces()); + DumpBacktraceRange(statements, "target_link_libraries", + target->Target->GetLinkImplementationBacktraces()); + + crossRefs[kRELATED_STATEMENTS_KEY] = std::move(statements); + result[kTARGET_CROSS_REFERENCES_KEY] = std::move(crossRefs); + if (target->HaveWellDefinedOutputFiles()) { Json::Value artifacts = Json::arrayValue; artifacts.append( @@ -854,7 +903,7 @@ static Json::Value DumpTargetsList( std::vector<cmGeneratorTarget*> targetList; for (const auto& lgIt : generators) { - auto list = lgIt->GetGeneratorTargets(); + const auto& list = lgIt->GetGeneratorTargets(); targetList.insert(targetList.end(), list.begin(), list.end()); } std::sort(targetList.begin(), targetList.end()); @@ -917,7 +966,7 @@ static Json::Value DumpConfigurationsList(const cmake* cm) return result; } -cmServerResponse cmServerProtocol1_0::ProcessCodeModel( +cmServerResponse cmServerProtocol1::ProcessCodeModel( const cmServerRequest& request) { if (this->m_State != STATE_COMPUTED) { @@ -929,7 +978,7 @@ cmServerResponse cmServerProtocol1_0::ProcessCodeModel( return request.Reply(result); } -cmServerResponse cmServerProtocol1_0::ProcessCompute( +cmServerResponse cmServerProtocol1::ProcessCompute( const cmServerRequest& request) { if (this->m_State > STATE_CONFIGURED) { @@ -949,7 +998,7 @@ cmServerResponse cmServerProtocol1_0::ProcessCompute( return request.Reply(Json::Value()); } -cmServerResponse cmServerProtocol1_0::ProcessConfigure( +cmServerResponse cmServerProtocol1::ProcessConfigure( const cmServerRequest& request) { if (this->m_State == STATE_INACTIVE) { @@ -1055,7 +1104,7 @@ cmServerResponse cmServerProtocol1_0::ProcessConfigure( return request.Reply(Json::Value()); } -cmServerResponse cmServerProtocol1_0::ProcessGlobalSettings( +cmServerResponse cmServerProtocol1::ProcessGlobalSettings( const cmServerRequest& request) { cmake* cm = this->CMakeInstance(); @@ -1091,7 +1140,7 @@ static void setBool(const cmServerRequest& request, const std::string& key, setter(request.Data[key].asBool()); } -cmServerResponse cmServerProtocol1_0::ProcessSetGlobalSettings( +cmServerResponse cmServerProtocol1::ProcessSetGlobalSettings( const cmServerRequest& request) { const std::vector<std::string> boolValues = { @@ -1123,7 +1172,7 @@ cmServerResponse cmServerProtocol1_0::ProcessSetGlobalSettings( return request.Reply(Json::Value()); } -cmServerResponse cmServerProtocol1_0::ProcessFileSystemWatchers( +cmServerResponse cmServerProtocol1::ProcessFileSystemWatchers( const cmServerRequest& request) { const cmFileMonitor* const fm = FileMonitor(); @@ -1142,7 +1191,7 @@ cmServerResponse cmServerProtocol1_0::ProcessFileSystemWatchers( return request.Reply(result); } -cmServerProtocol1_0::GeneratorInformation::GeneratorInformation( +cmServerProtocol1::GeneratorInformation::GeneratorInformation( const std::string& generatorName, const std::string& extraGeneratorName, const std::string& toolset, const std::string& platform, const std::string& sourceDirectory, const std::string& buildDirectory) @@ -1155,7 +1204,7 @@ cmServerProtocol1_0::GeneratorInformation::GeneratorInformation( { } -void cmServerProtocol1_0::GeneratorInformation::SetupGenerator( +void cmServerProtocol1::GeneratorInformation::SetupGenerator( cmake* cm, std::string* errorMessage) { const std::string fullGeneratorName = diff --git a/Source/cmServerProtocol.h b/Source/cmServerProtocol.h index 83b3d58..145708c 100644 --- a/Source/cmServerProtocol.h +++ b/Source/cmServerProtocol.h @@ -11,6 +11,7 @@ #include <string> #include <utility> +class cmConnection; class cmFileMonitor; class cmServer; class cmServerRequest; @@ -52,9 +53,11 @@ public: const std::string Type; const std::string Cookie; const Json::Value Data; + cmConnection* Connection; private: - cmServerRequest(cmServer* server, const std::string& t, const std::string& c, + cmServerRequest(cmServer* server, cmConnection* connection, + const std::string& t, const std::string& c, const Json::Value& d); void ReportProgress(int min, int current, int max, @@ -98,7 +101,7 @@ private: friend class cmServer; }; -class cmServerProtocol1_0 : public cmServerProtocol +class cmServerProtocol1 : public cmServerProtocol { public: std::pair<int, int> ProtocolVersion() const override; diff --git a/Source/cmSourceFile.h b/Source/cmSourceFile.h index 0be659c..e739d18 100644 --- a/Source/cmSourceFile.h +++ b/Source/cmSourceFile.h @@ -120,4 +120,10 @@ private: // TODO: Factor out into platform information modules. #define CM_HEADER_REGEX "\\.(h|hh|h\\+\\+|hm|hpp|hxx|in|txx|inl)$" +#define CM_SOURCE_REGEX \ + "\\.(C|M|c|c\\+\\+|cc|cpp|cxx|f|f90|for|fpp|ftn|m|mm|rc|def|r|odl|idl|hpj" \ + "|bat)$" + +#define CM_RESOURCE_REGEX "\\.(pdf|plist|png|jpeg|jpg|storyboard|xcassets)$" + #endif diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx index 7a097ba..b07eae1 100644 --- a/Source/cmStringCommand.cxx +++ b/Source/cmStringCommand.cxx @@ -62,6 +62,9 @@ bool cmStringCommand::InitialPass(std::vector<std::string> const& args, if (subCommand == "APPEND") { return this->HandleAppendCommand(args); } + if (subCommand == "PREPEND") { + return this->HandlePrependCommand(args); + } if (subCommand == "CONCAT") { return this->HandleConcatCommand(args); } @@ -309,6 +312,7 @@ bool cmStringCommand::RegexMatchAll(std::vector<std::string> const& args) std::string output; const char* p = input.c_str(); while (re.find(p)) { + this->Makefile->ClearMatches(); this->Makefile->StoreMatches(re); std::string::size_type l = re.start(); std::string::size_type r = re.end(); @@ -391,6 +395,7 @@ bool cmStringCommand::RegexReplace(std::vector<std::string> const& args) std::string output; std::string::size_type base = 0; while (re.find(input.c_str() + base)) { + this->Makefile->ClearMatches(); this->Makefile->StoreMatches(re); std::string::size_type l2 = re.start(); std::string::size_type r = re.end(); @@ -641,6 +646,30 @@ bool cmStringCommand::HandleAppendCommand(std::vector<std::string> const& args) return true; } +bool cmStringCommand::HandlePrependCommand( + std::vector<std::string> const& args) +{ + if (args.size() < 2) { + this->SetError("sub-command PREPEND requires at least one argument."); + return false; + } + + // Skip if nothing to prepend. + if (args.size() < 3) { + return true; + } + + const std::string& variable = args[1]; + + std::string value = cmJoin(cmMakeRange(args).advance(2), std::string()); + const char* oldValue = this->Makefile->GetDefinition(variable); + if (oldValue) { + value += oldValue; + } + this->Makefile->AddDefinition(variable, value.c_str()); + return true; +} + bool cmStringCommand::HandleConcatCommand(std::vector<std::string> const& args) { if (args.size() < 2) { diff --git a/Source/cmStringCommand.h b/Source/cmStringCommand.h index 88015ad..0dded15 100644 --- a/Source/cmStringCommand.h +++ b/Source/cmStringCommand.h @@ -46,6 +46,7 @@ protected: bool HandleLengthCommand(std::vector<std::string> const& args); bool HandleSubstringCommand(std::vector<std::string> const& args); bool HandleAppendCommand(std::vector<std::string> const& args); + bool HandlePrependCommand(std::vector<std::string> const& args); bool HandleConcatCommand(std::vector<std::string> const& args); bool HandleStripCommand(std::vector<std::string> const& args); bool HandleRandomCommand(std::vector<std::string> const& args); diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index f7192e0..9f214c3 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -934,19 +934,17 @@ bool cmSystemTools::RenameFile(const char* oldname, const char* newname) #endif } -bool cmSystemTools::ComputeFileMD5(const std::string& source, char* md5out) +std::string cmSystemTools::ComputeFileHash(const std::string& source, + cmCryptoHash::Algo algo) { #if defined(CMAKE_BUILD_WITH_CMAKE) - cmCryptoHash md5(cmCryptoHash::AlgoMD5); - std::string const str = md5.HashFile(source); - strncpy(md5out, str.c_str(), 32); - return !str.empty(); + cmCryptoHash hash(algo); + return hash.HashFile(source); #else (void)source; - (void)md5out; - cmSystemTools::Message("md5sum not supported in bootstrapping mode", + cmSystemTools::Message("hashsum not supported in bootstrapping mode", "Error"); - return false; + return std::string(); #endif } diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 9de7967..e163c91 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -5,6 +5,7 @@ #include "cmConfigure.h" +#include "cmCryptoHash.h" #include "cmProcessOutput.h" #include "cmsys/Process.h" #include "cmsys/SystemTools.hxx" // IWYU pragma: export @@ -179,8 +180,9 @@ public: if possible). */ static bool RenameFile(const char* oldname, const char* newname); - ///! Compute the md5sum of a file - static bool ComputeFileMD5(const std::string& source, char* md5out); + ///! Compute the hash of a file + static std::string ComputeFileHash(const std::string& source, + cmCryptoHash::Algo algo); /** Compute the md5sum of a string. */ static std::string ComputeStringMD5(const std::string& input); diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index c95a3ca..501aebf 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -248,6 +248,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, this->SetPropertyDefault("AUTOUIC", CM_NULLPTR); this->SetPropertyDefault("AUTORCC", CM_NULLPTR); this->SetPropertyDefault("AUTOMOC_DEPEND_FILTERS", CM_NULLPTR); + this->SetPropertyDefault("AUTOMOC_MACRO_NAMES", CM_NULLPTR); this->SetPropertyDefault("AUTOMOC_MOC_OPTIONS", CM_NULLPTR); this->SetPropertyDefault("AUTOUIC_OPTIONS", CM_NULLPTR); this->SetPropertyDefault("AUTOUIC_SEARCH_PATHS", CM_NULLPTR); @@ -276,6 +277,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, this->SetPropertyDefault("CUDA_STANDARD", CM_NULLPTR); this->SetPropertyDefault("CUDA_STANDARD_REQUIRED", CM_NULLPTR); this->SetPropertyDefault("CUDA_EXTENSIONS", CM_NULLPTR); + this->SetPropertyDefault("CUDA_COMPILER_LAUNCHER", CM_NULLPTR); this->SetPropertyDefault("LINK_SEARCH_START_STATIC", CM_NULLPTR); this->SetPropertyDefault("LINK_SEARCH_END_STATIC", CM_NULLPTR); } diff --git a/Source/cmVS10CLFlagTable.h b/Source/cmVS10CLFlagTable.h index dbd760e..df4d58c 100644 --- a/Source/cmVS10CLFlagTable.h +++ b/Source/cmVS10CLFlagTable.h @@ -70,7 +70,8 @@ static cmVS7FlagTable cmVS10CLFlagTable[] = { cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue }, { "PrecompiledHeader", "Yu", "Use", "Use", cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue }, - { "PrecompiledHeader", "", "Not Using Precompiled Headers", "NotUsing", 0 }, + { "PrecompiledHeader", "Y-", "Not Using Precompiled Headers", "NotUsing", + 0 }, { "AssemblerOutput", "", "No Listing", "NoListing", 0 }, { "AssemblerOutput", "FA", "Assembly-Only Listing", "AssemblyCode", 0 }, diff --git a/Source/cmVS10CSharpFlagTable.h b/Source/cmVS10CSharpFlagTable.h index 493ec2b..18d587c 100644 --- a/Source/cmVS10CSharpFlagTable.h +++ b/Source/cmVS10CSharpFlagTable.h @@ -25,7 +25,8 @@ static cmVS7FlagTable cmVS10CSharpFlagTable[] = { { "ApplicationIcon", "win32icon", "", "", cmIDEFlagTable::UserValueRequired }, - { "Win32Manifest", "win32manifest:", "", "true", 0 }, + { "ApplicationManifest", "win32manifest:", "", "", + cmIDEFlagTable::UserValueRequired }, { "NoWin32Manifest", "nowin32manifest", "", "true", 0 }, diff --git a/Source/cmVS11CLFlagTable.h b/Source/cmVS11CLFlagTable.h index 7531709..d156938 100644 --- a/Source/cmVS11CLFlagTable.h +++ b/Source/cmVS11CLFlagTable.h @@ -74,7 +74,8 @@ static cmVS7FlagTable cmVS11CLFlagTable[] = { cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue }, { "PrecompiledHeader", "Yu", "Use", "Use", cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue }, - { "PrecompiledHeader", "", "Not Using Precompiled Headers", "NotUsing", 0 }, + { "PrecompiledHeader", "Y-", "Not Using Precompiled Headers", "NotUsing", + 0 }, { "AssemblerOutput", "", "No Listing", "NoListing", 0 }, { "AssemblerOutput", "FA", "Assembly-Only Listing", "AssemblyCode", 0 }, diff --git a/Source/cmVS11CSharpFlagTable.h b/Source/cmVS11CSharpFlagTable.h index 71870b6..e3ba83c 100644 --- a/Source/cmVS11CSharpFlagTable.h +++ b/Source/cmVS11CSharpFlagTable.h @@ -25,7 +25,8 @@ static cmVS7FlagTable cmVS11CSharpFlagTable[] = { { "ApplicationIcon", "win32icon", "", "", cmIDEFlagTable::UserValueRequired }, - { "Win32Manifest", "win32manifest:", "", "true", 0 }, + { "ApplicationManifest", "win32manifest:", "", "", + cmIDEFlagTable::UserValueRequired }, { "NoWin32Manifest", "nowin32manifest", "", "true", 0 }, diff --git a/Source/cmVS12CLFlagTable.h b/Source/cmVS12CLFlagTable.h index 9515c91..a4f2518 100644 --- a/Source/cmVS12CLFlagTable.h +++ b/Source/cmVS12CLFlagTable.h @@ -78,7 +78,8 @@ static cmVS7FlagTable cmVS12CLFlagTable[] = { cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue }, { "PrecompiledHeader", "Yu", "Use", "Use", cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue }, - { "PrecompiledHeader", "", "Not Using Precompiled Headers", "NotUsing", 0 }, + { "PrecompiledHeader", "Y-", "Not Using Precompiled Headers", "NotUsing", + 0 }, { "AssemblerOutput", "", "No Listing", "NoListing", 0 }, { "AssemblerOutput", "FA", "Assembly-Only Listing", "AssemblyCode", 0 }, diff --git a/Source/cmVS12CSharpFlagTable.h b/Source/cmVS12CSharpFlagTable.h index f98b184..f8db636 100644 --- a/Source/cmVS12CSharpFlagTable.h +++ b/Source/cmVS12CSharpFlagTable.h @@ -25,7 +25,8 @@ static cmVS7FlagTable cmVS12CSharpFlagTable[] = { { "ApplicationIcon", "win32icon", "", "", cmIDEFlagTable::UserValueRequired }, - { "Win32Manifest", "win32manifest:", "", "true", 0 }, + { "ApplicationManifest", "win32manifest:", "", "", + cmIDEFlagTable::UserValueRequired }, { "NoWin32Manifest", "nowin32manifest", "", "true", 0 }, diff --git a/Source/cmVS140CLFlagTable.h b/Source/cmVS140CLFlagTable.h index 60b4379..2b89042 100644 --- a/Source/cmVS140CLFlagTable.h +++ b/Source/cmVS140CLFlagTable.h @@ -80,7 +80,8 @@ static cmVS7FlagTable cmVS140CLFlagTable[] = { cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue }, { "PrecompiledHeader", "Yu", "Use", "Use", cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue }, - { "PrecompiledHeader", "", "Not Using Precompiled Headers", "NotUsing", 0 }, + { "PrecompiledHeader", "Y-", "Not Using Precompiled Headers", "NotUsing", + 0 }, { "AssemblerOutput", "", "No Listing", "NoListing", 0 }, { "AssemblerOutput", "FA", "Assembly-Only Listing", "AssemblyCode", 0 }, diff --git a/Source/cmVS140CSharpFlagTable.h b/Source/cmVS140CSharpFlagTable.h index 256c35f..055d5cb 100644 --- a/Source/cmVS140CSharpFlagTable.h +++ b/Source/cmVS140CSharpFlagTable.h @@ -25,7 +25,8 @@ static cmVS7FlagTable cmVS140CSharpFlagTable[] = { { "ApplicationIcon", "win32icon", "", "", cmIDEFlagTable::UserValueRequired }, - { "Win32Manifest", "win32manifest:", "", "true", 0 }, + { "ApplicationManifest", "win32manifest:", "", "", + cmIDEFlagTable::UserValueRequired }, { "NoWin32Manifest", "nowin32manifest", "", "true", 0 }, diff --git a/Source/cmVS141CLFlagTable.h b/Source/cmVS141CLFlagTable.h index f751fc8..e8b8f5c 100644 --- a/Source/cmVS141CLFlagTable.h +++ b/Source/cmVS141CLFlagTable.h @@ -87,7 +87,8 @@ static cmVS7FlagTable cmVS141CLFlagTable[] = { cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue }, { "PrecompiledHeader", "Yu", "Use", "Use", cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue }, - { "PrecompiledHeader", "", "Not Using Precompiled Headers", "NotUsing", 0 }, + { "PrecompiledHeader", "Y-", "Not Using Precompiled Headers", "NotUsing", + 0 }, { "AssemblerOutput", "", "No Listing", "NoListing", 0 }, { "AssemblerOutput", "FA", "Assembly-Only Listing", "AssemblyCode", 0 }, diff --git a/Source/cmVS141CSharpFlagTable.h b/Source/cmVS141CSharpFlagTable.h index 8508581..5de9bf3 100644 --- a/Source/cmVS141CSharpFlagTable.h +++ b/Source/cmVS141CSharpFlagTable.h @@ -25,7 +25,8 @@ static cmVS7FlagTable cmVS141CSharpFlagTable[] = { { "ApplicationIcon", "win32icon", "", "", cmIDEFlagTable::UserValueRequired }, - { "Win32Manifest", "win32manifest:", "", "true", 0 }, + { "ApplicationManifest", "win32manifest:", "", "", + cmIDEFlagTable::UserValueRequired }, { "NoWin32Manifest", "nowin32manifest", "", "true", 0 }, diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 88fa19c..e1a0c83 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -25,6 +25,12 @@ static std::string cmVS10EscapeXML(std::string arg) return arg; } +static std::string cmVS10EscapeQuotes(std::string arg) +{ + cmSystemTools::ReplaceString(arg, "\"", """); + return arg; +} + static std::string cmVS10EscapeComment(std::string comment) { // MSBuild takes the CDATA of a <Message></Message> element and just @@ -79,7 +85,7 @@ cmVisualStudio10TargetGenerator::cmVisualStudio10TargetGenerator( this->LocalGenerator = (cmLocalVisualStudio7Generator*)this->GeneratorTarget->GetLocalGenerator(); this->Name = this->GeneratorTarget->GetName(); - this->GUID = this->GlobalGenerator->GetGUID(this->Name.c_str()); + this->GUID = this->GlobalGenerator->GetGUID(this->Name); this->Platform = gg->GetPlatformName(); this->NsightTegra = gg->IsNsightTegra(); for (int i = 0; i < 4; ++i) { @@ -144,7 +150,7 @@ void cmVisualStudio10TargetGenerator::WritePlatformConfigTag( (*stream) << config << "|" << this->Platform; (*stream) << "'"; // handle special case for 32 bit C# targets - if (csproj == this->ProjectType && this->Platform == "Win32") { + if (this->ProjectType == csproj && this->Platform == "Win32") { (*stream) << " Or "; (*stream) << "'$(Configuration)|$(Platform)'=='"; (*stream) << config << "|x86"; @@ -292,7 +298,7 @@ void cmVisualStudio10TargetGenerator::Generate() this->WriteString("</PropertyGroup>\n", 1); } - if (csproj != this->ProjectType) { + if (this->ProjectType != csproj) { this->WriteProjectConfigurations(); } this->WriteString("<PropertyGroup Label=\"Globals\">\n", 1); @@ -309,7 +315,7 @@ void cmVisualStudio10TargetGenerator::Generate() this->GeneratorTarget->GetProperty("VS_GLOBAL_PROJECT_TYPES"); if (vsProjectTypes) { std::string tagName = "ProjectTypes"; - if (csproj == this->ProjectType) { + if (this->ProjectType == csproj) { tagName = "ProjectTypeGuids"; } this->WriteString("", 2); @@ -405,7 +411,7 @@ void cmVisualStudio10TargetGenerator::Generate() globalKey == "ROOTNAMESPACE" || globalKey == "KEYWORD") { continue; } - const char* value = this->GeneratorTarget->GetProperty(keyIt->c_str()); + const char* value = this->GeneratorTarget->GetProperty(*keyIt); if (!value) continue; this->WriteString("<", 2); @@ -463,7 +469,7 @@ void cmVisualStudio10TargetGenerator::Generate() this->WriteProjectConfigurationValues(); - if (vcxproj == this->ProjectType) { + if (this->ProjectType == vcxproj) { this->WriteString("<Import Project=\"" VS10_CXX_PROPS "\" />\n", 1); } this->WriteString("<ImportGroup Label=\"ExtensionSettings\">\n", 1); @@ -566,7 +572,7 @@ void cmVisualStudio10TargetGenerator::Generate() this->WriteString(import.c_str(), 2); } this->WriteString("</ImportGroup>\n", 1); - if (csproj == this->ProjectType) { + if (this->ProjectType == csproj) { for (std::vector<std::string>::const_iterator i = this->Configurations.begin(); i != this->Configurations.end(); ++i) { @@ -576,6 +582,18 @@ void cmVisualStudio10TargetGenerator::Generate() this->WriteEvents(*i); this->WriteString("</PropertyGroup>\n", 1); } + // make sure custom commands are executed before build (if necessary) + this->WriteString("<PropertyGroup>\n", 1); + this->WriteString("<BuildDependsOn>\n", 2); + for (std::set<std::string>::const_iterator i = + this->CSharpCustomCommandNames.begin(); + i != this->CSharpCustomCommandNames.end(); ++i) { + this->WriteString(i->c_str(), 3); + (*this->BuildFileStream) << ";\n"; + } + this->WriteString("$(BuildDependsOn)\n", 3); + this->WriteString("</BuildDependsOn>\n", 2); + this->WriteString("</PropertyGroup>\n", 1); } this->WriteString("</Project>", 0); // The groups are stored in a separate file for VS 10 @@ -657,9 +675,39 @@ void cmVisualStudio10TargetGenerator::WriteDotNetReference( this->WriteString("<HintPath>", 3); (*this->BuildFileStream) << hint << "</HintPath>\n"; } + this->WriteDotNetReferenceCustomTags(ref); this->WriteString("</Reference>\n", 2); } +void cmVisualStudio10TargetGenerator::WriteDotNetReferenceCustomTags( + std::string const& ref) +{ + + static const std::string refpropPrefix = "VS_DOTNET_REFERENCEPROP_"; + static const std::string refpropInfix = "_TAG_"; + const std::string refPropFullPrefix = refpropPrefix + ref + refpropInfix; + typedef std::map<std::string, std::string> CustomTags; + CustomTags tags; + cmPropertyMap const& props = this->GeneratorTarget->Target->GetProperties(); + for (cmPropertyMap::const_iterator i = props.begin(); i != props.end(); + ++i) { + if (i->first.find(refPropFullPrefix) == 0) { + std::string refTag = i->first.substr(refPropFullPrefix.length()); + std::string refVal = i->second.GetValue(); + if (!refTag.empty() && !refVal.empty()) { + tags[refTag] = refVal; + } + } + } + for (CustomTags::const_iterator tag = tags.begin(); tag != tags.end(); + ++tag) { + this->WriteString("<", 3); + (*this->BuildFileStream) << tag->first << ">" + << cmVS10EscapeXML(tag->second) << "</" + << tag->first << ">\n"; + } +} + void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup() { std::vector<cmSourceFile const*> resxObjs; @@ -675,7 +723,7 @@ void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup() this->WriteString("<EmbeddedResource Include=\"", 2); this->ConvertToWindowsSlash(obj); bool useRelativePath = false; - if (csproj == this->ProjectType && this->InSourceBuild) { + if (this->ProjectType == csproj && this->InSourceBuild) { // If we do an in-source build and the resource file is in a // subdirectory // of the .csproj file, we have to use relative pathnames, otherwise @@ -688,7 +736,7 @@ void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup() } (*this->BuildFileStream) << obj << "\">\n"; - if (csproj != this->ProjectType) { + if (this->ProjectType != csproj) { this->WriteString("<DependentUpon>", 3); std::string hFileName = obj.substr(0, obj.find_last_of(".")) + ".h"; (*this->BuildFileStream) << hFileName << "</DependentUpon>\n"; @@ -696,7 +744,7 @@ void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup() for (std::vector<std::string>::const_iterator i = this->Configurations.begin(); i != this->Configurations.end(); ++i) { - this->WritePlatformConfigTag("LogicalName", i->c_str(), 3); + this->WritePlatformConfigTag("LogicalName", *i, 3); if (this->GeneratorTarget->GetProperty("VS_GLOBAL_ROOTNAMESPACE") || // Handle variant of VS_GLOBAL_<variable> for RootNamespace. this->GeneratorTarget->GetProperty("VS_GLOBAL_RootNamespace")) { @@ -758,7 +806,7 @@ void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup() for (cmPropertyMap::const_iterator p = props.begin(); p != props.end(); ++p) { static const std::string propNamePrefix = "VS_CSHARP_"; - if (p->first.find(propNamePrefix.c_str()) == 0) { + if (p->first.find(propNamePrefix) == 0) { std::string tagName = p->first.substr(propNamePrefix.length()); if (!tagName.empty()) { std::string value = props.GetPropertyValue(p->first); @@ -798,7 +846,7 @@ void cmVisualStudio10TargetGenerator::WriteXamlFilesGroup() } this->WriteSource(xamlType, *oi, ">\n"); - if (csproj == this->ProjectType && !this->InSourceBuild) { + if (this->ProjectType == csproj && !this->InSourceBuild) { // add <Link> tag to written XAML source if necessary const std::string srcDir = this->Makefile->GetCurrentSourceDirectory(); const std::string binDir = this->Makefile->GetCurrentBinaryDirectory(); @@ -914,10 +962,10 @@ void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues() for (std::vector<std::string>::const_iterator i = this->Configurations.begin(); i != this->Configurations.end(); ++i) { - this->WritePlatformConfigTag("PropertyGroup", i->c_str(), 1, + this->WritePlatformConfigTag("PropertyGroup", *i, 1, " Label=\"Configuration\"", "\n"); - if (csproj != this->ProjectType) { + if (this->ProjectType != csproj) { std::string configType = "<ConfigurationType>"; if (const char* vsConfigurationType = this->GeneratorTarget->GetProperty("VS_CONFIGURATION_TYPE")) { @@ -1038,8 +1086,7 @@ void cmVisualStudio10TargetGenerator::WriteMSToolConfigurationValuesManaged( this->WriteString("<DefineDebug>true</DefineDebug>\n", 2); } - std::string outDir = - this->GeneratorTarget->GetDirectory(config.c_str()) + "/"; + std::string outDir = this->GeneratorTarget->GetDirectory(config) + "/"; this->ConvertToWindowsSlash(outDir); this->WriteString("<OutputPath>", 2); (*this->BuildFileStream) << cmVS10EscapeXML(outDir) << "</OutputPath>\n"; @@ -1119,6 +1166,7 @@ void cmVisualStudio10TargetGenerator::WriteNsightTegraConfigurationValues( void cmVisualStudio10TargetGenerator::WriteCustomCommands() { this->SourcesVisited.clear(); + this->CSharpCustomCommandNames.clear(); std::vector<cmSourceFile const*> customCommands; this->GeneratorTarget->GetCustomCommands(customCommands, ""); for (std::vector<cmSourceFile const*>::const_iterator si = @@ -1140,9 +1188,14 @@ void cmVisualStudio10TargetGenerator::WriteCustomCommand( } } if (cmCustomCommand const* command = sf->GetCustomCommand()) { - this->WriteString("<ItemGroup>\n", 1); + // C# projects write their <Target> within WriteCustomRule() + if (this->ProjectType != csproj) { + this->WriteString("<ItemGroup>\n", 1); + } this->WriteCustomRule(sf, *command); - this->WriteString("</ItemGroup>\n", 1); + if (this->ProjectType != csproj) { + this->WriteString("</ItemGroup>\n", 1); + } } } } @@ -1177,8 +1230,20 @@ void cmVisualStudio10TargetGenerator::WriteCustomRule( } cmLocalVisualStudio7Generator* lg = this->LocalGenerator; - this->WriteSource("CustomBuild", source, ">\n"); - + if (this->ProjectType != csproj) { + this->WriteSource("CustomBuild", source, ">\n"); + } else { + this->WriteString("<ItemGroup>\n", 1); + std::string link; + this->GetCSharpSourceLink(source, link); + this->WriteSource("None", source, ">\n"); + if (!link.empty()) { + this->WriteString("<Link>", 3); + (*this->BuildFileStream) << link << "</Link>\n"; + } + this->WriteString("</None>\n", 2); + this->WriteString("</ItemGroup>\n", 1); + } for (std::vector<std::string>::const_iterator i = this->Configurations.begin(); i != this->Configurations.end(); ++i) { @@ -1186,41 +1251,90 @@ void cmVisualStudio10TargetGenerator::WriteCustomRule( std::string comment = lg->ConstructComment(ccg); comment = cmVS10EscapeComment(comment); std::string script = cmVS10EscapeXML(lg->ConstructScript(ccg)); - this->WritePlatformConfigTag("Message", i->c_str(), 3); - (*this->BuildFileStream) << cmVS10EscapeXML(comment) << "</Message>\n"; - this->WritePlatformConfigTag("Command", i->c_str(), 3); - (*this->BuildFileStream) << script << "</Command>\n"; - this->WritePlatformConfigTag("AdditionalInputs", i->c_str(), 3); - - (*this->BuildFileStream) << cmVS10EscapeXML(source->GetFullPath()); + // input files for custom command + std::stringstream inputs; + inputs << cmVS10EscapeXML(source->GetFullPath()); for (std::vector<std::string>::const_iterator d = ccg.GetDepends().begin(); d != ccg.GetDepends().end(); ++d) { std::string dep; - if (this->LocalGenerator->GetRealDependency(d->c_str(), i->c_str(), - dep)) { + if (this->LocalGenerator->GetRealDependency(*d, *i, dep)) { this->ConvertToWindowsSlash(dep); - (*this->BuildFileStream) << ";" << cmVS10EscapeXML(dep); + inputs << ";" << cmVS10EscapeXML(dep); } } - (*this->BuildFileStream) << ";%(AdditionalInputs)</AdditionalInputs>\n"; - this->WritePlatformConfigTag("Outputs", i->c_str(), 3); + // output files for custom command + std::stringstream outputs; const char* sep = ""; for (std::vector<std::string>::const_iterator o = ccg.GetOutputs().begin(); o != ccg.GetOutputs().end(); ++o) { std::string out = *o; this->ConvertToWindowsSlash(out); - (*this->BuildFileStream) << sep << cmVS10EscapeXML(out); + outputs << sep << cmVS10EscapeXML(out); sep = ";"; } - (*this->BuildFileStream) << "</Outputs>\n"; - if (this->LocalGenerator->GetVersion() > - cmGlobalVisualStudioGenerator::VS10) { - // VS >= 11 let us turn off linking of custom command outputs. - this->WritePlatformConfigTag("LinkObjects", i->c_str(), 3); - (*this->BuildFileStream) << "false</LinkObjects>\n"; + if (this->ProjectType == csproj) { + std::string name = "CustomCommand_" + *i + "_" + + cmSystemTools::ComputeStringMD5(sourcePath); + std::string inputs_s = inputs.str(); + std::string outputs_s = outputs.str(); + comment = cmVS10EscapeQuotes(comment); + script = cmVS10EscapeQuotes(script); + inputs_s = cmVS10EscapeQuotes(inputs_s); + outputs_s = cmVS10EscapeQuotes(outputs_s); + this->WriteCustomRuleCSharp(*i, name, script, inputs_s, outputs_s, + comment); + } else { + this->WriteCustomRuleCpp(*i, script, inputs.str(), outputs.str(), + comment); } } - this->WriteString("</CustomBuild>\n", 2); + if (this->ProjectType != csproj) { + this->WriteString("</CustomBuild>\n", 2); + } +} + +void cmVisualStudio10TargetGenerator::WriteCustomRuleCpp( + std::string const& config, std::string const& script, + std::string const& inputs, std::string const& outputs, + std::string const& comment) +{ + this->WritePlatformConfigTag("Message", config, 3); + (*this->BuildFileStream) << cmVS10EscapeXML(comment) << "</Message>\n"; + this->WritePlatformConfigTag("Command", config, 3); + (*this->BuildFileStream) << script << "</Command>\n"; + this->WritePlatformConfigTag("AdditionalInputs", config, 3); + (*this->BuildFileStream) << inputs; + (*this->BuildFileStream) << ";%(AdditionalInputs)</AdditionalInputs>\n"; + this->WritePlatformConfigTag("Outputs", config, 3); + (*this->BuildFileStream) << outputs << "</Outputs>\n"; + if (this->LocalGenerator->GetVersion() > + cmGlobalVisualStudioGenerator::VS10) { + // VS >= 11 let us turn off linking of custom command outputs. + this->WritePlatformConfigTag("LinkObjects", config, 3); + (*this->BuildFileStream) << "false</LinkObjects>\n"; + } +} + +void cmVisualStudio10TargetGenerator::WriteCustomRuleCSharp( + std::string const& config, std::string const& name, + std::string const& script, std::string const& inputs, + std::string const& outputs, std::string const& comment) +{ + this->CSharpCustomCommandNames.insert(name); + std::stringstream attributes; + attributes << "\n Name=\"" << name << "\""; + attributes << "\n Inputs=\"" << inputs << "\""; + attributes << "\n Outputs=\"" << outputs << "\""; + this->WritePlatformConfigTag("Target", config, 1, attributes.str().c_str(), + "\n"); + if (!comment.empty()) { + this->WriteString("<Exec Command=\"", 2); + (*this->BuildFileStream) << "echo " << cmVS10EscapeXML(comment) + << "\" />\n"; + } + this->WriteString("<Exec Command=\"", 2); + (*this->BuildFileStream) << script << "\" />\n"; + this->WriteString("</Target>\n", 1); } std::string cmVisualStudio10TargetGenerator::ConvertPath( @@ -1243,7 +1357,7 @@ void cmVisualStudio10TargetGenerator::ConvertToWindowsSlash(std::string& s) } void cmVisualStudio10TargetGenerator::WriteGroups() { - if (csproj == this->ProjectType) { + if (this->ProjectType == csproj) { return; } @@ -1355,7 +1469,7 @@ void cmVisualStudio10TargetGenerator::WriteGroups() std::string guidName = "SG_Filter_"; guidName += name; this->WriteString("<UniqueIdentifier>", 3); - std::string guid = this->GlobalGenerator->GetGUID(guidName.c_str()); + std::string guid = this->GlobalGenerator->GetGUID(guidName); (*this->BuildFileStream) << "{" << guid << "}" << "</UniqueIdentifier>\n"; this->WriteString("</Filter>\n", 2); @@ -1366,7 +1480,7 @@ void cmVisualStudio10TargetGenerator::WriteGroups() this->WriteString("<Filter Include=\"Resource Files\">\n", 2); std::string guidName = "SG_Filter_Resource Files"; this->WriteString("<UniqueIdentifier>", 3); - std::string guid = this->GlobalGenerator->GetGUID(guidName.c_str()); + std::string guid = this->GlobalGenerator->GetGUID(guidName); (*this->BuildFileStream) << "{" << guid << "}" << "</UniqueIdentifier>\n"; this->WriteString("<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;", 3); @@ -1485,7 +1599,7 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf) std::string copyToOutDir; std::string includeInVsix; std::string ext = cmSystemTools::LowerCase(sf->GetExtension()); - if (csproj == this->ProjectType) { + if (this->ProjectType == csproj) { // EVERY extra source file must have a <Link>, otherwise it might not // be visible in Visual Studio at all. The path relative to current // source- or binary-dir is used within the link, if the file is @@ -1564,6 +1678,10 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf) toolHasSettings = true; } + // Collect VS_CSHARP_* property values (if some are set) + std::map<std::string, std::string> sourceFileTags; + this->GetCSharpSourceProperties(sf, sourceFileTags); + if (this->NsightTegra) { // Nsight Tegra needs specific file types to check up-to-dateness. std::string name = cmSystemTools::LowerCase(sf->GetLocation().GetName()); @@ -1680,7 +1798,8 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf) (*this->BuildFileStream) << cmVS10EscapeXML(includeInVsix) << "</IncludeInVSIX>\n"; } - + // write source file specific tags + this->WriteCSharpSourceProperties(sourceFileTags); this->WriteString("</", 2); (*this->BuildFileStream) << tool << ">\n"; } else { @@ -1929,7 +2048,7 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( std::string configDefines = defines; std::string defPropName = "COMPILE_DEFINITIONS_"; defPropName += configUpper; - if (const char* ccdefs = sf.GetProperty(defPropName.c_str())) { + if (const char* ccdefs = sf.GetProperty(defPropName)) { if (!configDefines.empty()) { configDefines += ";"; } @@ -2002,48 +2121,23 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( std::string xamlFileName = fileName.substr(0, fileName.find_last_of(".")); (*this->BuildFileStream) << xamlFileName << "</DependentUpon>\n"; } - if (csproj == this->ProjectType) { + if (this->ProjectType == csproj) { std::string f = source->GetFullPath(); typedef std::map<std::string, std::string> CsPropMap; CsPropMap sourceFileTags; // set <Link> tag if necessary - if (!this->InSourceBuild) { - const std::string stripFromPath = - this->Makefile->GetCurrentSourceDirectory(); - if (f.find(stripFromPath) != std::string::npos) { - std::string link = f.substr(stripFromPath.length() + 1); - this->ConvertToWindowsSlash(link); - sourceFileTags["Link"] = link; - } - } - const cmPropertyMap& props = sf.GetProperties(); - for (cmPropertyMap::const_iterator p = props.begin(); p != props.end(); - ++p) { - static const std::string propNamePrefix = "VS_CSHARP_"; - if (p->first.find(propNamePrefix.c_str()) == 0) { - std::string tagName = p->first.substr(propNamePrefix.length()); - if (!tagName.empty()) { - const std::string val = props.GetPropertyValue(p->first); - if (!val.empty()) { - sourceFileTags[tagName] = val; - } else { - sourceFileTags.erase(tagName); - } - } - } + std::string link; + this->GetCSharpSourceLink(source, link); + if (!link.empty()) { + sourceFileTags["Link"] = link; } + this->GetCSharpSourceProperties(&sf, sourceFileTags); // write source file specific tags if (!sourceFileTags.empty()) { hasFlags = true; (*this->BuildFileStream) << firstString; firstString = ""; - for (CsPropMap::const_iterator i = sourceFileTags.begin(); - i != sourceFileTags.end(); ++i) { - this->WriteString("<", 3); - (*this->BuildFileStream) - << i->first << ">" << cmVS10EscapeXML(i->second) << "</" << i->first - << ">\n"; - } + this->WriteCSharpSourceProperties(sourceFileTags); } } @@ -2069,7 +2163,7 @@ void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions() if (ttype > cmStateEnums::GLOBAL_TARGET) { return; } - if (csproj == this->ProjectType) { + if (this->ProjectType == csproj) { return; } @@ -2081,7 +2175,7 @@ void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions() this->Configurations.begin(); config != this->Configurations.end(); ++config) { if (ttype >= cmStateEnums::UTILITY) { - this->WritePlatformConfigTag("IntDir", config->c_str(), 2); + this->WritePlatformConfigTag("IntDir", *config, 2); *this->BuildFileStream << "$(Platform)\\$(Configuration)\\$(ProjectName)\\" << "</IntDir>\n"; @@ -2098,30 +2192,30 @@ void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions() targetNameFull = this->GeneratorTarget->GetName(); targetNameFull += ".lib"; } else { - outDir = this->GeneratorTarget->GetDirectory(config->c_str()) + "/"; - targetNameFull = this->GeneratorTarget->GetFullName(config->c_str()); + outDir = this->GeneratorTarget->GetDirectory(*config) + "/"; + targetNameFull = this->GeneratorTarget->GetFullName(*config); } this->ConvertToWindowsSlash(intermediateDir); this->ConvertToWindowsSlash(outDir); - this->WritePlatformConfigTag("OutDir", config->c_str(), 2); + this->WritePlatformConfigTag("OutDir", *config, 2); *this->BuildFileStream << cmVS10EscapeXML(outDir) << "</OutDir>\n"; - this->WritePlatformConfigTag("IntDir", config->c_str(), 2); + this->WritePlatformConfigTag("IntDir", *config, 2); *this->BuildFileStream << cmVS10EscapeXML(intermediateDir) << "</IntDir>\n"; if (const char* workingDir = this->GeneratorTarget->GetProperty( "VS_DEBUGGER_WORKING_DIRECTORY")) { - this->WritePlatformConfigTag("LocalDebuggerWorkingDirectory", - config->c_str(), 2); + this->WritePlatformConfigTag("LocalDebuggerWorkingDirectory", *config, + 2); *this->BuildFileStream << cmVS10EscapeXML(workingDir) << "</LocalDebuggerWorkingDirectory>\n"; } std::string name = cmSystemTools::GetFilenameWithoutLastExtension(targetNameFull); - this->WritePlatformConfigTag("TargetName", config->c_str(), 2); + this->WritePlatformConfigTag("TargetName", *config, 2); *this->BuildFileStream << cmVS10EscapeXML(name) << "</TargetName>\n"; std::string ext = @@ -2131,7 +2225,7 @@ void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions() // A single "." appears to be treated as an empty extension. ext = "."; } - this->WritePlatformConfigTag("TargetExt", config->c_str(), 2); + this->WritePlatformConfigTag("TargetExt", *config, 2); *this->BuildFileStream << cmVS10EscapeXML(ext) << "</TargetExt>\n"; this->OutputLinkIncremental(*config); @@ -2146,7 +2240,7 @@ void cmVisualStudio10TargetGenerator::OutputLinkIncremental( if (!this->MSTools) { return; } - if (csproj == this->ProjectType) { + if (this->ProjectType == csproj) { return; } // static libraries and things greater than modules do not need @@ -2158,13 +2252,13 @@ void cmVisualStudio10TargetGenerator::OutputLinkIncremental( Options& linkOptions = *(this->LinkOptions[configName]); const char* incremental = linkOptions.GetFlag("LinkIncremental"); - this->WritePlatformConfigTag("LinkIncremental", configName.c_str(), 2); + this->WritePlatformConfigTag("LinkIncremental", configName, 2); *this->BuildFileStream << (incremental ? incremental : "true") << "</LinkIncremental>\n"; linkOptions.RemoveFlag("LinkIncremental"); const char* manifest = linkOptions.GetFlag("GenerateManifest"); - this->WritePlatformConfigTag("GenerateManifest", configName.c_str(), 2); + this->WritePlatformConfigTag("GenerateManifest", configName, 2); *this->BuildFileStream << (manifest ? manifest : "true") << "</GenerateManifest>\n"; linkOptions.RemoveFlag("GenerateManifest"); @@ -2175,7 +2269,7 @@ void cmVisualStudio10TargetGenerator::OutputLinkIncremental( for (const char** f = flags; *f; ++f) { const char* flag = *f; if (const char* value = linkOptions.GetFlag(flag)) { - this->WritePlatformConfigTag(flag, configName.c_str(), 2); + this->WritePlatformConfigTag(flag, configName, 2); *this->BuildFileStream << value << "</" << flag << ">\n"; linkOptions.RemoveFlag(flag); } @@ -2219,7 +2313,7 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( std::string flags; const std::string& linkLanguage = - this->GeneratorTarget->GetLinkerLanguage(configName.c_str()); + this->GeneratorTarget->GetLinkerLanguage(configName); if (linkLanguage.empty()) { cmSystemTools::Error( "CMake can not determine linker language for target: ", @@ -2250,13 +2344,13 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( baseFlagVar += "_FLAGS"; flags = this->GeneratorTarget->Target->GetMakefile()->GetRequiredDefinition( - baseFlagVar.c_str()); + baseFlagVar); std::string flagVar = baseFlagVar + std::string("_") + cmSystemTools::UpperCase(configName); flags += " "; flags += this->GeneratorTarget->Target->GetMakefile()->GetRequiredDefinition( - flagVar.c_str()); + flagVar); this->LocalGenerator->AddCompileOptions(flags, this->GeneratorTarget, langForClCompile, configName); } @@ -2275,7 +2369,7 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( std::string defineFlags = this->GeneratorTarget->Target->GetMakefile()->GetDefineFlags(); if (this->MSTools) { - if (vcxproj == this->ProjectType) { + if (this->ProjectType == vcxproj) { clOptions.FixExceptionHandlingDefault(); clOptions.AddFlag("PrecompiledHeader", "NotUsing"); std::string asmLocation = configName + "/"; @@ -2287,12 +2381,12 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( std::vector<std::string> targetDefines; switch (this->ProjectType) { case vcxproj: - this->GeneratorTarget->GetCompileDefinitions(targetDefines, - configName.c_str(), "CXX"); + this->GeneratorTarget->GetCompileDefinitions(targetDefines, configName, + "CXX"); break; case csproj: - this->GeneratorTarget->GetCompileDefinitions( - targetDefines, configName.c_str(), "CSharp"); + this->GeneratorTarget->GetCompileDefinitions(targetDefines, configName, + "CSharp"); break; } clOptions.AddDefines(targetDefines); @@ -2332,7 +2426,7 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( } } - if (csproj != this->ProjectType && clOptions.IsManaged()) { + if (this->ProjectType != csproj && clOptions.IsManaged()) { this->Managed = true; std::string managedType = clOptions.GetFlag("CompileAsManaged"); if (managedType == "Safe") { @@ -2340,6 +2434,12 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( clOptions.AddFlag("CallingConvention", ""); } } + if (this->ProjectType == csproj) { + // /nowin32manifest overrides /win32manifest: parameter + if (clOptions.HasFlag("NoWin32Manifest")) { + clOptions.RemoveFlag("ApplicationManifest"); + } + } this->ClOptions[configName] = pOptions.release(); return true; @@ -2392,8 +2492,7 @@ void cmVisualStudio10TargetGenerator::WriteClOptions( } // Specify the compiler program database file if configured. - std::string pdb = - this->GeneratorTarget->GetCompilePDBPath(configName.c_str()); + std::string pdb = this->GeneratorTarget->GetCompilePDBPath(configName); if (!pdb.empty()) { this->ConvertToWindowsSlash(pdb); this->WriteString("<ProgramDataBaseFileName>", 3); @@ -2535,8 +2634,8 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaOptions( cudaOptions.FixCudaCodeGeneration(); std::vector<std::string> targetDefines; - this->GeneratorTarget->GetCompileDefinitions(targetDefines, - configName.c_str(), "CUDA"); + this->GeneratorTarget->GetCompileDefinitions(targetDefines, configName, + "CUDA"); cudaOptions.AddDefines(targetDefines); // Add a definition for the configuration name. @@ -3006,11 +3105,11 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions( linkFlagVarBase += "_LINKER_FLAGS"; flags += " "; flags += this->GeneratorTarget->Target->GetMakefile()->GetRequiredDefinition( - linkFlagVarBase.c_str()); + linkFlagVarBase); std::string linkFlagVar = linkFlagVarBase + "_" + CONFIG; flags += " "; flags += this->GeneratorTarget->Target->GetMakefile()->GetRequiredDefinition( - linkFlagVar.c_str()); + linkFlagVar); const char* targetLinkFlags = this->GeneratorTarget->GetProperty("LINK_FLAGS"); if (targetLinkFlags) { @@ -3020,13 +3119,13 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions( std::string flagsProp = "LINK_FLAGS_"; flagsProp += CONFIG; if (const char* flagsConfig = - this->GeneratorTarget->GetProperty(flagsProp.c_str())) { + this->GeneratorTarget->GetProperty(flagsProp)) { flags += " "; flags += flagsConfig; } cmComputeLinkInformation* pcli = - this->GeneratorTarget->GetLinkInformation(config.c_str()); + this->GeneratorTarget->GetLinkInformation(config); if (!pcli) { cmSystemTools::Error( "CMake can not compute cmComputeLinkInformation for target: ", @@ -3054,8 +3153,7 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions( std::string standardLibsVar = "CMAKE_"; standardLibsVar += linkLanguage; standardLibsVar += "_STANDARD_LIBRARIES"; - std::string const libs = - this->Makefile->GetSafeDefinition(standardLibsVar.c_str()); + std::string const libs = this->Makefile->GetSafeDefinition(standardLibsVar); cmSystemTools::ParseWindowsCommandLine(libs.c_str(), libVec); linkOptions.AddFlag("AdditionalDependencies", libVec); @@ -3083,13 +3181,12 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions( std::string targetNameImport; std::string targetNamePDB; if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) { - this->GeneratorTarget->GetExecutableNames(targetName, targetNameFull, - targetNameImport, targetNamePDB, - config.c_str()); + this->GeneratorTarget->GetExecutableNames( + targetName, targetNameFull, targetNameImport, targetNamePDB, config); } else { this->GeneratorTarget->GetLibraryNames(targetName, targetNameSO, targetNameFull, targetNameImport, - targetNamePDB, config.c_str()); + targetNamePDB, config); } if (this->MSTools) { @@ -3130,11 +3227,11 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions( linkOptions.AddFlag("GenerateDebugInformation", "false"); - std::string pdb = this->GeneratorTarget->GetPDBDirectory(config.c_str()); + std::string pdb = this->GeneratorTarget->GetPDBDirectory(config); pdb += "/"; pdb += targetNamePDB; std::string imLib = this->GeneratorTarget->GetDirectory( - config.c_str(), cmStateEnums::ImportLibraryArtifact); + config, cmStateEnums::ImportLibraryArtifact); imLib += "/"; imLib += targetNameImport; @@ -3209,7 +3306,7 @@ bool cmVisualStudio10TargetGenerator::ComputeLibOptions( std::string const& config) { cmComputeLinkInformation* pcli = - this->GeneratorTarget->GetLinkInformation(config.c_str()); + this->GeneratorTarget->GetLinkInformation(config); if (!pcli) { cmSystemTools::Error( "CMake can not compute cmComputeLinkInformation for target: ", @@ -3224,8 +3321,8 @@ bool cmVisualStudio10TargetGenerator::ComputeLibOptions( this->LocalGenerator->GetCurrentBinaryDirectory(); for (ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l) { if (l->IsPath && cmVS10IsTargetsFile(l->Value)) { - std::string path = this->LocalGenerator->ConvertToRelativePath( - currentBinDir, l->Value.c_str()); + std::string path = + this->LocalGenerator->ConvertToRelativePath(currentBinDir, l->Value); this->ConvertToWindowsSlash(path); this->AddTargetsFileAndConfigPair(path, config); } @@ -3241,7 +3338,7 @@ void cmVisualStudio10TargetGenerator::WriteLinkOptions( this->GeneratorTarget->GetType() > cmStateEnums::MODULE_LIBRARY) { return; } - if (csproj == this->ProjectType) { + if (this->ProjectType == csproj) { return; } Options& linkOptions = *(this->LinkOptions[config]); @@ -3270,8 +3367,8 @@ void cmVisualStudio10TargetGenerator::AddLibraries( this->LocalGenerator->GetCurrentBinaryDirectory(); for (ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l) { if (l->IsPath) { - std::string path = this->LocalGenerator->ConvertToRelativePath( - currentBinDir, l->Value.c_str()); + std::string path = + this->LocalGenerator->ConvertToRelativePath(currentBinDir, l->Value); this->ConvertToWindowsSlash(path); if (cmVS10IsTargetsFile(l->Value)) { vsTargetVec.push_back(path); @@ -3311,7 +3408,7 @@ void cmVisualStudio10TargetGenerator::WriteMidlOptions( if (!this->MSTools) { return; } - if (csproj == this->ProjectType) { + if (this->ProjectType == csproj) { return; } @@ -3353,17 +3450,20 @@ void cmVisualStudio10TargetGenerator::WriteMidlOptions( void cmVisualStudio10TargetGenerator::WriteItemDefinitionGroups() { + if (this->ProjectType == csproj) { + return; + } for (std::vector<std::string>::const_iterator i = this->Configurations.begin(); i != this->Configurations.end(); ++i) { std::vector<std::string> includes; this->LocalGenerator->GetIncludeDirectories( - includes, this->GeneratorTarget, "C", i->c_str()); + includes, this->GeneratorTarget, "C", *i); for (std::vector<std::string>::iterator ii = includes.begin(); ii != includes.end(); ++ii) { this->ConvertToWindowsSlash(*ii); } - this->WritePlatformConfigTag("ItemDefinitionGroup", i->c_str(), 1); + this->WritePlatformConfigTag("ItemDefinitionGroup", *i, 1); *this->BuildFileStream << "\n"; // output cl compile flags <ClCompile></ClCompile> if (this->GeneratorTarget->GetType() <= cmStateEnums::OBJECT_LIBRARY) { @@ -3377,7 +3477,7 @@ void cmVisualStudio10TargetGenerator::WriteItemDefinitionGroups() // output midl flags <Midl></Midl> this->WriteMidlOptions(*i, includes); // write events - if (csproj != this->ProjectType) { + if (this->ProjectType != csproj) { this->WriteEvents(*i); } // output link flags <Link></Link> @@ -3443,17 +3543,21 @@ void cmVisualStudio10TargetGenerator::WriteEvent( script += cmVS10EscapeXML(lg->ConstructScript(ccg)); } comment = cmVS10EscapeComment(comment); - if (csproj != this->ProjectType) { + if (this->ProjectType != csproj) { this->WriteString("<Message>", 3); (*this->BuildFileStream) << cmVS10EscapeXML(comment) << "</Message>\n"; this->WriteString("<Command>", 3); } else { - if (!comment.empty()) { + std::string strippedComment = comment; + strippedComment.erase( + std::remove(strippedComment.begin(), strippedComment.end(), '\t'), + strippedComment.end()); + if (!comment.empty() && !strippedComment.empty()) { (*this->BuildFileStream) << "echo " << cmVS10EscapeXML(comment) << "\n"; } } (*this->BuildFileStream) << script; - if (csproj != this->ProjectType) { + if (this->ProjectType != csproj) { (*this->BuildFileStream) << "</Command>"; } (*this->BuildFileStream) << "\n"; @@ -3497,11 +3601,12 @@ void cmVisualStudio10TargetGenerator::WriteProjectReferences() this->ConvertToWindowsSlash(path); (*this->BuildFileStream) << cmVS10EscapeXML(path) << "\">\n"; this->WriteString("<Project>", 3); - (*this->BuildFileStream) - << "{" << this->GlobalGenerator->GetGUID(name.c_str()) << "}"; + (*this->BuildFileStream) << "{" << this->GlobalGenerator->GetGUID(name) + << "}"; (*this->BuildFileStream) << "</Project>\n"; this->WriteString("<Name>", 3); (*this->BuildFileStream) << name << "</Name>\n"; + this->WriteDotNetReferenceCustomTags(name); this->WriteString("</ProjectReference>\n", 2); } this->WriteString("</ItemGroup>\n", 1); @@ -3770,7 +3875,7 @@ void cmVisualStudio10TargetGenerator::WriteApplicationTypeSettings() this->WriteString("<XapOutputs>true</XapOutputs>\n", 2); this->WriteString("<XapFilename>", 2); (*this->BuildFileStream) - << cmVS10EscapeXML(this->Name.c_str()) + << cmVS10EscapeXML(this->Name) << "_$(Configuration)_$(Platform).xap</XapFilename>\n"; } } @@ -4289,6 +4394,59 @@ bool cmVisualStudio10TargetGenerator::ForceOld(const std::string& source) const return true; } +void cmVisualStudio10TargetGenerator::GetCSharpSourceProperties( + cmSourceFile const* sf, std::map<std::string, std::string>& tags) +{ + if (this->ProjectType == csproj) { + const cmPropertyMap& props = sf->GetProperties(); + for (cmPropertyMap::const_iterator p = props.begin(); p != props.end(); + ++p) { + static const std::string propNamePrefix = "VS_CSHARP_"; + if (p->first.find(propNamePrefix) == 0) { + std::string tagName = p->first.substr(propNamePrefix.length()); + if (!tagName.empty()) { + const std::string val = props.GetPropertyValue(p->first); + if (!val.empty()) { + tags[tagName] = val; + } else { + tags.erase(tagName); + } + } + } + } + } +} + +void cmVisualStudio10TargetGenerator::WriteCSharpSourceProperties( + const std::map<std::string, std::string>& tags) +{ + if (!tags.empty()) { + for (std::map<std::string, std::string>::const_iterator i = tags.begin(); + i != tags.end(); ++i) { + this->WriteString("<", 3); + (*this->BuildFileStream) << i->first << ">" << cmVS10EscapeXML(i->second) + << "</" << i->first << ">\n"; + } + } +} + +void cmVisualStudio10TargetGenerator::GetCSharpSourceLink( + cmSourceFile const* sf, std::string& link) +{ + std::string f = sf->GetFullPath(); + if (!this->InSourceBuild) { + const std::string stripFromPath = + this->Makefile->GetCurrentSourceDirectory(); + if (f.find(stripFromPath) != std::string::npos) { + link = f.substr(stripFromPath.length() + 1); + if (const char* l = sf->GetProperty("VS_CSHARP_Link")) { + link = l; + } + this->ConvertToWindowsSlash(link); + } + } +} + std::string cmVisualStudio10TargetGenerator::GetCMakeFilePath( const char* relativeFilePath) const { diff --git a/Source/cmVisualStudio10TargetGenerator.h b/Source/cmVisualStudio10TargetGenerator.h index 6106615..2d98994 100644 --- a/Source/cmVisualStudio10TargetGenerator.h +++ b/Source/cmVisualStudio10TargetGenerator.h @@ -66,6 +66,7 @@ private: void WriteAllSources(); void WriteDotNetReferences(); void WriteDotNetReference(std::string const& ref, std::string const& hint); + void WriteDotNetReferenceCustomTags(std::string const& ref); void WriteEmbeddedResourceGroup(); void WriteWinRTReferences(); void WriteWinRTPackageCertificateKeyFile(); @@ -126,6 +127,16 @@ private: void OutputLinkIncremental(std::string const& configName); void WriteCustomRule(cmSourceFile const* source, cmCustomCommand const& command); + void WriteCustomRuleCpp(std::string const& config, std::string const& script, + std::string const& inputs, + std::string const& outputs, + std::string const& comment); + void WriteCustomRuleCSharp(std::string const& config, + std::string const& commandName, + std::string const& script, + std::string const& inputs, + std::string const& outputs, + std::string const& comment); void WriteCustomCommands(); void WriteCustomCommand(cmSourceFile const* sf); void WriteGroups(); @@ -153,6 +164,12 @@ private: bool ForceOld(const std::string& source) const; + void GetCSharpSourceProperties(cmSourceFile const* sf, + std::map<std::string, std::string>& tags); + void WriteCSharpSourceProperties( + const std::map<std::string, std::string>& tags); + void GetCSharpSourceLink(cmSourceFile const* sf, std::string& link); + private: typedef cmVisualStudioGeneratorOptions Options; typedef std::map<std::string, Options*> OptionsMap; @@ -187,6 +204,7 @@ private: cmGeneratedFileStream* BuildFileStream; cmLocalVisualStudio7Generator* LocalGenerator; std::set<cmSourceFile const*> SourcesVisited; + std::set<std::string> CSharpCustomCommandNames; bool IsMissingFiles; std::vector<std::string> AddedFiles; std::string DefaultArtifactDir; diff --git a/Source/cmXCodeScheme.cxx b/Source/cmXCodeScheme.cxx index 5c22531..bca39af 100644 --- a/Source/cmXCodeScheme.cxx +++ b/Source/cmXCodeScheme.cxx @@ -10,13 +10,12 @@ #include "cmGeneratorTarget.h" #include "cmXMLSafe.h" -cmXCodeScheme::cmXCodeScheme(cmXCodeObject* xcObj, +cmXCodeScheme::cmXCodeScheme(cmXCodeObject* xcObj, const TestObjects& tests, const std::vector<std::string>& configList, unsigned int xcVersion) : Target(xcObj) + , Tests(tests) , TargetName(xcObj->GetTarget()->GetName()) - , BuildableName(xcObj->GetTarget()->GetFullName()) - , TargetId(xcObj->GetId()) , ConfigList(configList) , XcodeVersion(xcVersion) { @@ -58,7 +57,7 @@ void cmXCodeScheme::WriteXCodeXCScheme(std::ostream& fout, xout.Attribute("version", "1.3"); WriteBuildAction(xout, container); - WriteTestAction(xout, FindConfiguration("Debug")); + WriteTestAction(xout, FindConfiguration("Debug"), container); WriteLaunchAction(xout, FindConfiguration("Debug"), container); WriteProfileAction(xout, FindConfiguration("Release")); WriteAnalyzeAction(xout, FindConfiguration("Debug")); @@ -84,14 +83,7 @@ void cmXCodeScheme::WriteBuildAction(cmXMLWriter& xout, xout.Attribute("buildForArchiving", "YES"); xout.Attribute("buildForAnalyzing", "YES"); - xout.StartElement("BuildableReference"); - xout.BreakAttributes(); - xout.Attribute("BuildableIdentifier", "primary"); - xout.Attribute("BlueprintIdentifier", this->TargetId); - xout.Attribute("BuildableName", this->BuildableName); - xout.Attribute("BlueprintName", this->TargetName); - xout.Attribute("ReferencedContainer", "container:" + container); - xout.EndElement(); + WriteBuildableReference(xout, this->Target, container); xout.EndElement(); // BuildActionEntry xout.EndElement(); // BuildActionEntries @@ -99,7 +91,8 @@ void cmXCodeScheme::WriteBuildAction(cmXMLWriter& xout, } void cmXCodeScheme::WriteTestAction(cmXMLWriter& xout, - std::string configuration) + std::string configuration, + const std::string& container) { xout.StartElement("TestAction"); xout.BreakAttributes(); @@ -111,8 +104,22 @@ void cmXCodeScheme::WriteTestAction(cmXMLWriter& xout, xout.Attribute("shouldUseLaunchSchemeArgsEnv", "YES"); xout.StartElement("Testables"); + for (TestObjects::const_iterator it = this->Tests.begin(); + it != this->Tests.end(); ++it) { + xout.StartElement("TestableReference"); + xout.BreakAttributes(); + xout.Attribute("skipped", "NO"); + WriteBuildableReference(xout, *it, container); + xout.EndElement(); // TestableReference + } xout.EndElement(); + if (IsTestable()) { + xout.StartElement("MacroExpansion"); + WriteBuildableReference(xout, this->Target, container); + xout.EndElement(); // MacroExpansion + } + xout.StartElement("AdditionalOptions"); xout.EndElement(); @@ -146,14 +153,7 @@ void cmXCodeScheme::WriteLaunchAction(cmXMLWriter& xout, xout.StartElement("MacroExpansion"); } - xout.StartElement("BuildableReference"); - xout.BreakAttributes(); - xout.Attribute("BuildableIdentifier", "primary"); - xout.Attribute("BlueprintIdentifier", this->TargetId); - xout.Attribute("BuildableName", this->BuildableName); - xout.Attribute("BlueprintName", this->TargetName); - xout.Attribute("ReferencedContainer", "container:" + container); - xout.EndElement(); + WriteBuildableReference(xout, this->Target, container); xout.EndElement(); // MacroExpansion @@ -195,6 +195,20 @@ void cmXCodeScheme::WriteArchiveAction(cmXMLWriter& xout, xout.EndElement(); } +void cmXCodeScheme::WriteBuildableReference(cmXMLWriter& xout, + const cmXCodeObject* xcObj, + const std::string& container) +{ + xout.StartElement("BuildableReference"); + xout.BreakAttributes(); + xout.Attribute("BuildableIdentifier", "primary"); + xout.Attribute("BlueprintIdentifier", xcObj->GetId()); + xout.Attribute("BuildableName", xcObj->GetTarget()->GetFullName()); + xout.Attribute("BlueprintName", xcObj->GetTarget()->GetName()); + xout.Attribute("ReferencedContainer", "container:" + container); + xout.EndElement(); +} + std::string cmXCodeScheme::WriteVersionString() { std::ostringstream v; @@ -215,6 +229,11 @@ std::string cmXCodeScheme::FindConfiguration(const std::string& name) return name; } +bool cmXCodeScheme::IsTestable() const +{ + return !this->Tests.empty() || IsExecutable(this->Target); +} + bool cmXCodeScheme::IsExecutable(const cmXCodeObject* target) { cmGeneratorTarget* gt = target->GetTarget(); diff --git a/Source/cmXCodeScheme.h b/Source/cmXCodeScheme.h index 379afed..def75b1 100644 --- a/Source/cmXCodeScheme.h +++ b/Source/cmXCodeScheme.h @@ -5,6 +5,8 @@ #include "cmConfigure.h" // IWYU pragma: keep +#include <vector> + #include "cmGlobalXCodeGenerator.h" #include "cmSystemTools.h" #include "cmXCodeObject.h" @@ -16,7 +18,9 @@ class cmXCodeScheme { public: - cmXCodeScheme(cmXCodeObject* xcObj, + typedef std::vector<const cmXCodeObject*> TestObjects; + + cmXCodeScheme(cmXCodeObject* xcObj, const TestObjects& tests, const std::vector<std::string>& configList, unsigned int xcVersion); @@ -25,25 +29,30 @@ public: private: const cmXCodeObject* const Target; + const TestObjects Tests; const std::string& TargetName; - const std::string BuildableName; - const std::string& TargetId; const std::vector<std::string>& ConfigList; const unsigned int XcodeVersion; void WriteXCodeXCScheme(std::ostream& fout, const std::string& container); void WriteBuildAction(cmXMLWriter& xout, const std::string& container); - void WriteTestAction(cmXMLWriter& xout, std::string configuration); + void WriteTestAction(cmXMLWriter& xout, std::string configuration, + const std::string& container); void WriteLaunchAction(cmXMLWriter& xout, std::string configuration, const std::string& container); void WriteProfileAction(cmXMLWriter& xout, std::string configuration); void WriteAnalyzeAction(cmXMLWriter& xout, std::string configuration); void WriteArchiveAction(cmXMLWriter& xout, std::string configuration); + void WriteBuildableReference(cmXMLWriter& xout, const cmXCodeObject* xcObj, + const std::string& container); + std::string WriteVersionString(); std::string FindConfiguration(const std::string& name); + bool IsTestable() const; + static bool IsExecutable(const cmXCodeObject* target); }; diff --git a/Source/cm_sys_stat.h b/Source/cm_sys_stat.h index 26e4baa..796f027 100644 --- a/Source/cm_sys_stat.h +++ b/Source/cm_sys_stat.h @@ -7,6 +7,11 @@ typedef unsigned short mode_t; #endif +#if defined(WIN32) +typedef unsigned short uid_t; +typedef unsigned short gid_t; +#endif + #include <sys/types.h> // include sys/stat.h after sys/types.h #include <sys/stat.h> diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index c5a6836..dd88083 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -15,6 +15,11 @@ #ifdef CMAKE_BUILD_WITH_CMAKE #include "cmDocumentation.h" #include "cmDynamicLoader.h" +#ifdef _WIN32 +#include <fcntl.h> /* _O_TEXT */ +#include <stdlib.h> /* _set_fmode, _fmode */ +#endif +#include "cm_uv.h" #endif #include "cmsys/Encoding.hxx" @@ -26,14 +31,6 @@ #include <string> #include <vector> -#ifdef CMAKE_USE_LIBUV -#ifdef _WIN32 -#include <fcntl.h> /* _O_TEXT */ -#include <stdlib.h> /* _set_fmode, _fmode */ -#endif -#include "cm_uv.h" -#endif - #ifdef CMAKE_BUILD_WITH_CMAKE static const char* cmDocumentationName[][2] = { { CM_NULLPTR, " cmake - Cross-Platform Makefile Generator." }, @@ -172,7 +169,7 @@ int main(int ac, char const* const* av) ac = args.argc(); av = args.argv(); -#if defined(CMAKE_USE_LIBUV) && defined(_WIN32) +#if defined(CMAKE_BUILD_WITH_CMAKE) && defined(_WIN32) // Perform libuv one-time initialization now, and then un-do its // global _fmode setting so that using libuv does not change the // default file text/binary mode. See libuv issue 840. @@ -197,8 +194,6 @@ int main(int ac, char const* const* av) int ret = do_cmake(ac, av); #ifdef CMAKE_BUILD_WITH_CMAKE cmDynamicLoader::FlushCache(); -#endif -#ifdef CMAKE_USE_LIBUV uv_loop_close(uv_default_loop()); #endif return ret; diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index d5b0861..c546c7e 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -44,6 +44,8 @@ #include <stdlib.h> #include <time.h> +class cmConnection; + int cmcmd_cmake_ninja_depends(std::vector<std::string>::const_iterator argBeg, std::vector<std::string>::const_iterator argEnd); int cmcmd_cmake_ninja_dyndep(std::vector<std::string>::const_iterator argBeg, @@ -88,6 +90,11 @@ void CMakeCommandUsage(const char* program) << " environment - display the current environment\n" << " make_directory <dir>... - create parent and <dir> directories\n" << " md5sum <file>... - create MD5 checksum of files\n" + << " sha1sum <file>... - create SHA1 checksum of files\n" + << " sha224sum <file>... - create SHA224 checksum of files\n" + << " sha256sum <file>... - create SHA256 checksum of files\n" + << " sha384sum <file>... - create SHA384 checksum of files\n" + << " sha512sum <file>... - create SHA512 checksum of files\n" << " remove [-f] <file>... - remove the file(s), use -f to force " "it\n" << " remove_directory dir - remove a directory and its contents\n" @@ -641,24 +648,28 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args) // Command to calculate the md5sum of a file if (args[1] == "md5sum" && args.size() >= 3) { - char md5out[32]; - int retval = 0; - for (std::string::size_type cc = 2; cc < args.size(); cc++) { - const char* filename = args[cc].c_str(); - // Cannot compute md5sum of a directory - if (cmSystemTools::FileIsDirectory(filename)) { - std::cerr << "Error: " << filename << " is a directory" << std::endl; - retval++; - } else if (!cmSystemTools::ComputeFileMD5(filename, md5out)) { - // To mimic md5sum behavior in a shell: - std::cerr << filename << ": No such file or directory" << std::endl; - retval++; - } else { - std::cout << std::string(md5out, 32) << " " << filename - << std::endl; - } - } - return retval; + return HashSumFile(args, cmCryptoHash::AlgoMD5); + } + + // Command to calculate the sha1sum of a file + if (args[1] == "sha1sum" && args.size() >= 3) { + return HashSumFile(args, cmCryptoHash::AlgoSHA1); + } + + if (args[1] == "sha224sum" && args.size() >= 3) { + return HashSumFile(args, cmCryptoHash::AlgoSHA224); + } + + if (args[1] == "sha256sum" && args.size() >= 3) { + return HashSumFile(args, cmCryptoHash::AlgoSHA256); + } + + if (args[1] == "sha384sum" && args.size() >= 3) { + return HashSumFile(args, cmCryptoHash::AlgoSHA384); + } + + if (args[1] == "sha512sum" && args.size() >= 3) { + return HashSumFile(args, cmCryptoHash::AlgoSHA512); } // Command to change directory and run a program. @@ -1013,7 +1024,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args) } } #if defined(HAVE_SERVER_MODE) && HAVE_SERVER_MODE - cmServerConnection* conn; + cmConnection* conn; if (isDebug) { conn = new cmServerStdIoConnection; } else { @@ -1074,6 +1085,33 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args) return 1; } +int cmcmd::HashSumFile(std::vector<std::string>& args, cmCryptoHash::Algo algo) +{ + if (args.size() < 3) { + return -1; + } + int retval = 0; + + for (std::string::size_type cc = 2; cc < args.size(); cc++) { + const char* filename = args[cc].c_str(); + // Cannot compute sum of a directory + if (cmSystemTools::FileIsDirectory(filename)) { + std::cerr << "Error: " << filename << " is a directory" << std::endl; + retval++; + } else { + std::string value = cmSystemTools::ComputeFileHash(filename, algo); + if (value.empty()) { + // To mimic "md5sum/shasum" behavior in a shell: + std::cerr << filename << ": No such file or directory" << std::endl; + retval++; + } else { + std::cout << value << " " << filename << std::endl; + } + } + } + return retval; +} + int cmcmd::SymlinkLibrary(std::vector<std::string>& args) { int result = 0; diff --git a/Source/cmcmd.h b/Source/cmcmd.h index 929f1ae..faac1d2 100644 --- a/Source/cmcmd.h +++ b/Source/cmcmd.h @@ -4,6 +4,7 @@ #define cmcmd_h #include "cmConfigure.h" // IWYU pragma: keep +#include "cmCryptoHash.h" #include <string> #include <vector> @@ -18,6 +19,8 @@ public: static int ExecuteCMakeCommand(std::vector<std::string>&); protected: + static int HashSumFile(std::vector<std::string>& args, + cmCryptoHash::Algo algo); static int SymlinkLibrary(std::vector<std::string>& args); static int SymlinkExecutable(std::vector<std::string>& args); static bool SymlinkInternal(std::string const& file, diff --git a/Source/ctest.cxx b/Source/ctest.cxx index 84e815d..8f9e676 100644 --- a/Source/ctest.cxx +++ b/Source/ctest.cxx @@ -83,6 +83,8 @@ static const char* cmDocumentationOptions[][2] = { { "--max-width <width>", "Set the max width for a test name to output" }, { "--interactive-debug-mode [0|1]", "Set the interactive mode to 0 or 1." }, { "--no-label-summary", "Disable timing summary information for labels." }, + { "--no-subproject-summary", "Disable timing summary information for " + "subprojects." }, { "--build-and-test", "Configure, build and run a test." }, { "--build-target", "Specify a specific target to build." }, { "--build-nocmake", "Run the build without running cmake first." }, diff --git a/Source/kwsys/CMakeLists.txt b/Source/kwsys/CMakeLists.txt index e915b1a..d7d0c51 100644 --- a/Source/kwsys/CMakeLists.txt +++ b/Source/kwsys/CMakeLists.txt @@ -20,6 +20,21 @@ # KWSYS_HEADER_ROOT = The directory into which to generate the kwsys headers. # A directory called "${KWSYS_NAMESPACE}" will be # created under this root directory to hold the files. +# KWSYS_SPLIT_OBJECTS_FROM_INTERFACE +# = Instead of creating a single ${KWSYS_NAMESPACE} library +# target, create three separate targets: +# ${KWSYS_NAMESPACE} +# - An INTERFACE library only containing usage +# requirements. +# ${KWSYS_NAMESPACE}_objects +# - An OBJECT library for the built kwsys objects. +# Note: This is omitted from the install rules +# ${KWSYS_NAMESPACE}_private +# - An INTERFACE library combining both that is +# appropriate for use with PRIVATE linking in +# target_link_libraries. Because of how interface +# properties propagate, this target is not suitable +# for use with PUBLIC or INTERFACE linking. # # Example: # @@ -79,6 +94,10 @@ FOREACH(p ENDFOREACH() SET(CMAKE_LEGACY_CYGWIN_WIN32 0) +IF(CMAKE_VERSION VERSION_LESS 3.0) + SET(KWSYS_SPLIT_OBJECTS_FROM_INTERFACE 0) +ENDIF() + #----------------------------------------------------------------------------- # If a namespace is not specified, use "kwsys" and enable testing. # This should be the case only when kwsys is not included inside @@ -430,6 +449,11 @@ SET_SOURCE_FILES_PROPERTIES(ProcessUNIX.c System.c PROPERTIES COMPILE_FLAGS "-DKWSYS_C_HAS_PTRDIFF_T=${KWSYS_C_HAS_PTRDIFF_T} -DKWSYS_C_HAS_SSIZE_T=${KWSYS_C_HAS_SSIZE_T}" ) +IF(DEFINED KWSYS_PROCESS_USE_SELECT) + GET_PROPERTY(ProcessUNIX_FLAGS SOURCE ProcessUNIX.c PROPERTY COMPILE_FLAGS) + SET_PROPERTY(SOURCE ProcessUNIX.c PROPERTY COMPILE_FLAGS "${ProcessUNIX_FLAGS} -DKWSYSPE_USE_SELECT=${KWSYSPE_USE_SELECT}") +ENDIF() + IF(KWSYS_USE_DynamicLoader) GET_PROPERTY(KWSYS_SUPPORTS_SHARED_LIBS GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS) IF(KWSYS_SUPPORTS_SHARED_LIBS) @@ -795,68 +819,144 @@ ENDFOREACH() #----------------------------------------------------------------------------- # Add the library with the configured name and list of sources. IF(KWSYS_C_SRCS OR KWSYS_CXX_SRCS) - ADD_LIBRARY(${KWSYS_NAMESPACE} ${KWSYS_LIBRARY_TYPE} - ${KWSYS_C_SRCS} ${KWSYS_CXX_SRCS}) - SET_PROPERTY(TARGET ${KWSYS_NAMESPACE} PROPERTY C_CLANG_TIDY "") - SET_PROPERTY(TARGET ${KWSYS_NAMESPACE} PROPERTY CXX_CLANG_TIDY "") - SET_PROPERTY(TARGET ${KWSYS_NAMESPACE} PROPERTY C_INCLUDE_WHAT_YOU_USE "") - SET_PROPERTY(TARGET ${KWSYS_NAMESPACE} PROPERTY CXX_INCLUDE_WHAT_YOU_USE "") - SET_PROPERTY(TARGET ${KWSYS_NAMESPACE} PROPERTY LABELS ${KWSYS_LABELS_LIB}) + IF(KWSYS_SPLIT_OBJECTS_FROM_INTERFACE) + SET(KWSYS_TARGET_INTERFACE ${KWSYS_NAMESPACE}) + SET(KWSYS_TARGET_OBJECT ${KWSYS_NAMESPACE}_objects) + SET(KWSYS_TARGET_LINK ${KWSYS_NAMESPACE}_private) + SET(KWSYS_TARGET_INSTALL ${KWSYS_TARGET_INTERFACE} ${KWSYS_TARGET_LINK}) + SET(KWSYS_LINK_DEPENDENCY INTERFACE) + ADD_LIBRARY(${KWSYS_TARGET_OBJECT} OBJECT + ${KWSYS_C_SRCS} ${KWSYS_CXX_SRCS}) + IF(KWSYS_BUILD_SHARED) + SET_PROPERTY(TARGET ${KWSYS_TARGET_OBJECT} PROPERTY + POSITION_INDEPENDENT_CODE TRUE) + ENDIF() + ADD_LIBRARY(${KWSYS_TARGET_INTERFACE} INTERFACE) + ADD_LIBRARY(${KWSYS_TARGET_LINK} INTERFACE) + TARGET_LINK_LIBRARIES(${KWSYS_TARGET_LINK} INTERFACE + ${KWSYS_TARGET_INTERFACE}) + TARGET_SOURCES(${KWSYS_TARGET_LINK} INTERFACE + $<TARGET_OBJECTS:${KWSYS_TARGET_OBJECT}>) + ELSE() + SET(KWSYS_TARGET_INTERFACE ${KWSYS_NAMESPACE}) + SET(KWSYS_TARGET_OBJECT ${KWSYS_NAMESPACE}) + SET(KWSYS_TARGET_LINK ${KWSYS_NAMESPACE}) + set(KWSYS_TARGET_INSTALL ${KWSYS_TARGET_LINK}) + SET(KWSYS_LINK_DEPENDENCY PUBLIC) + ADD_LIBRARY(${KWSYS_TARGET_INTERFACE} ${KWSYS_LIBRARY_TYPE} + ${KWSYS_C_SRCS} ${KWSYS_CXX_SRCS}) + ENDIF() + SET_TARGET_PROPERTIES(${KWSYS_TARGET_OBJECT} PROPERTIES + C_CLANG_TIDY "" + CXX_CLANG_TIDY "" + C_INCLUDE_WHAT_YOU_USE "" + CXX_INCLUDE_WHAT_YOU_USE "" + LABELS "${KWSYS_LABELS_LIB}") IF(KWSYS_USE_DynamicLoader) IF(UNIX) - TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} ${CMAKE_DL_LIBS}) + TARGET_LINK_LIBRARIES(${KWSYS_TARGET_INTERFACE} ${KWSYS_LINK_DEPENDENCY} + ${CMAKE_DL_LIBS}) ENDIF() ENDIF() IF(KWSYS_USE_SystemInformation) IF(WIN32) - TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} ws2_32) + TARGET_LINK_LIBRARIES(${KWSYS_TARGET_INTERFACE} ${KWSYS_LINK_DEPENDENCY} ws2_32) IF(KWSYS_SYS_HAS_PSAPI) - TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} Psapi) + TARGET_LINK_LIBRARIES(${KWSYS_TARGET_INTERFACE} ${KWSYS_LINK_DEPENDENCY} + Psapi) ENDIF() ELSEIF(UNIX) IF (EXECINFO_LIB AND KWSYS_CXX_HAS_BACKTRACE) # backtrace on FreeBSD is not in libc - TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} ${EXECINFO_LIB}) + TARGET_LINK_LIBRARIES(${KWSYS_TARGET_INTERFACE} ${KWSYS_LINK_DEPENDENCY} + ${EXECINFO_LIB}) ENDIF() IF (KWSYS_CXX_HAS_DLADDR) # for symbol lookup using dladdr - TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} ${CMAKE_DL_LIBS}) + TARGET_LINK_LIBRARIES(${KWSYS_TARGET_INTERFACE} ${KWSYS_LINK_DEPENDENCY} + ${CMAKE_DL_LIBS}) ENDIF() IF (CMAKE_SYSTEM_NAME STREQUAL "SunOS") - TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} socket) + TARGET_LINK_LIBRARIES(${KWSYS_TARGET_INTERFACE} ${KWSYS_LINK_DEPENDENCY} + socket) ENDIF() ENDIF() ENDIF() # Apply user-defined target properties to the library. IF(KWSYS_PROPERTIES_CXX) - SET_TARGET_PROPERTIES(${KWSYS_NAMESPACE} PROPERTIES - ${KWSYS_PROPERTIES_CXX} - ) + SET_TARGET_PROPERTIES(${KWSYS_TARGET_INTERFACE} PROPERTIES + ${KWSYS_PROPERTIES_CXX}) + ENDIF() + + # Set up include usage requirement + IF(COMMAND TARGET_INCLUDE_DIRECTORIES) + TARGET_INCLUDE_DIRECTORIES(${KWSYS_TARGET_INTERFACE} INTERFACE + $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>) + IF(KWSYS_INSTALL_INCLUDE_DIR) + TARGET_INCLUDE_DIRECTORIES(${KWSYS_TARGET_INTERFACE} INTERFACE + $<INSTALL_INTERFACE:${KWSYS_INSTALL_INCLUDE_DIR}>) + ENDIF() ENDIF() # Create an install target for the library. IF(KWSYS_INSTALL_LIBRARY_RULE) - INSTALL(TARGETS ${KWSYS_NAMESPACE} ${KWSYS_INSTALL_LIBRARY_RULE}) + INSTALL(TARGETS ${KWSYS_TARGET_INSTALL} ${KWSYS_INSTALL_LIBRARY_RULE}) ENDIF() ENDIF() # Add a C-only library if requested. IF(KWSYS_ENABLE_C AND KWSYS_C_SRCS) - ADD_LIBRARY(${KWSYS_NAMESPACE}_c ${KWSYS_LIBRARY_TYPE} ${KWSYS_C_SRCS}) - SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}_c PROPERTY LABELS ${KWSYS_LABELS_LIB}) + IF(KWSYS_SPLIT_OBJECTS_FROM_INTERFACE) + SET(KWSYS_TARGET_C_INTERFACE ${KWSYS_NAMESPACE}_c) + SET(KWSYS_TARGET_C_OBJECT ${KWSYS_NAMESPACE}_c_objects) + SET(KWSYS_TARGET_C_LINK ${KWSYS_NAMESPACE}_c_private) + SET(KWSYS_TARGET_C_INSTALL + ${KWSYS_TARGET_C_INTERFACE} ${KWSYS_TARGET_C_LINK}) + SET(KWSYS_LINK_DEPENDENCY INTERFACE) + ADD_LIBRARY(${KWSYS_TARGET_C_OBJECT} OBJECT ${KWSYS_C_SRCS}) + IF(KWSYS_BUILD_SHARED) + SET_PROPERTY(TARGET ${KWSYS_TARGET_C_OBJECT} PROPERTY + POSITION_INDEPENDENT_CODE TRUE) + ENDIF() + ADD_LIBRARY(${KWSYS_TARGET_C_INTERFACE} INTERFACE) + ADD_LIBRARY(${KWSYS_TARGET_C_LINK} INTERFACE) + TARGET_LINK_LIBRARIES(${KWSYS_TARGET_C_LINK} INTERFACE + ${KWSYS_TARGET_C_INTERFACE}) + TARGET_SOURCES(${KWSYS_TARGET_C_LINK} INTERFACE + $<TARGET_OBJECTS:${KWSYS_TARGET_C_OBJECT}>) + ELSE() + SET(KWSYS_TARGET_C_INTERFACE ${KWSYS_NAMESPACE}_c) + SET(KWSYS_TARGET_C_OBJECT ${KWSYS_NAMESPACE}_c) + SET(KWSYS_TARGET_C_LINK ${KWSYS_NAMESPACE}_c) + SET(KWSYS_TARGET_C_INSTALL ${KWSYS_TARGET_C_LINK}) + SET(KWSYS_LINK_DEPENDENCY PUBLIC) + ADD_LIBRARY(${KWSYS_TARGET_C_INTERFACE} ${KWSYS_LIBRARY_TYPE} + ${KWSYS_C_SRCS}) + ENDIF() + SET_TARGET_PROPERTIES(${KWSYS_TARGET_C_OBJECT} PROPERTIES + LABELS "${KWSYS_LABELS_LIB}") # Apply user-defined target properties to the library. IF(KWSYS_PROPERTIES_C) - SET_TARGET_PROPERTIES(${KWSYS_NAMESPACE}_c PROPERTIES - ${KWSYS_PROPERTIES_C} - ) + SET_TARGET_PROPERTIES(${KWSYS_TARGET_C_INTERFACE} PROPERTIES + ${KWSYS_PROPERTIES_C}) + ENDIF() + + # Set up include usage requirement + IF(COMMAND TARGET_INCLUDE_DIRECTORIES) + TARGET_INCLUDE_DIRECTORIES(${KWSYS_TARGET_C_INTERFACE} INTERFACE + $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>) + IF(KWSYS_INSTALL_INCLUDE_DIR) + TARGET_INCLUDE_DIRECTORIES(${KWSYS_TARGET_C_INTERFACE} INTERFACE + $<INSTALL_INTERFACE:${KWSYS_INSTALL_INCLUDE_DIR}>) + ENDIF() ENDIF() # Create an install target for the library. IF(KWSYS_INSTALL_LIBRARY_RULE) - INSTALL(TARGETS ${KWSYS_NAMESPACE}_c ${KWSYS_INSTALL_LIBRARY_RULE}) + INSTALL(TARGETS ${KWSYS_TARGET_C_INSTALL}) ENDIF() ENDIF() @@ -915,7 +1015,7 @@ 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_NAMESPACE}_c) + TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE}TestsC ${KWSYS_TARGET_C_LINK}) FOREACH(test ${KWSYS_C_TESTS}) ADD_TEST(kwsys.${test} ${EXEC_DIR}/${KWSYS_NAMESPACE}TestsC ${test} ${KWSYS_TEST_ARGS_${test}}) SET_PROPERTY(TEST kwsys.${test} PROPERTY LABELS ${KWSYS_LABELS_TEST}) @@ -950,7 +1050,7 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR) SET_PROPERTY(TARGET testConsoleBufChild PROPERTY C_INCLUDE_WHAT_YOU_USE "") SET_PROPERTY(TARGET testConsoleBufChild PROPERTY CXX_INCLUDE_WHAT_YOU_USE "") SET_PROPERTY(TARGET testConsoleBufChild PROPERTY LABELS ${KWSYS_LABELS_EXE}) - TARGET_LINK_LIBRARIES(testConsoleBufChild ${KWSYS_NAMESPACE}) + TARGET_LINK_LIBRARIES(testConsoleBufChild ${KWSYS_TARGET_LINK}) SET(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS} testConsoleBuf ) @@ -969,7 +1069,7 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR) # If kwsys contains the DynamicLoader, need extra library ADD_LIBRARY(${KWSYS_NAMESPACE}TestDynload MODULE testDynload.c) SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}TestDynload PROPERTY LABELS ${KWSYS_LABELS_LIB}) - ADD_DEPENDENCIES(${KWSYS_NAMESPACE}TestDynload ${KWSYS_NAMESPACE}) + ADD_DEPENDENCIES(${KWSYS_NAMESPACE}TestDynload ${KWSYS_TARGET_INTERFACE}) ENDIF() CREATE_TEST_SOURCELIST( KWSYS_CXX_TEST_SRCS ${KWSYS_NAMESPACE}TestsCxx.cxx @@ -981,7 +1081,7 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR) SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}TestsCxx PROPERTY C_INCLUDE_WHAT_YOU_USE "") 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_NAMESPACE}) + TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE}TestsCxx ${KWSYS_TARGET_LINK}) SET(TEST_SYSTEMTOOLS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") SET(TEST_SYSTEMTOOLS_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}") @@ -1032,7 +1132,7 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR) # Process tests. ADD_EXECUTABLE(${KWSYS_NAMESPACE}TestProcess testProcess.c) SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}TestProcess PROPERTY LABELS ${KWSYS_LABELS_EXE}) - TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE}TestProcess ${KWSYS_NAMESPACE}_c) + TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE}TestProcess ${KWSYS_TARGET_C_LINK}) IF(NOT CYGWIN) SET(KWSYS_TEST_PROCESS_7 7) ENDIF() @@ -1060,7 +1160,7 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR) 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_NAMESPACE}_c) + 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}) diff --git a/Source/kwsys/ProcessUNIX.c b/Source/kwsys/ProcessUNIX.c index 9ebcfce..3b32ca7 100644 --- a/Source/kwsys/ProcessUNIX.c +++ b/Source/kwsys/ProcessUNIX.c @@ -99,7 +99,8 @@ static inline void kwsysProcess_usleep(unsigned int msec) * pipes' file handles to be non-blocking and just poll them directly * without select(). */ -#if !defined(__BEOS__) && !defined(__VMS) && !defined(__MINT__) +#if !defined(__BEOS__) && !defined(__VMS) && !defined(__MINT__) && \ + !defined(KWSYSPE_USE_SELECT) #define KWSYSPE_USE_SELECT 1 #endif diff --git a/Source/kwsys/RegularExpression.cxx b/Source/kwsys/RegularExpression.cxx index 6d7f832..26e84e0 100644 --- a/Source/kwsys/RegularExpression.cxx +++ b/Source/kwsys/RegularExpression.cxx @@ -258,11 +258,6 @@ const unsigned char MAGIC = 0234; #define UCHARAT(p) (reinterpret_cast<const unsigned char*>(p))[0] -#define FAIL(m) \ - { \ - regerror(m); \ - return (0); \ - } #define ISMULT(c) ((c) == '*' || (c) == '+' || (c) == '?') #define META "^$.[()|?+*\\" diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index 1c4fe33..11f3b81 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -22,7 +22,6 @@ #include KWSYS_HEADER(FStream.hxx) #include KWSYS_HEADER(Encoding.hxx) -#include <algorithm> #include <fstream> #include <iostream> #include <set> @@ -848,6 +847,8 @@ void SystemTools::ReplaceString(std::string& source, const char* replace, free(orig); } +#if defined(_WIN32) && !defined(__CYGWIN__) + #if defined(KEY_WOW64_32KEY) && defined(KEY_WOW64_64KEY) #define KWSYS_ST_KEY_WOW64_32KEY KEY_WOW64_32KEY #define KWSYS_ST_KEY_WOW64_64KEY KEY_WOW64_64KEY @@ -856,7 +857,6 @@ void SystemTools::ReplaceString(std::string& source, const char* replace, #define KWSYS_ST_KEY_WOW64_64KEY 0x0100 #endif -#if defined(_WIN32) && !defined(__CYGWIN__) static bool SystemToolsParseRegistryKey(const std::string& key, HKEY& primaryKey, std::string& second, std::string& valuename) @@ -3709,16 +3709,6 @@ std::string SystemTools::JoinPath( return result; } -void SystemTools::RemoveEmptyPathElements(std::vector<std::string>& path) -{ - if (path.empty()) { - return; - } - - path.erase(std::remove(path.begin() + 1, path.end(), std::string("")), - path.end()); -} - bool SystemTools::ComparePath(const std::string& c1, const std::string& c2) { #if defined(_WIN32) || defined(__APPLE__) @@ -3807,11 +3797,7 @@ std::string SystemTools::GetFilenamePath(const std::string& filename) */ std::string SystemTools::GetFilenameName(const std::string& filename) { -#if defined(_WIN32) std::string::size_type slash_pos = filename.find_last_of("/\\"); -#else - std::string::size_type slash_pos = filename.rfind('/'); -#endif if (slash_pos != std::string::npos) { return filename.substr(slash_pos + 1); } else { diff --git a/Source/kwsys/SystemTools.hxx.in b/Source/kwsys/SystemTools.hxx.in index 5e091c2..1672e92 100644 --- a/Source/kwsys/SystemTools.hxx.in +++ b/Source/kwsys/SystemTools.hxx.in @@ -461,6 +461,10 @@ public: * produce the original path. Home directory references are * automatically expanded if expand_home_dir is true and this * platform supports them. + * + * This does *not* normalize the input path. All components are + * preserved, including empty ones. Typically callers should use + * this only on paths that have already been normalized. */ static void SplitPath(const std::string& p, std::vector<std::string>& components, @@ -469,15 +473,15 @@ public: /** * Join components of a path name into a single string. See * SplitPath for the format of the components. + * + * This does *not* normalize the input path. All components are + * preserved, including empty ones. Typically callers should use + * this only on paths that have already been normalized. */ static std::string JoinPath(const std::vector<std::string>& components); static std::string JoinPath(std::vector<std::string>::const_iterator first, std::vector<std::string>::const_iterator last); - /** Removes empty components from path. - */ - static void RemoveEmptyPathElements(std::vector<std::string>& path); - /** * Compare a path or components of a path. */ diff --git a/Source/kwsys/testSystemTools.cxx b/Source/kwsys/testSystemTools.cxx index e6fbf6c..1871f5d 100644 --- a/Source/kwsys/testSystemTools.cxx +++ b/Source/kwsys/testSystemTools.cxx @@ -758,6 +758,30 @@ static bool CheckGetPath() return res; } +static bool CheckGetFilenameName() +{ + const char* windowsFilepath = "C:\\somewhere\\something"; + const char* unixFilepath = "/somewhere/something"; + + std::string expectedFilename = "something"; + + bool res = true; + std::string filename = kwsys::SystemTools::GetFilenameName(windowsFilepath); + if (filename != expectedFilename) { + std::cerr << "GetFilenameName(" << windowsFilepath << ") yielded " + << filename << " instead of " << expectedFilename << std::endl; + res = false; + } + + filename = kwsys::SystemTools::GetFilenameName(unixFilepath); + if (filename != expectedFilename) { + std::cerr << "GetFilenameName(" << unixFilepath << ") yielded " << filename + << " instead of " << expectedFilename << std::endl; + res = false; + } + return res; +} + static bool CheckFind() { bool res = true; @@ -875,5 +899,7 @@ int testSystemTools(int, char* []) res &= CheckGetLineFromStream(); + res &= CheckGetFilenameName(); + return res ? 0 : 1; } diff --git a/Tests/AliasTarget/CMakeLists.txt b/Tests/AliasTarget/CMakeLists.txt index e156420..fc70135 100644 --- a/Tests/AliasTarget/CMakeLists.txt +++ b/Tests/AliasTarget/CMakeLists.txt @@ -4,13 +4,6 @@ project(AliasTarget) set(CMAKE_CXX_STANDARD 98) -# Those versions of the HP compiler that need a flag to get proper C++98 -# template support also need a flag to use the newer C++ library. -if (CMAKE_CXX_COMPILER_ID STREQUAL HP AND - CMAKE_CXX98_STANDARD_COMPILE_OPTION STREQUAL "+hpxstd98") - string(APPEND CMAKE_CXX_FLAGS " -AA") -endif () - # Clang/C2 in C++98 mode cannot properly handle some of MSVC headers if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC") diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index d16df1c..13d796e 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1285,12 +1285,28 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release --build-exe-dir "${CMake_BINARY_DIR}/Tests/Qt5Autogen" --force-new-ctest-process --build-options ${build_options} - -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE} -DQT_TEST_VERSION=5 + -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE} + -DQT_TEST_VERSION=5 ${QtAutogen_BUILD_OPTIONS} --test-command ${run_autogen_test} ) list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Qt5Autogen") + add_test(NAME Qt5AutogenRerun COMMAND ${CMAKE_CTEST_COMMAND} + --build-and-test + "${CMake_SOURCE_DIR}/Tests/QtAutogenRerun" + "${CMake_BINARY_DIR}/Tests/Qt5AutogenRerun" + ${build_generator_args} + --build-project QtAutogenRerun + --build-exe-dir "${CMake_BINARY_DIR}/Tests/Qt5AutogenRerun" + --force-new-ctest-process + --build-options ${build_options} + -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE} + -DQT_TEST_VERSION=5 + ${QtAutogen_BUILD_OPTIONS} + ) + list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Qt5AutogenRerun") + add_test(Qt5AutoUicInterface ${CMAKE_CTEST_COMMAND} --build-and-test "${CMake_SOURCE_DIR}/Tests/QtAutoUicInterface" @@ -1315,12 +1331,28 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release --build-exe-dir "${CMake_BINARY_DIR}/Tests/Qt4Autogen" --force-new-ctest-process --build-options ${build_options} - -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE} -DQT_TEST_VERSION=4 + -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE} + -DQT_TEST_VERSION=4 ${QtAutogen_BUILD_OPTIONS} --test-command ${run_autogen_test} ) list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Qt4Autogen") + add_test(NAME Qt4AutogenRerun COMMAND ${CMAKE_CTEST_COMMAND} + --build-and-test + "${CMake_SOURCE_DIR}/Tests/QtAutogenRerun" + "${CMake_BINARY_DIR}/Tests/Qt4AutogenRerun" + ${build_generator_args} + --build-project QtAutogenRerun + --build-exe-dir "${CMake_BINARY_DIR}/Tests/Qt4AutogenRerun" + --force-new-ctest-process + --build-options ${build_options} + -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE} + -DQT_TEST_VERSION=4 + ${QtAutogen_BUILD_OPTIONS} + ) + list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Qt4AutogenRerun") + add_test(Qt4AutoUicInterface ${CMAKE_CTEST_COMMAND} --build-and-test "${CMake_SOURCE_DIR}/Tests/QtAutoUicInterface" @@ -1330,7 +1362,8 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release --build-exe-dir "${CMake_BINARY_DIR}/Tests/Qt4AutoUicInterface" --force-new-ctest-process --build-options ${build_options} - -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE} -DQT_TEST_VERSION=4 + -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE} + -DQT_TEST_VERSION=4 --test-command ${run_autouic_test} ) list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Qt4AutoUicInterface") @@ -2082,7 +2115,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release set(reg_nasm "[HKEY_CURRENT_USER\\SOFTWARE\\nasm]") foreach(reg vs10 vs11 vs12 vs14 ws80 ws81 ws10_0 wp80 wp81 wince tegra nasm) get_filename_component(r "${reg_${reg}}" ABSOLUTE) - if(IS_DIRECTORY "${r}") + if(IS_DIRECTORY "${r}" AND NOT "${r}" STREQUAL "/registry") set(${reg} 1) else() set(${reg} 0) diff --git a/Tests/CMakeTests/CMakeHostSystemInformationTest.cmake.in b/Tests/CMakeTests/CMakeHostSystemInformationTest.cmake.in index 3294a2f..a3c2b05 100644 --- a/Tests/CMakeTests/CMakeHostSystemInformationTest.cmake.in +++ b/Tests/CMakeTests/CMakeHostSystemInformationTest.cmake.in @@ -22,6 +22,25 @@ try_and_print(TOTAL_VIRTUAL_MEMORY) try_and_print(AVAILABLE_VIRTUAL_MEMORY) try_and_print(TOTAL_PHYSICAL_MEMORY) try_and_print(AVAILABLE_PHYSICAL_MEMORY) +try_and_print(IS_64BIT) +try_and_print(HAS_FPU) +try_and_print(HAS_MMX) +try_and_print(HAS_MMX_PLUS) +try_and_print(HAS_SSE) +try_and_print(HAS_SSE2) +try_and_print(HAS_SSE_FP) +try_and_print(HAS_SSE_MMX) +try_and_print(HAS_AMD_3DNOW) +try_and_print(HAS_AMD_3DNOW_PLUS) +try_and_print(HAS_IA64) +try_and_print(HAS_SERIAL_NUMBER) +try_and_print(PROCESSOR_SERIAL_NUMBER) +try_and_print(PROCESSOR_NAME) +try_and_print(PROCESSOR_DESCRIPTION) +try_and_print(OS_NAME) +try_and_print(OS_RELEASE) +try_and_print(OS_VERSION) +try_and_print(OS_PLATFORM) include("@CMAKE_CURRENT_SOURCE_DIR@/CheckCMakeTest.cmake") diff --git a/Tests/CMakeTests/PushCheckStateTest.cmake.in b/Tests/CMakeTests/PushCheckStateTest.cmake.in index b4c48f4..cbd879d 100644 --- a/Tests/CMakeTests/PushCheckStateTest.cmake.in +++ b/Tests/CMakeTests/PushCheckStateTest.cmake.in @@ -1,3 +1,4 @@ +cmake_minimum_required(VERSION 3.8) include(CMakePushCheckState) set(CMAKE_EXTRA_INCLUDE_FILES file1) @@ -26,6 +27,27 @@ set(CMAKE_REQUIRED_LIBRARIES lib3) set(CMAKE_REQUIRED_FLAGS flag3) set(CMAKE_REQUIRED_QUIET 3) +cmake_push_check_state(RESET) + +foreach(pair IN ITEMS + EXTRA_INCLUDE_FILES| + REQUIRED_INCLUDES| + REQUIRED_DEFINITIONS| + REQUIRED_LIBRARIES| + REQUIRED_FLAGS| + REQUIRED_QUIET| + ) + string(REPLACE "|" ";" pair "${pair}") + list(GET pair 0 var) + list(GET pair 1 expected) + if (NOT "${CMAKE_${var}}" STREQUAL "${expected}") + set(fatal TRUE) + message("ERROR: CMAKE_${var} is \"${CMAKE_${var}}\" (expected \"${expected}\")" ) + endif() +endforeach() + +cmake_pop_check_state() + cmake_pop_check_state() foreach(pair IN ITEMS diff --git a/Tests/CompileFeatures/CMakeLists.txt b/Tests/CompileFeatures/CMakeLists.txt index 4a5558d..b560acd 100644 --- a/Tests/CompileFeatures/CMakeLists.txt +++ b/Tests/CompileFeatures/CMakeLists.txt @@ -428,6 +428,14 @@ else() HAVE_FINAL=$<COMPILE_FEATURES:cxx_final> HAVE_INHERITING_CONSTRUCTORS_AND_FINAL=$<COMPILE_FEATURES:cxx_inheriting_constructors,cxx_final> ) + if (CMAKE_CXX_STANDARD_DEFAULT) + target_compile_definitions(CompileFeaturesGenex PRIVATE + TEST_CXX_STD + HAVE_CXX_STD_11=$<COMPILE_FEATURES:cxx_std_11> + HAVE_CXX_STD_14=$<COMPILE_FEATURES:cxx_std_14> + HAVE_CXX_STD_17=$<COMPILE_FEATURES:cxx_std_17> + ) + endif() add_executable(CompileFeaturesGenex2 genex_test.cpp) target_compile_features(CompileFeaturesGenex2 PRIVATE cxx_std_11) diff --git a/Tests/CompileFeatures/default_dialect.cpp b/Tests/CompileFeatures/default_dialect.cpp index 9b65b42..0de1125 100644 --- a/Tests/CompileFeatures/default_dialect.cpp +++ b/Tests/CompileFeatures/default_dialect.cpp @@ -2,25 +2,30 @@ template <long l> struct Outputter; +#if defined(_MSC_VER) && defined(_MSVC_LANG) +#define CXX_STD _MSVC_LANG +#else +#define CXX_STD __cplusplus +#endif + #if DEFAULT_CXX17 -#if __cplusplus <= 201402L -Outputter<__cplusplus> o; +#if CXX_STD <= 201402L +Outputter<CXX_STD> o; #endif #elif DEFAULT_CXX14 -#if __cplusplus != 201402L -Outputter<__cplusplus> o; +#if CXX_STD != 201402L +Outputter<CXX_STD> o; #endif #elif DEFAULT_CXX11 -#if __cplusplus != 201103L -Outputter<__cplusplus> o; +#if CXX_STD != 201103L +Outputter<CXX_STD> o; #endif #else #if !DEFAULT_CXX98 #error Buildsystem error #endif -#if __cplusplus != 199711L && __cplusplus != 1 && \ - !defined(__GXX_EXPERIMENTAL_CXX0X__) -Outputter<__cplusplus> o; +#if CXX_STD != 199711L && CXX_STD != 1 && !defined(__GXX_EXPERIMENTAL_CXX0X__) +Outputter<CXX_STD> o; #endif #endif diff --git a/Tests/CompileFeatures/genex_test.cpp b/Tests/CompileFeatures/genex_test.cpp index 5ae8a78..5303e73 100644 --- a/Tests/CompileFeatures/genex_test.cpp +++ b/Tests/CompileFeatures/genex_test.cpp @@ -11,6 +11,18 @@ #error EXPECT_OVERRIDE_CONTROL not defined #endif +#ifdef TEST_CXX_STD +#if !HAVE_CXX_STD_11 +#error HAVE_CXX_STD_11 is false with CXX_STANDARD == 11 +#endif +#if HAVE_CXX_STD_14 +#error HAVE_CXX_STD_14 is true with CXX_STANDARD == 11 +#endif +#if HAVE_CXX_STD_17 +#error HAVE_CXX_STD_17 is true with CXX_STANDARD == 11 +#endif +#endif + #if !HAVE_OVERRIDE_CONTROL #if EXPECT_OVERRIDE_CONTROL #error "Expect override control feature" diff --git a/Tests/Complex/CMakeLists.txt b/Tests/Complex/CMakeLists.txt index 075faa7..2e41754 100644 --- a/Tests/Complex/CMakeLists.txt +++ b/Tests/Complex/CMakeLists.txt @@ -356,6 +356,8 @@ endwhile() set(SHOULD_BE_ZERO ) set(SHOULD_BE_ONE 1) +set(SHOULD_BE_ZERO_AND_INDENTED ) +set(SHOULD_BE_ONE_AND_INDENTED 1) # test elseif functionality, the mess below tries to catch problem # of clauses being executed early or late etc @@ -438,13 +440,6 @@ set(CMAKE_CXX_STANDARD 98) # set(CMAKE_CXX_EXTENSIONS TRUE) -# Those versions of the HP compiler that need a flag to get proper C++98 -# template support also need a flag to use the newer C++ library. -if (CMAKE_CXX_COMPILER_ID STREQUAL HP AND - CMAKE_CXX98_STANDARD_COMPILE_OPTION STREQUAL "+hpxstd98") - string(APPEND CMAKE_CXX_FLAGS " -AA") -endif () - # Clang/C2 in C++98 mode cannot properly handle some of MSVC headers if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC") diff --git a/Tests/Complex/Executable/complex.cxx b/Tests/Complex/Executable/complex.cxx index 3b09229..ca39870 100644 --- a/Tests/Complex/Executable/complex.cxx +++ b/Tests/Complex/Executable/complex.cxx @@ -261,6 +261,12 @@ int main() cmPassed("ONE_VAR is defined."); #endif +#ifndef ONE_VAR_AND_INDENTED + cmFailed("cmakedefine is broken, ONE_VAR_AND_INDENTED is not defined."); +#else + cmPassed("ONE_VAR_AND_INDENTED is defined."); +#endif + #ifndef ONE_VAR_IS_DEFINED cmFailed("cmakedefine, SET or VARIABLE_REQUIRES is broken, " "ONE_VAR_IS_DEFINED is not defined."); @@ -274,6 +280,12 @@ int main() cmPassed("ZERO_VAR is not defined."); #endif +#ifdef ZERO_VAR_AND_INDENTED + cmFailed("cmakedefine is broken, ZERO_VAR_AND_INDENTED is defined."); +#else + cmPassed("ZERO_VAR_AND_INDENTED is not defined."); +#endif + #ifndef STRING_VAR cmFailed("the CONFIGURE_FILE command is broken, STRING_VAR is not defined."); #else @@ -1030,6 +1042,16 @@ int main() } else { cmFailed("cmakedefine01 is not working for 1"); } + if (SHOULD_BE_ZERO_AND_INDENTED == 0) { + cmPassed("cmakedefine01 is working for 0 and indented"); + } else { + cmFailed("cmakedefine01 is not working for 0 and indented"); + } + if (SHOULD_BE_ONE_AND_INDENTED == 1) { + cmPassed("cmakedefine01 is working for 1 and indented"); + } else { + cmFailed("cmakedefine01 is not working for 1 and indented"); + } #ifdef FORCE_TEST cmFailed("CMake SET CACHE FORCE"); #else diff --git a/Tests/Complex/VarTests.cmake b/Tests/Complex/VarTests.cmake index 8be59be..9761986 100644 --- a/Tests/Complex/VarTests.cmake +++ b/Tests/Complex/VarTests.cmake @@ -2,6 +2,7 @@ # Test SET # set (ZERO_VAR 0) +set (ZERO_VAR_AND_INDENTED 0) set (ZERO_VAR2 0) if(ZERO_VAR) @@ -11,6 +12,7 @@ else() endif() set(ONE_VAR 1) +set(ONE_VAR_AND_INDENTED 1) set(ONE_VAR2 1) set(STRING_VAR "CMake is great" CACHE STRING "test a cache variable") diff --git a/Tests/Complex/cmTestConfigure.h.in b/Tests/Complex/cmTestConfigure.h.in index d7424b1..72317bc 100644 --- a/Tests/Complex/cmTestConfigure.h.in +++ b/Tests/Complex/cmTestConfigure.h.in @@ -1,8 +1,10 @@ // Test SET, VARIABLE_REQUIRES #cmakedefine ONE_VAR +# cmakedefine ONE_VAR_AND_INDENTED #cmakedefine ONE_VAR_IS_DEFINED #cmakedefine ZERO_VAR +# cmakedefine ZERO_VAR_AND_INDENTED #define STRING_VAR "${STRING_VAR}" @@ -32,6 +34,8 @@ #cmakedefine01 SHOULD_BE_ZERO #cmakedefine01 SHOULD_BE_ONE +# cmakedefine01 SHOULD_BE_ZERO_AND_INDENTED +# cmakedefine01 SHOULD_BE_ONE_AND_INDENTED // Needed to check for files #define BINARY_DIR "${Complex_BINARY_DIR}" diff --git a/Tests/ComplexOneConfig/CMakeLists.txt b/Tests/ComplexOneConfig/CMakeLists.txt index 1b833b2..628cd4e 100644 --- a/Tests/ComplexOneConfig/CMakeLists.txt +++ b/Tests/ComplexOneConfig/CMakeLists.txt @@ -313,6 +313,8 @@ endwhile() set(SHOULD_BE_ZERO ) set(SHOULD_BE_ONE 1) +set(SHOULD_BE_ZERO_AND_INDENTED ) +set(SHOULD_BE_ONE_AND_INDENTED 1) # test elseif functionality, the mess below tries to catch problem # of clauses being executed early or late etc @@ -395,13 +397,6 @@ set(CMAKE_CXX_STANDARD 98) # set(CMAKE_CXX_EXTENSIONS TRUE) -# Those versions of the HP compiler that need a flag to get proper C++98 -# template support also need a flag to use the newer C++ library. -if (CMAKE_CXX_COMPILER_ID STREQUAL HP AND - CMAKE_CXX98_STANDARD_COMPILE_OPTION STREQUAL "+hpxstd98") - string(APPEND CMAKE_CXX_FLAGS " -AA") -endif () - # Clang/C2 in C++98 mode cannot properly handle some of MSVC headers if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC") diff --git a/Tests/ComplexOneConfig/Executable/complex.cxx b/Tests/ComplexOneConfig/Executable/complex.cxx index 9e4eaad..9b94962 100644 --- a/Tests/ComplexOneConfig/Executable/complex.cxx +++ b/Tests/ComplexOneConfig/Executable/complex.cxx @@ -261,6 +261,12 @@ int main() cmPassed("ONE_VAR is defined."); #endif +#ifndef ONE_VAR_AND_INDENTED + cmFailed("cmakedefine is broken, ONE_VAR_AND_INDENTED is not defined."); +#else + cmPassed("ONE_VAR_AND_INDENTED is defined."); +#endif + #ifndef ONE_VAR_IS_DEFINED cmFailed("cmakedefine, SET or VARIABLE_REQUIRES is broken, " "ONE_VAR_IS_DEFINED is not defined."); @@ -274,6 +280,12 @@ int main() cmPassed("ZERO_VAR is not defined."); #endif +#ifdef ZERO_VAR_AND_INDENTED + cmFailed("cmakedefine is broken, ZERO_VAR_AND_INDENTED is defined."); +#else + cmPassed("ZERO_VAR_AND_INDENTED is not defined."); +#endif + #ifndef STRING_VAR cmFailed("the CONFIGURE_FILE command is broken, STRING_VAR is not defined."); #else @@ -1030,6 +1042,16 @@ int main() } else { cmFailed("cmakedefine01 is not working for 1"); } + if (SHOULD_BE_ZERO_AND_INDENTED == 0) { + cmPassed("cmakedefine01 is working for 0 and indented"); + } else { + cmFailed("cmakedefine01 is not working for 0 and indented"); + } + if (SHOULD_BE_ONE_AND_INDENTED == 1) { + cmPassed("cmakedefine01 is working for 1 and indented"); + } else { + cmFailed("cmakedefine01 is not working for 1 and indented"); + } #ifdef FORCE_TEST cmFailed("CMake SET CACHE FORCE"); #else diff --git a/Tests/ComplexOneConfig/VarTests.cmake b/Tests/ComplexOneConfig/VarTests.cmake index 7dd8519..42afd19 100644 --- a/Tests/ComplexOneConfig/VarTests.cmake +++ b/Tests/ComplexOneConfig/VarTests.cmake @@ -2,6 +2,7 @@ # Test SET # set (ZERO_VAR 0) +set (ZERO_VAR_AND_INDENTED 0) set (ZERO_VAR2 0) if(ZERO_VAR) @@ -11,6 +12,7 @@ else() endif() set(ONE_VAR 1) +set(ONE_VAR_AND_INDENTED 1) set(ONE_VAR2 1) set(STRING_VAR "CMake is great" CACHE STRING "test a cache variable") diff --git a/Tests/ComplexOneConfig/cmTestConfigure.h.in b/Tests/ComplexOneConfig/cmTestConfigure.h.in index d7424b1..72317bc 100644 --- a/Tests/ComplexOneConfig/cmTestConfigure.h.in +++ b/Tests/ComplexOneConfig/cmTestConfigure.h.in @@ -1,8 +1,10 @@ // Test SET, VARIABLE_REQUIRES #cmakedefine ONE_VAR +# cmakedefine ONE_VAR_AND_INDENTED #cmakedefine ONE_VAR_IS_DEFINED #cmakedefine ZERO_VAR +# cmakedefine ZERO_VAR_AND_INDENTED #define STRING_VAR "${STRING_VAR}" @@ -32,6 +34,8 @@ #cmakedefine01 SHOULD_BE_ZERO #cmakedefine01 SHOULD_BE_ONE +# cmakedefine01 SHOULD_BE_ZERO_AND_INDENTED +# cmakedefine01 SHOULD_BE_ONE_AND_INDENTED // Needed to check for files #define BINARY_DIR "${Complex_BINARY_DIR}" diff --git a/Tests/Cuda/Complex/CMakeLists.txt b/Tests/Cuda/Complex/CMakeLists.txt index 450ef48..a7137e3 100644 --- a/Tests/Cuda/Complex/CMakeLists.txt +++ b/Tests/Cuda/Complex/CMakeLists.txt @@ -42,7 +42,6 @@ add_executable(CudaComplex main.cpp) target_link_libraries(CudaComplex PUBLIC CudaComplexMixedLib) if(APPLE) - # We need to add the default path to the driver (libcuda.dylib) as an rpath, so that - # the static cuda runtime can find it at runtime. - target_link_libraries(CudaComplex PRIVATE -Wl,-rpath,/usr/local/cuda/lib) + # Help the static cuda runtime find the driver (libcuda.dyllib) at runtime. + set_property(TARGET CudaComplex PROPERTY BUILD_RPATH ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES}) endif() diff --git a/Tests/Cuda/ObjectLibrary/CMakeLists.txt b/Tests/Cuda/ObjectLibrary/CMakeLists.txt index 1d93be7..276dc92 100644 --- a/Tests/Cuda/ObjectLibrary/CMakeLists.txt +++ b/Tests/Cuda/ObjectLibrary/CMakeLists.txt @@ -10,8 +10,8 @@ add_library(CudaMixedObjectLib OBJECT static.cu static.cpp) add_executable(CudaObjectLibrary main.cpp $<TARGET_OBJECTS:CudaMixedObjectLib>) + if(APPLE) - # We need to add the default path to the driver (libcuda.dylib) as an rpath, so that - # the static cuda runtime can find it at runtime. - target_link_libraries(CudaObjectLibrary PRIVATE -Wl,-rpath,/usr/local/cuda/lib) + # Help the static cuda runtime find the driver (libcuda.dyllib) at runtime. + set_property(TARGET CudaObjectLibrary PROPERTY BUILD_RPATH ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES}) endif() diff --git a/Tests/Cuda/WithC/CMakeLists.txt b/Tests/Cuda/WithC/CMakeLists.txt index 1f25ab4..831ce12 100644 --- a/Tests/Cuda/WithC/CMakeLists.txt +++ b/Tests/Cuda/WithC/CMakeLists.txt @@ -6,7 +6,6 @@ string(APPEND CMAKE_CUDA_FLAGS " -gencode arch=compute_30,code=compute_30") add_executable(CudaWithC main.c cuda.cu) if(APPLE) - # We need to add the default path to the driver (libcuda.dylib) as an rpath, so that - # the static cuda runtime can find it at runtime. - target_link_libraries(CudaWithC PRIVATE -Wl,-rpath,/usr/local/cuda/lib) + # Help the static cuda runtime find the driver (libcuda.dyllib) at runtime. + set_property(TARGET CudaWithC PROPERTY BUILD_RPATH ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES}) endif() diff --git a/Tests/CudaOnly/ExportPTX/CMakeLists.txt b/Tests/CudaOnly/ExportPTX/CMakeLists.txt index 10249c6..65d5243 100644 --- a/Tests/CudaOnly/ExportPTX/CMakeLists.txt +++ b/Tests/CudaOnly/ExportPTX/CMakeLists.txt @@ -67,9 +67,8 @@ target_compile_definitions(CudaOnlyExportPTX PRIVATE "CONFIG_TYPE=gen_$<LOWER_CASE:$<CONFIG>>") if(APPLE) - # We need to add the default path to the driver (libcuda.dylib) as an rpath, so that - # the static cuda runtime can find it at runtime. - target_link_libraries(CudaOnlyExportPTX PRIVATE -Wl,-rpath,/usr/local/cuda/lib) + # Help the static cuda runtime find the driver (libcuda.dyllib) at runtime. + set_property(TARGET CudaOnlyExportPTX PROPERTY BUILD_RPATH ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES}) endif() #Verify that we can install object targets properly diff --git a/Tests/CudaOnly/ResolveDeviceSymbols/CMakeLists.txt b/Tests/CudaOnly/ResolveDeviceSymbols/CMakeLists.txt index b96bb98..8d6551b 100644 --- a/Tests/CudaOnly/ResolveDeviceSymbols/CMakeLists.txt +++ b/Tests/CudaOnly/ResolveDeviceSymbols/CMakeLists.txt @@ -46,7 +46,6 @@ add_executable(CudaOnlyResolveDeviceSymbols main.cu) target_link_libraries(CudaOnlyResolveDeviceSymbols PRIVATE CUDAResolveDeviceLib) if(APPLE) - # We need to add the default path to the driver (libcuda.dylib) as an rpath, so that - # the static cuda runtime can find it at runtime. - target_link_libraries(CudaOnlyResolveDeviceSymbols PRIVATE -Wl,-rpath,/usr/local/cuda/lib) + # Help the static cuda runtime find the driver (libcuda.dyllib) at runtime. + set_property(TARGET CudaOnlyResolveDeviceSymbols PROPERTY BUILD_RPATH ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES}) endif() diff --git a/Tests/CudaOnly/SeparateCompilation/CMakeLists.txt b/Tests/CudaOnly/SeparateCompilation/CMakeLists.txt index 3d4a170..7ef626f 100644 --- a/Tests/CudaOnly/SeparateCompilation/CMakeLists.txt +++ b/Tests/CudaOnly/SeparateCompilation/CMakeLists.txt @@ -48,8 +48,7 @@ if (CMAKE_GENERATOR MATCHES "^Visual Studio") PROPERTIES CUDA_SEPARABLE_COMPILATION ON) endif() -if (APPLE) - # We need to add the default path to the driver (libcuda.dylib) as an rpath, so that - # the static cuda runtime can find it at runtime. - target_link_libraries(CudaOnlySeparateCompilation PRIVATE -Wl,-rpath,/usr/local/cuda/lib) +if(APPLE) + # Help the static cuda runtime find the driver (libcuda.dyllib) at runtime. + set_property(TARGET CudaOnlySeparateCompilation PROPERTY BUILD_RPATH ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES}) endif() diff --git a/Tests/CudaOnly/WithDefs/CMakeLists.txt b/Tests/CudaOnly/WithDefs/CMakeLists.txt index e25f141..0bc4e5c 100644 --- a/Tests/CudaOnly/WithDefs/CMakeLists.txt +++ b/Tests/CudaOnly/WithDefs/CMakeLists.txt @@ -37,8 +37,7 @@ target_compile_definitions(CudaOnlyWithDefs $<$<CONFIG:RELEASE>:$<BUILD_INTERFACE:${release_compile_defs}>> ) -#we need to add an rpath for the cuda library so that everything -#loads properly on the mac -if(CMAKE_SYSTEM_NAME MATCHES "Darwin") - set_target_properties(CudaOnlyWithDefs PROPERTIES LINK_FLAGS "-Wl,-rpath,${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES}") +if(APPLE) + # Help the static cuda runtime find the driver (libcuda.dyllib) at runtime. + set_property(TARGET CudaOnlyWithDefs PROPERTY BUILD_RPATH ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES}) endif() diff --git a/Tests/FindProtobuf/Test/CMakeLists.txt b/Tests/FindProtobuf/Test/CMakeLists.txt index 8b6e38a..10ce976 100644 --- a/Tests/FindProtobuf/Test/CMakeLists.txt +++ b/Tests/FindProtobuf/Test/CMakeLists.txt @@ -30,3 +30,5 @@ add_executable(test_var_protoc main-protoc.cxx) target_include_directories(test_var_protoc PRIVATE ${Protobuf_INCLUDE_DIRS}) target_link_libraries(test_var_protoc PRIVATE ${Protobuf_PROTOC_LIBRARIES}) add_test(NAME test_var_protoc COMMAND test_var_protoc) + +add_test(NAME test_tgt_protoc_version COMMAND protobuf::protoc --version) diff --git a/Tests/MFC/CMakeLists.txt.in b/Tests/MFC/CMakeLists.txt.in index e6bfabd..bf98e91 100644 --- a/Tests/MFC/CMakeLists.txt.in +++ b/Tests/MFC/CMakeLists.txt.in @@ -45,6 +45,11 @@ set(files set(CMAKE_MFC_FLAG "@CMAKE_MFC_FLAG_VALUE@") +FIND_PACKAGE(MFC) +IF (NOT MFC_FOUND) + MESSAGE(FATAL_ERROR "MFC Could not be found during the MFC test") +ENDIF() + if("${CMAKE_MFC_FLAG}" STREQUAL "1") msvc_link_to_static_crt() else() diff --git a/Tests/Plugin/CMakeLists.txt b/Tests/Plugin/CMakeLists.txt index 9e2b4ab..227d990 100644 --- a/Tests/Plugin/CMakeLists.txt +++ b/Tests/Plugin/CMakeLists.txt @@ -28,13 +28,6 @@ include_directories( ${Plugin_SOURCE_DIR}/include ) -# Those versions of the HP compiler that need a flag to get proper C++98 -# template support also need a flag to use the newer C++ library. -if (CMAKE_CXX_COMPILER_ID STREQUAL HP AND - CMAKE_CXX98_STANDARD_COMPILE_OPTION STREQUAL "+hpxstd98") - string(APPEND CMAKE_CXX_FLAGS " -AA") -endif () - # Clang/C2 in C++98 mode cannot properly handle some of MSVC headers if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC") diff --git a/Tests/Qt4Targets/CMakeLists.txt b/Tests/Qt4Targets/CMakeLists.txt index ae0a02b..2ca11e4 100644 --- a/Tests/Qt4Targets/CMakeLists.txt +++ b/Tests/Qt4Targets/CMakeLists.txt @@ -20,6 +20,16 @@ if (WIN32) endif() endif() +# Qt4 moc does not support utf8 paths in _parameter files generated by +# qt4_wrap_cpp and qt4_generate_moc +# https://bugreports.qt.io/browse/QTBUG-35480 +# Do a simple check if there is are non ASCII character in the build path +string(REGEX MATCH "[^ -~]+" NON_ASCII_BDIR ${CMAKE_CURRENT_BINARY_DIR}) +if(NON_ASCII_BDIR) + message(WARNING "Build path contains non ASCII characters. Skipping Qt4 test.") + return() +endif() + qt4_generate_moc(main_gen_test.cpp "${CMAKE_CURRENT_BINARY_DIR}/main_gen_test.moc" TARGET Qt4GenerateMacroTest diff --git a/Tests/QtAutoUicInterface/CMakeLists.txt b/Tests/QtAutoUicInterface/CMakeLists.txt index 3ea1294..a5c2d99 100644 --- a/Tests/QtAutoUicInterface/CMakeLists.txt +++ b/Tests/QtAutoUicInterface/CMakeLists.txt @@ -53,8 +53,9 @@ set_property(TARGET KI18n APPEND PROPERTY # END upstream -if(${CMAKE_GENERATOR} MATCHES "Visual Studio") -set(INC_DIR "include_${CMAKE_BUILD_TYPE}" ) +get_property(_GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) +if(_GENERATOR_IS_MULTI_CONFIG) +set(INC_DIR "include_$<CONFIG>" ) else() set(INC_DIR "include" ) endif() diff --git a/Tests/QtAutogen/CMakeLists.txt b/Tests/QtAutogen/CMakeLists.txt index 073c5fd..be864c3 100644 --- a/Tests/QtAutogen/CMakeLists.txt +++ b/Tests/QtAutogen/CMakeLists.txt @@ -1,14 +1,7 @@ -cmake_minimum_required(VERSION 3.7) - +cmake_minimum_required(VERSION 3.9) +cmake_policy(SET CMP0071 NEW) project(QtAutogen) -# Tell find_package(Qt5) where to find Qt. -if(QT_QMAKE_EXECUTABLE) - get_filename_component(Qt_BIN_DIR "${QT_QMAKE_EXECUTABLE}" PATH) - get_filename_component(Qt_PREFIX_DIR "${Qt_BIN_DIR}" PATH) - set(CMAKE_PREFIX_PATH ${Qt_PREFIX_DIR}) -endif() - if (QT_TEST_VERSION STREQUAL 4) find_package(Qt4 REQUIRED) @@ -22,6 +15,9 @@ if (QT_TEST_VERSION STREQUAL 4) macro(qtx_wrap_cpp) qt4_wrap_cpp(${ARGN}) endmacro() + macro(qtx_generate_moc) + qt4_generate_moc(${ARGN}) + endmacro() else() if (NOT QT_TEST_VERSION STREQUAL 5) @@ -41,11 +37,52 @@ else() macro(qtx_wrap_cpp) qt5_wrap_cpp(${ARGN}) endmacro() + macro(qtx_generate_moc) + qt5_generate_moc(${ARGN}) + endmacro() endif() get_property(QT_COMPILE_FEATURES TARGET ${QT_QTCORE_TARGET} PROPERTY INTERFACE_COMPILE_FEATURES) +# Qt4 moc does not support utf8 paths in _parameter files generated by +# qtx_wrap_cpp +# https://bugreports.qt.io/browse/QTBUG-35480 +# Do a simple check if there is are non ASCII character in the build path +string(REGEX MATCH "[^ -~]+" NON_ASCII_BDIR ${CMAKE_CURRENT_BINARY_DIR}) +if((NOT NON_ASCII_BDIR) OR (NOT QT_TEST_VERSION STREQUAL 4)) + set(ALLOW_WRAP_CPP TRUE) +endif() +# On windows qtx_wrap_cpp also fails in Qt5 when used on a path that +# contains non ASCII characters +if(NON_ASCII_BDIR AND WIN32) + set(ALLOW_WRAP_CPP FALSE) +endif() + +# -- Test +# MOC only +add_executable(mocOnly mocOnlySource/main.cpp mocOnlySource/StyleA.cpp mocOnlySource/StyleB.cpp) +set_property(TARGET mocOnly PROPERTY AUTOMOC ON) +target_link_libraries(mocOnly ${QT_LIBRARIES}) + +# -- Test +# MOC AUTOMOC_MACRO_NAMES +if (NOT QT_TEST_VERSION STREQUAL 4) + add_executable(mocMacroName mocMacroName/main.cpp mocMacroName/MacroName.cpp) + set_property(TARGET mocMacroName PROPERTY AUTOMOC ON) + set_property(TARGET mocMacroName PROPERTY AUTOMOC_MACRO_NAMES "QO_ALIAS") + target_link_libraries(mocMacroName ${QT_LIBRARIES}) +endif() + +# -- Test +# UIC only +if(ALLOW_WRAP_CPP) + qtx_wrap_cpp(uicOnlyMoc uicOnlySource/uiconly.h) + add_executable(uicOnly uicOnlySource/uiconly.cpp ${uicOnlyMoc}) + set_property(TARGET uicOnly PROPERTY AUTOUIC ON) + target_link_libraries(uicOnly ${QT_LIBRARIES}) +endif() + # -- Test # RCC only add_executable(rccOnly rccOnly.cpp rccOnlyRes.qrc) @@ -59,13 +96,6 @@ set_property(TARGET rccEmpty PROPERTY AUTORCC ON) target_link_libraries(rccEmpty ${QT_QTCORE_TARGET}) # -- Test -# UIC only -qtx_wrap_cpp(uicOnlyMoc uicOnlySource/uiconly.h) -add_executable(uicOnly uicOnlySource/uiconly.cpp ${uicOnlyMoc}) -set_property(TARGET uicOnly PROPERTY AUTOUIC ON) -target_link_libraries(uicOnly ${QT_LIBRARIES}) - -# -- Test # Add not_generated_file.qrc to the source list to get the file-level # dependency, but don't generate a c++ file from it. Disable the AUTORCC # feature for this target. This tests that qrc files in the sources don't @@ -80,154 +110,30 @@ set_target_properties(no_link_language PROPERTIES AUTOMOC TRUE) target_compile_features(no_link_language PRIVATE ${QT_COMPILE_FEATURES}) target_compile_features(empty PRIVATE ${QT_COMPILE_FEATURES}) -# -- Test -# When a file listed in a .qrc file changes the target must be rebuilt -set(timeformat "%Y%j%H%M%S") -set(RCC_DEPENDS_SRC "${CMAKE_CURRENT_SOURCE_DIR}/rccDepends") -set(RCC_DEPENDS_BIN "${CMAKE_CURRENT_BINARY_DIR}/rccDepends") -configure_file(${RCC_DEPENDS_SRC}/res1a.qrc.in ${RCC_DEPENDS_BIN}/res1.qrc COPYONLY) -configure_file(${RCC_DEPENDS_SRC}/res2a.qrc.in ${RCC_DEPENDS_BIN}/res2.qrc.in COPYONLY) -try_compile(RCC_DEPENDS - "${RCC_DEPENDS_BIN}" - "${RCC_DEPENDS_SRC}" - rccDepends - CMAKE_FLAGS "-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}" - "-DQT_TEST_VERSION=${QT_TEST_VERSION}" - "-DCMAKE_PREFIX_PATH=${Qt_PREFIX_DIR}" - OUTPUT_VARIABLE output -) -if (NOT RCC_DEPENDS) - message(SEND_ERROR "Initial build of rccDepends failed. Output: ${output}") -endif() -# Get name and timestamp of the output binary -file(STRINGS "${RCC_DEPENDS_BIN}/target.txt" targetList) -list(GET targetList 0 rccDependsBin) -file(TIMESTAMP "${rccDependsBin}" timeBegin "${timeformat}") -# Sleep, touch regular qrc input file, rebuild and compare timestamp -execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) # Ensure that the timestamp will change. -execute_process(COMMAND "${CMAKE_COMMAND}" -E touch "${RCC_DEPENDS_BIN}/res1/input.txt") -execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${RCC_DEPENDS_BIN}" RESULT_VARIABLE result) -if (result) - message(SEND_ERROR "Second build of rccDepends failed.") -endif() -file(TIMESTAMP "${rccDependsBin}" timeStep1 "${timeformat}") -if (NOT timeStep1 GREATER timeBegin) - message(SEND_ERROR "File (${rccDependsBin}) should have changed in the first step!") -endif() -# Sleep, update regular qrc file, rebuild and compare timestamp -execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) # Ensure that the timestamp will change. -configure_file(${RCC_DEPENDS_SRC}/res1b.qrc.in ${RCC_DEPENDS_BIN}/res1.qrc COPYONLY) -execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${RCC_DEPENDS_BIN}" RESULT_VARIABLE result) -if (result) - message(SEND_ERROR "Third build of rccDepends failed.") -endif() -file(TIMESTAMP "${rccDependsBin}" timeStep2 "${timeformat}") -if (NOT timeStep2 GREATER timeStep1) - message(SEND_ERROR "File (${rccDependsBin}) should have changed in the second step!") -endif() -# Sleep, touch regular qrc newly added input file, rebuild and compare timestamp -execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) # Ensure that the timestamp will change. -execute_process(COMMAND "${CMAKE_COMMAND}" -E touch "${RCC_DEPENDS_BIN}/res1/inputAdded.txt") -execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${RCC_DEPENDS_BIN}" RESULT_VARIABLE result) -if (result) - message(SEND_ERROR "Fourth build of rccDepends failed.") -endif() -file(TIMESTAMP "${rccDependsBin}" timeStep3 "${timeformat}") -if (NOT timeStep3 GREATER timeStep2) - message(SEND_ERROR "File (${rccDependsBin}) should have changed in the third step!") -endif() -# Sleep, touch generated qrc input file, rebuild and compare timestamp -execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) # Ensure that the timestamp will change. -execute_process(COMMAND "${CMAKE_COMMAND}" -E touch "${RCC_DEPENDS_BIN}/res2/input.txt") -execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${RCC_DEPENDS_BIN}" RESULT_VARIABLE result) -if (result) - message(SEND_ERROR "Fifth build of rccDepends failed.") -endif() -file(TIMESTAMP "${rccDependsBin}" timeStep4 "${timeformat}") -if (NOT timeStep4 GREATER timeStep3) - message(SEND_ERROR "File (${rccDependsBin}) should have changed in the fourth step!") -endif() -# Sleep, update generated qrc file, rebuild and compare timestamp -execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) # Ensure that the timestamp will change. -configure_file(${RCC_DEPENDS_SRC}/res2b.qrc.in ${RCC_DEPENDS_BIN}/res2.qrc.in COPYONLY) -execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${RCC_DEPENDS_BIN}" RESULT_VARIABLE result) -if (result) - message(SEND_ERROR "Sixth build of rccDepends failed.") -endif() -file(TIMESTAMP "${rccDependsBin}" timeStep5 "${timeformat}") -if (NOT timeStep5 GREATER timeStep4) - message(SEND_ERROR "File (${rccDependsBin}) should have changed in the fitfh step!") -endif() -# Sleep, touch generated qrc newly added input file, rebuild and compare timestamp -execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) # Ensure that the timestamp will change. -execute_process(COMMAND "${CMAKE_COMMAND}" -E touch "${RCC_DEPENDS_BIN}/res2/inputAdded.txt") -execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${RCC_DEPENDS_BIN}" RESULT_VARIABLE result) -if (result) - message(SEND_ERROR "Seventh build of rccDepends failed.") -endif() -file(TIMESTAMP "${rccDependsBin}" timeStep6 "${timeformat}") -if (NOT timeStep6 GREATER timeStep5) - message(SEND_ERROR "File (${rccDependsBin}) should have changed in the sixth step!") -endif() - - -# -- Test -# Ensure a repeated build succeeds when a header containing a QObject changes -set(timeformat "%Y%j%H%M%S") -configure_file(mocRerun/test1a.h.in mocRerun/test1.h COPYONLY) -try_compile(MOC_RERUN - "${CMAKE_CURRENT_BINARY_DIR}/mocRerun" - "${CMAKE_CURRENT_SOURCE_DIR}/mocRerun" - mocRerun - CMAKE_FLAGS "-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}" - "-DQT_TEST_VERSION=${QT_TEST_VERSION}" - "-DCMAKE_PREFIX_PATH=${Qt_PREFIX_DIR}" - OUTPUT_VARIABLE output -) -if (NOT MOC_RERUN) - message(SEND_ERROR "Initial build of mocRerun failed. Output: ${output}") -endif() -# Get name and timestamp of the output binary -file(STRINGS "${CMAKE_CURRENT_BINARY_DIR}/mocRerun/target1.txt" target1List) -list(GET target1List 0 binFile) -file(TIMESTAMP "${binFile}" timeBegin "${timeformat}") -# Change file content and rebuild -execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) -configure_file(mocRerun/test1b.h.in mocRerun/test1.h COPYONLY) -execute_process(COMMAND "${CMAKE_COMMAND}" --build . - WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/mocRerun" - RESULT_VARIABLE mocRerun_result - ) -if (mocRerun_result) - message(SEND_ERROR "Second build of mocRerun failed.") -endif() -# Compare timestamps -file(TIMESTAMP "${binFile}" timeStep1 "${timeformat}") -if (NOT timeStep1 GREATER timeBegin) - message(SEND_ERROR "File (${binFile}) should have changed in the first step!") -endif() # -- Test # Test for SKIP_AUTOMOC and SKIP_AUTOGEN on an AUTOMOC enabled target -qtx_wrap_cpp(skipMocWrapMoc - skipSource/qItemA.hpp - skipSource/qItemB.hpp) -set(skipMocSources - skipMoc.cpp - skipSource/qItemA.cpp - skipSource/qItemB.cpp - skipSource/qItemC.cpp) -set_property(SOURCE skipSource/qItemA.cpp PROPERTY SKIP_AUTOMOC ON) -set_property(SOURCE skipSource/qItemB.cpp PROPERTY SKIP_AUTOGEN ON) -# AUTOMOC enabled only -add_executable(skipMocA ${skipMocSources} ${skipMocWrapMoc}) -set_property(TARGET skipMocA PROPERTY AUTOMOC ON) -target_link_libraries(skipMocA ${QT_LIBRARIES}) -# AUTOMOC and AUTOUIC enabled -add_executable(skipMocB ${skipMocSources} ${skipMocWrapMoc}) -set_property(TARGET skipMocB PROPERTY AUTOMOC ON) -set_property(TARGET skipMocB PROPERTY AUTOUIC ON) -target_link_libraries(skipMocB ${QT_LIBRARIES}) +if(ALLOW_WRAP_CPP) + qtx_wrap_cpp(skipMocWrapMoc + skipSource/qItemA.hpp + skipSource/qItemB.hpp) + set(skipMocSources + skipMoc.cpp + skipSource/qItemA.cpp + skipSource/qItemB.cpp + skipSource/qItemC.cpp) + set_property(SOURCE skipSource/qItemA.cpp PROPERTY SKIP_AUTOMOC ON) + set_property(SOURCE skipSource/qItemB.cpp PROPERTY SKIP_AUTOGEN ON) + # AUTOMOC enabled only + add_executable(skipMocA ${skipMocSources} ${skipMocWrapMoc}) + set_property(TARGET skipMocA PROPERTY AUTOMOC ON) + target_link_libraries(skipMocA ${QT_LIBRARIES}) + # AUTOMOC and AUTOUIC enabled + add_executable(skipMocB ${skipMocSources} ${skipMocWrapMoc}) + set_property(TARGET skipMocB PROPERTY AUTOMOC ON) + set_property(TARGET skipMocB PROPERTY AUTOUIC ON) + target_link_libraries(skipMocB ${QT_LIBRARIES}) +endif() # -- Test # Test for SKIP_AUTOUIC and SKIP_AUTOGEN on an AUTOUIC enabled target @@ -280,80 +186,15 @@ add_subdirectory(mocDepends) # -- Test # Tests various include moc patterns -add_subdirectory(mocIncludeStrict) - -# -- Test -# Tests various include moc patterns -add_subdirectory(mocIncludeRelaxed) +if(ALLOW_WRAP_CPP) + add_subdirectory(mocIncludeStrict) + add_subdirectory(mocIncludeRelaxed) +endif() # -- Test -# Tests Q_PLUGIN_METADATA json file change detection -if (NOT QT_TEST_VERSION STREQUAL 4) - try_compile(MOC_PLUGIN - "${CMAKE_CURRENT_BINARY_DIR}/mocPlugin" - "${CMAKE_CURRENT_SOURCE_DIR}/mocPlugin" - mocPlugin - CMAKE_FLAGS "-DQT_TEST_VERSION=${QT_TEST_VERSION}" - "-DCMAKE_PREFIX_PATH=${Qt_PREFIX_DIR}" - OUTPUT_VARIABLE output - ) - if (NOT MOC_PLUGIN) - message(SEND_ERROR "Initial build of mocPlugin failed. Output: ${output}") - endif() - - set(timeformat "%Y%j%H%M%S") - set(mocPlugSrcDir "${CMAKE_CURRENT_SOURCE_DIR}/mocPlugin") - set(mocPlugBinDir "${CMAKE_CURRENT_BINARY_DIR}/mocPlugin") - find_library(plAFile "PlugA" PATHS "${mocPlugBinDir}/Debug" "${mocPlugBinDir}" NO_DEFAULT_PATH) - find_library(plBFile "PlugB" PATHS "${mocPlugBinDir}/Debug" "${mocPlugBinDir}" NO_DEFAULT_PATH) - find_library(plCFile "PlugC" PATHS "${mocPlugBinDir}/Debug" "${mocPlugBinDir}" NO_DEFAULT_PATH) - find_library(plDFile "PlugD" PATHS "${mocPlugBinDir}/Debug" "${mocPlugBinDir}" NO_DEFAULT_PATH) - - file(TIMESTAMP "${plAFile}" plABefore "${timeformat}") - file(TIMESTAMP "${plBFile}" plBBefore "${timeformat}") - file(TIMESTAMP "${plCFile}" plCBefore "${timeformat}") - file(TIMESTAMP "${plDFile}" plDBefore "${timeformat}") - - # Ensure that the timestamp will change and change the json files - execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) - configure_file("${mocPlugSrcDir}/jsonIn/StyleD.json" "${mocPlugBinDir}/jsonFiles/StyleC.json") - configure_file("${mocPlugSrcDir}/jsonIn/StyleC.json" "${mocPlugBinDir}/jsonFiles/sub/StyleD.json") - execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${mocPlugBinDir}") - - file(TIMESTAMP "${plAFile}" plAAfter "${timeformat}") - file(TIMESTAMP "${plBFile}" plBAfter "${timeformat}") - file(TIMESTAMP "${plCFile}" plCAfter "${timeformat}") - file(TIMESTAMP "${plDFile}" plDAfter "${timeformat}") - - if (plAAfter GREATER plABefore) - message(SEND_ERROR "file (${plAFile}) should not have changed!") - endif() - if (plBAfter GREATER plBBefore) - message(SEND_ERROR "file (${plBFile}) should not have changed!") - endif() - if (NOT plCAfter GREATER plCBefore) - message(SEND_ERROR "file (${plCFile}) should have changed!") - endif() - if (NOT plDAfter GREATER plDBefore) - message(SEND_ERROR "file (${plDFile}) should have changed!") - endif() - - # Test custom macro - file(TIMESTAMP "${plCFile}" plCBefore "${timeformat}") - file(TIMESTAMP "${plDFile}" plDBefore "${timeformat}") - execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) - configure_file("${mocPlugSrcDir}/jsonIn/StyleD.json" "${mocPlugBinDir}/jsonFiles/StyleC_Custom.json") - configure_file("${mocPlugSrcDir}/jsonIn/StyleC.json" "${mocPlugBinDir}/jsonFiles/sub/StyleD_Custom.json") - execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${mocPlugBinDir}") - file(TIMESTAMP "${plCFile}" plCAfter "${timeformat}") - file(TIMESTAMP "${plDFile}" plDAfter "${timeformat}") - if (NOT plCAfter GREATER plCBefore) - message(SEND_ERROR "file (${plCFile}) should have changed!") - endif() - if (NOT plDAfter GREATER plDBefore) - message(SEND_ERROR "file (${plDFile}) should have changed!") - endif() - +# Tests policy 0071 +if(ALLOW_WRAP_CPP) + add_subdirectory(mocCMP0071) endif() # -- Test @@ -361,5 +202,9 @@ endif() add_subdirectory(uicInclude) # -- Test +# OBJECT libraries +add_subdirectory(objectLibrary) + +# -- Test # Complex test case add_subdirectory(complex) diff --git a/Tests/QtAutogen/complex/CMakeLists.txt b/Tests/QtAutogen/complex/CMakeLists.txt index d48f6cc..2043ccf 100644 --- a/Tests/QtAutogen/complex/CMakeLists.txt +++ b/Tests/QtAutogen/complex/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.7) +cmake_minimum_required(VERSION 3.9) # -- Test: AUTOMOC AUTORCC AUTOUIC add_definitions(-DFOO -DSomeDefine="Barx") diff --git a/Tests/QtAutogen/mocCMP0071/CMakeLists.txt b/Tests/QtAutogen/mocCMP0071/CMakeLists.txt new file mode 100644 index 0000000..003fa08 --- /dev/null +++ b/Tests/QtAutogen/mocCMP0071/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 3.9) +project(mocCMP0071 CXX) +add_subdirectory(OLD) +add_subdirectory(NEW) diff --git a/Tests/QtAutogen/mocCMP0071/NEW/CMakeLists.txt b/Tests/QtAutogen/mocCMP0071/NEW/CMakeLists.txt new file mode 100644 index 0000000..0237afc --- /dev/null +++ b/Tests/QtAutogen/mocCMP0071/NEW/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.9) +cmake_policy(SET CMP0071 NEW) + +# *Generate* files +set(CSD ${CMAKE_CURRENT_SOURCE_DIR}) +set(CBD ${CMAKE_CURRENT_BINARY_DIR}) +add_custom_command( + OUTPUT ${CBD}/Obj_p.h ${CBD}/Obj.hpp ${CBD}/Obj.cpp ${CBD}/main.cpp + COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/../Obj_p.h ${CBD}/Obj_p.h + COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/../Obj.hpp ${CBD}/Obj.hpp + COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/../Obj.cpp ${CBD}/Obj.cpp + COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/../main.cpp ${CBD}/main.cpp) + +add_executable(mocCMP0071New ${CBD}/Obj.cpp ${CBD}/main.cpp) +target_link_libraries(mocCMP0071New ${QT_LIBRARIES}) +set_target_properties(mocCMP0071New PROPERTIES AUTOMOC ON) diff --git a/Tests/QtAutogen/mocCMP0071/OLD/CMakeLists.txt b/Tests/QtAutogen/mocCMP0071/OLD/CMakeLists.txt new file mode 100644 index 0000000..5699433 --- /dev/null +++ b/Tests/QtAutogen/mocCMP0071/OLD/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 3.9) +cmake_policy(SET CMP0071 OLD) + +# *Generate* files +set(CSD ${CMAKE_CURRENT_SOURCE_DIR}) +set(CBD ${CMAKE_CURRENT_BINARY_DIR}) +add_custom_command( + OUTPUT ${CBD}/Obj_p.h ${CBD}/Obj.hpp ${CBD}/Obj.cpp ${CBD}/main.cpp + COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/../Obj_p.h ${CBD}/Obj_p.h + COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/../Obj.hpp ${CBD}/Obj.hpp + COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/../Obj.cpp ${CBD}/Obj.cpp + COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/../main.cpp ${CBD}/main.cpp) + +# Generate moc files externally +qtx_wrap_cpp(mocCMP0071OldMoc ${CBD}/Obj.hpp ${CBD}/Obj_p.h) +add_executable(mocCMP0071Old ${CBD}/Obj.cpp ${CBD}/main.cpp ${mocCMP0071OldMoc}) +target_link_libraries(mocCMP0071Old ${QT_LIBRARIES}) +set_target_properties(mocCMP0071Old PROPERTIES AUTOMOC ON) diff --git a/Tests/QtAutogen/mocCMP0071/Obj.cpp b/Tests/QtAutogen/mocCMP0071/Obj.cpp new file mode 100644 index 0000000..1ae50ed --- /dev/null +++ b/Tests/QtAutogen/mocCMP0071/Obj.cpp @@ -0,0 +1,20 @@ +#include "Obj.hpp" +#include "Obj_p.h" + +ObjPrivate::ObjPrivate() +{ +} + +ObjPrivate::~ObjPrivate() +{ +} + +Obj::Obj() + : d(new ObjPrivate) +{ +} + +Obj::~Obj() +{ + delete d; +} diff --git a/Tests/QtAutogen/mocCMP0071/Obj.hpp b/Tests/QtAutogen/mocCMP0071/Obj.hpp new file mode 100644 index 0000000..f064e47 --- /dev/null +++ b/Tests/QtAutogen/mocCMP0071/Obj.hpp @@ -0,0 +1,19 @@ +#ifndef OBJ_HPP +#define OBJ_HPP + +#include <QObject> + +// Object source comes without any _moc/.moc includes +class ObjPrivate; +class Obj : public QObject +{ + Q_OBJECT +public: + Obj(); + ~Obj(); + +private: + ObjPrivate* const d; +}; + +#endif diff --git a/Tests/QtAutogen/mocCMP0071/Obj_p.h b/Tests/QtAutogen/mocCMP0071/Obj_p.h new file mode 100644 index 0000000..cb1e5df --- /dev/null +++ b/Tests/QtAutogen/mocCMP0071/Obj_p.h @@ -0,0 +1,14 @@ +#ifndef OBJ_P_HPP +#define OBJ_P_HPP + +#include <QObject> + +class ObjPrivate : public QObject +{ + Q_OBJECT +public: + ObjPrivate(); + ~ObjPrivate(); +}; + +#endif diff --git a/Tests/QtAutogen/mocCMP0071/main.cpp b/Tests/QtAutogen/mocCMP0071/main.cpp new file mode 100644 index 0000000..3887840 --- /dev/null +++ b/Tests/QtAutogen/mocCMP0071/main.cpp @@ -0,0 +1,7 @@ +#include "Obj.hpp" + +int main(int argv, char** args) +{ + Obj obj; + return 0; +} diff --git a/Tests/QtAutogen/mocDepends/CMakeLists.txt b/Tests/QtAutogen/mocDepends/CMakeLists.txt index a67dcfe..d71d740 100644 --- a/Tests/QtAutogen/mocDepends/CMakeLists.txt +++ b/Tests/QtAutogen/mocDepends/CMakeLists.txt @@ -1,5 +1,6 @@ -cmake_minimum_required(VERSION 3.7) -project(mocDepends) +cmake_minimum_required(VERSION 3.9) +cmake_policy(SET CMP0071 NEW) +project(mocDepends CXX) if (QT_TEST_VERSION STREQUAL 4) find_package(Qt4 REQUIRED) @@ -15,33 +16,80 @@ endif() include_directories(${CMAKE_CURRENT_BINARY_DIR}) -# -- Test 1 using generated header -# This tests the dependency of AUTOMOC of mocDepends1 to the generated object.hpp -add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/object.hpp - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/invalid.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/object.hpp - COMMAND ${CMAKE_COMMAND} -E sleep 3 - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/object.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/object.hpp - ) - -add_executable(mocDepends1 test1.cpp - ${CMAKE_CURRENT_BINARY_DIR}/object.hpp -) +# -- Test 1: Depend on generated header +# The ORIGIN_autogen target must depend on the same *GENERATED* source files as +# the ORIGIN target. This is a requirement to ensure that all files for the +# ORIGIN target are generated before the ORIGIN_autogen target is built. +# +# This tests the dependency of the mocDepends1_autogen target of mocDepends1 +# to the source file test1_object.hpp, which is *GENERATED* by a custom command. +# If mocDepends1_autogen gets built *before* or in *parallel* to the +# custom command, the build will fail. That's because test1_object.hpp, +# which is required by mocDepends1_autogen, is only valid after the +# custom command has been completed. +# +# The sleep seconds artificially increase the build time of the custom command +# to simulate a slow file generation process that takes longer to run than +# the build of the mocDepends1_autogen target. +add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/test1_object.hpp + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/invalid.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/test1_object.hpp + COMMAND ${CMAKE_COMMAND} -E sleep 3 + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/object.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/test1_object.hpp) + +add_executable(mocDepends1 test1.cpp ${CMAKE_CURRENT_BINARY_DIR}/test1_object.hpp) target_link_libraries(mocDepends1 ${QT_CORE_TARGET}) set_target_properties(mocDepends1 PROPERTIES AUTOMOC TRUE) -set_property(TARGET mocDepends1 PROPERTY __UNDOCUMENTED_AUTOGEN_GENERATED_FILES 1) - -# -- Test 2 using generated library -# This tests the dependency of AUTOMOC of mocDepends2 to the -# generated simpleLib.hpp which belongs to a linked library of mocDepends2 -add_custom_command(OUTPUT simpleLib.hpp simpleLib.cpp - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/invalid.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/simpleLib.hpp - COMMAND ${CMAKE_COMMAND} -E sleep 3 - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/simpleLib.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/simpleLib.hpp - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/simpleLib.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/simpleLib.cpp - ) -add_library(SimpleLib STATIC simpleLib.hpp simpleLib.cpp) - -add_executable(mocDepends2 test2.cpp ) -target_link_libraries(mocDepends2 SimpleLib ${QT_CORE_TARGET}) + +# -- Test 2: Depend on header generating target +# The ORIGIN_autogen target must depend on the same user defined targets +# as the ORIGIN target. This is a requirement to ensure that all files for the +# ORIGIN target are generated before the ORIGIN_autogen target is built. +# +# This tests the dependency of the mocDepends2_autogen target of mocDepends2 +# to the utility target mocDepends2Object. If mocDepends2_autogen gets built +# *before* or in *parallel* to mocDepends2Object, the build will fail. That's +# because test2_object.hpp, which is required by mocDepends2_autogen, +# is only valid after the mocDepends2Object build has been completed. +# +# The sleep seconds artificially increase the build time of mocDepends2Object +# to simulate a slow utility target build that takes longer to run than +# the build of the mocDepends2_autogen target. +add_custom_target(mocDepends2Object + BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/test2_object.hpp + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/invalid.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/test2_object.hpp + COMMAND ${CMAKE_COMMAND} -E sleep 3 + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/object.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/test2_object.hpp) + +add_executable(mocDepends2 test2.cpp) +target_link_libraries(mocDepends2 ${QT_CORE_TARGET}) set_target_properties(mocDepends2 PROPERTIES AUTOMOC TRUE) -set_property(TARGET mocDepends2 PROPERTY __UNDOCUMENTED_AUTOGEN_GENERATED_FILES 1) +add_dependencies(mocDepends2 mocDepends2Object) + +# -- Test 3: Depend on generated linked library +# The ORIGIN_autogen target must depend on the same linked libraries +# as the ORIGIN target. This is a requirement to ensure that all files for the +# ORIGIN target are generated before the ORIGIN_autogen target is built. +# +# This tests the dependency of the mocDepends3_autogen target of mocDepends3 +# to the user generated library SimpleLib, which mocDepends3 links to. +# If mocDepends3_autogen gets built *before* or in *parallel* to SimpleLib, +# the build will fail. That's because simpleLib.hpp, which is required by +# mocDepends3_autogen, is only valid after the SimpleLib build has been +# completed. +# +# The sleep seconds artificially increase the build time of SimpleLib +# to simulate a slow utility library build that takes longer to run than +# the build of the mocDepends3_autogen target. +add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/simpleLib.hpp ${CMAKE_CURRENT_BINARY_DIR}/simpleLib.cpp + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/invalid.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/simpleLib.hpp + COMMAND ${CMAKE_COMMAND} -E sleep 3 + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/simpleLib.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/simpleLib.hpp + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/simpleLib.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/simpleLib.cpp) +add_library(SimpleLib STATIC ${CMAKE_CURRENT_BINARY_DIR}/simpleLib.hpp ${CMAKE_CURRENT_BINARY_DIR}/simpleLib.cpp) +target_link_libraries(SimpleLib ${QT_CORE_TARGET}) + +add_executable(mocDepends3 test3.cpp) +target_link_libraries(mocDepends3 SimpleLib ${QT_CORE_TARGET}) +set_target_properties(mocDepends3 PROPERTIES AUTOMOC TRUE) diff --git a/Tests/QtAutogen/mocDepends/simpleLib.hpp.in b/Tests/QtAutogen/mocDepends/simpleLib.hpp.in index 758f1f6..b65b0cb 100644 --- a/Tests/QtAutogen/mocDepends/simpleLib.hpp.in +++ b/Tests/QtAutogen/mocDepends/simpleLib.hpp.in @@ -1,8 +1,11 @@ #ifndef SIMPLE_LIB_H #define SIMPLE_LIB_H -class SimpleLib +#include <QObject> + +class SimpleLib : public QObject { + Q_OBJECT public: SimpleLib(); ~SimpleLib(); diff --git a/Tests/QtAutogen/mocDepends/test1.cpp b/Tests/QtAutogen/mocDepends/test1.cpp index 92c259c..002dfd8 100644 --- a/Tests/QtAutogen/mocDepends/test1.cpp +++ b/Tests/QtAutogen/mocDepends/test1.cpp @@ -1,9 +1,8 @@ -#include "object.hpp" +#include "test1_object.hpp" int main() { Object obj; - return 0; } diff --git a/Tests/QtAutogen/mocDepends/test2.cpp b/Tests/QtAutogen/mocDepends/test2.cpp index 155b19b..3fd845e 100644 --- a/Tests/QtAutogen/mocDepends/test2.cpp +++ b/Tests/QtAutogen/mocDepends/test2.cpp @@ -1,10 +1,9 @@ -#include "test2.hpp" +#include "moc_test2_object.cpp" +#include "test2_object.hpp" int main() { - SimpleLib obj; - LObject lobject; - + Object obj; return 0; } diff --git a/Tests/QtAutogen/mocDepends/test3.cpp b/Tests/QtAutogen/mocDepends/test3.cpp new file mode 100644 index 0000000..a009598 --- /dev/null +++ b/Tests/QtAutogen/mocDepends/test3.cpp @@ -0,0 +1,12 @@ + +#include "test3.hpp" + +int main() +{ + SimpleLib libObject; + LObject lobject; + return 0; +} + +// AUTOMOC the SimpleLib header simpleLib.hpp +#include "moc_simpleLib.cpp" diff --git a/Tests/QtAutogen/mocDepends/test2.hpp b/Tests/QtAutogen/mocDepends/test3.hpp index 0125f07..408335b 100644 --- a/Tests/QtAutogen/mocDepends/test2.hpp +++ b/Tests/QtAutogen/mocDepends/test3.hpp @@ -1,5 +1,5 @@ -#ifndef TEST2_HPP -#define TEST2_HPP +#ifndef TEST3_HPP +#define TEST3_HPP #include "simpleLib.hpp" #include <QObject> diff --git a/Tests/QtAutogen/mocInclude/EObjA.cpp b/Tests/QtAutogen/mocInclude/EObjA.cpp new file mode 100644 index 0000000..ca713b2 --- /dev/null +++ b/Tests/QtAutogen/mocInclude/EObjA.cpp @@ -0,0 +1,43 @@ +#include "EObjA.hpp" +#include "EObjAExtra.hpp" +#include "EObjA_p.hpp" + +class EObjALocal : public QObject +{ + Q_OBJECT +public: + EObjALocal(); + ~EObjALocal(); +}; + +EObjALocal::EObjALocal() +{ +} + +EObjALocal::~EObjALocal() +{ +} + +EObjAPrivate::EObjAPrivate() +{ + EObjALocal localObj; + EObjAExtra extraObj; +} + +EObjAPrivate::~EObjAPrivate() +{ +} + +EObjA::EObjA() + : d(new EObjAPrivate) +{ +} + +EObjA::~EObjA() +{ +} + +// For EObjALocal +#include "EObjA.moc" +// - Not the own header +#include "moc_EObjAExtra.cpp" diff --git a/Tests/QtAutogen/mocInclude/EObjA.hpp b/Tests/QtAutogen/mocInclude/EObjA.hpp new file mode 100644 index 0000000..0939ab6 --- /dev/null +++ b/Tests/QtAutogen/mocInclude/EObjA.hpp @@ -0,0 +1,19 @@ +#ifndef EOBJA_HPP +#define EOBJA_HPP + +#include <QObject> + +// Sources includes a moc_ includes of an extra object +class EObjAPrivate; +class EObjA : public QObject +{ + Q_OBJECT +public: + EObjA(); + ~EObjA(); + +private: + EObjAPrivate* const d; +}; + +#endif diff --git a/Tests/QtAutogen/mocInclude/EObjAExtra.cpp b/Tests/QtAutogen/mocInclude/EObjAExtra.cpp new file mode 100644 index 0000000..369ca8f --- /dev/null +++ b/Tests/QtAutogen/mocInclude/EObjAExtra.cpp @@ -0,0 +1,20 @@ +#include "EObjAExtra.hpp" +#include "EObjAExtra_p.hpp" + +EObjAExtraPrivate::EObjAExtraPrivate() +{ +} + +EObjAExtraPrivate::~EObjAExtraPrivate() +{ +} + +EObjAExtra::EObjAExtra() + : d(new EObjAExtraPrivate) +{ +} + +EObjAExtra::~EObjAExtra() +{ + delete d; +} diff --git a/Tests/QtAutogen/mocInclude/EObjAExtra.hpp b/Tests/QtAutogen/mocInclude/EObjAExtra.hpp new file mode 100644 index 0000000..b10681d --- /dev/null +++ b/Tests/QtAutogen/mocInclude/EObjAExtra.hpp @@ -0,0 +1,18 @@ +#ifndef EOBJAEXTRA_HPP +#define EOBJAEXTRA_HPP + +#include <QObject> + +class EObjAExtraPrivate; +class EObjAExtra : public QObject +{ + Q_OBJECT +public: + EObjAExtra(); + ~EObjAExtra(); + +private: + EObjAExtraPrivate* const d; +}; + +#endif diff --git a/Tests/QtAutogen/mocInclude/EObjAExtra_p.hpp b/Tests/QtAutogen/mocInclude/EObjAExtra_p.hpp new file mode 100644 index 0000000..dea6cb5 --- /dev/null +++ b/Tests/QtAutogen/mocInclude/EObjAExtra_p.hpp @@ -0,0 +1,12 @@ +#ifndef EOBJAEXTRA_P_HPP +#define EOBJAEXTRA_P_HPP + +class EObjAExtraPrivate : public QObject +{ + Q_OBJECT +public: + EObjAExtraPrivate(); + ~EObjAExtraPrivate(); +}; + +#endif diff --git a/Tests/QtAutogen/mocInclude/EObjA_p.hpp b/Tests/QtAutogen/mocInclude/EObjA_p.hpp new file mode 100644 index 0000000..1e0d7e1 --- /dev/null +++ b/Tests/QtAutogen/mocInclude/EObjA_p.hpp @@ -0,0 +1,12 @@ +#ifndef EOBJA_P_HPP +#define EOBJA_P_HPP + +class EObjAPrivate : public QObject +{ + Q_OBJECT +public: + EObjAPrivate(); + ~EObjAPrivate(); +}; + +#endif diff --git a/Tests/QtAutogen/mocInclude/EObjB.cpp b/Tests/QtAutogen/mocInclude/EObjB.cpp new file mode 100644 index 0000000..d19fbfa --- /dev/null +++ b/Tests/QtAutogen/mocInclude/EObjB.cpp @@ -0,0 +1,44 @@ +#include "EObjB.hpp" +#include "EObjB_p.hpp" +#include "subExtra/EObjBExtra.hpp" + +class EObjBLocal : public QObject +{ + Q_OBJECT +public: + EObjBLocal(); + ~EObjBLocal(); +}; + +EObjBLocal::EObjBLocal() +{ +} + +EObjBLocal::~EObjBLocal() +{ +} + +EObjBPrivate::EObjBPrivate() +{ + EObjBLocal localObj; + EObjBExtra extraObj; +} + +EObjBPrivate::~EObjBPrivate() +{ +} + +EObjB::EObjB() + : d(new EObjBPrivate) +{ +} + +EObjB::~EObjB() +{ +} + +// For EObjBLocal +#include "EObjB.moc" +// - Not the own header +// - in a subdirectory +#include "subExtra/moc_EObjBExtra.cpp" diff --git a/Tests/QtAutogen/mocInclude/EObjB.hpp b/Tests/QtAutogen/mocInclude/EObjB.hpp new file mode 100644 index 0000000..6632bdb --- /dev/null +++ b/Tests/QtAutogen/mocInclude/EObjB.hpp @@ -0,0 +1,19 @@ +#ifndef EOBJB_HPP +#define EOBJB_HPP + +#include <QObject> + +// Sources includes a moc_ includes of an extra object in a subdirectory +class EObjBPrivate; +class EObjB : public QObject +{ + Q_OBJECT +public: + EObjB(); + ~EObjB(); + +private: + EObjBPrivate* const d; +}; + +#endif diff --git a/Tests/QtAutogen/mocInclude/EObjB_p.hpp b/Tests/QtAutogen/mocInclude/EObjB_p.hpp new file mode 100644 index 0000000..2905f28 --- /dev/null +++ b/Tests/QtAutogen/mocInclude/EObjB_p.hpp @@ -0,0 +1,12 @@ +#ifndef EOBJB_P_HPP +#define EOBJB_P_HPP + +class EObjBPrivate : public QObject +{ + Q_OBJECT +public: + EObjBPrivate(); + ~EObjBPrivate(); +}; + +#endif diff --git a/Tests/QtAutogen/mocInclude/LObjA.cpp b/Tests/QtAutogen/mocInclude/LObjA.cpp new file mode 100644 index 0000000..9aae991 --- /dev/null +++ b/Tests/QtAutogen/mocInclude/LObjA.cpp @@ -0,0 +1,39 @@ +#include "LObjA.hpp" +#include "LObjA_p.h" + +class LObjALocal : public QObject +{ + Q_OBJECT +public: + LObjALocal(); + ~LObjALocal(); +}; + +LObjALocal::LObjALocal() +{ +} + +LObjALocal::~LObjALocal() +{ +} + +LObjAPrivate::LObjAPrivate() +{ + LObjALocal localObj; +} + +LObjAPrivate::~LObjAPrivate() +{ +} + +LObjA::LObjA() + : d(new LObjAPrivate) +{ +} + +LObjA::~LObjA() +{ + delete d; +} + +#include "LObjA.moc" diff --git a/Tests/QtAutogen/mocInclude/LObjA.hpp b/Tests/QtAutogen/mocInclude/LObjA.hpp new file mode 100644 index 0000000..aac670c --- /dev/null +++ b/Tests/QtAutogen/mocInclude/LObjA.hpp @@ -0,0 +1,19 @@ +#ifndef LOBJA_HPP +#define LOBJA_HPP + +#include <QObject> + +// Object source comes with a .moc include +class LObjAPrivate; +class LObjA : public QObject +{ + Q_OBJECT +public: + LObjA(); + ~LObjA(); + +private: + LObjAPrivate* const d; +}; + +#endif diff --git a/Tests/QtAutogen/mocInclude/LObjA_p.h b/Tests/QtAutogen/mocInclude/LObjA_p.h new file mode 100644 index 0000000..ebe8395 --- /dev/null +++ b/Tests/QtAutogen/mocInclude/LObjA_p.h @@ -0,0 +1,12 @@ +#ifndef LOBJA_P_HPP +#define LOBJA_P_HPP + +class LObjAPrivate : public QObject +{ + Q_OBJECT +public: + LObjAPrivate(); + ~LObjAPrivate(); +}; + +#endif diff --git a/Tests/QtAutogen/mocInclude/LObjB.cpp b/Tests/QtAutogen/mocInclude/LObjB.cpp new file mode 100644 index 0000000..7485d8f --- /dev/null +++ b/Tests/QtAutogen/mocInclude/LObjB.cpp @@ -0,0 +1,40 @@ +#include "LObjB.hpp" +#include "LObjB_p.h" + +class LObjBLocal : public QObject +{ + Q_OBJECT +public: + LObjBLocal(); + ~LObjBLocal(); +}; + +LObjBLocal::LObjBLocal() +{ +} + +LObjBLocal::~LObjBLocal() +{ +} + +LObjBPrivate::LObjBPrivate() +{ + LObjBLocal localObj; +} + +LObjBPrivate::~LObjBPrivate() +{ +} + +LObjB::LObjB() + : d(new LObjBPrivate) +{ +} + +LObjB::~LObjB() +{ + delete d; +} + +#include "LObjB.moc" +#include "moc_LObjB.cpp" diff --git a/Tests/QtAutogen/mocInclude/LObjB.hpp b/Tests/QtAutogen/mocInclude/LObjB.hpp new file mode 100644 index 0000000..eb4e58d --- /dev/null +++ b/Tests/QtAutogen/mocInclude/LObjB.hpp @@ -0,0 +1,19 @@ +#ifndef LLObjB_HPP +#define LLObjB_HPP + +#include <QObject> + +// Object source comes with a .moc and a _moc include +class LObjBPrivate; +class LObjB : public QObject +{ + Q_OBJECT +public: + LObjB(); + ~LObjB(); + +private: + LObjBPrivate* const d; +}; + +#endif diff --git a/Tests/QtAutogen/mocInclude/LObjB_p.h b/Tests/QtAutogen/mocInclude/LObjB_p.h new file mode 100644 index 0000000..b871f2d --- /dev/null +++ b/Tests/QtAutogen/mocInclude/LObjB_p.h @@ -0,0 +1,12 @@ +#ifndef LOBJB_P_HPP +#define LOBJB_P_HPP + +class LObjBPrivate : public QObject +{ + Q_OBJECT +public: + LObjBPrivate(); + ~LObjBPrivate(); +}; + +#endif diff --git a/Tests/QtAutogen/mocInclude/ObjA.cpp b/Tests/QtAutogen/mocInclude/ObjA.cpp index 1b0311d..6f6b90e 100644 --- a/Tests/QtAutogen/mocInclude/ObjA.cpp +++ b/Tests/QtAutogen/mocInclude/ObjA.cpp @@ -1,24 +1,20 @@ #include "ObjA.hpp" +#include "ObjA_p.h" -class SubObjA : public QObject +ObjAPrivate::ObjAPrivate() { - Q_OBJECT - -public: - SubObjA() {} - ~SubObjA() {} - - Q_SLOT - void aSlot(); -}; +} -void SubObjA::aSlot() +ObjAPrivate::~ObjAPrivate() { } -void ObjA::go() +ObjA::ObjA() + : d(new ObjAPrivate) { - SubObjA subObj; } -#include "ObjA.moc" +ObjA::~ObjA() +{ + delete d; +} diff --git a/Tests/QtAutogen/mocInclude/ObjA.hpp b/Tests/QtAutogen/mocInclude/ObjA.hpp index 281e90d..f16c924 100644 --- a/Tests/QtAutogen/mocInclude/ObjA.hpp +++ b/Tests/QtAutogen/mocInclude/ObjA.hpp @@ -3,11 +3,17 @@ #include <QObject> +// Object source comes without any _moc/.moc includes +class ObjAPrivate; class ObjA : public QObject { Q_OBJECT - Q_SLOT - void go(); +public: + ObjA(); + ~ObjA(); + +private: + ObjAPrivate* const d; }; #endif diff --git a/Tests/QtAutogen/mocInclude/ObjA_p.h b/Tests/QtAutogen/mocInclude/ObjA_p.h new file mode 100644 index 0000000..eb60c98 --- /dev/null +++ b/Tests/QtAutogen/mocInclude/ObjA_p.h @@ -0,0 +1,12 @@ +#ifndef OBJA_P_HPP +#define OBJA_P_HPP + +class ObjAPrivate : public QObject +{ + Q_OBJECT +public: + ObjAPrivate(); + ~ObjAPrivate(); +}; + +#endif diff --git a/Tests/QtAutogen/mocInclude/ObjB.cpp b/Tests/QtAutogen/mocInclude/ObjB.cpp index 5ff315d..a6f2509 100644 --- a/Tests/QtAutogen/mocInclude/ObjB.cpp +++ b/Tests/QtAutogen/mocInclude/ObjB.cpp @@ -1,25 +1,22 @@ #include "ObjB.hpp" +#include "ObjB_p.h" -class SubObjB : public QObject +ObjBPrivate::ObjBPrivate() { - Q_OBJECT - -public: - SubObjB() {} - ~SubObjB() {} +} - Q_SLOT - void aSlot(); -}; +ObjBPrivate::~ObjBPrivate() +{ +} -void SubObjB::aSlot() +ObjB::ObjB() + : d(new ObjBPrivate) { } -void ObjB::go() +ObjB::~ObjB() { - SubObjB subObj; + delete d; } -#include "ObjB.moc" #include "moc_ObjB.cpp" diff --git a/Tests/QtAutogen/mocInclude/ObjB.hpp b/Tests/QtAutogen/mocInclude/ObjB.hpp index 94f3d49..2ac8d17 100644 --- a/Tests/QtAutogen/mocInclude/ObjB.hpp +++ b/Tests/QtAutogen/mocInclude/ObjB.hpp @@ -1,13 +1,19 @@ -#ifndef OBJB_HPP -#define OBJB_HPP +#ifndef ObjB_HPP +#define ObjB_HPP #include <QObject> +// Object source comes with a _moc include +class ObjBPrivate; class ObjB : public QObject { Q_OBJECT - Q_SLOT - void go(); +public: + ObjB(); + ~ObjB(); + +private: + ObjBPrivate* const d; }; #endif diff --git a/Tests/QtAutogen/mocInclude/ObjB_p.h b/Tests/QtAutogen/mocInclude/ObjB_p.h new file mode 100644 index 0000000..418da65 --- /dev/null +++ b/Tests/QtAutogen/mocInclude/ObjB_p.h @@ -0,0 +1,12 @@ +#ifndef OBJB_P_HPP +#define OBJB_P_HPP + +class ObjBPrivate : public QObject +{ + Q_OBJECT +public: + ObjBPrivate(); + ~ObjBPrivate(); +}; + +#endif diff --git a/Tests/QtAutogen/mocInclude/ObjC.cpp b/Tests/QtAutogen/mocInclude/ObjC.cpp deleted file mode 100644 index 8ca34cb..0000000 --- a/Tests/QtAutogen/mocInclude/ObjC.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "ObjC.hpp" - -class SubObjC : public QObject -{ - Q_OBJECT - -public: - SubObjC() {} - ~SubObjC() {} - - Q_SLOT - void aSlot(); -}; - -void SubObjC::aSlot() -{ -} - -void ObjC::go() -{ - SubObjC subObj; -} - -#include "ObjC.moc" -// Not the own header -#include "moc_ObjD.cpp" diff --git a/Tests/QtAutogen/mocInclude/ObjC.hpp b/Tests/QtAutogen/mocInclude/ObjC.hpp deleted file mode 100644 index a8e98eb..0000000 --- a/Tests/QtAutogen/mocInclude/ObjC.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef OBJC_HPP -#define OBJC_HPP - -#include <QObject> - -class ObjC : public QObject -{ - Q_OBJECT - Q_SLOT - void go(); -}; - -#endif diff --git a/Tests/QtAutogen/mocInclude/ObjD.cpp b/Tests/QtAutogen/mocInclude/ObjD.cpp deleted file mode 100644 index c18aec1..0000000 --- a/Tests/QtAutogen/mocInclude/ObjD.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "ObjD.hpp" - -class SubObjD : public QObject -{ - Q_OBJECT - -public: - SubObjD() {} - ~SubObjD() {} - - Q_SLOT - void aSlot(); -}; - -void SubObjD::aSlot() -{ -} - -void ObjD::go() -{ - SubObjD subObj; -} - -#include "ObjD.moc" -// Header in subdirectory -#include "subA/moc_SubObjA.cpp" diff --git a/Tests/QtAutogen/mocInclude/ObjD.hpp b/Tests/QtAutogen/mocInclude/ObjD.hpp deleted file mode 100644 index b6ee098..0000000 --- a/Tests/QtAutogen/mocInclude/ObjD.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef OBJD_HPP -#define OBJD_HPP - -#include <QObject> - -class ObjD : public QObject -{ - Q_OBJECT - Q_SLOT - void go(); -}; - -#endif diff --git a/Tests/QtAutogen/mocInclude/SObjA.cpp b/Tests/QtAutogen/mocInclude/SObjA.cpp new file mode 100644 index 0000000..7e75bf9 --- /dev/null +++ b/Tests/QtAutogen/mocInclude/SObjA.cpp @@ -0,0 +1,11 @@ +#include "SObjA.hpp" + +SObjA::SObjA() +{ +} + +SObjA::~SObjA() +{ +} + +#include "SObjA.moc" diff --git a/Tests/QtAutogen/mocInclude/SObjA.hpp b/Tests/QtAutogen/mocInclude/SObjA.hpp new file mode 100644 index 0000000..1436abc --- /dev/null +++ b/Tests/QtAutogen/mocInclude/SObjA.hpp @@ -0,0 +1,15 @@ +#ifndef SOBJA_HPP +#define SOBJA_HPP + +#include <QObject> + +// Object source includes externally generated .moc file +class SObjA : public QObject +{ + Q_OBJECT +public: + SObjA(); + ~SObjA(); +}; + +#endif diff --git a/Tests/QtAutogen/mocInclude/SObjB.cpp.in b/Tests/QtAutogen/mocInclude/SObjB.cpp.in new file mode 100644 index 0000000..b1cc12a --- /dev/null +++ b/Tests/QtAutogen/mocInclude/SObjB.cpp.in @@ -0,0 +1,11 @@ +#include "SObjB.hpp" + +SObjB::SObjB() +{ +} + +SObjB::~SObjB() +{ +} + +#include "SObjB.moc" diff --git a/Tests/QtAutogen/mocInclude/SObjB.hpp.in b/Tests/QtAutogen/mocInclude/SObjB.hpp.in new file mode 100644 index 0000000..5e396ae --- /dev/null +++ b/Tests/QtAutogen/mocInclude/SObjB.hpp.in @@ -0,0 +1,15 @@ +#ifndef SOBJB_HPP +#define SOBJB_HPP + +#include <QObject> + +// Object source includes externally generated .moc file +class SObjB : public QObject +{ + Q_OBJECT +public: + SObjB(); + ~SObjB(); +}; + +#endif diff --git a/Tests/QtAutogen/mocInclude/SObjC.cpp b/Tests/QtAutogen/mocInclude/SObjC.cpp new file mode 100644 index 0000000..1e8d397 --- /dev/null +++ b/Tests/QtAutogen/mocInclude/SObjC.cpp @@ -0,0 +1,35 @@ +#include "SObjC.hpp" + +void SObjCLocalFunction(); + +class SObjCLocal : public QObject +{ + Q_OBJECT + +public: + SObjCLocal(); + ~SObjCLocal(); +}; + +SObjCLocal::SObjCLocal() +{ +} + +SObjCLocal::~SObjCLocal() +{ +} + +SObjC::SObjC() +{ + SObjCLocal localObject; + SObjCLocalFunction(); +} + +SObjC::~SObjC() +{ +} + +#include "SObjC.moc" +#include "moc_SObjC.cpp" +// Include moc_ file for which the header is SKIP_AUTOMOC enabled +#include "moc_SObjCExtra.cpp" diff --git a/Tests/QtAutogen/mocInclude/SObjC.hpp b/Tests/QtAutogen/mocInclude/SObjC.hpp new file mode 100644 index 0000000..def0f9d --- /dev/null +++ b/Tests/QtAutogen/mocInclude/SObjC.hpp @@ -0,0 +1,15 @@ +#ifndef SOBJC_HPP +#define SOBJC_HPP + +#include <QObject> + +// Object source includes externally generated .moc file +class SObjC : public QObject +{ + Q_OBJECT +public: + SObjC(); + ~SObjC(); +}; + +#endif diff --git a/Tests/QtAutogen/mocInclude/SObjCExtra.cpp b/Tests/QtAutogen/mocInclude/SObjCExtra.cpp new file mode 100644 index 0000000..55dd1c3 --- /dev/null +++ b/Tests/QtAutogen/mocInclude/SObjCExtra.cpp @@ -0,0 +1,31 @@ +#include "SObjCExtra.hpp" + +class SObjCLocalExtra : public QObject +{ + Q_OBJECT + +public: + SObjCLocalExtra(); + ~SObjCLocalExtra(); +}; + +SObjCLocalExtra::SObjCLocalExtra() +{ +} + +SObjCLocalExtra::~SObjCLocalExtra() +{ +} + +SObjCExtra::SObjCExtra() +{ +} + +SObjCExtra::~SObjCExtra() +{ +} + +// Externally generated header moc +#include "SObjCExtra_extMoc.cpp" +// AUTOMOC generated source moc +#include "SObjCExtra.moc" diff --git a/Tests/QtAutogen/mocInclude/SObjCExtra.hpp b/Tests/QtAutogen/mocInclude/SObjCExtra.hpp new file mode 100644 index 0000000..08545ac --- /dev/null +++ b/Tests/QtAutogen/mocInclude/SObjCExtra.hpp @@ -0,0 +1,15 @@ +#ifndef SOBJCEXTRA_HPP +#define SOBJCEXTRA_HPP + +#include <QObject> + +// Object source includes externally generated .moc file +class SObjCExtra : public QObject +{ + Q_OBJECT +public: + SObjCExtra(); + ~SObjCExtra(); +}; + +#endif diff --git a/Tests/QtAutogen/mocInclude/SObjCExtra.moc.in b/Tests/QtAutogen/mocInclude/SObjCExtra.moc.in new file mode 100644 index 0000000..00fc4aa --- /dev/null +++ b/Tests/QtAutogen/mocInclude/SObjCExtra.moc.in @@ -0,0 +1,4 @@ + +void SObjCLocalFunction() +{ +} diff --git a/Tests/QtAutogen/mocInclude/shared.cmake b/Tests/QtAutogen/mocInclude/shared.cmake new file mode 100644 index 0000000..d05f27c --- /dev/null +++ b/Tests/QtAutogen/mocInclude/shared.cmake @@ -0,0 +1,71 @@ +# Test moc include patterns +include_directories("../mocInclude") +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +# Generate .moc file externally and enabled SKIP_AUTOMOC on the file +qtx_generate_moc( + ${CMAKE_CURRENT_SOURCE_DIR}/../mocInclude/SObjA.hpp + ${CMAKE_CURRENT_BINARY_DIR}/SObjA.moc) +set_property(SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/../mocInclude/SObjA.cpp PROPERTY SKIP_AUTOMOC ON) + +# Generate .moc file externally from generated source file +# and enabled SKIP_AUTOMOC on the source file +add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/SObjB.hpp + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_CURRENT_SOURCE_DIR}/../mocInclude/SObjB.hpp.in + ${CMAKE_CURRENT_BINARY_DIR}/SObjB.hpp) +add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/SObjB.cpp + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_CURRENT_SOURCE_DIR}/../mocInclude/SObjB.cpp.in + ${CMAKE_CURRENT_BINARY_DIR}/SObjB.cpp) +qtx_generate_moc( + ${CMAKE_CURRENT_BINARY_DIR}/SObjB.hpp + ${CMAKE_CURRENT_BINARY_DIR}/SObjB.moc) +set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/SObjB.cpp PROPERTY SKIP_AUTOMOC ON) + +# Generate moc file externally and enabled SKIP_AUTOMOC on the header +qtx_generate_moc( + ${CMAKE_CURRENT_SOURCE_DIR}/../mocInclude/SObjCExtra.hpp + ${CMAKE_CURRENT_BINARY_DIR}/SObjCExtra_extMoc.cpp) +set_property( + SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/../mocInclude/SObjCExtra.hpp + PROPERTY SKIP_AUTOMOC ON) +# Custom target to depend on +set(SOBJC_MOC ${CMAKE_CURRENT_BINARY_DIR}/moc_SObjCExtra.cpp) +add_custom_target("${MOC_INCLUDE_NAME}_SOBJC" + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/SObjCExtra_extMoc.cpp + BYPRODUCTS ${SOBJC_MOC} + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_CURRENT_SOURCE_DIR}/../mocInclude/SObjCExtra.moc.in + ${SOBJC_MOC}) + +# MOC_INCLUDE_NAME must be defined by the includer +add_executable(${MOC_INCLUDE_NAME} + # Common sources + ../mocInclude/ObjA.cpp + ../mocInclude/ObjB.cpp + + ../mocInclude/LObjA.cpp + ../mocInclude/LObjB.cpp + + ../mocInclude/EObjA.cpp + ../mocInclude/EObjAExtra.cpp + ../mocInclude/EObjB.cpp + ../mocInclude/subExtra/EObjBExtra.cpp + + ../mocInclude/SObjA.cpp + ${CMAKE_CURRENT_BINARY_DIR}/SObjA.moc + ${CMAKE_CURRENT_BINARY_DIR}/SObjB.cpp + ${CMAKE_CURRENT_BINARY_DIR}/SObjB.moc + ../mocInclude/SObjC.cpp + ../mocInclude/SObjCExtra.hpp + ../mocInclude/SObjCExtra.cpp + + ../mocInclude/subGlobal/GObj.cpp + main.cpp +) +add_dependencies(${MOC_INCLUDE_NAME} "${MOC_INCLUDE_NAME}_SOBJC") +target_link_libraries(${MOC_INCLUDE_NAME} ${QT_LIBRARIES}) +set_target_properties(${MOC_INCLUDE_NAME} PROPERTIES AUTOMOC ON) diff --git a/Tests/QtAutogen/mocInclude/subA/SubObjA.cpp b/Tests/QtAutogen/mocInclude/subA/SubObjA.cpp deleted file mode 100644 index a05f6e3..0000000 --- a/Tests/QtAutogen/mocInclude/subA/SubObjA.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "SubObjA.hpp" - -namespace subA { - -class SubObjA : public QObject -{ - Q_OBJECT - -public: - SubObjA() {} - ~SubObjA() {} - - Q_SLOT - void aSlot(); -}; - -void SubObjA::aSlot() -{ -} - -void ObjA::go() -{ - SubObjA subObj; -} -} - -#include "SubObjA.moc" diff --git a/Tests/QtAutogen/mocInclude/subA/SubObjA.hpp b/Tests/QtAutogen/mocInclude/subA/SubObjA.hpp deleted file mode 100644 index 31a18b6..0000000 --- a/Tests/QtAutogen/mocInclude/subA/SubObjA.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef SUBOBJA_HPP -#define SUBOBJA_HPP - -#include <QObject> - -namespace subA { - -class ObjA : public QObject -{ - Q_OBJECT - Q_SLOT - void go(); -}; -} - -#endif diff --git a/Tests/QtAutogen/mocInclude/subB/SubObjB.cpp b/Tests/QtAutogen/mocInclude/subB/SubObjB.cpp deleted file mode 100644 index 1e77639..0000000 --- a/Tests/QtAutogen/mocInclude/subB/SubObjB.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "SubObjB.hpp" - -namespace subB { - -class SubObjB : public QObject -{ - Q_OBJECT - -public: - SubObjB() {} - ~SubObjB() {} - - Q_SLOT - void aSlot(); -}; - -void SubObjB::aSlot() -{ -} - -void ObjB::go() -{ - SubObjB subObj; -} -} - -#include "SubObjB.moc" diff --git a/Tests/QtAutogen/mocInclude/subB/SubObjB.hpp b/Tests/QtAutogen/mocInclude/subB/SubObjB.hpp deleted file mode 100644 index 3f29fa2..0000000 --- a/Tests/QtAutogen/mocInclude/subB/SubObjB.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef SUBOBJB_HPP -#define SUBOBJB_HPP - -#include <QObject> - -namespace subB { - -class ObjB : public QObject -{ - Q_OBJECT - Q_SLOT - void go(); -}; -} - -#endif diff --git a/Tests/QtAutogen/mocInclude/subC/SubObjC.cpp b/Tests/QtAutogen/mocInclude/subC/SubObjC.cpp deleted file mode 100644 index c2d94ef..0000000 --- a/Tests/QtAutogen/mocInclude/subC/SubObjC.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "SubObjC.hpp" - -namespace subC { - -class SubObjC : public QObject -{ - Q_OBJECT - -public: - SubObjC() {} - ~SubObjC() {} - - Q_SLOT - void aSlot(); -}; - -void SubObjC::aSlot() -{ -} - -void ObjC::go() -{ - SubObjC subObj; -} -} - -#include "SubObjC.moc" diff --git a/Tests/QtAutogen/mocInclude/subC/SubObjC.hpp b/Tests/QtAutogen/mocInclude/subC/SubObjC.hpp deleted file mode 100644 index dc251fd..0000000 --- a/Tests/QtAutogen/mocInclude/subC/SubObjC.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef SUBOBJC_HPP -#define SUBOBJC_HPP - -#include <QObject> - -namespace subC { - -class ObjC : public QObject -{ - Q_OBJECT - Q_SLOT - void go(); -}; -} - -#endif diff --git a/Tests/QtAutogen/mocInclude/subExtra/EObjBExtra.cpp b/Tests/QtAutogen/mocInclude/subExtra/EObjBExtra.cpp new file mode 100644 index 0000000..c697866 --- /dev/null +++ b/Tests/QtAutogen/mocInclude/subExtra/EObjBExtra.cpp @@ -0,0 +1,20 @@ +#include "EObjBExtra.hpp" +#include "EObjBExtra_p.hpp" + +EObjBExtraPrivate::EObjBExtraPrivate() +{ +} + +EObjBExtraPrivate::~EObjBExtraPrivate() +{ +} + +EObjBExtra::EObjBExtra() + : d(new EObjBExtraPrivate) +{ +} + +EObjBExtra::~EObjBExtra() +{ + delete d; +} diff --git a/Tests/QtAutogen/mocInclude/subExtra/EObjBExtra.hpp b/Tests/QtAutogen/mocInclude/subExtra/EObjBExtra.hpp new file mode 100644 index 0000000..3798d7f --- /dev/null +++ b/Tests/QtAutogen/mocInclude/subExtra/EObjBExtra.hpp @@ -0,0 +1,18 @@ +#ifndef EOBJBEXTRA_HPP +#define EOBJBEXTRA_HPP + +#include <QObject> + +class EObjBExtraPrivate; +class EObjBExtra : public QObject +{ + Q_OBJECT +public: + EObjBExtra(); + ~EObjBExtra(); + +private: + EObjBExtraPrivate* const d; +}; + +#endif diff --git a/Tests/QtAutogen/mocInclude/subExtra/EObjBExtra_p.hpp b/Tests/QtAutogen/mocInclude/subExtra/EObjBExtra_p.hpp new file mode 100644 index 0000000..db8a096 --- /dev/null +++ b/Tests/QtAutogen/mocInclude/subExtra/EObjBExtra_p.hpp @@ -0,0 +1,12 @@ +#ifndef EOBJBEXTRA_P_HPP +#define EOBJBEXTRA_P_HPP + +class EObjBExtraPrivate : public QObject +{ + Q_OBJECT +public: + EObjBExtraPrivate(); + ~EObjBExtraPrivate(); +}; + +#endif diff --git a/Tests/QtAutogen/mocInclude/subGlobal/GObj.cpp b/Tests/QtAutogen/mocInclude/subGlobal/GObj.cpp new file mode 100644 index 0000000..6b92f21 --- /dev/null +++ b/Tests/QtAutogen/mocInclude/subGlobal/GObj.cpp @@ -0,0 +1,41 @@ +#include "GObj.hpp" +#include "GObj_p.hpp" + +namespace subGlobal { + +class GObjLocal : public QObject +{ + Q_OBJECT +public: + GObjLocal(); + ~GObjLocal(); +}; + +GObjLocal::GObjLocal() +{ +} + +GObjLocal::~GObjLocal() +{ +} + +GObjPrivate::GObjPrivate() +{ +} + +GObjPrivate::~GObjPrivate() +{ +} + +GObj::GObj() +{ + GObjLocal localObj; +} + +GObj::~GObj() +{ +} +} + +// For the local QObject +#include "GObj.moc" diff --git a/Tests/QtAutogen/mocInclude/subGlobal/GObj.hpp b/Tests/QtAutogen/mocInclude/subGlobal/GObj.hpp new file mode 100644 index 0000000..2f9ee82 --- /dev/null +++ b/Tests/QtAutogen/mocInclude/subGlobal/GObj.hpp @@ -0,0 +1,17 @@ +#ifndef GOBJ_HPP +#define GOBJ_HPP + +#include <QObject> + +namespace subGlobal { + +class GObj : public QObject +{ + Q_OBJECT +public: + GObj(); + ~GObj(); +}; +} + +#endif diff --git a/Tests/QtAutogen/mocInclude/subGlobal/GObj_p.hpp b/Tests/QtAutogen/mocInclude/subGlobal/GObj_p.hpp new file mode 100644 index 0000000..7b37dfd --- /dev/null +++ b/Tests/QtAutogen/mocInclude/subGlobal/GObj_p.hpp @@ -0,0 +1,15 @@ +#ifndef GOBJ_P_HPP +#define GOBJ_P_HPP + +namespace subGlobal { + +class GObjPrivate : public QObject +{ + Q_OBJECT +public: + GObjPrivate(); + ~GObjPrivate(); +}; +} + +#endif diff --git a/Tests/QtAutogen/mocIncludeRelaxed/CMakeLists.txt b/Tests/QtAutogen/mocIncludeRelaxed/CMakeLists.txt index 6a0829d..97ba1df 100644 --- a/Tests/QtAutogen/mocIncludeRelaxed/CMakeLists.txt +++ b/Tests/QtAutogen/mocIncludeRelaxed/CMakeLists.txt @@ -2,17 +2,16 @@ set(CMAKE_AUTOMOC_RELAXED_MODE TRUE) -include_directories("../mocInclude") +# Shared executable +set(MOC_INCLUDE_NAME "mocIncludeRelaxed") +include(${CMAKE_CURRENT_SOURCE_DIR}/../mocInclude/shared.cmake) -add_executable(mocIncludeRelaxed - ../mocInclude/ObjA.cpp - ../mocInclude/ObjB.cpp - ../mocInclude/ObjC.cpp - ../mocInclude/ObjD.cpp - ../mocInclude/subA/SubObjA.cpp - ../mocInclude/subB/SubObjB.cpp - ../mocInclude/subC/SubObjC.cpp - main.cpp +# Relaxed ony executable +add_executable(mocIncludeRelaxedOnly + RObjA.cpp + RObjB.cpp + RObjC.cpp + RMain.cpp ) -target_link_libraries(mocIncludeRelaxed ${QT_LIBRARIES}) -set_target_properties(mocIncludeRelaxed PROPERTIES AUTOMOC ON) +target_link_libraries(mocIncludeRelaxedOnly ${QT_LIBRARIES}) +set_target_properties(mocIncludeRelaxedOnly PROPERTIES AUTOMOC ON) diff --git a/Tests/QtAutogen/mocIncludeRelaxed/RMain.cpp b/Tests/QtAutogen/mocIncludeRelaxed/RMain.cpp new file mode 100644 index 0000000..5b2c070 --- /dev/null +++ b/Tests/QtAutogen/mocIncludeRelaxed/RMain.cpp @@ -0,0 +1,12 @@ +// Relaxed AUTOMOC objects +#include "RObjA.hpp" +#include "RObjB.hpp" +#include "RObjC.hpp" + +int main(int argv, char** args) +{ + RObjA rObjA; + RObjB rObjB; + RObjC rObjC; + return 0; +} diff --git a/Tests/QtAutogen/mocIncludeRelaxed/RObjA.cpp b/Tests/QtAutogen/mocIncludeRelaxed/RObjA.cpp new file mode 100644 index 0000000..2e2cf6a --- /dev/null +++ b/Tests/QtAutogen/mocIncludeRelaxed/RObjA.cpp @@ -0,0 +1,12 @@ +#include "RObjA.hpp" + +RObjA::RObjA() +{ +} + +RObjA::~RObjA() +{ +} + +// Relaxed include should moc the header instead +#include "RObjA.moc" diff --git a/Tests/QtAutogen/mocIncludeRelaxed/RObjA.hpp b/Tests/QtAutogen/mocIncludeRelaxed/RObjA.hpp new file mode 100644 index 0000000..5974187 --- /dev/null +++ b/Tests/QtAutogen/mocIncludeRelaxed/RObjA.hpp @@ -0,0 +1,14 @@ +#ifndef ROBJA_HPP +#define ROBJA_HPP + +#include <QObject> + +class RObjA : public QObject +{ + Q_OBJECT +public: + RObjA(); + ~RObjA(); +}; + +#endif diff --git a/Tests/QtAutogen/mocIncludeRelaxed/RObjB.cpp b/Tests/QtAutogen/mocIncludeRelaxed/RObjB.cpp new file mode 100644 index 0000000..c56d10f --- /dev/null +++ b/Tests/QtAutogen/mocIncludeRelaxed/RObjB.cpp @@ -0,0 +1,22 @@ +#include "RObjB.hpp" +#include "RObjBExtra.hpp" + +RObjBExtra::RObjBExtra() +{ +} + +RObjBExtra::~RObjBExtra() +{ +} + +RObjB::RObjB() +{ + RObjBExtra extraObject; +} + +RObjB::~RObjB() +{ +} + +// Relaxed mode should run moc on RObjBExtra.hpp instead +#include "RObjBExtra.moc" diff --git a/Tests/QtAutogen/mocIncludeRelaxed/RObjB.hpp b/Tests/QtAutogen/mocIncludeRelaxed/RObjB.hpp new file mode 100644 index 0000000..d6d0474 --- /dev/null +++ b/Tests/QtAutogen/mocIncludeRelaxed/RObjB.hpp @@ -0,0 +1,14 @@ +#ifndef ROBJB_HPP +#define ROBJB_HPP + +#include <QObject> + +class RObjB : public QObject +{ + Q_OBJECT +public: + RObjB(); + ~RObjB(); +}; + +#endif diff --git a/Tests/QtAutogen/mocIncludeRelaxed/RObjBExtra.hpp b/Tests/QtAutogen/mocIncludeRelaxed/RObjBExtra.hpp new file mode 100644 index 0000000..5d6be75 --- /dev/null +++ b/Tests/QtAutogen/mocIncludeRelaxed/RObjBExtra.hpp @@ -0,0 +1,14 @@ +#ifndef ROBJBEXTRA_HPP +#define ROBJBEXTRA_HPP + +#include <QObject> + +class RObjBExtra : public QObject +{ + Q_OBJECT +public: + RObjBExtra(); + ~RObjBExtra(); +}; + +#endif diff --git a/Tests/QtAutogen/mocIncludeRelaxed/RObjC.cpp b/Tests/QtAutogen/mocIncludeRelaxed/RObjC.cpp new file mode 100644 index 0000000..4ba32f5 --- /dev/null +++ b/Tests/QtAutogen/mocIncludeRelaxed/RObjC.cpp @@ -0,0 +1,30 @@ +#include "RObjC.hpp" +#include <QObject> + +class RObjCPrivate : public QObject +{ + Q_OBJECT +public: + RObjCPrivate(); + ~RObjCPrivate(); +}; + +RObjCPrivate::RObjCPrivate() +{ +} + +RObjCPrivate::~RObjCPrivate() +{ +} + +RObjC::RObjC() +{ + RObjCPrivate privateObject; +} + +RObjC::~RObjC() +{ +} + +// Relaxed include should moc this source instead of the header +#include "moc_RObjC.cpp" diff --git a/Tests/QtAutogen/mocIncludeRelaxed/RObjC.hpp b/Tests/QtAutogen/mocIncludeRelaxed/RObjC.hpp new file mode 100644 index 0000000..5552ede --- /dev/null +++ b/Tests/QtAutogen/mocIncludeRelaxed/RObjC.hpp @@ -0,0 +1,14 @@ +#ifndef ROBJC_HPP +#define ROBJC_HPP + +#include <QObject> + +class RObjC : public QObject +{ + Q_OBJECT +public: + RObjC(); + ~RObjC(); +}; + +#endif diff --git a/Tests/QtAutogen/mocIncludeRelaxed/main.cpp b/Tests/QtAutogen/mocIncludeRelaxed/main.cpp index 142d59e..5a3148d 100644 --- a/Tests/QtAutogen/mocIncludeRelaxed/main.cpp +++ b/Tests/QtAutogen/mocIncludeRelaxed/main.cpp @@ -1,14 +1,26 @@ +#include "EObjA.hpp" +#include "EObjB.hpp" +#include "LObjA.hpp" +#include "LObjB.hpp" #include "ObjA.hpp" #include "ObjB.hpp" -#include "ObjC.hpp" +#include "SObjA.hpp" +#include "SObjB.hpp" +#include "subGlobal/GObj.hpp" int main(int argv, char** args) { + subGlobal::GObj gObj; ObjA objA; ObjB objB; - ObjC objC; + LObjA lObjA; + LObjB lObjB; + EObjA eObjA; + EObjB eObjB; + SObjA sObjA; + SObjB sObjB; return 0; } // Header in global subdirectory -#include "subB/moc_SubObjB.cpp" +#include "subGlobal/moc_GObj.cpp" diff --git a/Tests/QtAutogen/mocIncludeStrict/CMakeLists.txt b/Tests/QtAutogen/mocIncludeStrict/CMakeLists.txt index 22e93a8..789354a 100644 --- a/Tests/QtAutogen/mocIncludeStrict/CMakeLists.txt +++ b/Tests/QtAutogen/mocIncludeStrict/CMakeLists.txt @@ -1,18 +1,6 @@ # Test moc include patterns set(CMAKE_AUTOMOC_RELAXED_MODE FALSE) +set(MOC_INCLUDE_NAME "mocIncludeStrict") -include_directories("../mocInclude") - -add_executable(mocIncludeStrict - ../mocInclude/ObjA.cpp - ../mocInclude/ObjB.cpp - ../mocInclude/ObjC.cpp - ../mocInclude/ObjD.cpp - ../mocInclude/subA/SubObjA.cpp - ../mocInclude/subB/SubObjB.cpp - ../mocInclude/subC/SubObjC.cpp - main.cpp -) -target_link_libraries(mocIncludeStrict ${QT_LIBRARIES}) -set_target_properties(mocIncludeStrict PROPERTIES AUTOMOC ON) +include(${CMAKE_CURRENT_SOURCE_DIR}/../mocInclude/shared.cmake) diff --git a/Tests/QtAutogen/mocIncludeStrict/main.cpp b/Tests/QtAutogen/mocIncludeStrict/main.cpp index 142d59e..5a3148d 100644 --- a/Tests/QtAutogen/mocIncludeStrict/main.cpp +++ b/Tests/QtAutogen/mocIncludeStrict/main.cpp @@ -1,14 +1,26 @@ +#include "EObjA.hpp" +#include "EObjB.hpp" +#include "LObjA.hpp" +#include "LObjB.hpp" #include "ObjA.hpp" #include "ObjB.hpp" -#include "ObjC.hpp" +#include "SObjA.hpp" +#include "SObjB.hpp" +#include "subGlobal/GObj.hpp" int main(int argv, char** args) { + subGlobal::GObj gObj; ObjA objA; ObjB objB; - ObjC objC; + LObjA lObjA; + LObjB lObjB; + EObjA eObjA; + EObjB eObjB; + SObjA sObjA; + SObjB sObjB; return 0; } // Header in global subdirectory -#include "subB/moc_SubObjB.cpp" +#include "subGlobal/moc_GObj.cpp" diff --git a/Tests/QtAutogen/mocMacroName/MacroAlias.hpp b/Tests/QtAutogen/mocMacroName/MacroAlias.hpp new file mode 100644 index 0000000..cf06f2a --- /dev/null +++ b/Tests/QtAutogen/mocMacroName/MacroAlias.hpp @@ -0,0 +1,7 @@ +#ifndef MACROALIAS_HPP +#define MACROALIAS_HPP + +#include <QObject> +#define QO_ALIAS Q_OBJECT + +#endif diff --git a/Tests/QtAutogen/mocMacroName/MacroName.cpp b/Tests/QtAutogen/mocMacroName/MacroName.cpp new file mode 100644 index 0000000..78d04a8 --- /dev/null +++ b/Tests/QtAutogen/mocMacroName/MacroName.cpp @@ -0,0 +1,9 @@ +#include "MacroName.hpp" + +MacroName::MacroName() +{ +} + +void MacroName::aSlot() +{ +} diff --git a/Tests/QtAutogen/mocMacroName/MacroName.hpp b/Tests/QtAutogen/mocMacroName/MacroName.hpp new file mode 100644 index 0000000..b6c7306 --- /dev/null +++ b/Tests/QtAutogen/mocMacroName/MacroName.hpp @@ -0,0 +1,20 @@ +#ifndef MACRONAME_HPP +#define MACRONAME_HPP + +#include "MacroAlias.hpp" + +// Test Qt object macro hidden in a macro (AUTOMOC_MACRO_NAMES) +class MacroName : public QObject +{ + QO_ALIAS +public: + MacroName(); + +signals: + void aSignal(); + +public slots: + void aSlot(); +}; + +#endif diff --git a/Tests/QtAutogen/mocMacroName/main.cpp b/Tests/QtAutogen/mocMacroName/main.cpp new file mode 100644 index 0000000..67ee81f --- /dev/null +++ b/Tests/QtAutogen/mocMacroName/main.cpp @@ -0,0 +1,7 @@ +#include "MacroName.hpp" + +int main(int argv, char** args) +{ + MacroName macroName; + return 0; +} diff --git a/Tests/QtAutogen/mocOnlySource/StyleA.cpp b/Tests/QtAutogen/mocOnlySource/StyleA.cpp new file mode 100644 index 0000000..ced1dd1 --- /dev/null +++ b/Tests/QtAutogen/mocOnlySource/StyleA.cpp @@ -0,0 +1,5 @@ +#include "StyleA.hpp" + +StyleA::StyleA() +{ +} diff --git a/Tests/QtAutogen/mocOnlySource/StyleA.hpp b/Tests/QtAutogen/mocOnlySource/StyleA.hpp new file mode 100644 index 0000000..66735b6 --- /dev/null +++ b/Tests/QtAutogen/mocOnlySource/StyleA.hpp @@ -0,0 +1,15 @@ +#ifndef STYLEA_HPP +#define STYLEA_HPP + +#include <QObject> + +/// Q_OBJECT on a single new line +/// +class StyleA : public QObject +{ + Q_OBJECT +public: + StyleA(); +}; + +#endif diff --git a/Tests/QtAutogen/mocOnlySource/StyleB.cpp b/Tests/QtAutogen/mocOnlySource/StyleB.cpp new file mode 100644 index 0000000..bec6c1c --- /dev/null +++ b/Tests/QtAutogen/mocOnlySource/StyleB.cpp @@ -0,0 +1,5 @@ +#include "StyleB.hpp" + +StyleB::StyleB() +{ +} diff --git a/Tests/QtAutogen/mocOnlySource/StyleB.hpp b/Tests/QtAutogen/mocOnlySource/StyleB.hpp new file mode 100644 index 0000000..425daf8 --- /dev/null +++ b/Tests/QtAutogen/mocOnlySource/StyleB.hpp @@ -0,0 +1,16 @@ +#ifndef STYLEB_HPP +#define STYLEB_HPP + +#include <QObject> + +/* clang-format off */ +/// Q_OBJECT behind a brace +/// +class StyleB : public QObject +{ Q_OBJECT +public: + StyleB(); +}; +/* clang-format on */ + +#endif diff --git a/Tests/QtAutogen/mocOnlySource/main.cpp b/Tests/QtAutogen/mocOnlySource/main.cpp new file mode 100644 index 0000000..06f8d81 --- /dev/null +++ b/Tests/QtAutogen/mocOnlySource/main.cpp @@ -0,0 +1,9 @@ +#include "StyleA.hpp" +#include "StyleB.hpp" + +int main(int argv, char** args) +{ + StyleA styleA; + StyleB styleB; + return 0; +} diff --git a/Tests/QtAutogen/objectLibrary/CMakeLists.txt b/Tests/QtAutogen/objectLibrary/CMakeLists.txt new file mode 100644 index 0000000..9b29a40 --- /dev/null +++ b/Tests/QtAutogen/objectLibrary/CMakeLists.txt @@ -0,0 +1,14 @@ +set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(CMAKE_AUTOMOC ON) + +# Object library a defined in a subdirectory +add_subdirectory(a) + +# Object library b defined locally +include_directories(b) +add_library(b OBJECT b/classb.cpp) +target_compile_features(b PRIVATE ${QT_COMPILE_FEATURES}) + +# Executable with OBJECT library generator expressions +add_executable(someProgram main.cpp $<TARGET_OBJECTS:a> $<TARGET_OBJECTS:b>) +target_link_libraries(someProgram ${QT_LIBRARIES}) diff --git a/Tests/QtAutogen/objectLibrary/a/CMakeLists.txt b/Tests/QtAutogen/objectLibrary/a/CMakeLists.txt new file mode 100644 index 0000000..fe76ac3 --- /dev/null +++ b/Tests/QtAutogen/objectLibrary/a/CMakeLists.txt @@ -0,0 +1,2 @@ +add_library(a OBJECT classa.cpp) +target_compile_features(a PRIVATE ${QT_COMPILE_FEATURES}) diff --git a/Tests/QtAutogen/objectLibrary/a/classa.cpp b/Tests/QtAutogen/objectLibrary/a/classa.cpp new file mode 100644 index 0000000..4f08fda --- /dev/null +++ b/Tests/QtAutogen/objectLibrary/a/classa.cpp @@ -0,0 +1,7 @@ +#include "classa.h" +#include <QDebug> + +void ClassA::slotDoSomething() +{ + qDebug() << m_member; +} diff --git a/Tests/QtAutogen/objectLibrary/a/classa.h b/Tests/QtAutogen/objectLibrary/a/classa.h new file mode 100644 index 0000000..fa5fed9 --- /dev/null +++ b/Tests/QtAutogen/objectLibrary/a/classa.h @@ -0,0 +1,23 @@ +#ifndef CLASSA_H +#define CLASSA_H + +#include <QObject> +#include <QString> + +class ClassA : public QObject +{ + Q_OBJECT +public: + ClassA() + : m_member("Hello A") + { + } + +public slots: + void slotDoSomething(); + +private: + QString m_member; +}; + +#endif diff --git a/Tests/QtAutogen/objectLibrary/b/classb.cpp b/Tests/QtAutogen/objectLibrary/b/classb.cpp new file mode 100644 index 0000000..26e0926 --- /dev/null +++ b/Tests/QtAutogen/objectLibrary/b/classb.cpp @@ -0,0 +1,7 @@ +#include "classb.h" +#include <QDebug> + +void ClassB::slotDoSomething() +{ + qDebug() << m_member; +} diff --git a/Tests/QtAutogen/objectLibrary/b/classb.h b/Tests/QtAutogen/objectLibrary/b/classb.h new file mode 100644 index 0000000..783bb48 --- /dev/null +++ b/Tests/QtAutogen/objectLibrary/b/classb.h @@ -0,0 +1,23 @@ +#ifndef CLASSB_H +#define CLASSB_H + +#include <QObject> +#include <QString> + +class ClassB : public QObject +{ + Q_OBJECT +public: + ClassB() + : m_member("Hello B") + { + } + +public slots: + void slotDoSomething(); + +private: + QString m_member; +}; + +#endif diff --git a/Tests/QtAutogen/objectLibrary/main.cpp b/Tests/QtAutogen/objectLibrary/main.cpp new file mode 100644 index 0000000..cacf0fd --- /dev/null +++ b/Tests/QtAutogen/objectLibrary/main.cpp @@ -0,0 +1,13 @@ +#include "a/classa.h" +#include "b/classb.h" + +int main(int argc, char** argv) +{ + ClassA a; + a.slotDoSomething(); + + ClassB b; + b.slotDoSomething(); + + return 0; +} diff --git a/Tests/QtAutogen/uicInclude/PageC2.ui b/Tests/QtAutogen/uicInclude/PageC2.ui new file mode 100644 index 0000000..daab868 --- /dev/null +++ b/Tests/QtAutogen/uicInclude/PageC2.ui @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>PageC2</class> + <widget class="QWidget" name="PageC2"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QTreeView" name="treeView"/> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/Tests/QtAutogen/uicInclude/dirB/sub/PageB.ui b/Tests/QtAutogen/uicInclude/dirB/PageB.ui index fa6dfa6..fa6dfa6 100644 --- a/Tests/QtAutogen/uicInclude/dirB/sub/PageB.ui +++ b/Tests/QtAutogen/uicInclude/dirB/PageB.ui diff --git a/Tests/QtAutogen/uicInclude/dirB/PageB2.ui b/Tests/QtAutogen/uicInclude/dirB/PageB2.ui new file mode 100644 index 0000000..2225150 --- /dev/null +++ b/Tests/QtAutogen/uicInclude/dirB/PageB2.ui @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>PageB2</class> + <widget class="QWidget" name="PageB2"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QTreeView" name="treeView"/> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/Tests/QtAutogen/uicInclude/dirB/subB/PageBsub.ui b/Tests/QtAutogen/uicInclude/dirB/subB/PageBsub.ui new file mode 100644 index 0000000..873016e --- /dev/null +++ b/Tests/QtAutogen/uicInclude/dirB/subB/PageBsub.ui @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>PageBsub</class> + <widget class="QWidget" name="PageBsub"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QTreeView" name="treeView"/> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/Tests/QtAutogen/uicInclude/main.cpp b/Tests/QtAutogen/uicInclude/main.cpp index 4ca66a7..c8e7609 100644 --- a/Tests/QtAutogen/uicInclude/main.cpp +++ b/Tests/QtAutogen/uicInclude/main.cpp @@ -6,5 +6,13 @@ int main(int argv, char** args) return 0; } -#include "sub/ui_PageB.h" +// .ui files in CMAKE_AUTOUIC_SEARCH_PATHS +#include "ui_PageA.h" +// .ui files in AUTOUIC_SEARCH_PATHS +#include "sub/gen/deep/ui_PageB2.h" +#include "subB/ui_PageBsub.h" +#include "ui_PageB.h" +// .ui files in source's vicinity +#include "sub/gen/deep/ui_PageC2.h" +#include "subC/ui_PageCsub.h" #include "ui_PageC.h" diff --git a/Tests/QtAutogen/uicInclude/subC/PageCsub.ui b/Tests/QtAutogen/uicInclude/subC/PageCsub.ui new file mode 100644 index 0000000..0268326 --- /dev/null +++ b/Tests/QtAutogen/uicInclude/subC/PageCsub.ui @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>PageCsub</class> + <widget class="QWidget" name="PageCsub"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QTreeView" name="treeView"/> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/Tests/QtAutogenRerun/CMakeLists.txt b/Tests/QtAutogenRerun/CMakeLists.txt new file mode 100644 index 0000000..088025f --- /dev/null +++ b/Tests/QtAutogenRerun/CMakeLists.txt @@ -0,0 +1,239 @@ +cmake_minimum_required(VERSION 3.9) +cmake_policy(SET CMP0071 NEW) +project(QtAutogenRerun) + +# Tell find_package(Qt5) where to find Qt. +if(QT_QMAKE_EXECUTABLE) + get_filename_component(Qt_BIN_DIR "${QT_QMAKE_EXECUTABLE}" PATH) + get_filename_component(Qt_PREFIX_DIR "${Qt_BIN_DIR}" PATH) + set(CMAKE_PREFIX_PATH ${Qt_PREFIX_DIR}) +endif() + +if (QT_TEST_VERSION STREQUAL 4) + find_package(Qt4 REQUIRED) + + # Include this directory before using the UseQt4 file. + add_subdirectory(defines_test) + + include(UseQt4) + + set(QT_QTCORE_TARGET Qt4::QtCore) + +else() + if (NOT QT_TEST_VERSION STREQUAL 5) + message(SEND_ERROR "Invalid Qt version specified.") + endif() + find_package(Qt5Widgets REQUIRED) + + set(QT_QTCORE_TARGET Qt5::Core) + + include_directories(${Qt5Widgets_INCLUDE_DIRS}) + set(QT_LIBRARIES Qt5::Widgets) + + if(Qt5_POSITION_INDEPENDENT_CODE AND CMAKE_CXX_COMPILE_OPTIONS_PIC) + add_definitions(${CMAKE_CXX_COMPILE_OPTIONS_PIC}) + endif() + +endif() + +# -- Test +# Dummy test to generate clean target +add_executable(dummy dummy.cpp) + +# -- Test +# When a file listed in a .qrc file changes the target must be rebuilt +set(timeformat "%Y%j%H%M%S") +set(RCC_DEPENDS_SRC "${CMAKE_CURRENT_SOURCE_DIR}/rccDepends") +set(RCC_DEPENDS_BIN "${CMAKE_CURRENT_BINARY_DIR}/rccDepends") +configure_file(${RCC_DEPENDS_SRC}/res1a.qrc.in ${RCC_DEPENDS_BIN}/res1.qrc COPYONLY) +configure_file(${RCC_DEPENDS_SRC}/res2a.qrc.in ${RCC_DEPENDS_BIN}/res2.qrc.in COPYONLY) +try_compile(RCC_DEPENDS + "${RCC_DEPENDS_BIN}" + "${RCC_DEPENDS_SRC}" + rccDepends + CMAKE_FLAGS "-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}" + "-DQT_TEST_VERSION=${QT_TEST_VERSION}" + "-DCMAKE_PREFIX_PATH=${Qt_PREFIX_DIR}" + OUTPUT_VARIABLE output +) +if (NOT RCC_DEPENDS) + message(SEND_ERROR "Initial build of rccDepends failed. Output: ${output}") +endif() +# Get name and timestamp of the output binary +file(STRINGS "${RCC_DEPENDS_BIN}/target.txt" targetList ENCODING UTF-8) +list(GET targetList 0 rccDependsBin) +file(TIMESTAMP "${rccDependsBin}" timeBegin "${timeformat}") +# Sleep, touch regular qrc input file, rebuild and compare timestamp +execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) # Ensure that the timestamp will change. +execute_process(COMMAND "${CMAKE_COMMAND}" -E touch "${RCC_DEPENDS_BIN}/res1/input.txt") +execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${RCC_DEPENDS_BIN}" RESULT_VARIABLE result) +if (result) + message(SEND_ERROR "Second build of rccDepends failed.") +endif() +file(TIMESTAMP "${rccDependsBin}" timeStep1 "${timeformat}") +if (NOT timeStep1 GREATER timeBegin) + message(SEND_ERROR "File (${rccDependsBin}) should have changed in the first step!") +endif() +# Sleep, update regular qrc file, rebuild and compare timestamp +execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) # Ensure that the timestamp will change. +configure_file(${RCC_DEPENDS_SRC}/res1b.qrc.in ${RCC_DEPENDS_BIN}/res1.qrc COPYONLY) +execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${RCC_DEPENDS_BIN}" RESULT_VARIABLE result) +if (result) + message(SEND_ERROR "Third build of rccDepends failed.") +endif() +file(TIMESTAMP "${rccDependsBin}" timeStep2 "${timeformat}") +if (NOT timeStep2 GREATER timeStep1) + message(SEND_ERROR "File (${rccDependsBin}) should have changed in the second step!") +endif() +# Sleep, touch regular qrc newly added input file, rebuild and compare timestamp +execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) # Ensure that the timestamp will change. +execute_process(COMMAND "${CMAKE_COMMAND}" -E touch "${RCC_DEPENDS_BIN}/res1/inputAdded.txt") +execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${RCC_DEPENDS_BIN}" RESULT_VARIABLE result) +if (result) + message(SEND_ERROR "Fourth build of rccDepends failed.") +endif() +file(TIMESTAMP "${rccDependsBin}" timeStep3 "${timeformat}") +if (NOT timeStep3 GREATER timeStep2) + message(SEND_ERROR "File (${rccDependsBin}) should have changed in the third step!") +endif() +# Sleep, touch generated qrc input file, rebuild and compare timestamp +execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) # Ensure that the timestamp will change. +execute_process(COMMAND "${CMAKE_COMMAND}" -E touch "${RCC_DEPENDS_BIN}/res2/input.txt") +execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${RCC_DEPENDS_BIN}" RESULT_VARIABLE result) +if (result) + message(SEND_ERROR "Fifth build of rccDepends failed.") +endif() +file(TIMESTAMP "${rccDependsBin}" timeStep4 "${timeformat}") +if (NOT timeStep4 GREATER timeStep3) + message(SEND_ERROR "File (${rccDependsBin}) should have changed in the fourth step!") +endif() +# Sleep, update generated qrc file, rebuild and compare timestamp +execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) # Ensure that the timestamp will change. +configure_file(${RCC_DEPENDS_SRC}/res2b.qrc.in ${RCC_DEPENDS_BIN}/res2.qrc.in COPYONLY) +execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${RCC_DEPENDS_BIN}" RESULT_VARIABLE result) +if (result) + message(SEND_ERROR "Sixth build of rccDepends failed.") +endif() +file(TIMESTAMP "${rccDependsBin}" timeStep5 "${timeformat}") +if (NOT timeStep5 GREATER timeStep4) + message(SEND_ERROR "File (${rccDependsBin}) should have changed in the fitfh step!") +endif() +# Sleep, touch generated qrc newly added input file, rebuild and compare timestamp +execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) # Ensure that the timestamp will change. +execute_process(COMMAND "${CMAKE_COMMAND}" -E touch "${RCC_DEPENDS_BIN}/res2/inputAdded.txt") +execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${RCC_DEPENDS_BIN}" RESULT_VARIABLE result) +if (result) + message(SEND_ERROR "Seventh build of rccDepends failed.") +endif() +file(TIMESTAMP "${rccDependsBin}" timeStep6 "${timeformat}") +if (NOT timeStep6 GREATER timeStep5) + message(SEND_ERROR "File (${rccDependsBin}) should have changed in the sixth step!") +endif() + + +# -- Test +# Ensure a repeated build succeeds when a header containing a QObject changes +set(timeformat "%Y%j%H%M%S") +configure_file(mocRerun/test1a.h.in mocRerun/test1.h COPYONLY) +try_compile(MOC_RERUN + "${CMAKE_CURRENT_BINARY_DIR}/mocRerun" + "${CMAKE_CURRENT_SOURCE_DIR}/mocRerun" + mocRerun + CMAKE_FLAGS "-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}" + "-DQT_TEST_VERSION=${QT_TEST_VERSION}" + "-DCMAKE_PREFIX_PATH=${Qt_PREFIX_DIR}" + OUTPUT_VARIABLE output +) +if (NOT MOC_RERUN) + message(SEND_ERROR "Initial build of mocRerun failed. Output: ${output}") +endif() +# Get name and timestamp of the output binary +file(STRINGS "${CMAKE_CURRENT_BINARY_DIR}/mocRerun/target1.txt" target1List ENCODING UTF-8) +list(GET target1List 0 binFile) +file(TIMESTAMP "${binFile}" timeBegin "${timeformat}") +# Change file content and rebuild +execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) +configure_file(mocRerun/test1b.h.in mocRerun/test1.h COPYONLY) +execute_process(COMMAND "${CMAKE_COMMAND}" --build . + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/mocRerun" + RESULT_VARIABLE mocRerun_result + ) +if (mocRerun_result) + message(SEND_ERROR "Second build of mocRerun failed.") +endif() +# Compare timestamps +file(TIMESTAMP "${binFile}" timeStep1 "${timeformat}") +if (NOT timeStep1 GREATER timeBegin) + message(SEND_ERROR "File (${binFile}) should have changed in the first step!") +endif() + + +# -- Test +# Tests Q_PLUGIN_METADATA json file change detection +if (NOT QT_TEST_VERSION STREQUAL 4) + try_compile(MOC_PLUGIN + "${CMAKE_CURRENT_BINARY_DIR}/mocPlugin" + "${CMAKE_CURRENT_SOURCE_DIR}/mocPlugin" + mocPlugin + CMAKE_FLAGS "-DQT_TEST_VERSION=${QT_TEST_VERSION}" + "-DCMAKE_PREFIX_PATH=${Qt_PREFIX_DIR}" + OUTPUT_VARIABLE output + ) + if (NOT MOC_PLUGIN) + message(SEND_ERROR "Initial build of mocPlugin failed. Output: ${output}") + endif() + + set(timeformat "%Y%j%H%M%S") + set(mocPlugSrcDir "${CMAKE_CURRENT_SOURCE_DIR}/mocPlugin") + set(mocPlugBinDir "${CMAKE_CURRENT_BINARY_DIR}/mocPlugin") + find_library(plAFile "PlugA" PATHS "${mocPlugBinDir}/Debug" "${mocPlugBinDir}" NO_DEFAULT_PATH) + find_library(plBFile "PlugB" PATHS "${mocPlugBinDir}/Debug" "${mocPlugBinDir}" NO_DEFAULT_PATH) + find_library(plCFile "PlugC" PATHS "${mocPlugBinDir}/Debug" "${mocPlugBinDir}" NO_DEFAULT_PATH) + find_library(plDFile "PlugD" PATHS "${mocPlugBinDir}/Debug" "${mocPlugBinDir}" NO_DEFAULT_PATH) + + file(TIMESTAMP "${plAFile}" plABefore "${timeformat}") + file(TIMESTAMP "${plBFile}" plBBefore "${timeformat}") + file(TIMESTAMP "${plCFile}" plCBefore "${timeformat}") + file(TIMESTAMP "${plDFile}" plDBefore "${timeformat}") + + # Ensure that the timestamp will change and change the json files + execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) + configure_file("${mocPlugSrcDir}/jsonIn/StyleD.json" "${mocPlugBinDir}/jsonFiles/StyleC.json") + configure_file("${mocPlugSrcDir}/jsonIn/StyleC.json" "${mocPlugBinDir}/jsonFiles/sub/StyleD.json") + execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${mocPlugBinDir}") + + file(TIMESTAMP "${plAFile}" plAAfter "${timeformat}") + file(TIMESTAMP "${plBFile}" plBAfter "${timeformat}") + file(TIMESTAMP "${plCFile}" plCAfter "${timeformat}") + file(TIMESTAMP "${plDFile}" plDAfter "${timeformat}") + + if (plAAfter GREATER plABefore) + message(SEND_ERROR "file (${plAFile}) should not have changed!") + endif() + if (plBAfter GREATER plBBefore) + message(SEND_ERROR "file (${plBFile}) should not have changed!") + endif() + if (NOT plCAfter GREATER plCBefore) + message(SEND_ERROR "file (${plCFile}) should have changed!") + endif() + if (NOT plDAfter GREATER plDBefore) + message(SEND_ERROR "file (${plDFile}) should have changed!") + endif() + + # Test custom macro + file(TIMESTAMP "${plCFile}" plCBefore "${timeformat}") + file(TIMESTAMP "${plDFile}" plDBefore "${timeformat}") + execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) + configure_file("${mocPlugSrcDir}/jsonIn/StyleD.json" "${mocPlugBinDir}/jsonFiles/StyleC_Custom.json") + configure_file("${mocPlugSrcDir}/jsonIn/StyleC.json" "${mocPlugBinDir}/jsonFiles/sub/StyleD_Custom.json") + execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${mocPlugBinDir}") + file(TIMESTAMP "${plCFile}" plCAfter "${timeformat}") + file(TIMESTAMP "${plDFile}" plDAfter "${timeformat}") + if (NOT plCAfter GREATER plCBefore) + message(SEND_ERROR "file (${plCFile}) should have changed!") + endif() + if (NOT plDAfter GREATER plDBefore) + message(SEND_ERROR "file (${plDFile}) should have changed!") + endif() + +endif() diff --git a/Tests/QtAutogenRerun/defines_test/CMakeLists.txt b/Tests/QtAutogenRerun/defines_test/CMakeLists.txt new file mode 100644 index 0000000..9ee9a22 --- /dev/null +++ b/Tests/QtAutogenRerun/defines_test/CMakeLists.txt @@ -0,0 +1,4 @@ + +add_executable(defines_test defines_test.cpp) +set_target_properties(defines_test PROPERTIES AUTOMOC TRUE) +target_link_libraries(defines_test Qt4::QtGui) diff --git a/Tests/QtAutogenRerun/defines_test/defines_test.cpp b/Tests/QtAutogenRerun/defines_test/defines_test.cpp new file mode 100644 index 0000000..cf4e9cb --- /dev/null +++ b/Tests/QtAutogenRerun/defines_test/defines_test.cpp @@ -0,0 +1,38 @@ + +#include <QObject> + +#ifdef QT_GUI_LIB +#include <QTextDocument> + +class SomeDocument : public QTextDocument +{ + Q_OBJECT + +Q_SIGNALS: + void someSig(); +}; +#endif + +#ifdef QT_CORE_LIB +class SomeObject : public QObject +{ + Q_OBJECT + +Q_SIGNALS: + void someSig(); +}; +#endif + +int main(int argc, char** argv) +{ +#ifdef QT_CORE_LIB + QMetaObject sosmo = SomeObject::staticMetaObject; +#endif +#ifdef QT_GUI_LIB + QMetaObject sdsmo = SomeDocument::staticMetaObject; +#endif + + return 0; +} + +#include "defines_test.moc" diff --git a/Tests/QtAutogenRerun/dummy.cpp b/Tests/QtAutogenRerun/dummy.cpp new file mode 100644 index 0000000..4837a76 --- /dev/null +++ b/Tests/QtAutogenRerun/dummy.cpp @@ -0,0 +1,5 @@ + +int main(int argv, char** args) +{ + return 0; +} diff --git a/Tests/QtAutogen/mocPlugin/CMakeLists.txt b/Tests/QtAutogenRerun/mocPlugin/CMakeLists.txt index f80aa29..9b224fb 100644 --- a/Tests/QtAutogen/mocPlugin/CMakeLists.txt +++ b/Tests/QtAutogenRerun/mocPlugin/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.9) project(mocPlugin CXX) set(CMAKE_AUTOMOC_DEPEND_FILTERS diff --git a/Tests/QtAutogen/mocPlugin/StyleA.cpp b/Tests/QtAutogenRerun/mocPlugin/StyleA.cpp index b5e8753..b5e8753 100644 --- a/Tests/QtAutogen/mocPlugin/StyleA.cpp +++ b/Tests/QtAutogenRerun/mocPlugin/StyleA.cpp diff --git a/Tests/QtAutogen/mocPlugin/StyleA.hpp b/Tests/QtAutogenRerun/mocPlugin/StyleA.hpp index 1b6154d..1b6154d 100644 --- a/Tests/QtAutogen/mocPlugin/StyleA.hpp +++ b/Tests/QtAutogenRerun/mocPlugin/StyleA.hpp diff --git a/Tests/QtAutogen/mocPlugin/StyleA.json b/Tests/QtAutogenRerun/mocPlugin/StyleA.json index cc33953..cc33953 100644 --- a/Tests/QtAutogen/mocPlugin/StyleA.json +++ b/Tests/QtAutogenRerun/mocPlugin/StyleA.json diff --git a/Tests/QtAutogen/mocPlugin/StyleA_Custom.json b/Tests/QtAutogenRerun/mocPlugin/StyleA_Custom.json index cc33953..cc33953 100644 --- a/Tests/QtAutogen/mocPlugin/StyleA_Custom.json +++ b/Tests/QtAutogenRerun/mocPlugin/StyleA_Custom.json diff --git a/Tests/QtAutogen/mocPlugin/StyleB.cpp b/Tests/QtAutogenRerun/mocPlugin/StyleB.cpp index 17d4400..17d4400 100644 --- a/Tests/QtAutogen/mocPlugin/StyleB.cpp +++ b/Tests/QtAutogenRerun/mocPlugin/StyleB.cpp diff --git a/Tests/QtAutogen/mocPlugin/StyleB.hpp b/Tests/QtAutogenRerun/mocPlugin/StyleB.hpp index 163c9b2..163c9b2 100644 --- a/Tests/QtAutogen/mocPlugin/StyleB.hpp +++ b/Tests/QtAutogenRerun/mocPlugin/StyleB.hpp diff --git a/Tests/QtAutogen/mocPlugin/StyleC.cpp b/Tests/QtAutogenRerun/mocPlugin/StyleC.cpp index 37e7564..37e7564 100644 --- a/Tests/QtAutogen/mocPlugin/StyleC.cpp +++ b/Tests/QtAutogenRerun/mocPlugin/StyleC.cpp diff --git a/Tests/QtAutogen/mocPlugin/StyleC.hpp b/Tests/QtAutogenRerun/mocPlugin/StyleC.hpp index 52a887a..52a887a 100644 --- a/Tests/QtAutogen/mocPlugin/StyleC.hpp +++ b/Tests/QtAutogenRerun/mocPlugin/StyleC.hpp diff --git a/Tests/QtAutogen/mocPlugin/StyleCommon.hpp b/Tests/QtAutogenRerun/mocPlugin/StyleCommon.hpp index f1a7ec6..f1a7ec6 100644 --- a/Tests/QtAutogen/mocPlugin/StyleCommon.hpp +++ b/Tests/QtAutogenRerun/mocPlugin/StyleCommon.hpp diff --git a/Tests/QtAutogen/mocPlugin/StyleD.cpp b/Tests/QtAutogenRerun/mocPlugin/StyleD.cpp index 7e4b121..7e4b121 100644 --- a/Tests/QtAutogen/mocPlugin/StyleD.cpp +++ b/Tests/QtAutogenRerun/mocPlugin/StyleD.cpp diff --git a/Tests/QtAutogen/mocPlugin/StyleD.hpp b/Tests/QtAutogenRerun/mocPlugin/StyleD.hpp index df8a439..df8a439 100644 --- a/Tests/QtAutogen/mocPlugin/StyleD.hpp +++ b/Tests/QtAutogenRerun/mocPlugin/StyleD.hpp diff --git a/Tests/QtAutogen/mocPlugin/StyleE.cpp b/Tests/QtAutogenRerun/mocPlugin/StyleE.cpp index 8fc9a7f..8fc9a7f 100644 --- a/Tests/QtAutogen/mocPlugin/StyleE.cpp +++ b/Tests/QtAutogenRerun/mocPlugin/StyleE.cpp diff --git a/Tests/QtAutogen/mocPlugin/StyleE.hpp b/Tests/QtAutogenRerun/mocPlugin/StyleE.hpp index e7915a8..e7915a8 100644 --- a/Tests/QtAutogen/mocPlugin/StyleE.hpp +++ b/Tests/QtAutogenRerun/mocPlugin/StyleE.hpp diff --git a/Tests/QtAutogen/mocPlugin/jsonIn/StyleB.json b/Tests/QtAutogenRerun/mocPlugin/jsonIn/StyleB.json index 129cac4..129cac4 100644 --- a/Tests/QtAutogen/mocPlugin/jsonIn/StyleB.json +++ b/Tests/QtAutogenRerun/mocPlugin/jsonIn/StyleB.json diff --git a/Tests/QtAutogen/mocPlugin/jsonIn/StyleB_Custom.json b/Tests/QtAutogenRerun/mocPlugin/jsonIn/StyleB_Custom.json index 129cac4..129cac4 100644 --- a/Tests/QtAutogen/mocPlugin/jsonIn/StyleB_Custom.json +++ b/Tests/QtAutogenRerun/mocPlugin/jsonIn/StyleB_Custom.json diff --git a/Tests/QtAutogen/mocPlugin/jsonIn/StyleC.json b/Tests/QtAutogenRerun/mocPlugin/jsonIn/StyleC.json index 119aaa4..119aaa4 100644 --- a/Tests/QtAutogen/mocPlugin/jsonIn/StyleC.json +++ b/Tests/QtAutogenRerun/mocPlugin/jsonIn/StyleC.json diff --git a/Tests/QtAutogen/mocPlugin/jsonIn/StyleD.json b/Tests/QtAutogenRerun/mocPlugin/jsonIn/StyleD.json index 732c547..732c547 100644 --- a/Tests/QtAutogen/mocPlugin/jsonIn/StyleD.json +++ b/Tests/QtAutogenRerun/mocPlugin/jsonIn/StyleD.json diff --git a/Tests/QtAutogen/mocPlugin/main.cpp b/Tests/QtAutogenRerun/mocPlugin/main.cpp index 3ba2ddc..3ba2ddc 100644 --- a/Tests/QtAutogen/mocPlugin/main.cpp +++ b/Tests/QtAutogenRerun/mocPlugin/main.cpp diff --git a/Tests/QtAutogen/mocRerun/CMakeLists.txt b/Tests/QtAutogenRerun/mocRerun/CMakeLists.txt index 14b077b..7380bdd 100644 --- a/Tests/QtAutogen/mocRerun/CMakeLists.txt +++ b/Tests/QtAutogenRerun/mocRerun/CMakeLists.txt @@ -1,4 +1,5 @@ -cmake_minimum_required(VERSION 3.7) +cmake_minimum_required(VERSION 3.9) +cmake_policy(SET CMP0071 NEW) project(mocRerun CXX) if (QT_TEST_VERSION STREQUAL 4) @@ -27,7 +28,6 @@ add_executable(mocRerun ${CMAKE_CURRENT_BINARY_DIR}/main.cpp res1.qrc ) -set_property(TARGET mocRerun PROPERTY __UNDOCUMENTED_AUTOGEN_GENERATED_FILES 1) target_include_directories(mocRerun PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) target_link_libraries(mocRerun ${QT_CORE_TARGET}) # Write target name to text file diff --git a/Tests/QtAutogen/mocRerun/input.txt b/Tests/QtAutogenRerun/mocRerun/input.txt index da62762..da62762 100644 --- a/Tests/QtAutogen/mocRerun/input.txt +++ b/Tests/QtAutogenRerun/mocRerun/input.txt diff --git a/Tests/QtAutogen/mocRerun/main.cpp.in b/Tests/QtAutogenRerun/mocRerun/main.cpp.in index b37ff61..b37ff61 100644 --- a/Tests/QtAutogen/mocRerun/main.cpp.in +++ b/Tests/QtAutogenRerun/mocRerun/main.cpp.in diff --git a/Tests/QtAutogen/mocRerun/res1.qrc b/Tests/QtAutogenRerun/mocRerun/res1.qrc index fb804b5..fb804b5 100644 --- a/Tests/QtAutogen/mocRerun/res1.qrc +++ b/Tests/QtAutogenRerun/mocRerun/res1.qrc diff --git a/Tests/QtAutogen/mocRerun/test1a.h.in b/Tests/QtAutogenRerun/mocRerun/test1a.h.in index a335046..a335046 100644 --- a/Tests/QtAutogen/mocRerun/test1a.h.in +++ b/Tests/QtAutogenRerun/mocRerun/test1a.h.in diff --git a/Tests/QtAutogen/mocRerun/test1b.h.in b/Tests/QtAutogenRerun/mocRerun/test1b.h.in index 6128eeb..6128eeb 100644 --- a/Tests/QtAutogen/mocRerun/test1b.h.in +++ b/Tests/QtAutogenRerun/mocRerun/test1b.h.in diff --git a/Tests/QtAutogen/rccDepends/CMakeLists.txt b/Tests/QtAutogenRerun/rccDepends/CMakeLists.txt index 878ae5d..edc0ac3 100644 --- a/Tests/QtAutogen/rccDepends/CMakeLists.txt +++ b/Tests/QtAutogenRerun/rccDepends/CMakeLists.txt @@ -1,5 +1,5 @@ -cmake_minimum_required(VERSION 3.7) -project(rccDepends) +cmake_minimum_required(VERSION 3.9) +project(rccDepends CXX) set(CMAKE_AUTORCC ON) diff --git a/Tests/QtAutogen/rccDepends/main.cpp b/Tests/QtAutogenRerun/rccDepends/main.cpp index 766b775..766b775 100644 --- a/Tests/QtAutogen/rccDepends/main.cpp +++ b/Tests/QtAutogenRerun/rccDepends/main.cpp diff --git a/Tests/QtAutogen/rccDepends/res/input1.txt.in b/Tests/QtAutogenRerun/rccDepends/res/input1.txt.in index da62762..da62762 100644 --- a/Tests/QtAutogen/rccDepends/res/input1.txt.in +++ b/Tests/QtAutogenRerun/rccDepends/res/input1.txt.in diff --git a/Tests/QtAutogen/rccDepends/res/input2.txt.in b/Tests/QtAutogenRerun/rccDepends/res/input2.txt.in index 08e14b7..08e14b7 100644 --- a/Tests/QtAutogen/rccDepends/res/input2.txt.in +++ b/Tests/QtAutogenRerun/rccDepends/res/input2.txt.in diff --git a/Tests/QtAutogen/rccDepends/res1a.qrc.in b/Tests/QtAutogenRerun/rccDepends/res1a.qrc.in index d111ffb..d111ffb 100644 --- a/Tests/QtAutogen/rccDepends/res1a.qrc.in +++ b/Tests/QtAutogenRerun/rccDepends/res1a.qrc.in diff --git a/Tests/QtAutogen/rccDepends/res1b.qrc.in b/Tests/QtAutogenRerun/rccDepends/res1b.qrc.in index 4cb3f04..4cb3f04 100644 --- a/Tests/QtAutogen/rccDepends/res1b.qrc.in +++ b/Tests/QtAutogenRerun/rccDepends/res1b.qrc.in diff --git a/Tests/QtAutogen/rccDepends/res2a.qrc.in b/Tests/QtAutogenRerun/rccDepends/res2a.qrc.in index 19f34ac..19f34ac 100644 --- a/Tests/QtAutogen/rccDepends/res2a.qrc.in +++ b/Tests/QtAutogenRerun/rccDepends/res2a.qrc.in diff --git a/Tests/QtAutogen/rccDepends/res2b.qrc.in b/Tests/QtAutogenRerun/rccDepends/res2b.qrc.in index 19e8ba1..19e8ba1 100644 --- a/Tests/QtAutogen/rccDepends/res2b.qrc.in +++ b/Tests/QtAutogenRerun/rccDepends/res2b.qrc.in diff --git a/Tests/README b/Tests/README deleted file mode 100644 index 8b2fda8..0000000 --- a/Tests/README +++ /dev/null @@ -1,39 +0,0 @@ -If you think about adding a new testcase then here is a small checklist you -can run through to find a proper place for it. Go through the list from the -beginning and stop once you find something that matches your tests needs, -i.e. if you will test a module and only need the configure mode use the -instructions from section 2, not 3. - -1. Your testcase can run in CMake script mode, i.e. "cmake -P something" - -Put your test in Tests/CMakeTests/ directory as a .cmake.in file. It will be -put into the test binary directory by configure_file(... @ONLY) and run from -there. Use the AddCMakeTest() macro in Tests/CMakeTests/CMakeLists.txt to add -your test to the test runs. - -2. Your test needs CMake to run in configure mode, but will not build anything - -This includes tests that will build something using try_compile() and friends, -but nothing that expects add_executable(), add_library(), or add_test() to run. - -If the test configures the project only once and it must succeed then put it -into the Tests/CMakeOnly/ directory. Create a subdirectory named like your -test and write the CMakeLists.txt you need into that subdirectory. Use the -add_CMakeOnly_test() macro from Tests/CMakeOnly/CMakeLists.txt to add your -test to the test runs. - -If the test configures the project with multiple variations and verifies -success or failure each time then put it into the Tests/RunCMake/ directory. -Read the instructions in Tests/RunCMake/CMakeLists.txt to add a test. - -3. If you are testing something from the Modules directory - -Put your test in the Tests/Modules/ directory. Create a subdirectory there -named after your test. Use the ADD_TEST_MACRO macro from Tests/CMakeLists.txt -to add your test to the test run. If you have put your stuff in -Tests/Modules/Foo then you call it using ADD_TEST_MACRO(Module.Foo Foo). - -4. You are doing other stuff. - -Find a good place ;) In doubt mail to cmake-developers@cmake.org and ask for -advise. diff --git a/Tests/README.rst b/Tests/README.rst new file mode 100644 index 0000000..3e98938 --- /dev/null +++ b/Tests/README.rst @@ -0,0 +1,31 @@ +CMake Tests Directory +********************* + +This directory contains the CMake test suite. +See also the `CMake Source Code Guide`_. + +.. _`CMake Source Code Guide`: ../Help/dev/source.rst + +Many tests exist as immediate subdirectories, but some tests +are organized as follows. + +* ``CMakeLib/``: + Source code, used for tests, that links to the ``CMakeLib`` library + defined over in ``Source/``. + +* ``CMakeOnly/``: + Deprecated. Tests that run CMake to generate a project but not build it. + Superseded by ``Tests/RunCMake/``. + +* ``Find*/``: + Tests for specific find modules that can only be run on machines with + the corresponding packages installed. They are enabled in + ``CMakeLists.txt`` by undocumented options used on CI builds. + +* ``Module/``: + Tests for specific CMake modules. + +* ``RunCMake/``: + Tests that run CMake and/or other tools while precisely checking + their return code and stdout/stderr content. Useful for testing + error cases and diagnostic output. diff --git a/Tests/RunCMake/BuildDepends/C-Exe-Manifest.cmake b/Tests/RunCMake/BuildDepends/C-Exe-Manifest.cmake index ef33012..87b0de0 100644 --- a/Tests/RunCMake/BuildDepends/C-Exe-Manifest.cmake +++ b/Tests/RunCMake/BuildDepends/C-Exe-Manifest.cmake @@ -11,7 +11,7 @@ endif() ]]) endif() -file(GENERATE OUTPUT check-$<LOWER_CASE:$<CONFIG>>.cmake CONTENT " +file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/check-$<LOWER_CASE:$<CONFIG>>.cmake CONTENT " set(check_pairs \"$<TARGET_FILE:main>|${CMAKE_CURRENT_BINARY_DIR}/test.manifest\" ) diff --git a/Tests/RunCMake/BuildDepends/C-Exe.cmake b/Tests/RunCMake/BuildDepends/C-Exe.cmake index 5057ca9..ad5cd4d 100644 --- a/Tests/RunCMake/BuildDepends/C-Exe.cmake +++ b/Tests/RunCMake/BuildDepends/C-Exe.cmake @@ -2,7 +2,7 @@ enable_language(C) add_executable(main ${CMAKE_CURRENT_BINARY_DIR}/main.c) -file(GENERATE OUTPUT check-$<LOWER_CASE:$<CONFIG>>.cmake CONTENT " +file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/check-$<LOWER_CASE:$<CONFIG>>.cmake CONTENT " set(check_pairs \"$<TARGET_FILE:main>|${CMAKE_CURRENT_BINARY_DIR}/main.c\" ) diff --git a/Tests/RunCMake/BuildDepends/Custom-Always.cmake b/Tests/RunCMake/BuildDepends/Custom-Always.cmake index d412708..c7e7fb0 100644 --- a/Tests/RunCMake/BuildDepends/Custom-Always.cmake +++ b/Tests/RunCMake/BuildDepends/Custom-Always.cmake @@ -16,7 +16,7 @@ add_custom_command( add_custom_target(drive ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/after-always) -file(GENERATE OUTPUT check-$<LOWER_CASE:$<CONFIG>>.cmake CONTENT " +file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/check-$<LOWER_CASE:$<CONFIG>>.cmake CONTENT " set(check_pairs \"${CMAKE_CURRENT_BINARY_DIR}/always-updated|${CMAKE_CURRENT_BINARY_DIR}/before-always\" \"${CMAKE_CURRENT_BINARY_DIR}/after-always|${CMAKE_CURRENT_BINARY_DIR}/always-updated\" diff --git a/Tests/RunCMake/BuildDepends/Custom-Symbolic-and-Byproduct.cmake b/Tests/RunCMake/BuildDepends/Custom-Symbolic-and-Byproduct.cmake index 687c827..1e1f22a 100644 --- a/Tests/RunCMake/BuildDepends/Custom-Symbolic-and-Byproduct.cmake +++ b/Tests/RunCMake/BuildDepends/Custom-Symbolic-and-Byproduct.cmake @@ -16,7 +16,7 @@ add_custom_command( add_custom_target(drive ALL DEPENDS use-byproduct) add_dependencies(drive produce) -file(GENERATE OUTPUT check-$<LOWER_CASE:$<CONFIG>>.cmake CONTENT " +file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/check-$<LOWER_CASE:$<CONFIG>>.cmake CONTENT " if (check_step EQUAL 1) set(check_pairs \"${CMAKE_CURRENT_BINARY_DIR}/use-byproduct|${CMAKE_CURRENT_BINARY_DIR}/gen-byproduct-stamp\" diff --git a/Tests/RunCMake/BuildDepends/MakeCustomIncludes.cmake b/Tests/RunCMake/BuildDepends/MakeCustomIncludes.cmake index 0f92e0e..8b2ae78 100644 --- a/Tests/RunCMake/BuildDepends/MakeCustomIncludes.cmake +++ b/Tests/RunCMake/BuildDepends/MakeCustomIncludes.cmake @@ -6,7 +6,7 @@ add_custom_command( add_custom_target(generate ALL DEPENDS output.cxx) set_property(TARGET generate PROPERTY INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}) -file(GENERATE OUTPUT check-$<LOWER_CASE:$<CONFIG>>.cmake CONTENT " +file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/check-$<LOWER_CASE:$<CONFIG>>.cmake CONTENT " set(check_pairs \"${CMAKE_CURRENT_BINARY_DIR}/output.cxx|${CMAKE_CURRENT_BINARY_DIR}/MakeCustomIncludes.h\" ) diff --git a/Tests/RunCMake/BuildDepends/MakeInProjectOnly.cmake b/Tests/RunCMake/BuildDepends/MakeInProjectOnly.cmake index add9aeb..af6ad86 100644 --- a/Tests/RunCMake/BuildDepends/MakeInProjectOnly.cmake +++ b/Tests/RunCMake/BuildDepends/MakeInProjectOnly.cmake @@ -3,7 +3,7 @@ get_filename_component(include_dir "${CMAKE_BINARY_DIR}" PATH) include_directories("${include_dir}") add_executable(MakeInProjectOnly MakeInProjectOnly.c) set(CMAKE_DEPENDS_IN_PROJECT_ONLY 1) -file(GENERATE OUTPUT check-$<LOWER_CASE:$<CONFIG>>.cmake CONTENT " +file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/check-$<LOWER_CASE:$<CONFIG>>.cmake CONTENT " if (check_step EQUAL 1) set(check_pairs \"$<TARGET_FILE:MakeInProjectOnly>|${include_dir}/MakeInProjectOnly.h\" diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 79f487d..13df4a8 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -148,6 +148,7 @@ add_RunCMake_test(GeneratorExpression) add_RunCMake_test(GeneratorPlatform) add_RunCMake_test(GeneratorToolset) add_RunCMake_test(GNUInstallDirs -DSYSTEM_NAME=${CMAKE_SYSTEM_NAME}) +add_RunCMake_test(GoogleTest) # Note: does not actually depend on Google Test add_RunCMake_test(TargetPropertyGeneratorExpressions) add_RunCMake_test(Languages) add_RunCMake_test(LinkStatic) @@ -181,8 +182,10 @@ add_RunCMake_test(add_custom_target) add_RunCMake_test(add_dependencies) add_RunCMake_test(add_subdirectory) add_RunCMake_test(build_command) +add_executable(exit_code exit_code.c) +set(execute_process_ARGS -DEXIT_CODE_EXE=$<TARGET_FILE:exit_code>) if(NOT CMake_TEST_EXTERNAL_CMAKE) - set(execute_process_ARGS -DTEST_ENCODING_EXE=$<TARGET_FILE:testEncoding>) + list(APPEND execute_process_ARGS -DTEST_ENCODING_EXE=$<TARGET_FILE:testEncoding>) endif() add_RunCMake_test(execute_process) add_RunCMake_test(export) @@ -213,6 +216,7 @@ add_RunCMake_test(get_property) add_RunCMake_test(if) add_RunCMake_test(include) add_RunCMake_test(include_directories) +add_RunCMake_test(include_guard) add_RunCMake_test(list) add_RunCMake_test(message) add_RunCMake_test(project -DCMake_TEST_RESOURCES=${CMake_TEST_RESOURCES}) @@ -220,6 +224,7 @@ add_RunCMake_test(return) add_RunCMake_test(separate_arguments) add_RunCMake_test(set_property) add_RunCMake_test(string) +add_RunCMake_test(test_include_dirs) foreach(var CMAKE_C_COMPILER_ID CMAKE_C_COMPILER_VERSION @@ -341,7 +346,11 @@ if("${CMAKE_GENERATOR}" MATCHES "Make|Ninja") add_RunCMake_test(ClangTidy -DPSEUDO_TIDY=$<TARGET_FILE:pseudo_tidy>) add_RunCMake_test(IncludeWhatYouUse -DPSEUDO_IWYU=$<TARGET_FILE:pseudo_iwyu>) add_RunCMake_test(Cpplint -DPSEUDO_CPPLINT=$<TARGET_FILE:pseudo_cpplint>) + if(DEFINED CMake_TEST_CUDA) + list(APPEND CompilerLauncher_ARGS -DCMake_TEST_CUDA=${CMake_TEST_CUDA}) + endif() add_RunCMake_test(CompilerLauncher) + add_RunCMake_test(ctest_labels_for_subprojects) endif() add_RunCMake_test_group(CPack "DEB;RPM;7Z;TBZ2;TGZ;TXZ;TZ;ZIP;STGZ") @@ -371,3 +380,7 @@ if(CMake_TEST_ANDROID_NDK OR CMake_TEST_ANDROID_STANDALONE_TOOLCHAIN) endif() set_property(TEST RunCMake.Android PROPERTY TIMEOUT ${CMake_TEST_ANDROID_TIMEOUT}) endif() + +if(${CMAKE_GENERATOR} MATCHES "Visual Studio ([^89]|[89][0-9])") + add_RunCMake_test(CSharpCustomCommand) +endif() diff --git a/Tests/RunCMake/CPack/CMakeLists.txt b/Tests/RunCMake/CPack/CMakeLists.txt index c361af0..1b3dbb2 100644 --- a/Tests/RunCMake/CPack/CMakeLists.txt +++ b/Tests/RunCMake/CPack/CMakeLists.txt @@ -15,3 +15,7 @@ include(tests/${RunCMake_TEST_FILE_PREFIX}/test.cmake) set(CPACK_GENERATOR "${GENERATOR_TYPE}") include(CPack) + +if(COMMAND run_after_include_cpack) + run_after_include_cpack() +endif() diff --git a/Tests/RunCMake/CPack/README.txt b/Tests/RunCMake/CPack/README.txt index 7c98f69..cf7c02c 100644 --- a/Tests/RunCMake/CPack/README.txt +++ b/Tests/RunCMake/CPack/README.txt @@ -91,6 +91,11 @@ If test will be used for multiple generators but some of them require some generator specific commands then those commands should be added to 'test.cmake' script wrapped with 'if(GENERATOR_TYPE STREQUAL <name_of_the_generator>)'. +NOTE: In some cases (for example when testing CPackComponent.cmake functions) +the test has to run some functions after CPack.cmake is included. In such cases +a function run_after_include_cpack can be declared in test.cmake file and that +function will run after the inclusion of CPack.cmake. + build phase (optional and not available for source package tests) ----------------------------------------------------------------- diff --git a/Tests/RunCMake/CPackInstallProperties/FilenameGenex.cmake b/Tests/RunCMake/CPackInstallProperties/FilenameGenex.cmake index 1a373b9..8fc1218 100644 --- a/Tests/RunCMake/CPackInstallProperties/FilenameGenex.cmake +++ b/Tests/RunCMake/CPackInstallProperties/FilenameGenex.cmake @@ -1,6 +1,6 @@ add_executable(mytest test.cpp) -file(GENERATE OUTPUT runtest_info.cmake CONTENT [[ +file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/runtest_info.cmake CONTENT [[ set(EXPECTED_MYTEST_NAME "$<TARGET_FILE_NAME:mytest>") ]]) diff --git a/Tests/RunCMake/CPackInstallProperties/PerConfigValue.cmake b/Tests/RunCMake/CPackInstallProperties/PerConfigValue.cmake index 77fe8ed..b23d3c7 100644 --- a/Tests/RunCMake/CPackInstallProperties/PerConfigValue.cmake +++ b/Tests/RunCMake/CPackInstallProperties/PerConfigValue.cmake @@ -6,7 +6,7 @@ foreach(CONFIG IN LISTS CMAKE_CONFIGURATION_TYPES) OUTPUT_NAME_${UPPER_CONFIG} bar_${CONFIG}) endforeach() -file(GENERATE OUTPUT runtest_info_$<CONFIG>.cmake CONTENT [[ +file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/runtest_info_$<CONFIG>.cmake CONTENT [[ set(CPACK_BUILD_CONFIG "$<CONFIG>") set(EXPECTED_MYTEST_NAME "$<TARGET_FILE_NAME:mytest>") ]]) diff --git a/Tests/RunCMake/CPackInstallProperties/ValueGenex.cmake b/Tests/RunCMake/CPackInstallProperties/ValueGenex.cmake index 2e1d465..2001d9f 100644 --- a/Tests/RunCMake/CPackInstallProperties/ValueGenex.cmake +++ b/Tests/RunCMake/CPackInstallProperties/ValueGenex.cmake @@ -1,6 +1,6 @@ add_executable(mytest test.cpp) -file(GENERATE OUTPUT runtest_info.cmake CONTENT [[ +file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/runtest_info.cmake CONTENT [[ set(EXPECTED_MYTEST_NAME "$<TARGET_FILE_NAME:mytest>") ]]) diff --git a/Tests/RunCMake/CSharpCustomCommand/CMakeLists.txt b/Tests/RunCMake/CSharpCustomCommand/CMakeLists.txt new file mode 100644 index 0000000..74b3ff8 --- /dev/null +++ b/Tests/RunCMake/CSharpCustomCommand/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.3) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/CSharpCustomCommand/CommandWithOutput-check.cmake b/Tests/RunCMake/CSharpCustomCommand/CommandWithOutput-check.cmake new file mode 100644 index 0000000..60d77eb --- /dev/null +++ b/Tests/RunCMake/CSharpCustomCommand/CommandWithOutput-check.cmake @@ -0,0 +1,21 @@ +if(checkLevel EQUAL 0) + message("checking generation (${srcName} does not exist)") + if(EXISTS "${generatedFileName}") + set(RunCMake_TEST_FAILED "file \"${generatedFileName}\" should not exist") + endif() +elseif(checkLevel EQUAL 1) + message("checking build 1 (generate ${srcName})") + if(NOT "${actual_stdout}" MATCHES "${commandComment}") + set(RunCMake_TEST_FAILED "command not executed") + endif() +elseif(checkLevel EQUAL 2) + message("checking build 2 (no change in ${srcName}.in)") + if("${actual_stdout}" MATCHES "${commandComment}") + set(RunCMake_TEST_FAILED "command executed") + endif() +elseif(checkLevel EQUAL 3) + message("checking build 3 (update ${srcName})") + if(NOT "${actual_stdout}" MATCHES "${commandComment}") + set(RunCMake_TEST_FAILED "command not executed") + endif() +endif() diff --git a/Tests/RunCMake/CSharpCustomCommand/CommandWithOutput.cmake b/Tests/RunCMake/CSharpCustomCommand/CommandWithOutput.cmake new file mode 100644 index 0000000..68341fa --- /dev/null +++ b/Tests/RunCMake/CSharpCustomCommand/CommandWithOutput.cmake @@ -0,0 +1,13 @@ +enable_language(CSharp) + +add_executable(CSharpCustomCommand dummy.cs) + +add_custom_command(OUTPUT ${generatedFileName} + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${inputFileName} ${generatedFileName} + MAIN_DEPENDENCY ${inputFileName} + COMMENT "${commandComment}") + +target_sources(CSharpCustomCommand PRIVATE + ${inputFileName} + ${generatedFileName}) diff --git a/Tests/RunCMake/CSharpCustomCommand/RunCMakeTest.cmake b/Tests/RunCMake/CSharpCustomCommand/RunCMakeTest.cmake new file mode 100644 index 0000000..fa5618a --- /dev/null +++ b/Tests/RunCMake/CSharpCustomCommand/RunCMakeTest.cmake @@ -0,0 +1,34 @@ +include(RunCMake) + +# Use a single build tree for a few tests without cleaning. +set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/CommandWithOutput-build) +set(RunCMake_TEST_NO_CLEAN 1) +file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") +file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") +set(RunCMake-check-file CommandWithOutput-check.cmake) + +set(srcName "test.cs") +set(srcFileName "${CMAKE_CURRENT_LIST_DIR}/${srcName}.in") +set(inputFileName "${RunCMake_TEST_BINARY_DIR}/${srcName}.in") +set(generatedFileName "${RunCMake_TEST_BINARY_DIR}/${srcName}") +set(commandComment "Generating ${srcName}") + +# copy the input file to build dir to avoid changing files in cmake +# source tree. +file(COPY "${srcFileName}" DESTINATION "${RunCMake_TEST_BINARY_DIR}") + +set(RunCMake_TEST_OPTIONS ${RunCMake_TEST_OPTIONS} + "-DinputFileName=${inputFileName}" + "-DgeneratedFileName=${generatedFileName}" + "-DcommandComment=${commandComment}") + +set(checkLevel 0) +run_cmake(CommandWithOutput) +set(checkLevel 1) +run_cmake_command(CommandWithOutput-build1 ${CMAKE_COMMAND} --build . --config Debug) +set(checkLevel 2) +run_cmake_command(CommandWithOutput-build2 ${CMAKE_COMMAND} --build . --config Debug) +# change file content to trigger custom command with next build +file(APPEND ${inputFileName} "\n") +set(checkLevel 3) +run_cmake_command(CommandWithOutput-build3 ${CMAKE_COMMAND} --build . --config Debug) diff --git a/Tests/RunCMake/CSharpCustomCommand/dummy.cs b/Tests/RunCMake/CSharpCustomCommand/dummy.cs new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/CSharpCustomCommand/dummy.cs diff --git a/Tests/RunCMake/CSharpCustomCommand/test.cs.in b/Tests/RunCMake/CSharpCustomCommand/test.cs.in new file mode 100644 index 0000000..05a7531 --- /dev/null +++ b/Tests/RunCMake/CSharpCustomCommand/test.cs.in @@ -0,0 +1,8 @@ +class TestCs +{ + public static int Main(string[] args) + { + System.Console.WriteLine("Test C#"); + return 0; + } +} diff --git a/Tests/RunCMake/CommandLine/E_md5sum-dir-result.txt b/Tests/RunCMake/CommandLine/E_md5sum-dir-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_md5sum-dir-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/E_md5sum-dir-stderr.txt b/Tests/RunCMake/CommandLine/E_md5sum-dir-stderr.txt new file mode 100644 index 0000000..061fd64 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_md5sum-dir-stderr.txt @@ -0,0 +1 @@ +Error: . is a directory diff --git a/Tests/RunCMake/CommandLine/E_md5sum-mixed-result.txt b/Tests/RunCMake/CommandLine/E_md5sum-mixed-result.txt new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_md5sum-mixed-result.txt @@ -0,0 +1 @@ +2 diff --git a/Tests/RunCMake/CommandLine/E_md5sum-mixed-stderr.txt b/Tests/RunCMake/CommandLine/E_md5sum-mixed-stderr.txt new file mode 100644 index 0000000..b6b84c3 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_md5sum-mixed-stderr.txt @@ -0,0 +1,2 @@ +Error: . is a directory +nonexisting: No such file or directory diff --git a/Tests/RunCMake/CommandLine/E_md5sum-mixed-stdout.txt b/Tests/RunCMake/CommandLine/E_md5sum-mixed-stdout.txt new file mode 100644 index 0000000..18e49be --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_md5sum-mixed-stdout.txt @@ -0,0 +1 @@ +275876e34cf609db118f3d84b799a790 ../dummy diff --git a/Tests/RunCMake/CommandLine/E_md5sum-no-file-result.txt b/Tests/RunCMake/CommandLine/E_md5sum-no-file-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_md5sum-no-file-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/E_md5sum-no-file-stderr.txt b/Tests/RunCMake/CommandLine/E_md5sum-no-file-stderr.txt new file mode 100644 index 0000000..732e8c4 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_md5sum-no-file-stderr.txt @@ -0,0 +1 @@ +nonexisting: No such file or directory diff --git a/Tests/RunCMake/CommandLine/E_md5sum-result.txt b/Tests/RunCMake/CommandLine/E_md5sum-result.txt new file mode 100644 index 0000000..573541a --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_md5sum-result.txt @@ -0,0 +1 @@ +0 diff --git a/Tests/RunCMake/CommandLine/E_md5sum-stdout.txt b/Tests/RunCMake/CommandLine/E_md5sum-stdout.txt new file mode 100644 index 0000000..18e49be --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_md5sum-stdout.txt @@ -0,0 +1 @@ +275876e34cf609db118f3d84b799a790 ../dummy diff --git a/Tests/RunCMake/CommandLine/E_sha1sum-dir-result.txt b/Tests/RunCMake/CommandLine/E_sha1sum-dir-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_sha1sum-dir-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/E_sha1sum-dir-stderr.txt b/Tests/RunCMake/CommandLine/E_sha1sum-dir-stderr.txt new file mode 100644 index 0000000..061fd64 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_sha1sum-dir-stderr.txt @@ -0,0 +1 @@ +Error: . is a directory diff --git a/Tests/RunCMake/CommandLine/E_sha1sum-no-file-result.txt b/Tests/RunCMake/CommandLine/E_sha1sum-no-file-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_sha1sum-no-file-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/E_sha1sum-no-file-stderr.txt b/Tests/RunCMake/CommandLine/E_sha1sum-no-file-stderr.txt new file mode 100644 index 0000000..732e8c4 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_sha1sum-no-file-stderr.txt @@ -0,0 +1 @@ +nonexisting: No such file or directory diff --git a/Tests/RunCMake/CommandLine/E_sha1sum-result.txt b/Tests/RunCMake/CommandLine/E_sha1sum-result.txt new file mode 100644 index 0000000..573541a --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_sha1sum-result.txt @@ -0,0 +1 @@ +0 diff --git a/Tests/RunCMake/CommandLine/E_sha1sum-stdout.txt b/Tests/RunCMake/CommandLine/E_sha1sum-stdout.txt new file mode 100644 index 0000000..689b85b --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_sha1sum-stdout.txt @@ -0,0 +1 @@ +829c3804401b0727f70f73d4415e162400cbe57b ../dummy diff --git a/Tests/RunCMake/CommandLine/E_sha224sum-dir-result.txt b/Tests/RunCMake/CommandLine/E_sha224sum-dir-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_sha224sum-dir-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/E_sha224sum-dir-stderr.txt b/Tests/RunCMake/CommandLine/E_sha224sum-dir-stderr.txt new file mode 100644 index 0000000..061fd64 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_sha224sum-dir-stderr.txt @@ -0,0 +1 @@ +Error: . is a directory diff --git a/Tests/RunCMake/CommandLine/E_sha224sum-no-file-result.txt b/Tests/RunCMake/CommandLine/E_sha224sum-no-file-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_sha224sum-no-file-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/E_sha224sum-no-file-stderr.txt b/Tests/RunCMake/CommandLine/E_sha224sum-no-file-stderr.txt new file mode 100644 index 0000000..732e8c4 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_sha224sum-no-file-stderr.txt @@ -0,0 +1 @@ +nonexisting: No such file or directory diff --git a/Tests/RunCMake/CommandLine/E_sha224sum-result.txt b/Tests/RunCMake/CommandLine/E_sha224sum-result.txt new file mode 100644 index 0000000..573541a --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_sha224sum-result.txt @@ -0,0 +1 @@ +0 diff --git a/Tests/RunCMake/CommandLine/E_sha224sum-stdout.txt b/Tests/RunCMake/CommandLine/E_sha224sum-stdout.txt new file mode 100644 index 0000000..5b3e217 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_sha224sum-stdout.txt @@ -0,0 +1 @@ +37d32c6dbabed711cb1d4620b64090fef0ef63ab16a4a51d668259e6 ../dummy diff --git a/Tests/RunCMake/CommandLine/E_sha256sum-dir-result.txt b/Tests/RunCMake/CommandLine/E_sha256sum-dir-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_sha256sum-dir-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/E_sha256sum-dir-stderr.txt b/Tests/RunCMake/CommandLine/E_sha256sum-dir-stderr.txt new file mode 100644 index 0000000..061fd64 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_sha256sum-dir-stderr.txt @@ -0,0 +1 @@ +Error: . is a directory diff --git a/Tests/RunCMake/CommandLine/E_sha256sum-no-file-result.txt b/Tests/RunCMake/CommandLine/E_sha256sum-no-file-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_sha256sum-no-file-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/E_sha256sum-no-file-stderr.txt b/Tests/RunCMake/CommandLine/E_sha256sum-no-file-stderr.txt new file mode 100644 index 0000000..732e8c4 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_sha256sum-no-file-stderr.txt @@ -0,0 +1 @@ +nonexisting: No such file or directory diff --git a/Tests/RunCMake/CommandLine/E_sha256sum-result.txt b/Tests/RunCMake/CommandLine/E_sha256sum-result.txt new file mode 100644 index 0000000..573541a --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_sha256sum-result.txt @@ -0,0 +1 @@ +0 diff --git a/Tests/RunCMake/CommandLine/E_sha256sum-stdout.txt b/Tests/RunCMake/CommandLine/E_sha256sum-stdout.txt new file mode 100644 index 0000000..9a18770 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_sha256sum-stdout.txt @@ -0,0 +1 @@ +b5a2c96250612366ea272ffac6d9744aaf4b45aacd96aa7cfcb931ee3b558259 ../dummy diff --git a/Tests/RunCMake/CommandLine/E_sha384sum-dir-result.txt b/Tests/RunCMake/CommandLine/E_sha384sum-dir-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_sha384sum-dir-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/E_sha384sum-dir-stderr.txt b/Tests/RunCMake/CommandLine/E_sha384sum-dir-stderr.txt new file mode 100644 index 0000000..061fd64 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_sha384sum-dir-stderr.txt @@ -0,0 +1 @@ +Error: . is a directory diff --git a/Tests/RunCMake/CommandLine/E_sha384sum-no-file-result.txt b/Tests/RunCMake/CommandLine/E_sha384sum-no-file-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_sha384sum-no-file-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/E_sha384sum-no-file-stderr.txt b/Tests/RunCMake/CommandLine/E_sha384sum-no-file-stderr.txt new file mode 100644 index 0000000..732e8c4 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_sha384sum-no-file-stderr.txt @@ -0,0 +1 @@ +nonexisting: No such file or directory diff --git a/Tests/RunCMake/CommandLine/E_sha384sum-result.txt b/Tests/RunCMake/CommandLine/E_sha384sum-result.txt new file mode 100644 index 0000000..573541a --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_sha384sum-result.txt @@ -0,0 +1 @@ +0 diff --git a/Tests/RunCMake/CommandLine/E_sha384sum-stdout.txt b/Tests/RunCMake/CommandLine/E_sha384sum-stdout.txt new file mode 100644 index 0000000..b706ac5 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_sha384sum-stdout.txt @@ -0,0 +1 @@ +43c1835ceba2e29596f05e3859d4fe2b6d124a181ed670f68e914bd3ed251b02b4be609608a13f23ec3d98da6c4eb8cd ../dummy diff --git a/Tests/RunCMake/CommandLine/E_sha512sum-dir-result.txt b/Tests/RunCMake/CommandLine/E_sha512sum-dir-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_sha512sum-dir-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/E_sha512sum-dir-stderr.txt b/Tests/RunCMake/CommandLine/E_sha512sum-dir-stderr.txt new file mode 100644 index 0000000..061fd64 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_sha512sum-dir-stderr.txt @@ -0,0 +1 @@ +Error: . is a directory diff --git a/Tests/RunCMake/CommandLine/E_sha512sum-no-file-result.txt b/Tests/RunCMake/CommandLine/E_sha512sum-no-file-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_sha512sum-no-file-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/E_sha512sum-no-file-stderr.txt b/Tests/RunCMake/CommandLine/E_sha512sum-no-file-stderr.txt new file mode 100644 index 0000000..732e8c4 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_sha512sum-no-file-stderr.txt @@ -0,0 +1 @@ +nonexisting: No such file or directory diff --git a/Tests/RunCMake/CommandLine/E_sha512sum-result.txt b/Tests/RunCMake/CommandLine/E_sha512sum-result.txt new file mode 100644 index 0000000..573541a --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_sha512sum-result.txt @@ -0,0 +1 @@ +0 diff --git a/Tests/RunCMake/CommandLine/E_sha512sum-stdout.txt b/Tests/RunCMake/CommandLine/E_sha512sum-stdout.txt new file mode 100644 index 0000000..4305383 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_sha512sum-stdout.txt @@ -0,0 +1 @@ +1692526aab84461a8aebcefddcba2b33fb5897ab180c53e8b345ae125484d0aaa35baf60487050be21ed8909a48eace93851bf139087ce1f7a87d97b6120a651 ../dummy diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake index f94b10a..6efcc12 100644 --- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake @@ -172,6 +172,30 @@ run_cmake_command(E_env-bad-arg1 ${CMAKE_COMMAND} -E env -bad-arg1) run_cmake_command(E_env-set ${CMAKE_COMMAND} -E env TEST_ENV=1 ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/E_env-set.cmake) run_cmake_command(E_env-unset ${CMAKE_COMMAND} -E env TEST_ENV=1 ${CMAKE_COMMAND} -E env --unset=TEST_ENV ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/E_env-unset.cmake) +run_cmake_command(E_md5sum-dir ${CMAKE_COMMAND} -E md5sum .) +run_cmake_command(E_sha1sum-dir ${CMAKE_COMMAND} -E sha1sum .) +run_cmake_command(E_sha224sum-dir ${CMAKE_COMMAND} -E sha224sum .) +run_cmake_command(E_sha256sum-dir ${CMAKE_COMMAND} -E sha256sum .) +run_cmake_command(E_sha384sum-dir ${CMAKE_COMMAND} -E sha384sum .) +run_cmake_command(E_sha512sum-dir ${CMAKE_COMMAND} -E sha512sum .) + +run_cmake_command(E_md5sum-no-file ${CMAKE_COMMAND} -E md5sum nonexisting) +run_cmake_command(E_sha1sum-no-file ${CMAKE_COMMAND} -E sha1sum nonexisting) +run_cmake_command(E_sha224sum-no-file ${CMAKE_COMMAND} -E sha224sum nonexisting) +run_cmake_command(E_sha256sum-no-file ${CMAKE_COMMAND} -E sha256sum nonexisting) +run_cmake_command(E_sha384sum-no-file ${CMAKE_COMMAND} -E sha384sum nonexisting) +run_cmake_command(E_sha512sum-no-file ${CMAKE_COMMAND} -E sha512sum nonexisting) + +file(WRITE "${RunCMake_BINARY_DIR}/dummy" "dummy") +run_cmake_command(E_md5sum ${CMAKE_COMMAND} -E md5sum ../dummy) +run_cmake_command(E_md5sum-mixed ${CMAKE_COMMAND} -E md5sum . ../dummy nonexisting) +run_cmake_command(E_sha1sum ${CMAKE_COMMAND} -E sha1sum ../dummy) +run_cmake_command(E_sha224sum ${CMAKE_COMMAND} -E sha224sum ../dummy) +run_cmake_command(E_sha256sum ${CMAKE_COMMAND} -E sha256sum ../dummy) +run_cmake_command(E_sha384sum ${CMAKE_COMMAND} -E sha384sum ../dummy) +run_cmake_command(E_sha512sum ${CMAKE_COMMAND} -E sha512sum ../dummy) +file(REMOVE "${RunCMake_BINARY_DIR}/dummy") + set(RunCMake_DEFAULT_stderr ".") run_cmake_command(E_sleep-no-args ${CMAKE_COMMAND} -E sleep) unset(RunCMake_DEFAULT_stderr) diff --git a/Tests/RunCMake/CompilerLauncher/CUDA-Build-stdout.txt b/Tests/RunCMake/CompilerLauncher/CUDA-Build-stdout.txt new file mode 100644 index 0000000..3313e31 --- /dev/null +++ b/Tests/RunCMake/CompilerLauncher/CUDA-Build-stdout.txt @@ -0,0 +1 @@ +.*-E env USED_LAUNCHER=1.* diff --git a/Tests/RunCMake/CompilerLauncher/CUDA-launch-Build-stdout.txt b/Tests/RunCMake/CompilerLauncher/CUDA-launch-Build-stdout.txt new file mode 100644 index 0000000..3313e31 --- /dev/null +++ b/Tests/RunCMake/CompilerLauncher/CUDA-launch-Build-stdout.txt @@ -0,0 +1 @@ +.*-E env USED_LAUNCHER=1.* diff --git a/Tests/RunCMake/CompilerLauncher/CUDA-launch.cmake b/Tests/RunCMake/CompilerLauncher/CUDA-launch.cmake new file mode 100644 index 0000000..6b4b816 --- /dev/null +++ b/Tests/RunCMake/CompilerLauncher/CUDA-launch.cmake @@ -0,0 +1,3 @@ +set(CTEST_USE_LAUNCHERS 1) +include(CTestUseLaunchers) +include(CUDA.cmake) diff --git a/Tests/RunCMake/CompilerLauncher/CUDA.cmake b/Tests/RunCMake/CompilerLauncher/CUDA.cmake new file mode 100644 index 0000000..fe5560b --- /dev/null +++ b/Tests/RunCMake/CompilerLauncher/CUDA.cmake @@ -0,0 +1,4 @@ +enable_language(CUDA) +set(CMAKE_CUDA_COMPILER_LAUNCHER "${CMAKE_COMMAND};-E;env;USED_LAUNCHER=1") +set(CMAKE_VERBOSE_MAKEFILE TRUE) +add_executable(main main.cu) diff --git a/Tests/RunCMake/CompilerLauncher/RunCMakeTest.cmake b/Tests/RunCMake/CompilerLauncher/RunCMakeTest.cmake index 5884d5c..ab26512 100644 --- a/Tests/RunCMake/CompilerLauncher/RunCMakeTest.cmake +++ b/Tests/RunCMake/CompilerLauncher/RunCMakeTest.cmake @@ -15,9 +15,14 @@ function(run_compiler_launcher lang) run_cmake_command(${lang}-Build ${CMAKE_COMMAND} --build . ${verbose_args}) endfunction() -run_compiler_launcher(C) -run_compiler_launcher(CXX) -if (NOT RunCMake_GENERATOR STREQUAL "Watcom WMake") - run_compiler_launcher(C-launch) - run_compiler_launcher(CXX-launch) +set(langs C CXX) +if(CMake_TEST_CUDA) + list(APPEND langs CUDA) endif() + +foreach(lang ${langs}) + run_compiler_launcher(${lang}) + if (NOT RunCMake_GENERATOR STREQUAL "Watcom WMake") + run_compiler_launcher(${lang}-launch) + endif() +endforeach() diff --git a/Tests/RunCMake/CompilerLauncher/main.cu b/Tests/RunCMake/CompilerLauncher/main.cu new file mode 100644 index 0000000..f8b643a --- /dev/null +++ b/Tests/RunCMake/CompilerLauncher/main.cu @@ -0,0 +1,4 @@ +int main() +{ + return 0; +} diff --git a/Tests/RunCMake/ExternalProject/NoOptions-stderr.txt b/Tests/RunCMake/ExternalProject/NoOptions-stderr.txt index 12a76c5..2fc7d29 100644 --- a/Tests/RunCMake/ExternalProject/NoOptions-stderr.txt +++ b/Tests/RunCMake/ExternalProject/NoOptions-stderr.txt @@ -6,12 +6,12 @@ is not an existing non-empty directory. Please specify one of: \* SOURCE_DIR with an existing non-empty directory + \* DOWNLOAD_COMMAND \* URL \* GIT_REPOSITORY + \* SVN_REPOSITORY \* HG_REPOSITORY \* CVS_REPOSITORY and CVS_MODULE - \* SVN_REVISION - \* DOWNLOAD_COMMAND Call Stack \(most recent call first\): .*/Modules/ExternalProject.cmake:[0-9]+ \(_ep_add_download_command\) NoOptions.cmake:[0-9]+ \(ExternalProject_Add\) diff --git a/Tests/RunCMake/ExternalProject/SourceEmpty-stderr.txt b/Tests/RunCMake/ExternalProject/SourceEmpty-stderr.txt index 58a343c..07c6e87 100644 --- a/Tests/RunCMake/ExternalProject/SourceEmpty-stderr.txt +++ b/Tests/RunCMake/ExternalProject/SourceEmpty-stderr.txt @@ -6,12 +6,12 @@ is not an existing non-empty directory. Please specify one of: \* SOURCE_DIR with an existing non-empty directory + \* DOWNLOAD_COMMAND \* URL \* GIT_REPOSITORY + \* SVN_REPOSITORY \* HG_REPOSITORY \* CVS_REPOSITORY and CVS_MODULE - \* SVN_REVISION - \* DOWNLOAD_COMMAND Call Stack \(most recent call first\): .*/Modules/ExternalProject.cmake:[0-9]+ \(_ep_add_download_command\) SourceEmpty.cmake:[0-9]+ \(ExternalProject_Add\) diff --git a/Tests/RunCMake/ExternalProject/SourceMissing-stderr.txt b/Tests/RunCMake/ExternalProject/SourceMissing-stderr.txt index e62f7cf..373f6e3 100644 --- a/Tests/RunCMake/ExternalProject/SourceMissing-stderr.txt +++ b/Tests/RunCMake/ExternalProject/SourceMissing-stderr.txt @@ -6,12 +6,12 @@ is not an existing non-empty directory. Please specify one of: \* SOURCE_DIR with an existing non-empty directory + \* DOWNLOAD_COMMAND \* URL \* GIT_REPOSITORY + \* SVN_REPOSITORY \* HG_REPOSITORY \* CVS_REPOSITORY and CVS_MODULE - \* SVN_REVISION - \* DOWNLOAD_COMMAND Call Stack \(most recent call first\): .*/Modules/ExternalProject.cmake:[0-9]+ \(_ep_add_download_command\) SourceMissing.cmake:[0-9]+ \(ExternalProject_Add\) diff --git a/Tests/RunCMake/File_Generate/CMP0070-NEW-check.cmake b/Tests/RunCMake/File_Generate/CMP0070-NEW-check.cmake new file mode 100644 index 0000000..05ec26e --- /dev/null +++ b/Tests/RunCMake/File_Generate/CMP0070-NEW-check.cmake @@ -0,0 +1,13 @@ +foreach(f + "${RunCMake_TEST_SOURCE_DIR}/relative-input-NEW.txt" + "${RunCMake_TEST_BINARY_DIR}/relative-output-NEW.txt" + ) + if(EXISTS "${f}") + file(READ "${f}" content) + if(NOT content MATCHES "^relative-input-NEW[\r\n]*$") + string(APPEND RunCMake_TEST_FAILED "File\n ${f}\ndoes not have expected content.\n") + endif() + else() + string(APPEND RunCMake_TEST_FAILED "Missing\n ${f}\n") + endif() +endforeach() diff --git a/Tests/RunCMake/File_Generate/CMP0070-NEW.cmake b/Tests/RunCMake/File_Generate/CMP0070-NEW.cmake new file mode 100644 index 0000000..1a03822 --- /dev/null +++ b/Tests/RunCMake/File_Generate/CMP0070-NEW.cmake @@ -0,0 +1,2 @@ +cmake_policy(SET CMP0070 NEW) +file(GENERATE OUTPUT relative-output-NEW.txt INPUT relative-input-NEW.txt) diff --git a/Tests/RunCMake/File_Generate/CMP0070-OLD-check.cmake b/Tests/RunCMake/File_Generate/CMP0070-OLD-check.cmake new file mode 100644 index 0000000..a71d822 --- /dev/null +++ b/Tests/RunCMake/File_Generate/CMP0070-OLD-check.cmake @@ -0,0 +1,13 @@ +foreach(f + "${RunCMake_TEST_BINARY_DIR}/relative-input-OLD.txt" + "${RunCMake_TEST_BINARY_DIR}/relative-output-OLD.txt" + ) + if(EXISTS "${f}") + file(READ "${f}" content) + if(NOT content MATCHES "^relative-input-OLD[\r\n]*$") + string(APPEND RunCMake_TEST_FAILED "File\n ${f}\ndoes not have expected content.\n") + endif() + else() + string(APPEND RunCMake_TEST_FAILED "Missing\n ${f}\n") + endif() +endforeach() diff --git a/Tests/RunCMake/File_Generate/CMP0070-OLD.cmake b/Tests/RunCMake/File_Generate/CMP0070-OLD.cmake new file mode 100644 index 0000000..0fb47cd --- /dev/null +++ b/Tests/RunCMake/File_Generate/CMP0070-OLD.cmake @@ -0,0 +1,3 @@ +cmake_policy(SET CMP0070 OLD) +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/relative-input-OLD.txt "relative-input-OLD\n") +file(GENERATE OUTPUT relative-output-OLD.txt INPUT relative-input-OLD.txt) diff --git a/Tests/RunCMake/File_Generate/CMP0070-WARN-check.cmake b/Tests/RunCMake/File_Generate/CMP0070-WARN-check.cmake new file mode 100644 index 0000000..1488df0 --- /dev/null +++ b/Tests/RunCMake/File_Generate/CMP0070-WARN-check.cmake @@ -0,0 +1,13 @@ +foreach(f + "${RunCMake_TEST_BINARY_DIR}/relative-input-WARN.txt" + "${RunCMake_TEST_BINARY_DIR}/relative-output-WARN.txt" + ) + if(EXISTS "${f}") + file(READ "${f}" content) + if(NOT content MATCHES "^relative-input-WARN[\r\n]*$") + string(APPEND RunCMake_TEST_FAILED "File\n ${f}\ndoes not have expected content.\n") + endif() + else() + string(APPEND RunCMake_TEST_FAILED "Missing\n ${f}\n") + endif() +endforeach() diff --git a/Tests/RunCMake/File_Generate/CMP0070-WARN-stderr.txt b/Tests/RunCMake/File_Generate/CMP0070-WARN-stderr.txt new file mode 100644 index 0000000..dbabaa9 --- /dev/null +++ b/Tests/RunCMake/File_Generate/CMP0070-WARN-stderr.txt @@ -0,0 +1,27 @@ +^CMake Warning \(dev\) in CMakeLists.txt: + Policy CMP0070 is not set: Define file\(GENERATE\) behavior for relative + paths. Run "cmake --help-policy CMP0070" for policy details. Use the + cmake_policy command to set the policy and suppress this warning. + + file\(GENERATE\) given relative INPUT path: + + relative-input-WARN.txt + + This is not defined behavior unless CMP0070 is set to NEW. For + compatibility with older versions of CMake, the previous undefined behavior + will be used. +This warning is for project developers. Use -Wno-dev to suppress it.( ++ +CMake Warning \(dev\) in CMakeLists.txt: + Policy CMP0070 is not set: Define file\(GENERATE\) behavior for relative + paths. Run "cmake --help-policy CMP0070" for policy details. Use the + cmake_policy command to set the policy and suppress this warning. + + file\(GENERATE\) given relative OUTPUT path: + + relative-output-WARN.txt + + This is not defined behavior unless CMP0070 is set to NEW. For + compatibility with older versions of CMake, the previous undefined behavior + will be used. +This warning is for project developers. Use -Wno-dev to suppress it.)+$ diff --git a/Tests/RunCMake/File_Generate/CMP0070-WARN.cmake b/Tests/RunCMake/File_Generate/CMP0070-WARN.cmake new file mode 100644 index 0000000..ccb0452 --- /dev/null +++ b/Tests/RunCMake/File_Generate/CMP0070-WARN.cmake @@ -0,0 +1,2 @@ +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/relative-input-WARN.txt "relative-input-WARN\n") +file(GENERATE OUTPUT relative-output-WARN.txt INPUT relative-input-WARN.txt) diff --git a/Tests/RunCMake/File_Generate/COMPILE_LANGUAGE-genex.cmake b/Tests/RunCMake/File_Generate/COMPILE_LANGUAGE-genex.cmake index e2b081d..59ccf19 100644 --- a/Tests/RunCMake/File_Generate/COMPILE_LANGUAGE-genex.cmake +++ b/Tests/RunCMake/File_Generate/COMPILE_LANGUAGE-genex.cmake @@ -7,6 +7,6 @@ target_compile_options(empty ) file(GENERATE - OUTPUT opts-$<COMPILE_LANGUAGE>.txt + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/opts-$<COMPILE_LANGUAGE>.txt CONTENT "$<TARGET_PROPERTY:empty,COMPILE_OPTIONS>\n" ) diff --git a/Tests/RunCMake/File_Generate/ReRunCMake.cmake b/Tests/RunCMake/File_Generate/ReRunCMake.cmake index 109d60e..541d86d 100644 --- a/Tests/RunCMake/File_Generate/ReRunCMake.cmake +++ b/Tests/RunCMake/File_Generate/ReRunCMake.cmake @@ -1,5 +1,5 @@ file(GENERATE - OUTPUT output_file.txt + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/output_file.txt" INPUT "${CMAKE_CURRENT_BINARY_DIR}/input_file.txt" ) diff --git a/Tests/RunCMake/File_Generate/RunCMakeTest.cmake b/Tests/RunCMake/File_Generate/RunCMakeTest.cmake index 82e903d..b660463 100644 --- a/Tests/RunCMake/File_Generate/RunCMakeTest.cmake +++ b/Tests/RunCMake/File_Generate/RunCMakeTest.cmake @@ -1,5 +1,9 @@ include(RunCMake) +run_cmake(CMP0070-NEW) +run_cmake(CMP0070-OLD) +run_cmake(CMP0070-WARN) + run_cmake(CommandConflict) if("${RunCMake_GENERATOR}" MATCHES "Visual Studio|Xcode") run_cmake(OutputConflict) diff --git a/Tests/RunCMake/File_Generate/WriteIfDifferent.cmake b/Tests/RunCMake/File_Generate/WriteIfDifferent.cmake index d1d832a..bb36a4c 100644 --- a/Tests/RunCMake/File_Generate/WriteIfDifferent.cmake +++ b/Tests/RunCMake/File_Generate/WriteIfDifferent.cmake @@ -1,5 +1,5 @@ file(GENERATE - OUTPUT output_file.txt + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/output_file.txt CONTENT "123" ) diff --git a/Tests/RunCMake/File_Generate/relative-input-NEW.txt b/Tests/RunCMake/File_Generate/relative-input-NEW.txt new file mode 100644 index 0000000..7293e90 --- /dev/null +++ b/Tests/RunCMake/File_Generate/relative-input-NEW.txt @@ -0,0 +1 @@ +relative-input-NEW diff --git a/Tests/RunCMake/Framework/FrameworkLayout.cmake b/Tests/RunCMake/Framework/FrameworkLayout.cmake index 3d62a8a..4f42459 100644 --- a/Tests/RunCMake/Framework/FrameworkLayout.cmake +++ b/Tests/RunCMake/Framework/FrameworkLayout.cmake @@ -22,4 +22,4 @@ set_source_files_properties(some.txt PROPERTIES MACOSX_PACKAGE_LOCATION somedir) add_custom_command(TARGET Framework POST_BUILD COMMAND /usr/bin/file $<TARGET_FILE:Framework>) -file(GENERATE OUTPUT FrameworkName.cmake CONTENT "set(framework-dir \"$<TARGET_BUNDLE_DIR:Framework>\")\n") +file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/FrameworkName.cmake CONTENT "set(framework-dir \"$<TARGET_BUNDLE_DIR:Framework>\")\n") diff --git a/Tests/RunCMake/GenerateExportHeader/GEH.cmake b/Tests/RunCMake/GenerateExportHeader/GEH.cmake index e0677a7..cfca8fe 100644 --- a/Tests/RunCMake/GenerateExportHeader/GEH.cmake +++ b/Tests/RunCMake/GenerateExportHeader/GEH.cmake @@ -45,13 +45,6 @@ include(GenerateExportHeader) set(CMAKE_CXX_STANDARD 98) -# Those versions of the HP compiler that need a flag to get proper C++98 -# template support also need a flag to use the newer C++ library. -if (CMAKE_CXX_COMPILER_ID STREQUAL HP AND - CMAKE_CXX98_STANDARD_COMPILE_OPTION STREQUAL "+hpxstd98") - string(APPEND CMAKE_CXX_FLAGS " -AA") -endif () - # Clang/C2 in C++98 mode cannot properly handle some of MSVC headers if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC") diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_command-stderr.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_command-stderr.txt index 789b4d0..c8b124a 100644 --- a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_command-stderr.txt +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_command-stderr.txt @@ -3,8 +3,8 @@ CMake Error at COMPILE_LANGUAGE-add_custom_command.cmake:6 \(add_custom_command\ \$<COMPILE_LANGUAGE> - \$<COMPILE_LANGUAGE:...> may only be used to specify include directories - compile definitions, compile options and to evaluate components of the + \$<COMPILE_LANGUAGE:...> may only be used to specify include directories, + compile definitions, compile options, and to evaluate components of the file\(GENERATE\) command. Call Stack \(most recent call first\): CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_target-stderr.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_target-stderr.txt index 400fbc0..e8cefc7 100644 --- a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_target-stderr.txt +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_target-stderr.txt @@ -3,8 +3,8 @@ CMake Error at COMPILE_LANGUAGE-add_custom_target.cmake:4 \(add_custom_target\): \$<COMPILE_LANGUAGE> - \$<COMPILE_LANGUAGE:...> may only be used to specify include directories - compile definitions, compile options and to evaluate components of the + \$<COMPILE_LANGUAGE:...> may only be used to specify include directories, + compile definitions, compile options, and to evaluate components of the file\(GENERATE\) command. Call Stack \(most recent call first\): CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_executable-stderr.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_executable-stderr.txt index e45bb02..7fa1f25 100644 --- a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_executable-stderr.txt +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_executable-stderr.txt @@ -3,8 +3,8 @@ CMake Error at COMPILE_LANGUAGE-add_executable.cmake:4 \(add_executable\): \$<COMPILE_LANGUAGE> - \$<COMPILE_LANGUAGE:...> may only be used to specify include directories - compile definitions, compile options and to evaluate components of the + \$<COMPILE_LANGUAGE:...> may only be used to specify include directories, + compile definitions, compile options, and to evaluate components of the file\(GENERATE\) command. Call Stack \(most recent call first\): CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_library-stderr.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_library-stderr.txt index c9ee6fe..ee60b58 100644 --- a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_library-stderr.txt +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_library-stderr.txt @@ -3,8 +3,8 @@ CMake Error at COMPILE_LANGUAGE-add_library.cmake:4 \(add_library\): \$<COMPILE_LANGUAGE> - \$<COMPILE_LANGUAGE:...> may only be used to specify include directories - compile definitions, compile options and to evaluate components of the + \$<COMPILE_LANGUAGE:...> may only be used to specify include directories, + compile definitions, compile options, and to evaluate components of the file\(GENERATE\) command. Call Stack \(most recent call first\): CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_test-stderr.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_test-stderr.txt index 9955f5d..fd8a731 100644 --- a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_test-stderr.txt +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_test-stderr.txt @@ -3,8 +3,8 @@ CMake Error at COMPILE_LANGUAGE-add_test.cmake:5 \(add_test\): \$<COMPILE_LANGUAGE> - \$<COMPILE_LANGUAGE:...> may only be used to specify include directories - compile definitions, compile options and to evaluate components of the + \$<COMPILE_LANGUAGE:...> may only be used to specify include directories, + compile definitions, compile options, and to evaluate components of the file\(GENERATE\) command. Call Stack \(most recent call first\): CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-install-stderr.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-install-stderr.txt index eca700f..bef7f63 100644 --- a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-install-stderr.txt +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-install-stderr.txt @@ -3,6 +3,6 @@ CMake Error: \$<COMPILE_LANGUAGE> - \$<COMPILE_LANGUAGE:...> may only be used to specify include directories - compile definitions, compile options and to evaluate components of the + \$<COMPILE_LANGUAGE:...> may only be used to specify include directories, + compile definitions, compile options, and to evaluate components of the file\(GENERATE\) command. diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-target_sources-stderr.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-target_sources-stderr.txt index 2d324e2..687d9b7 100644 --- a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-target_sources-stderr.txt +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-target_sources-stderr.txt @@ -3,8 +3,8 @@ CMake Error at COMPILE_LANGUAGE-target_sources.cmake:5 \(target_sources\): \$<COMPILE_LANGUAGE> - \$<COMPILE_LANGUAGE:...> may only be used to specify include directories - compile definitions, compile options and to evaluate components of the + \$<COMPILE_LANGUAGE:...> may only be used to specify include directories, + compile definitions, compile options, and to evaluate components of the file\(GENERATE\) command. Call Stack \(most recent call first\): CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/GoogleTest/CMakeLists.txt b/Tests/RunCMake/GoogleTest/CMakeLists.txt new file mode 100644 index 0000000..dc92486 --- /dev/null +++ b/Tests/RunCMake/GoogleTest/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.6) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-test-stdout.txt b/Tests/RunCMake/GoogleTest/GoogleTest-test-stdout.txt new file mode 100644 index 0000000..5f7753d --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTest-test-stdout.txt @@ -0,0 +1,25 @@ +Test project .* + Start 1: TEST:basic\.case_foo!1 +1/8 Test #1: TEST:basic\.case_foo!1 \.+ +Passed +[0-9.]+ sec + Start 2: TEST:basic\.case_bar!1 +2/8 Test #2: TEST:basic\.case_bar!1 \.+ +Passed +[0-9.]+ sec + Start 3: TEST:basic\.disabled_case!1 +3/8 Test #3: TEST:basic\.disabled_case!1 \.+\*+Not Run \(Disabled\) +[0-9.]+ sec + Start 4: TEST:disabled\.case!1 +4/8 Test #4: TEST:disabled\.case!1 \.+\*+Not Run \(Disabled\) +[0-9.]+ sec + Start 5: TEST:typed/short\.case!1 +5/8 Test #5: TEST:typed/short\.case!1 \.+ +Passed +[0-9.]+ sec + Start 6: TEST:typed/float\.case!1 +6/8 Test #6: TEST:typed/float\.case!1 \.+ +Passed +[0-9.]+ sec + Start 7: TEST:value/test\.case/1!1 +7/8 Test #7: TEST:value/test\.case/1!1 \.+ +Passed +[0-9.]+ sec + Start 8: TEST:value/test\.case/"foo"!1 +8/8 Test #8: TEST:value/test\.case/"foo"!1 \.+ +Passed +[0-9.]+ sec + +100% tests passed, 0 tests failed out of 6 + +Total Test time \(real\) = +[0-9.]+ sec + +The following tests did not run: +.*3 - TEST:basic\.disabled_case!1 \(Disabled\) +.*4 - TEST:disabled\.case!1 \(Disabled\) diff --git a/Tests/RunCMake/GoogleTest/GoogleTest.cmake b/Tests/RunCMake/GoogleTest/GoogleTest.cmake new file mode 100644 index 0000000..9a3677f --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTest.cmake @@ -0,0 +1,15 @@ +project(test_include_dirs) +include(CTest) +include(GoogleTest) + +enable_testing() + +add_executable(fake_gtest fake_gtest.cpp) + +gtest_discover_tests( + fake_gtest + TEST_PREFIX TEST: + TEST_SUFFIX !1 + EXTRA_ARGS how now "\"brown\" cow" + PROPERTIES LABELS TEST +) diff --git a/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake b/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake new file mode 100644 index 0000000..aec8568 --- /dev/null +++ b/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake @@ -0,0 +1,26 @@ +include(RunCMake) + +function(run_GoogleTest) + # Use a single build tree for a few tests without cleaning. + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-build) + set(RunCMake_TEST_NO_CLEAN 1) + if(RunCMake_GENERATOR MATCHES "Make|Ninja") + set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug) + endif() + file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") + file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") + run_cmake(GoogleTest) + run_cmake_command(GoogleTest-build + ${CMAKE_COMMAND} + --build . + --config Debug + ) + run_cmake_command(GoogleTest-test + ${CMAKE_CTEST_COMMAND} + -C Debug + -L TEST + --no-label-summary + ) +endfunction() + +run_GoogleTest() diff --git a/Tests/RunCMake/GoogleTest/fake_gtest.cpp b/Tests/RunCMake/GoogleTest/fake_gtest.cpp new file mode 100644 index 0000000..f1bd7ef --- /dev/null +++ b/Tests/RunCMake/GoogleTest/fake_gtest.cpp @@ -0,0 +1,41 @@ +#include <iostream> +#include <string> + +int main(int argc, char** argv) +{ + // Note: GoogleTest.cmake doesn't actually depend on Google Test as such; + // it only requires that we produces output in the expected format when + // invoked with --gtest_list_tests. Thus, we fake that here. This allows us + // to test the module without actually needing Google Test. + if (argc > 1 && std::string(argv[1]) == "--gtest_list_tests") { + std::cout << "basic." << std::endl; + std::cout << " case_foo" << std::endl; + std::cout << " case_bar" << std::endl; + std::cout << " DISABLED_disabled_case" << std::endl; + std::cout << "DISABLED_disabled." << std::endl; + std::cout << " case" << std::endl; + std::cout << "typed/0. # TypeParam = short" << std::endl; + std::cout << " case" << std::endl; + std::cout << "typed/1. # TypeParam = float" << std::endl; + std::cout << " case" << std::endl; + std::cout << "value/test." << std::endl; + std::cout << " case/0 # GetParam() = 1" << std::endl; + std::cout << " case/1 # GetParam() = \"foo\"" << std::endl; + return 0; + } + + if (argc > 5) { + // Simple test of EXTRA_ARGS + if (std::string(argv[3]) == "how" && std::string(argv[4]) == "now" && + std::string(argv[5]) == "\"brown\" cow") { + return 0; + } + } + + // Print arguments for debugging, if we didn't get the expected arguments + for (int i = 1; i < argc; ++i) { + std::cerr << "arg[" << i << "]: '" << argv[i] << "'\n"; + } + + return 1; +} diff --git a/Tests/RunCMake/TargetObjects/NoTarget.cmake b/Tests/RunCMake/TargetObjects/NoTarget.cmake index 5d7e33e..268577d 100644 --- a/Tests/RunCMake/TargetObjects/NoTarget.cmake +++ b/Tests/RunCMake/TargetObjects/NoTarget.cmake @@ -1,7 +1,7 @@ add_library(iface INTERFACE) target_sources(iface INTERFACE $<TARGET_OBJECTS:NoTarget>) -file(GENERATE OUTPUT test_output CONTENT $<TARGET_OBJECTS:NoTarget>) -file(GENERATE OUTPUT test_output2 CONTENT $<TARGET_PROPERTY:iface,INTERFACE_SOURCES>) +file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/test_output CONTENT $<TARGET_OBJECTS:NoTarget>) +file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/test_output2 CONTENT $<TARGET_PROPERTY:iface,INTERFACE_SOURCES>) install(FILES $<TARGET_OBJECTS:NoTarget> DESTINATION objects) diff --git a/Tests/RunCMake/TargetObjects/NotObjlibTarget.cmake b/Tests/RunCMake/TargetObjects/NotObjlibTarget.cmake index 8e5fdd0..3bb3e37 100644 --- a/Tests/RunCMake/TargetObjects/NotObjlibTarget.cmake +++ b/Tests/RunCMake/TargetObjects/NotObjlibTarget.cmake @@ -1,3 +1,3 @@ add_library(StaticLib empty.cpp) -file(GENERATE OUTPUT test_output CONTENT $<TARGET_OBJECTS:StaticLib>) +file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/test_output CONTENT $<TARGET_OBJECTS:StaticLib>) diff --git a/Tests/RunCMake/VS10Project/RunCMakeTest.cmake b/Tests/RunCMake/VS10Project/RunCMakeTest.cmake index 3af877f..6e7c2f3 100644 --- a/Tests/RunCMake/VS10Project/RunCMakeTest.cmake +++ b/Tests/RunCMake/VS10Project/RunCMakeTest.cmake @@ -4,3 +4,4 @@ run_cmake(VsTargetsFileReferences) run_cmake(VsCustomProps) run_cmake(VsDebuggerWorkingDir) run_cmake(VsCSharpCustomTags) +run_cmake(VsCSharpReferenceProps) diff --git a/Tests/RunCMake/VS10Project/VsCSharpCustomTags-check.cmake b/Tests/RunCMake/VS10Project/VsCSharpCustomTags-check.cmake index 70ea193..9eb4619 100644 --- a/Tests/RunCMake/VS10Project/VsCSharpCustomTags-check.cmake +++ b/Tests/RunCMake/VS10Project/VsCSharpCustomTags-check.cmake @@ -4,20 +4,31 @@ if(NOT EXISTS "${csProjectFile}") return() endif() -set(tagFound FALSE) +# test VS_CSHARP_* for the following extensions +set(fileExtensions + "cs" + "png" + "jpg" + "xml" + "settings") +# set(tagName "MyCustomTag") set(tagValue "MyCustomValue") file(STRINGS "${csProjectFile}" lines) -foreach(line IN LISTS lines) - if(line MATCHES "^ *<${tagName}>${tagValue}</${tagName}>") - message(STATUS "foo.csproj has tag ${tagName} with value ${tagValue} defined") - set(tagFound TRUE) + +foreach(e ${fileExtensions}) + string(TOUPPER ${e} eUC) + set(tagFound FALSE) + foreach(line IN LISTS lines) + if(line MATCHES "^ *<${tagName}${eUC}>${tagValue}${eUC}</${tagName}${eUC}>") + message(STATUS "foo.csproj has tag ${tagName}${eUC} with value ${tagValue}${eUC} defined") + set(tagFound TRUE) + endif() + endforeach() + if(NOT tagFound) + set(RunCMake_TEST_FAILED "Source file tag ${tagName}${eUC} with value ${tagValue}${eUC} not found.") + return() endif() endforeach() - -if(NOT tagFound) - set(RunCMake_TEST_FAILED "Source file tag ${tagName} with value ${tagValue} not found.") - return() -endif() diff --git a/Tests/RunCMake/VS10Project/VsCSharpCustomTags.cmake b/Tests/RunCMake/VS10Project/VsCSharpCustomTags.cmake index c51e9c3..45766a0 100644 --- a/Tests/RunCMake/VS10Project/VsCSharpCustomTags.cmake +++ b/Tests/RunCMake/VS10Project/VsCSharpCustomTags.cmake @@ -1,11 +1,27 @@ enable_language(CSharp) -add_library(foo foo.cs) -set(props_file "${CMAKE_CURRENT_SOURCE_DIR}/my.props") +# test VS_CSHARP_* for the following extensions +set(fileExtensions + "cs" + "png" + "jpg" + "xml" + "settings") +# set(tagName "MyCustomTag") set(tagValue "MyCustomValue") -set_source_files_properties(foo.cs - PROPERTIES - VS_CSHARP_${tagName} "${tagValue}") +set(fileNames) +foreach(e ${fileExtensions}) + set(currentFile "${CMAKE_CURRENT_BINARY_DIR}/foo.${e}") + list(APPEND fileNames ${currentFile}) + execute_process(COMMAND ${CMAKE_COMMAND} -E touch + "${currentFile}") + string(TOUPPER ${e} eUC) + set_source_files_properties("${currentFile}" + PROPERTIES + VS_CSHARP_${tagName}${eUC} "${tagValue}${eUC}") +endforeach() + +add_library(foo ${fileNames}) diff --git a/Tests/RunCMake/VS10Project/VsCSharpReferenceProps-check.cmake b/Tests/RunCMake/VS10Project/VsCSharpReferenceProps-check.cmake new file mode 100644 index 0000000..8b9bb67 --- /dev/null +++ b/Tests/RunCMake/VS10Project/VsCSharpReferenceProps-check.cmake @@ -0,0 +1,49 @@ +set(csProjectFile "${RunCMake_TEST_BINARY_DIR}/foo.csproj") +if(NOT EXISTS "${csProjectFile}") + set(RunCMake_TEST_FAILED "Project file ${csProjectFile} does not exist.") + return() +endif() + +set(test1Reference "System") +set(test1Tag "Hello") +set(test1Value "World") + +set(test2Reference "foo2") +set(test2Tag "Hallo") +set(test2Value "Welt") + +set(tag1Found FALSE) +set(ref1Found FALSE) + +file(STRINGS "${csProjectFile}" lines) + +foreach(i 1 2) + set(testReference "${test${i}Reference}") + set(testTag "${test${i}Tag}") + set(testValue "${test${i}Value}") + foreach(line IN LISTS lines) + if(line MATCHES "^ *<(Project|)Reference .*>$") + set(validTag FALSE) + if(line MATCHES "^ *<(Project|)Reference .*\".*${testReference}.*\".*>$") + set(validTag TRUE) + message(STATUS "foo.csproj is using reference ${testReference}") + set(ref${i}Found TRUE) + endif() + endif() + if(line MATCHES "^ *<${testTag}>${testValue}</${testTag}>$") + if(validTag) + message(STATUS "foo.csproj reference ${testReference} has tag ${testTag}") + set(tag${i}Found TRUE) + else() + message(STATUS "tag ${testTag} found in wrong place!") + set(tag${i}Found FALSE) + endif() + endif() + endforeach() +endforeach() + +if(NOT tag1Found OR NOT ref1Found OR + NOT tag2Found OR NOT ref2Found) + set(RunCMake_TEST_FAILED "Custom reference XML tag not found.") + return() +endif() diff --git a/Tests/RunCMake/VS10Project/VsCSharpReferenceProps.cmake b/Tests/RunCMake/VS10Project/VsCSharpReferenceProps.cmake new file mode 100644 index 0000000..2af1756 --- /dev/null +++ b/Tests/RunCMake/VS10Project/VsCSharpReferenceProps.cmake @@ -0,0 +1,19 @@ +enable_language(CSharp) +add_library(foo foo.cs) +add_library(foo2 foo.cs) + +set(test1Reference "System") +set(test1Tag "Hello") +set(test1Value "World") + +set(test2Reference "foo2") +set(test2Tag "Hallo") +set(test2Value "Welt") + +target_link_libraries(foo foo2) + +set_target_properties(foo PROPERTIES + VS_DOTNET_REFERENCES "${test1Reference};Blubb" + VS_DOTNET_REFERENCEPROP_${test1Reference}_TAG_${test1Tag} ${test1Value} + VS_DOTNET_REFERENCEPROP_${test2Reference}_TAG_${test2Tag} ${test2Value} + ) diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/CMakeLists.txt.in b/Tests/RunCMake/ctest_labels_for_subprojects/CMakeLists.txt.in new file mode 100644 index 0000000..30dd37e --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/CMakeLists.txt.in @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.9) +@CASE_CMAKELISTS_PREFIX_CODE@ +project(CTestLabelsForSubprojects@CASE_NAME@ NONE) +include(CTest) +@CASE_CMAKELISTS_SUFFIX_CODE@ diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/CTestConfig.cmake.in b/Tests/RunCMake/ctest_labels_for_subprojects/CTestConfig.cmake.in new file mode 100644 index 0000000..1e1905b --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/CTestConfig.cmake.in @@ -0,0 +1,2 @@ +set(CTEST_PROJECT_NAME "CTestLabelsForSubprojects@CASE_NAME@") +@CTEST_EXTRA_CONFIG@ diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/CTestConfigCTestScript-check.cmake b/Tests/RunCMake/ctest_labels_for_subprojects/CTestConfigCTestScript-check.cmake new file mode 100644 index 0000000..ea05851 --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/CTestConfigCTestScript-check.cmake @@ -0,0 +1,36 @@ +set(EXPERIMENTAL_FEATURE_REGEX "<Subproject name=\"MyExperimentalFeature\">.*<Label>MyExperimentalFeature</Label>.*</Subproject>") +set(PRODUCTION_CODE_REGEX "<Subproject name=\"MyProductionCode\">.*<Label>MyProductionCode</Label>.*</Subproject>") +set(SUBPROJECTS_REGEX "${EXPERIMENTAL_FEATURE_REGEX}.*${PRODUCTION_CODE_REGEX}") + +file(GLOB configure_xml_file "${RunCMake_TEST_BINARY_DIR}/Testing/*/Configure.xml") +if(configure_xml_file) + file(READ "${configure_xml_file}" configure_xml) + if(NOT configure_xml MATCHES "${SUBPROJECTS_REGEX}.*<Configure>") + set(RunCMake_TEST_FAILED "Configure.xml does not contain the expected list of subprojects") + endif() +else() + set(RunCMake_TEST_FAILED "Configure.xml not found") +endif() + +file(GLOB build_xml_file "${RunCMake_TEST_BINARY_DIR}/Testing/*/Build.xml") +if(build_xml_file) + file(READ "${build_xml_file}" build_xml) + set(BUILD_WARNING_REGEX "<Failure type=\"Warning\">.*<Labels>.*<Label>MyExperimentalFeature</Label>.*</Labels>") + if(NOT build_xml MATCHES "${SUBPROJECTS_REGEX}.*<Build>.*${BUILD_ERROR_REGEX}.*</Build>") + set(RunCMake_TEST_FAILED "Build.xml does not contain the expected list of subprojects and labels") + endif() +else() + set(RunCMake_TEST_FAILED "Build.xml not found") +endif() + +file(GLOB test_xml_file "${RunCMake_TEST_BINARY_DIR}/Testing/*/Test.xml") +if(test_xml_file) + file(READ "${test_xml_file}" test_xml) + set(TEST_FAILED_REGEX "<Test Status=\"failed\">.*<Labels>.*<Label>MyExperimentalFeature</Label>.*<Label>NotASubproject</Label>.*</Labels>") + set(TEST_PASSED_REGEX "<Test Status=\"passed\">.*<Labels>.*<Label>MyProductionCode</Label>.*</Labels>") + if(NOT test_xml MATCHES "${SUBPROJECTS_REGEX}.*<Testing>.*${TEST_FAILED_REGEX}.*${TEST_PASSED_REGEX}.*${TEST_NOTRUN_REGEX}.*</Testing>") + set(RunCMake_TEST_FAILED "Test.xml does not contain the expected list of subprojects and labels") + endif() +else() + set(RunCMake_TEST_FAILED "${CTEST_BINARY_DIRECTORY}/Testing/*/Test.xml not found") +endif() diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/CTestConfigCTestScript-stdout.txt b/Tests/RunCMake/ctest_labels_for_subprojects/CTestConfigCTestScript-stdout.txt new file mode 100644 index 0000000..ae00e51 --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/CTestConfigCTestScript-stdout.txt @@ -0,0 +1,7 @@ +17% tests passed, 5 tests failed out of 6 ++ +Subproject Time Summary: +MyExperimentalFeature += +[0-9.]+ sec \(5 tests\) +MyProductionCode += +[0-9.]+ sec \(1 test\) ++ +Total Test time \(real\) = +[0-9.]+ sec diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariable-check.cmake b/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariable-check.cmake new file mode 100644 index 0000000..ea05851 --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariable-check.cmake @@ -0,0 +1,36 @@ +set(EXPERIMENTAL_FEATURE_REGEX "<Subproject name=\"MyExperimentalFeature\">.*<Label>MyExperimentalFeature</Label>.*</Subproject>") +set(PRODUCTION_CODE_REGEX "<Subproject name=\"MyProductionCode\">.*<Label>MyProductionCode</Label>.*</Subproject>") +set(SUBPROJECTS_REGEX "${EXPERIMENTAL_FEATURE_REGEX}.*${PRODUCTION_CODE_REGEX}") + +file(GLOB configure_xml_file "${RunCMake_TEST_BINARY_DIR}/Testing/*/Configure.xml") +if(configure_xml_file) + file(READ "${configure_xml_file}" configure_xml) + if(NOT configure_xml MATCHES "${SUBPROJECTS_REGEX}.*<Configure>") + set(RunCMake_TEST_FAILED "Configure.xml does not contain the expected list of subprojects") + endif() +else() + set(RunCMake_TEST_FAILED "Configure.xml not found") +endif() + +file(GLOB build_xml_file "${RunCMake_TEST_BINARY_DIR}/Testing/*/Build.xml") +if(build_xml_file) + file(READ "${build_xml_file}" build_xml) + set(BUILD_WARNING_REGEX "<Failure type=\"Warning\">.*<Labels>.*<Label>MyExperimentalFeature</Label>.*</Labels>") + if(NOT build_xml MATCHES "${SUBPROJECTS_REGEX}.*<Build>.*${BUILD_ERROR_REGEX}.*</Build>") + set(RunCMake_TEST_FAILED "Build.xml does not contain the expected list of subprojects and labels") + endif() +else() + set(RunCMake_TEST_FAILED "Build.xml not found") +endif() + +file(GLOB test_xml_file "${RunCMake_TEST_BINARY_DIR}/Testing/*/Test.xml") +if(test_xml_file) + file(READ "${test_xml_file}" test_xml) + set(TEST_FAILED_REGEX "<Test Status=\"failed\">.*<Labels>.*<Label>MyExperimentalFeature</Label>.*<Label>NotASubproject</Label>.*</Labels>") + set(TEST_PASSED_REGEX "<Test Status=\"passed\">.*<Labels>.*<Label>MyProductionCode</Label>.*</Labels>") + if(NOT test_xml MATCHES "${SUBPROJECTS_REGEX}.*<Testing>.*${TEST_FAILED_REGEX}.*${TEST_PASSED_REGEX}.*${TEST_NOTRUN_REGEX}.*</Testing>") + set(RunCMake_TEST_FAILED "Test.xml does not contain the expected list of subprojects and labels") + endif() +else() + set(RunCMake_TEST_FAILED "${CTEST_BINARY_DIRECTORY}/Testing/*/Test.xml not found") +endif() diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariable-stdout.txt b/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariable-stdout.txt new file mode 100644 index 0000000..ae00e51 --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariable-stdout.txt @@ -0,0 +1,7 @@ +17% tests passed, 5 tests failed out of 6 ++ +Subproject Time Summary: +MyExperimentalFeature += +[0-9.]+ sec \(5 tests\) +MyProductionCode += +[0-9.]+ sec \(1 test\) ++ +Total Test time \(real\) = +[0-9.]+ sec diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariableCommandLine-check.cmake b/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariableCommandLine-check.cmake new file mode 100644 index 0000000..7beefba --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariableCommandLine-check.cmake @@ -0,0 +1,34 @@ +set(THIRD_PARTY_REGEX "<Subproject name=\"MyThirdPartyDependency\">.*<Label>MyThirdPartyDependency</Label>.*</Subproject>") +set(SUBPROJECTS_REGEX "${THIRD_PARTY_REGEX}") + +file(GLOB configure_xml_file "${RunCMake_TEST_BINARY_DIR}/Testing/*/Configure.xml") +if(configure_xml_file) + file(READ "${configure_xml_file}" configure_xml) + if(NOT configure_xml MATCHES "${SUBPROJECTS_REGEX}.*<Configure>") + set(RunCMake_TEST_FAILED "Configure.xml does not contain the expected list of subprojects") + endif() +else() + set(RunCMake_TEST_FAILED "Configure.xml not found") +endif() + +file(GLOB build_xml_file "${RunCMake_TEST_BINARY_DIR}/Testing/*/Build.xml") +if(build_xml_file) + file(READ "${build_xml_file}" build_xml) + set(BUILD_ERROR_REGEX "<Failure type=\"Error\">.*<Labels>.*<Label>MyThirdPartyDependency</Label>.*<Label>NotASubproject</Label>.*</Labels>") + if(NOT build_xml MATCHES "${SUBPROJECTS_REGEX}.*<Build>.*${BUILD_ERROR_REGEX}.*</Build>") + set(RunCMake_TEST_FAILED "Build.xml does not contain the expected list of subprojects and labels") + endif() +else() + set(RunCMake_TEST_FAILED "Build.xml not found") +endif() + +file(GLOB test_xml_file "${RunCMake_TEST_BINARY_DIR}/Testing/*/Test.xml") +if(test_xml_file) + file(READ "${test_xml_file}" test_xml) + set(TEST_NOTRUN_REGEX "<Test Status=\"notrun\">.*<Labels>.*<Label>MyThirdPartyDependency</Label>.*<Label>NotASubproject</Label>.*</Labels>") + if(NOT test_xml MATCHES "${SUBPROJECTS_REGEX}.*<Testing>.*${TEST_FAILED_REGEX}.*${TEST_PASSED_REGEX}.*${TEST_NOTRUN_REGEX}.*</Testing>") + set(RunCMake_TEST_FAILED "Test.xml does not contain the expected list of subprojects and labels") + endif() +else() + set(RunCMake_TEST_FAILED "${CTEST_BINARY_DIRECTORY}/Testing/*/Test.xml not found") +endif() diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariableCommandLine-result.txt b/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariableCommandLine-result.txt new file mode 100644 index 0000000..b57e2de --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariableCommandLine-result.txt @@ -0,0 +1 @@ +(-1|255) diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariableCommandLine-stderr.txt b/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariableCommandLine-stderr.txt new file mode 100644 index 0000000..38566fb --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariableCommandLine-stderr.txt @@ -0,0 +1 @@ +Unable to find executable:.*MyThirdPartyDependency/src/thirdparty diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariableCommandLine-stdout.txt b/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariableCommandLine-stdout.txt new file mode 100644 index 0000000..a78a99a --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariableCommandLine-stdout.txt @@ -0,0 +1,6 @@ +0% tests passed, 1 tests failed out of 1 ++ +Subproject Time Summary: +MyThirdPartyDependency += +[0-9.]+ sec \(1 test\) ++ +Total Test time \(real\) = +[0-9.]+ sec diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCMakeLists-result.txt b/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCMakeLists-result.txt new file mode 100644 index 0000000..45a4fb7 --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCMakeLists-result.txt @@ -0,0 +1 @@ +8 diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCMakeLists-stderr.txt b/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCMakeLists-stderr.txt new file mode 100644 index 0000000..ba4235d --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCMakeLists-stderr.txt @@ -0,0 +1 @@ +Errors while running CTest diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCMakeLists-stdout.txt b/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCMakeLists-stdout.txt new file mode 100644 index 0000000..b5d76a9 --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCMakeLists-stdout.txt @@ -0,0 +1,6 @@ +50% tests passed, 1 tests failed out of 2 ++ +Subproject Time Summary: +MySubproject += +[0-9.]+ sec \(2 tests\) ++ +Total Test time \(real\) = +[0-9.]+ sec diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCTestConfig-result.txt b/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCTestConfig-result.txt new file mode 100644 index 0000000..45a4fb7 --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCTestConfig-result.txt @@ -0,0 +1 @@ +8 diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCTestConfig-stderr.txt b/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCTestConfig-stderr.txt new file mode 100644 index 0000000..ba4235d --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCTestConfig-stderr.txt @@ -0,0 +1 @@ +Errors while running CTest diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCTestConfig-stdout.txt b/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCTestConfig-stdout.txt new file mode 100644 index 0000000..01851fd --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCTestConfig-stdout.txt @@ -0,0 +1,6 @@ +67% tests passed, 1 tests failed out of 3 ++ +Subproject Time Summary: +MySubproject += +[0-9.]+ sec \(2 tests\) ++ +Total Test time \(real\) = +[0-9.]+ sec diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCTestConfigNoSummary-result.txt b/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCTestConfigNoSummary-result.txt new file mode 100644 index 0000000..45a4fb7 --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCTestConfigNoSummary-result.txt @@ -0,0 +1 @@ +8 diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCTestConfigNoSummary-stderr.txt b/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCTestConfigNoSummary-stderr.txt new file mode 100644 index 0000000..ba4235d --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCTestConfigNoSummary-stderr.txt @@ -0,0 +1 @@ +Errors while running CTest diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCTestConfigNoSummary-stdout.txt b/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCTestConfigNoSummary-stdout.txt new file mode 100644 index 0000000..0209bfe --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCTestConfigNoSummary-stdout.txt @@ -0,0 +1,7 @@ +67% tests passed, 1 tests failed out of 3 ++ +Label Time Summary: +MySubproject += +[0-9.]+ sec \(2 tests\) +NotASubproject += +[0-9.]+ sec \(1 test\) ++ +Total Test time \(real\) = +[0-9.]+ sec diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCommandLine-result.txt b/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCommandLine-result.txt new file mode 100644 index 0000000..45a4fb7 --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCommandLine-result.txt @@ -0,0 +1 @@ +8 diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCommandLine-stderr.txt b/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCommandLine-stderr.txt new file mode 100644 index 0000000..ba4235d --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCommandLine-stderr.txt @@ -0,0 +1 @@ +Errors while running CTest diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCommandLine-stdout.txt b/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCommandLine-stdout.txt new file mode 100644 index 0000000..b5d76a9 --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCommandLine-stdout.txt @@ -0,0 +1,6 @@ +50% tests passed, 1 tests failed out of 2 ++ +Subproject Time Summary: +MySubproject += +[0-9.]+ sec \(2 tests\) ++ +Total Test time \(real\) = +[0-9.]+ sec diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/MyExperimentalFeature/CMakeLists.txt b/Tests/RunCMake/ctest_labels_for_subprojects/MyExperimentalFeature/CMakeLists.txt new file mode 100644 index 0000000..cc07a07 --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/MyExperimentalFeature/CMakeLists.txt @@ -0,0 +1,33 @@ +project(MyExperimentalFeature) +cmake_minimum_required(VERSION 3.8) + +include(CTest) + +set(CMAKE_DIRECTORY_LABELS "MyExperimentalFeature;NotASubproject") + +add_executable(testapp experimental.c) + +add_test(experimentalFail1 testapp 5) +set_tests_properties (experimentalFail1 + PROPERTIES PASS_REGULAR_EXPRESSION "Test!" + ) + +add_test(experimentalFail2 testapp -5) +set_tests_properties (experimentalFail2 + PROPERTIES PASS_REGULAR_EXPRESSION "Test!" + ) + +add_test(experimentalFail3 testapp -5) +set_tests_properties (experimentalFail3 + PROPERTIES PASS_REGULAR_EXPRESSION "Test!" + ) + +add_test(experimentalFail4 testapp -5) +set_tests_properties (experimentalFail4 + PROPERTIES PASS_REGULAR_EXPRESSION "Test!" + ) + +add_test(experimentalFail5 testapp -5) +set_tests_properties (experimentalFail5 + PROPERTIES PASS_REGULAR_EXPRESSION "Test!" + ) diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/MyExperimentalFeature/experimental.c b/Tests/RunCMake/ctest_labels_for_subprojects/MyExperimentalFeature/experimental.c new file mode 100644 index 0000000..7cb11ae --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/MyExperimentalFeature/experimental.c @@ -0,0 +1,16 @@ +#include <stdio.h> + +int main(void) +{ + int i = 0; + if (i > 0) { + printf("This doesn't happen.\n"); + printf("Neither does this.\n"); + } + i = i + 1; + if (i > 0) { + printf("This does happen.\n"); + } + + return 0; +} diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/MyProductionCode/CMakeLists.txt b/Tests/RunCMake/ctest_labels_for_subprojects/MyProductionCode/CMakeLists.txt new file mode 100644 index 0000000..c2ee673 --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/MyProductionCode/CMakeLists.txt @@ -0,0 +1,12 @@ +project(MyProductionCode) +cmake_minimum_required(VERSION 3.8) + +include(CTest) + +add_executable(production production.c) +add_test(NAME production COMMAND production) + +set_property(TARGET production PROPERTY LABELS MyProductionCode) +set_property(TEST production PROPERTY LABELS MyProductionCode) + +set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY LABELS "NotASubproject") diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/MyProductionCode/production.c b/Tests/RunCMake/ctest_labels_for_subprojects/MyProductionCode/production.c new file mode 100644 index 0000000..54dc2be --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/MyProductionCode/production.c @@ -0,0 +1,16 @@ +#include <stdio.h> + +int main(void) +{ + int j = 0; + if (j > 0) { + printf("This doesn't happen.\n"); + printf("Neither does this.\n"); + } + j = j + 1; + if (j > 0) { + printf("This does happen.\n"); + } + + return 0; +} diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/MyThirdPartyDependency/CMakeLists.txt b/Tests/RunCMake/ctest_labels_for_subprojects/MyThirdPartyDependency/CMakeLists.txt new file mode 100644 index 0000000..d5b9c2f --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/MyThirdPartyDependency/CMakeLists.txt @@ -0,0 +1,7 @@ +project(MyThirdPartyDependency) +cmake_minimum_required(VERSION 3.8) + +include(CTest) + +set_directory_properties(PROPERTIES LABELS "NotASubproject;MyThirdPartyDependency") +add_subdirectory(src) diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/MyThirdPartyDependency/src/CMakeLists.txt b/Tests/RunCMake/ctest_labels_for_subprojects/MyThirdPartyDependency/src/CMakeLists.txt new file mode 100644 index 0000000..dc6cb2a --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/MyThirdPartyDependency/src/CMakeLists.txt @@ -0,0 +1,10 @@ +project(MyThirdPartyDependency) +cmake_minimum_required(VERSION 3.8) + +include(CTest) + +add_executable(thirdparty thirdparty.c) +add_test(NAME thirdparty COMMAND thirdparty) + +set_property(TARGET thirdparty PROPERTY LABELS NotASubproject) +set_property(TEST thirdparty PROPERTY LABELS NotASubproject) diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/MyThirdPartyDependency/src/thirdparty.c b/Tests/RunCMake/ctest_labels_for_subprojects/MyThirdPartyDependency/src/thirdparty.c new file mode 100644 index 0000000..babe82d --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/MyThirdPartyDependency/src/thirdparty.c @@ -0,0 +1,14 @@ +#include <stdio.h> + +int main(void) +{ + printf(This function has an error!\n"); + n = 5; + return 0; +} + +int notcalled() +{ + printf(This function doesn't get called.\n"); + return 0; +} diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/RunCMakeTest.cmake b/Tests/RunCMake/ctest_labels_for_subprojects/RunCMakeTest.cmake new file mode 100644 index 0000000..dbe7bf8 --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/RunCMakeTest.cmake @@ -0,0 +1,185 @@ +include(RunCTest) + + +# 1. Specify subprojects in the CTest script +function(run_CTestScriptVariable) + set(CTEST_EXTRA_CONFIG "set(CTEST_USE_LAUNCHERS 1)") + set(CASE_TEST_PREFIX_CODE [[ +file(COPY "${CTEST_RUNCMAKE_SOURCE_DIRECTORY}/MyProductionCode" + DESTINATION ${CTEST_SOURCE_DIRECTORY}) +file(COPY "${CTEST_RUNCMAKE_SOURCE_DIRECTORY}/MyExperimentalFeature" + DESTINATION ${CTEST_SOURCE_DIRECTORY}) + +set(CTEST_LABELS_FOR_SUBPROJECTS "MyProductionCode;MyExperimentalFeature") + ]]) + set(CASE_CMAKELISTS_SUFFIX_CODE [[ +add_subdirectory(MyExperimentalFeature) +add_subdirectory(MyProductionCode) + ]]) + + run_ctest(CTestScriptVariable) + + unset(CTEST_EXTRA_CONFIG) + unset(CASE_TEST_PREFIX_CODE) + unset(CASE_CMAKELISTS_SUFFIX_CODE) +endfunction() +run_CTestScriptVariable() + +# 2. Specify subprojects via a CTest script variable on the command line e.g. +# ctest -S test.cmake -DCTEST_LABELS_FOR_SUBPROJECTS:STRING="MySubproject" +# Note: This test includes a failing build +function(run_CTestScriptVariableCommandLine) + set(CTEST_EXTRA_CONFIG "set(CTEST_USE_LAUNCHERS 1)") + set(CASE_TEST_PREFIX_CODE [[ +file(COPY "${CTEST_RUNCMAKE_SOURCE_DIRECTORY}/MyThirdPartyDependency" + DESTINATION ${CTEST_SOURCE_DIRECTORY}) + ]]) + set(CASE_CMAKELISTS_SUFFIX_CODE [[ +add_subdirectory(MyThirdPartyDependency) + ]]) + + run_ctest(CTestScriptVariableCommandLine "-DCTEST_LABELS_FOR_SUBPROJECTS:STRING=MyThirdPartyDependency") + + unset(CTEST_EXTRA_CONFIG) + unset(CASE_TEST_PREFIX_CODE) + unset(CASE_CMAKELISTS_SUFFIX_CODE) +endfunction() +run_CTestScriptVariableCommandLine() + +# 3. Set subprojects via a CTest module variable on the command line +# (will populate DartConfiguration.tcl) +function(run_ModuleVariableCommandLine) + set(RunCMake_TEST_SOURCE_DIR "${RunCMake_BINARY_DIR}/ModuleVariableCommandLine") + set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/ModuleVariableCommandLine-build") + set(RunCMake_TEST_NO_CLEAN 1) + file(REMOVE_RECURSE "${RunCMake_TEST_SOURCE_DIR}") + file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") + file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") + + set(CASE_CMAKELISTS_SUFFIX_CODE [[ +set(someFile "${CMAKE_CURRENT_SOURCE_DIR}/test.cmake") +add_test(NAME SuccessfulTest COMMAND "${CMAKE_COMMAND}" --version) +set_property(TEST SuccessfulTest PROPERTY LABELS MySubproject) +add_test(NAME FailingTest + COMMAND ${CMAKE_COMMAND} -E compare_files "${someFile}" "${someFile}xxx") +set_property(TEST FailingTest PROPERTY LABELS MySubproject) + ]]) + configure_file(${RunCMake_SOURCE_DIR}/CMakeLists.txt.in + ${RunCMake_TEST_SOURCE_DIR}/CMakeLists.txt @ONLY) + + set(RunCMake_TEST_OPTIONS "-DCTEST_LABELS_FOR_SUBPROJECTS:STRING=MySubproject") + run_cmake(ModuleVariableCommandLine-cmake) + unset(RunCMake_TEST_OPTIONS) + run_cmake_command(ModuleVariableCommandLine ${CMAKE_CTEST_COMMAND} -C Debug -V) + + unset(RunCMake_TEST_SOURCE_DIR) + unset(RunCMake_TEST_BINARY_DIR) + unset(RunCMake_TEST_NO_CLEAN) + unset(CASE_CMAKELISTS_SUFFIX_CODE) +endfunction() +run_ModuleVariableCommandLine() + +# 4. Set subprojects via a CTest module variable in CMakeLists.txt +# (will populate DartConfiguration.tcl) +function(run_ModuleVariableCMakeLists) + set(RunCMake_TEST_SOURCE_DIR "${RunCMake_BINARY_DIR}/ModuleVariableCMakeLists") + set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/ModuleVariableCMakeLists-build") + set(RunCMake_TEST_NO_CLEAN 1) + file(REMOVE_RECURSE "${RunCMake_TEST_SOURCE_DIR}") + file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") + file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") + + set(CASE_CMAKELISTS_PREFIX_CODE [[ +set(CTEST_LABELS_FOR_SUBPROJECTS MySubproject) +]]) + + set(CASE_CMAKELISTS_SUFFIX_CODE [[ +set(someFile "${CMAKE_CURRENT_SOURCE_DIR}/test.cmake") +add_test(NAME SuccessfulTest COMMAND "${CMAKE_COMMAND}" --version) +set_property(TEST SuccessfulTest PROPERTY LABELS MySubproject) +add_test(NAME FailingTest + COMMAND ${CMAKE_COMMAND} -E compare_files "${someFile}" "${someFile}xxx") +set_property(TEST FailingTest PROPERTY LABELS MySubproject) + ]]) + configure_file(${RunCMake_SOURCE_DIR}/CMakeLists.txt.in + ${RunCMake_TEST_SOURCE_DIR}/CMakeLists.txt @ONLY) + + run_cmake(ModuleVariableCMakeLists-cmake) + run_cmake_command(ModuleVariableCMakeLists ${CMAKE_CTEST_COMMAND} -C Debug -V) + + unset(RunCMake_TEST_SOURCE_DIR) + unset(RunCMake_TEST_BINARY_DIR) + unset(RunCMake_TEST_NO_CLEAN) + unset(CASE_CMAKELISTS_SUFFIX_CODE) + unset(CASE_CMAKELISTS_SUFFIX_CODE) +endfunction() +run_ModuleVariableCMakeLists() + +# The remaining tests set subprojects in CTestConfig.cmake. Settings in this +# config file are shared by both the CTest module and the ctest command line +# `Dashboard Client` mode (e.g. ctest -S). + +function(run_ModuleVariableCTestConfig CASE_NAME) + set(RunCMake_TEST_SOURCE_DIR "${RunCMake_BINARY_DIR}/${CASE_NAME}") + set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/${CASE_NAME}-build") + set(RunCMake_TEST_NO_CLEAN 1) + file(REMOVE_RECURSE "${RunCMake_TEST_SOURCE_DIR}") + file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") + file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") + + set(CTEST_EXTRA_CONFIG "set(CTEST_LABELS_FOR_SUBPROJECTS \"MySubproject\")") + configure_file(${RunCMake_SOURCE_DIR}/CTestConfig.cmake.in + ${RunCMake_TEST_SOURCE_DIR}/CTestConfig.cmake @ONLY) + + set(CASE_CMAKELISTS_SUFFIX_CODE [[ +set(someFile "${CMAKE_CURRENT_SOURCE_DIR}/test.cmake") +add_test(NAME SuccessfulTest COMMAND "${CMAKE_COMMAND}" --version) +set_property(TEST SuccessfulTest PROPERTY LABELS MySubproject) +add_test(NAME FailingTest + COMMAND ${CMAKE_COMMAND} -E compare_files "${someFile}" "${someFile}xxx") +set_property(TEST FailingTest PROPERTY LABELS MySubproject) +add_test(NAME AnotherSuccessfulTest COMMAND "${CMAKE_COMMAND}" --version) +set_property(TEST AnotherSuccessfulTest PROPERTY LABELS NotASubproject) + ]]) + configure_file(${RunCMake_SOURCE_DIR}/CMakeLists.txt.in + ${RunCMake_TEST_SOURCE_DIR}/CMakeLists.txt @ONLY) + + run_cmake(${CASE_NAME}-cmake) + run_cmake_command(${CASE_NAME} ${CMAKE_CTEST_COMMAND} -C Debug -V ${ARGN}) + + unset(RunCMake_TEST_SOURCE_DIR) + unset(RunCMake_TEST_BINARY_DIR) + unset(RunCMake_TEST_NO_CLEAN) + unset(CTEST_EXTRA_CONFIG) + unset(CASE_CMAKELISTS_SUFFIX_CODE) +endfunction() + +# 5. Check that the Subproject timing Summary is printed +run_ModuleVariableCTestConfig(ModuleVariableCTestConfig) + +# 6. Use --no-subproject-summary to disable the Subproject timing summary. +run_ModuleVariableCTestConfig(ModuleVariableCTestConfigNoSummary --no-subproject-summary) + +# 7. Verify that subprojects are sent to CDash when running a CTest script +function(run_CTestConfigCTestScript) + set(CTEST_EXTRA_CONFIG [[ +set(CTEST_USE_LAUNCHERS 1) +set(CTEST_LABELS_FOR_SUBPROJECTS "MyProductionCode;MyExperimentalFeature") + ]]) + set(CASE_TEST_PREFIX_CODE [[ +file(COPY "${CTEST_RUNCMAKE_SOURCE_DIRECTORY}/MyProductionCode" + DESTINATION ${CTEST_SOURCE_DIRECTORY}) +file(COPY "${CTEST_RUNCMAKE_SOURCE_DIRECTORY}/MyExperimentalFeature" + DESTINATION ${CTEST_SOURCE_DIRECTORY}) + ]]) + set(CASE_CMAKELISTS_SUFFIX_CODE [[ +add_subdirectory(MyExperimentalFeature) +add_subdirectory(MyProductionCode) + ]]) + run_ctest(CTestConfigCTestScript) + + unset(CTEST_EXTRA_CONFIG) + unset(CASE_TEST_PREFIX_CODE) + unset(CASE_CMAKELISTS_SUFFIX_CODE) +endfunction() +run_CTestConfigCTestScript() diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/test.cmake.in b/Tests/RunCMake/ctest_labels_for_subprojects/test.cmake.in new file mode 100644 index 0000000..8cec08d --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/test.cmake.in @@ -0,0 +1,21 @@ +cmake_minimum_required(VERSION 3.7) + +# Settings: + +set(CTEST_SITE "test-site") +set(CTEST_BUILD_NAME "test-build-name") +set(CTEST_SOURCE_DIRECTORY "@RunCMake_BINARY_DIR@/@CASE_NAME@") +set(CTEST_BINARY_DIRECTORY "@RunCMake_BINARY_DIR@/@CASE_NAME@-build") +set(CTEST_CMAKE_GENERATOR "@RunCMake_GENERATOR@") +set(CTEST_CMAKE_GENERATOR_PLATFORM "@RunCMake_GENERATOR_PLATFORM@") +set(CTEST_CMAKE_GENERATOR_TOOLSET "@RunCMake_GENERATOR_TOOLSET@") +set(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}") +set(CTEST_RUNCMAKE_SOURCE_DIRECTORY "@RunCMake_SOURCE_DIR@") + +@CASE_TEST_PREFIX_CODE@ + +set(ctest_test_args "@CASE_CTEST_TEST_ARGS@") +ctest_start(Experimental) +ctest_configure() +ctest_build() +ctest_test(${ctest_test_args}) diff --git a/Tests/RunCMake/execute_process/ExitValues-stdout.txt b/Tests/RunCMake/execute_process/ExitValues-stdout.txt new file mode 100644 index 0000000..3bcaf46 --- /dev/null +++ b/Tests/RunCMake/execute_process/ExitValues-stdout.txt @@ -0,0 +1,14 @@ +^-- 1 - 1 RESULT_VARIABLE: 0 +-- 1 - 2 RESULT_VARIABLE: [^0].* +-- 2 - 1 RESULT_VARIABLE: 0 +-- 2 - 1 RESULTS_VARIABLE: 0 +-- 2 - 2 RESULT_VARIABLE: [^0].* +-- 2 - 2 RESULTS_VARIABLE: [^0].* +-- 3 - 1 RESULTS_VARIABLE: 0 +-- 3 - 2 RESULTS_VARIABLE: [^0].* +-- 4 - 1 RESULT_VARIABLE: 0 +-- 4 - 1 RESULTS_VARIABLE: [^0].*;0;[^0].*;0;[^0].*;0 +-- 4 - 1 RESULTS_VARIABLE_LENGTH: 6 +-- 5 - 1 RESULT_VARIABLE: [^0].* +-- 5 - 1 RESULTS_VARIABLE: 0;0;[^0].* +-- 5 - 1 RESULTS_VARIABLE_LENGTH: 3$ diff --git a/Tests/RunCMake/execute_process/ExitValues.cmake b/Tests/RunCMake/execute_process/ExitValues.cmake new file mode 100644 index 0000000..d80a57b --- /dev/null +++ b/Tests/RunCMake/execute_process/ExitValues.cmake @@ -0,0 +1,120 @@ +#1st TEST RESULT_VARIABLE ONLY +execute_process(COMMAND ${EXIT_CODE_EXE} "zero_exit" + RESULT_VARIABLE r0 + ) +message(STATUS " 1 - 1 RESULT_VARIABLE: ${r0}") +if(NOT r0 EQUAL 0) + message(FATAL_ERROR "zero exit code expected") +endif() +execute_process(COMMAND ${EXIT_CODE_EXE} "non_zero_exit" + RESULT_VARIABLE r01 + ERROR_QUIET + ) +message(STATUS " 1 - 2 RESULT_VARIABLE: ${r01}") +if(r01 EQUAL 0) + message(FATAL_ERROR "non-zero exit code expected") +endif() +#2nd TEST RESULT_VARIABLE and RESULTS_VARIABLE +execute_process(COMMAND ${EXIT_CODE_EXE} "zero_exit" + RESULT_VARIABLE r1 + RESULTS_VARIABLE r1s + ) +message(STATUS " 2 - 1 RESULT_VARIABLE: ${r1}") +message(STATUS " 2 - 1 RESULTS_VARIABLE: ${r1s}") +if(NOT r1 EQUAL 0 OR NOT r1s EQUAL 0) + message(FATAL_ERROR "zero exit code expected") +endif() +execute_process(COMMAND ${EXIT_CODE_EXE} "non_zero_exit" + RESULT_VARIABLE r11 + RESULTS_VARIABLE r11s + ERROR_QUIET + ) +message(STATUS " 2 - 2 RESULT_VARIABLE: ${r11}") +message(STATUS " 2 - 2 RESULTS_VARIABLE: ${r11s}") +if(r11 EQUAL 0 OR r11s EQUAL 0) + message(FATAL_ERROR "non-zero exit code expected") +endif() +#3rd TEST RESULTS_VARIABLE +execute_process(COMMAND ${EXIT_CODE_EXE} "zero_exit" + RESULTS_VARIABLE r2s + ) +message(STATUS " 3 - 1 RESULTS_VARIABLE: ${r2s}") +if(NOT r2s EQUAL 0) + message(FATAL_ERROR "zero exit code expected") +endif() +execute_process(COMMAND ${EXIT_CODE_EXE} "non_zero_exit" + RESULTS_VARIABLE r21s + ERROR_QUIET + ) +message(STATUS " 3 - 2 RESULTS_VARIABLE: ${r21s}") +if(r21s EQUAL 0) + message(FATAL_ERROR "non-zero exit code expected") +endif() +#4th TEST RESULT_VARIABLE and RESULTS_VARIABLE WITH MULTICOMMAND +execute_process(COMMAND ${EXIT_CODE_EXE} "non_zero_exit" + COMMAND ${EXIT_CODE_EXE} "zero_exit" + COMMAND ${EXIT_CODE_EXE} "non_zero_exit" + COMMAND ${EXIT_CODE_EXE} "zero_exit" + COMMAND ${EXIT_CODE_EXE} "non_zero_exit" + COMMAND ${EXIT_CODE_EXE} "zero_exit" + RESULT_VARIABLE r31 + RESULTS_VARIABLE r31s + OUTPUT_QUIET + ERROR_QUIET + ) +message(STATUS " 4 - 1 RESULT_VARIABLE: ${r31}") +message(STATUS " 4 - 1 RESULTS_VARIABLE: ${r31s}") +if(NOT r31 EQUAL 0) + message(FATAL_ERROR "zero exit code expected for last command") +endif() +list(LENGTH r31s r31sLen) +message(STATUS " 4 - 1 RESULTS_VARIABLE_LENGTH: ${r31sLen}") +if(NOT r31sLen EQUAL 6) + message(FATAL_ERROR "length of RESULTS_VARIABLE is not as expected") +else() + foreach(loop_var RANGE 5) + list(GET r31s ${loop_var} rsLocal) + math(EXPR isOdd "${loop_var} % 2") + if(isOdd) + if(NOT rsLocal EQUAL 0) + message(FATAL_ERROR "zero exit code expected") + endif() + else() + if(rsLocal EQUAL 0) + message(FATAL_ERROR "non-zero exit code expected") + endif() + endif() + endforeach() +endif() +#5th TEST RESULT_VARIABLE and RESULTS_VARIABLE WITH MULTICOMMAND +execute_process(COMMAND ${EXIT_CODE_EXE} "zero_exit" + COMMAND ${EXIT_CODE_EXE} "zero_exit" + COMMAND ${EXIT_CODE_EXE} "non_zero_exit" + RESULT_VARIABLE r41 + RESULTS_VARIABLE r41s + OUTPUT_QUIET + ERROR_QUIET + ) +message(STATUS " 5 - 1 RESULT_VARIABLE: ${r41}") +message(STATUS " 5 - 1 RESULTS_VARIABLE: ${r41s}") +if(r41 EQUAL 0) + message(FATAL_ERROR "non-zero exit code expected for last command") +endif() +list(LENGTH r41s r41sLen) +message(STATUS " 5 - 1 RESULTS_VARIABLE_LENGTH: ${r41sLen}") +if(NOT r31sLen EQUAL 6) + message(FATAL_ERROR "length of RESULTS_VARIABLE is not as expected") +else() + list(GET r41s 0 rsLocal) + if(NOT rsLocal EQUAL 0) + message(FATAL_ERROR "zero exit code expected") + endif() + list(GET r41s 1 rsLocal) + if(NOT rsLocal EQUAL 0) + message(FATAL_ERROR "zero exit code expected") + endif() + list(GET r41s 2 rsLocal) + if(rsLocal EQUAL 0) + message(FATAL_ERROR "non-zero exit code expected") + endif() +endif() diff --git a/Tests/RunCMake/execute_process/RunCMakeTest.cmake b/Tests/RunCMake/execute_process/RunCMakeTest.cmake index 62e18c6..83589bb 100644 --- a/Tests/RunCMake/execute_process/RunCMakeTest.cmake +++ b/Tests/RunCMake/execute_process/RunCMakeTest.cmake @@ -11,3 +11,7 @@ run_cmake(EncodingMissing) if(TEST_ENCODING_EXE) run_cmake_command(EncodingUTF8 ${CMAKE_COMMAND} -DTEST_ENCODING=UTF8 -DTEST_ENCODING_EXE=${TEST_ENCODING_EXE} -P ${RunCMake_SOURCE_DIR}/Encoding.cmake) endif() + +if(EXIT_CODE_EXE) + run_cmake_command(ExitValues ${CMAKE_COMMAND} -DEXIT_CODE_EXE=${EXIT_CODE_EXE} -P ${RunCMake_SOURCE_DIR}/ExitValues.cmake) +endif() diff --git a/Tests/RunCMake/exit_code.c b/Tests/RunCMake/exit_code.c new file mode 100644 index 0000000..3eba019 --- /dev/null +++ b/Tests/RunCMake/exit_code.c @@ -0,0 +1,30 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +// Usage: +// +// /path/to/program arg1 [arg2 [...]] +// +// Return EXIT_SUCCESS if 'zero_exit' +// string was found in <arg1>. +// Return EXIT_FAILURE if 'non_zero_exit' +// string was found in <arg1>. + +int main(int argc, const char* argv[]) +{ + const char* substring_failure = "non_zero_exit"; + const char* substring_success = "zero_exit"; + const char* str = argv[1]; + if (argc < 2) { + return EXIT_FAILURE; + } + if (strcmp(str, substring_success) == 0) { + return EXIT_SUCCESS; + } else if (strcmp(str, substring_failure) == 0) { + return EXIT_FAILURE; + } + fprintf(stderr, "Failed to find string '%s' in '%s'\n", substring_success, + str); + return EXIT_FAILURE; +} diff --git a/Tests/RunCMake/include_guard/CMakeLists.txt b/Tests/RunCMake/include_guard/CMakeLists.txt new file mode 100644 index 0000000..d3137f6 --- /dev/null +++ b/Tests/RunCMake/include_guard/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.9) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/include_guard/DirectoryScope.cmake b/Tests/RunCMake/include_guard/DirectoryScope.cmake new file mode 100644 index 0000000..d6c5a3c --- /dev/null +++ b/Tests/RunCMake/include_guard/DirectoryScope.cmake @@ -0,0 +1,19 @@ +set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/Scripts") + +# Test include_guard with DIRECTORY scope + +# Add subdirectory which includes DirScript three times: +# 1. Include at inner function scope +# 2. At directory scope +# 3. At another subdirectory to check that the guard is checked +# against parent directories +add_subdirectory(sub_dir_script1) +# Add another directory which includes DirScript +add_subdirectory(sub_dir_script2) + +# check inclusions count +get_property(dir_count GLOBAL PROPERTY DIR_SCRIPT_COUNT) +if(NOT dir_count EQUAL 2) + message(FATAL_ERROR + "Wrong DIR_SCRIPT_COUNT value: ${dir_count}, expected: 2") +endif() diff --git a/Tests/RunCMake/include_guard/GlobalScope.cmake b/Tests/RunCMake/include_guard/GlobalScope.cmake new file mode 100644 index 0000000..02137fa --- /dev/null +++ b/Tests/RunCMake/include_guard/GlobalScope.cmake @@ -0,0 +1,11 @@ +set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/Scripts") + +# Test GLOBAL include guard +add_subdirectory(global_script_dir) +include(GlobScript) + +get_property(glob_count GLOBAL PROPERTY GLOB_SCRIPT_COUNT) +if(NOT glob_count EQUAL 1) + message(FATAL_ERROR + "Wrong GLOB_SCRIPT_COUNT value: ${glob_count}, expected: 1") +endif() diff --git a/Tests/RunCMake/include_guard/InvalidArgumentsNumber-result.txt b/Tests/RunCMake/include_guard/InvalidArgumentsNumber-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/include_guard/InvalidArgumentsNumber-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/include_guard/InvalidArgumentsNumber-stderr.txt b/Tests/RunCMake/include_guard/InvalidArgumentsNumber-stderr.txt new file mode 100644 index 0000000..cdd33ac --- /dev/null +++ b/Tests/RunCMake/include_guard/InvalidArgumentsNumber-stderr.txt @@ -0,0 +1,5 @@ +CMake Error at InvalidArgumentsNumber.cmake:1 \(include_guard\): + include_guard given an invalid number of arguments. The command takes at + most 1 argument. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/include_guard/InvalidArgumentsNumber.cmake b/Tests/RunCMake/include_guard/InvalidArgumentsNumber.cmake new file mode 100644 index 0000000..a63a395 --- /dev/null +++ b/Tests/RunCMake/include_guard/InvalidArgumentsNumber.cmake @@ -0,0 +1 @@ +include_guard(ARG1 ARG2) diff --git a/Tests/RunCMake/include_guard/InvalidScope-result.txt b/Tests/RunCMake/include_guard/InvalidScope-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/include_guard/InvalidScope-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/include_guard/InvalidScope-stderr.txt b/Tests/RunCMake/include_guard/InvalidScope-stderr.txt new file mode 100644 index 0000000..456709d --- /dev/null +++ b/Tests/RunCMake/include_guard/InvalidScope-stderr.txt @@ -0,0 +1,4 @@ +CMake Error at InvalidScope.cmake:1 \(include_guard\): + include_guard given an invalid scope: INVALID +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/include_guard/InvalidScope.cmake b/Tests/RunCMake/include_guard/InvalidScope.cmake new file mode 100644 index 0000000..f69f9fd --- /dev/null +++ b/Tests/RunCMake/include_guard/InvalidScope.cmake @@ -0,0 +1 @@ +include_guard(INVALID) diff --git a/Tests/RunCMake/include_guard/RunCMakeTest.cmake b/Tests/RunCMake/include_guard/RunCMakeTest.cmake new file mode 100644 index 0000000..e87bddd --- /dev/null +++ b/Tests/RunCMake/include_guard/RunCMakeTest.cmake @@ -0,0 +1,7 @@ +include(RunCMake) + +run_cmake(VariableScope) +run_cmake(DirectoryScope) +run_cmake(GlobalScope) +run_cmake(InvalidScope) +run_cmake(InvalidArgumentsNumber) diff --git a/Tests/RunCMake/include_guard/Scripts/DirScript.cmake b/Tests/RunCMake/include_guard/Scripts/DirScript.cmake new file mode 100644 index 0000000..e61d180 --- /dev/null +++ b/Tests/RunCMake/include_guard/Scripts/DirScript.cmake @@ -0,0 +1,12 @@ +include_guard(DIRECTORY) + +set(prop_name DIR_SCRIPT_COUNT) +get_property(count_is_set GLOBAL PROPERTY ${prop_name} SET) + +if(NOT count_is_set) + set_property(GLOBAL PROPERTY ${prop_name} 1) +else() + get_property(count GLOBAL PROPERTY ${prop_name}) + math(EXPR count "${count} + 1") + set_property(GLOBAL PROPERTY ${prop_name} ${count}) +endif() diff --git a/Tests/RunCMake/include_guard/Scripts/GlobScript.cmake b/Tests/RunCMake/include_guard/Scripts/GlobScript.cmake new file mode 100644 index 0000000..c26bf40 --- /dev/null +++ b/Tests/RunCMake/include_guard/Scripts/GlobScript.cmake @@ -0,0 +1,12 @@ +include_guard(GLOBAL) + +set(prop_name GLOB_SCRIPT_COUNT) +get_property(count_is_set GLOBAL PROPERTY ${prop_name} SET) + +if(NOT count_is_set) + set_property(GLOBAL PROPERTY ${prop_name} 1) +else() + get_property(count GLOBAL PROPERTY ${prop_name}) + math(EXPR count "${count} + 1") + set_property(GLOBAL PROPERTY ${prop_name} ${count}) +endif() diff --git a/Tests/RunCMake/include_guard/Scripts/VarScript.cmake b/Tests/RunCMake/include_guard/Scripts/VarScript.cmake new file mode 100644 index 0000000..3080377 --- /dev/null +++ b/Tests/RunCMake/include_guard/Scripts/VarScript.cmake @@ -0,0 +1,12 @@ +include_guard() + +set(prop_name VAR_SCRIPT_COUNT) +get_property(count_is_set GLOBAL PROPERTY ${prop_name} SET) + +if(NOT count_is_set) + set_property(GLOBAL PROPERTY ${prop_name} 1) +else() + get_property(count GLOBAL PROPERTY ${prop_name}) + math(EXPR count "${count} + 1") + set_property(GLOBAL PROPERTY ${prop_name} ${count}) +endif() diff --git a/Tests/RunCMake/include_guard/VariableScope.cmake b/Tests/RunCMake/include_guard/VariableScope.cmake new file mode 100644 index 0000000..7f8477d --- /dev/null +++ b/Tests/RunCMake/include_guard/VariableScope.cmake @@ -0,0 +1,24 @@ +set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/Scripts") + +# Test include_guard with VARIABLE scope +function(var_include_func) + # Include twice in the same scope + include(VarScript) + include(VarScript) + get_property(var_count GLOBAL PROPERTY VAR_SCRIPT_COUNT) + if(NOT var_count EQUAL 1) + message(FATAL_ERROR + "Wrong VAR_SCRIPT_COUNT value: ${var_count}, expected: 1") + endif() +endfunction() + +var_include_func() + +# Check again that include_guard has been reset +include(VarScript) + +get_property(var_count GLOBAL PROPERTY VAR_SCRIPT_COUNT) +if(NOT var_count EQUAL 2) + message(FATAL_ERROR + "Wrong VAR_SCRIPT_COUNT value: ${var_count}, expected: 2") +endif() diff --git a/Tests/RunCMake/include_guard/global_script_dir/CMakeLists.txt b/Tests/RunCMake/include_guard/global_script_dir/CMakeLists.txt new file mode 100644 index 0000000..ee7ea2e --- /dev/null +++ b/Tests/RunCMake/include_guard/global_script_dir/CMakeLists.txt @@ -0,0 +1 @@ +include(GlobScript) diff --git a/Tests/RunCMake/include_guard/sub_dir_script1/CMakeLists.txt b/Tests/RunCMake/include_guard/sub_dir_script1/CMakeLists.txt new file mode 100644 index 0000000..d3626e5 --- /dev/null +++ b/Tests/RunCMake/include_guard/sub_dir_script1/CMakeLists.txt @@ -0,0 +1,9 @@ +function(dir_check) + include(DirScript) +endfunction() + +dir_check() + +include(DirScript) + +add_subdirectory(sub_dir_script3) diff --git a/Tests/RunCMake/include_guard/sub_dir_script1/sub_dir_script3/CMakeLists.txt b/Tests/RunCMake/include_guard/sub_dir_script1/sub_dir_script3/CMakeLists.txt new file mode 100644 index 0000000..1c3b1b2 --- /dev/null +++ b/Tests/RunCMake/include_guard/sub_dir_script1/sub_dir_script3/CMakeLists.txt @@ -0,0 +1 @@ +include(DirScript) diff --git a/Tests/RunCMake/include_guard/sub_dir_script2/CMakeLists.txt b/Tests/RunCMake/include_guard/sub_dir_script2/CMakeLists.txt new file mode 100644 index 0000000..1c3b1b2 --- /dev/null +++ b/Tests/RunCMake/include_guard/sub_dir_script2/CMakeLists.txt @@ -0,0 +1 @@ +include(DirScript) diff --git a/Tests/RunCMake/string/Prepend.cmake b/Tests/RunCMake/string/Prepend.cmake new file mode 100644 index 0000000..8eaeebb --- /dev/null +++ b/Tests/RunCMake/string/Prepend.cmake @@ -0,0 +1,58 @@ +set(out) +string(PREPEND out) +if(DEFINED out) + message(FATAL_ERROR "\"string(PREPEND out)\" set out to \"${out}\"") +endif() + +set(out "") +string(PREPEND out) +if(NOT out STREQUAL "") + message(FATAL_ERROR "\"string(PREPEND out)\" set out to \"${out}\"") +endif() + +set(out x) +string(PREPEND out) +if(NOT out STREQUAL "x") + message(FATAL_ERROR "\"string(PREPEND out)\" set out to \"${out}\"") +endif() + + +set(out) +string(PREPEND out a) +if(NOT out STREQUAL "a") + message(FATAL_ERROR "\"string(PREPEND out a)\" set out to \"${out}\"") +endif() + +set(out "") +string(PREPEND out a) +if(NOT out STREQUAL "a") + message(FATAL_ERROR "\"string(PREPEND out a)\" set out to \"${out}\"") +endif() + +set(out x) +string(PREPEND out a) +if(NOT out STREQUAL "ax") + message(FATAL_ERROR "\"string(PREPEND out a)\" set out to \"${out}\"") +endif() + + +set(out x) +string(PREPEND out a "b") +if(NOT out STREQUAL "abx") + message(FATAL_ERROR "\"string(PREPEND out a \"b\")\" set out to \"${out}\"") +endif() + +set(b) +set(out x) +string(PREPEND out ${b}) +if(NOT out STREQUAL "x") + message(FATAL_ERROR "\"string(PREPEND out \${b})\" set out to \"${out}\"") +endif() + +set(b b) +set(out x) +string(PREPEND out a "${b}" [[ +${c}]]) +if(NOT out STREQUAL "ab\${c}x") + message(FATAL_ERROR "\"string(PREPEND out a \"\${b}\" [[\${c}]])\" set out to \"${out}\"") +endif() diff --git a/Tests/RunCMake/string/PrependNoArgs-result.txt b/Tests/RunCMake/string/PrependNoArgs-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/string/PrependNoArgs-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/string/PrependNoArgs-stderr.txt b/Tests/RunCMake/string/PrependNoArgs-stderr.txt new file mode 100644 index 0000000..8d433f9 --- /dev/null +++ b/Tests/RunCMake/string/PrependNoArgs-stderr.txt @@ -0,0 +1,4 @@ +CMake Error at PrependNoArgs.cmake:1 \(string\): + string sub-command PREPEND requires at least one argument. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/string/PrependNoArgs.cmake b/Tests/RunCMake/string/PrependNoArgs.cmake new file mode 100644 index 0000000..f324f28 --- /dev/null +++ b/Tests/RunCMake/string/PrependNoArgs.cmake @@ -0,0 +1 @@ +string(PREPEND) diff --git a/Tests/RunCMake/string/RegexMultiMatchClear-stderr.txt b/Tests/RunCMake/string/RegexMultiMatchClear-stderr.txt new file mode 100644 index 0000000..4360d79 --- /dev/null +++ b/Tests/RunCMake/string/RegexMultiMatchClear-stderr.txt @@ -0,0 +1,12 @@ +^matches: Some::;Scope +results from: string\(REGEX MATCHALL\) +CMAKE_MATCH_0: -->Scope<-- +CMAKE_MATCH_1: -->Scope<-- +CMAKE_MATCH_2: --><-- +CMAKE_MATCH_COUNT: -->1<-- +replace: \[Some\]\[Scope\] +results from: string\(REGEX REPLACE\) +CMAKE_MATCH_0: -->Scope<-- +CMAKE_MATCH_1: -->Scope<-- +CMAKE_MATCH_2: --><-- +CMAKE_MATCH_COUNT: -->1<--$ diff --git a/Tests/RunCMake/string/RegexMultiMatchClear.cmake b/Tests/RunCMake/string/RegexMultiMatchClear.cmake new file mode 100644 index 0000000..80b6b3c --- /dev/null +++ b/Tests/RunCMake/string/RegexMultiMatchClear.cmake @@ -0,0 +1,20 @@ +cmake_minimum_required (VERSION 3.0) +project (RegexClear NONE) + +function (output_results msg) + message("results from: ${msg}") + message("CMAKE_MATCH_0: -->${CMAKE_MATCH_0}<--") + message("CMAKE_MATCH_1: -->${CMAKE_MATCH_1}<--") + message("CMAKE_MATCH_2: -->${CMAKE_MATCH_2}<--") + message("CMAKE_MATCH_COUNT: -->${CMAKE_MATCH_COUNT}<--") +endfunction () + +set(haystack "Some::Scope") + +string(REGEX MATCHALL "^([^:]+)(::)?" matches "${haystack}") +message("matches: ${matches}") +output_results("string(REGEX MATCHALL)") + +string(REGEX REPLACE "^([^:]+)(::)?" "[\\1]" replace "${haystack}") +message("replace: ${replace}") +output_results("string(REGEX REPLACE)") diff --git a/Tests/RunCMake/string/RunCMakeTest.cmake b/Tests/RunCMake/string/RunCMakeTest.cmake index 38a77b0..513d1e3 100644 --- a/Tests/RunCMake/string/RunCMakeTest.cmake +++ b/Tests/RunCMake/string/RunCMakeTest.cmake @@ -3,6 +3,9 @@ include(RunCMake) run_cmake(Append) run_cmake(AppendNoArgs) +run_cmake(Prepend) +run_cmake(PrependNoArgs) + run_cmake(Concat) run_cmake(ConcatNoArgs) @@ -20,6 +23,7 @@ run_cmake(UuidMissingTypeValue) run_cmake(UuidBadType) run_cmake(RegexClear) +run_cmake(RegexMultiMatchClear) run_cmake(UTF-16BE) run_cmake(UTF-16LE) diff --git a/Tests/RunCMake/test_include_dirs/CMakeLists.txt b/Tests/RunCMake/test_include_dirs/CMakeLists.txt new file mode 100644 index 0000000..dc92486 --- /dev/null +++ b/Tests/RunCMake/test_include_dirs/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.6) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/test_include_dirs/RunCMakeTest.cmake b/Tests/RunCMake/test_include_dirs/RunCMakeTest.cmake new file mode 100644 index 0000000..d1633e4 --- /dev/null +++ b/Tests/RunCMake/test_include_dirs/RunCMakeTest.cmake @@ -0,0 +1,17 @@ +include(RunCMake) + +function(run_TID) + # Use a single build tree for a few tests without cleaning. + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/TID-build) + set(RunCMake_TEST_NO_CLEAN 1) + if(RunCMake_GENERATOR MATCHES "Make|Ninja") + set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug) + endif() + file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") + file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") + run_cmake(TID) + run_cmake_command(TID-build ${CMAKE_COMMAND} --build . --config Debug) + run_cmake_command(TID-test ${CMAKE_CTEST_COMMAND} -C Debug) +endfunction() + +run_TID() diff --git a/Tests/RunCMake/test_include_dirs/TID-test-stdout.txt b/Tests/RunCMake/test_include_dirs/TID-test-stdout.txt new file mode 100644 index 0000000..19bf051 --- /dev/null +++ b/Tests/RunCMake/test_include_dirs/TID-test-stdout.txt @@ -0,0 +1,17 @@ +Test project .* + Start 1: house\.dog +1/6 Test #1: house\.dog \.+ +Passed +[0-9.]+ sec + Start 2: house\.cat +2/6 Test #2: house\.cat \.+ +Passed +[0-9.]+ sec + Start 3: farm\.cow +3/6 Test #3: farm\.cow \.+ +Passed +[0-9.]+ sec + Start 4: farm\.pig +4/6 Test #4: farm\.pig \.+ +Passed +[0-9.]+ sec + Start 5: zoo\.fox +5/6 Test #5: zoo\.fox \.+ +Passed +[0-9.]+ sec + Start 6: zoo\.emu +6/6 Test #6: zoo\.emu \.+ +Passed +[0-9.]+ sec + +100% tests passed, 0 tests failed out of 6 + +Total Test time \(real\) = +[0-9.]+ sec diff --git a/Tests/RunCMake/test_include_dirs/TID.cmake b/Tests/RunCMake/test_include_dirs/TID.cmake new file mode 100644 index 0000000..1e74f90 --- /dev/null +++ b/Tests/RunCMake/test_include_dirs/TID.cmake @@ -0,0 +1,29 @@ +project(test_include_dirs) +include(CTest) + +enable_testing() + +add_executable(dummy dummy.cpp) + +function(generate_tests NAME) + set(ctest_file "${CMAKE_CURRENT_BINARY_DIR}/${NAME}_tests.cmake") + add_custom_command( + OUTPUT "${ctest_file}" + COMMAND "${CMAKE_COMMAND}" + -D "TEST_EXECUTABLE=$<TARGET_FILE:dummy>" + -D "TEST_SUITE=${NAME}" + -D "TEST_NAMES=${ARGN}" + -D "CTEST_FILE=${ctest_file}" + -P "${CMAKE_CURRENT_SOURCE_DIR}/add-tests.cmake" + VERBATIM + ) + add_custom_target(${NAME}_tests ALL DEPENDS "${ctest_file}") +endfunction() + +generate_tests(house dog cat) +generate_tests(farm cow pig) +generate_tests(zoo fox emu) + +set_property(DIRECTORY PROPERTY TEST_INCLUDE_FILE "house_tests.cmake") +set_property(DIRECTORY APPEND PROPERTY TEST_INCLUDE_FILES "farm_tests.cmake") +set_property(DIRECTORY APPEND PROPERTY TEST_INCLUDE_FILES "zoo_tests.cmake") diff --git a/Tests/RunCMake/test_include_dirs/add-tests.cmake b/Tests/RunCMake/test_include_dirs/add-tests.cmake new file mode 100644 index 0000000..e74665a --- /dev/null +++ b/Tests/RunCMake/test_include_dirs/add-tests.cmake @@ -0,0 +1,8 @@ +set(script) + +foreach(TEST_NAME ${TEST_NAMES}) + set(script "${script}add_test(\"${TEST_SUITE}.${TEST_NAME}\"") + set(script "${script} \"${TEST_EXECUTABLE}\")\n") +endforeach() + +file(WRITE "${CTEST_FILE}" "${script}") diff --git a/Tests/RunCMake/test_include_dirs/dummy.cpp b/Tests/RunCMake/test_include_dirs/dummy.cpp new file mode 100644 index 0000000..f8b643a --- /dev/null +++ b/Tests/RunCMake/test_include_dirs/dummy.cpp @@ -0,0 +1,4 @@ +int main() +{ + return 0; +} diff --git a/Tests/Server/CMakeLists.txt b/Tests/Server/CMakeLists.txt index e7eaa8d..2ad05c3 100644 --- a/Tests/Server/CMakeLists.txt +++ b/Tests/Server/CMakeLists.txt @@ -20,6 +20,7 @@ macro(do_test bsname file) endif() endmacro() +do_test("test_cache" "tc_cache.json") do_test("test_handshake" "tc_handshake.json") do_test("test_globalSettings" "tc_globalSettings.json") do_test("test_buildsystem1" "tc_buildsystem1.json") diff --git a/Tests/Server/cmakelib.py b/Tests/Server/cmakelib.py index 78450d5..2218e02 100644 --- a/Tests/Server/cmakelib.py +++ b/Tests/Server/cmakelib.py @@ -95,6 +95,21 @@ def initProc(cmakeCommand): return cmakeCommand +def exitProc(cmakeCommand): + # Tell the server to exit. + cmakeCommand.stdin.close() + cmakeCommand.stdout.close() + + # Wait for the server to exit. + # If this version of python supports it, terminate the server after a timeout. + try: + cmakeCommand.wait(timeout=5) + except TypeError: + cmakeCommand.wait() + except: + cmakeCommand.terminate() + raise + def waitForMessage(cmakeCommand, expected): data = ordered(expected) packet = ordered(waitForRawMessage(cmakeCommand)) @@ -197,3 +212,27 @@ def validateGlobalSettings(cmakeCommand, cmakeCommandPath, data): print("Validating", i) if (packet[i] != data[i]): sys.exit(1) + +def validateCache(cmakeCommand, data): + packet = waitForReply(cmakeCommand, 'cache', '', False) + + cache = packet['cache'] + + if (data['isEmpty']): + if (cache != []): + print('Expected empty cache, but got data.\n') + sys.exit(1) + return; + + if (cache == []): + print('Expected cache contents, but got none.\n') + sys.exit(1) + + hadHomeDir = False + for value in cache: + if (value['key'] == 'CMAKE_HOME_DIRECTORY'): + hadHomeDir = True + + if (not hadHomeDir): + print('No CMAKE_HOME_DIRECTORY found in cache.') + sys.exit(1) diff --git a/Tests/Server/server-test.py b/Tests/Server/server-test.py index 62d9008..f5a3f28 100644 --- a/Tests/Server/server-test.py +++ b/Tests/Server/server-test.py @@ -84,7 +84,7 @@ for obj in testData: if 'extraGenerator' in data: extraGenerator = data['extraGenerator'] if not os.path.isabs(buildDirectory): buildDirectory = buildDir + "/" + buildDirectory - if not os.path.isabs(sourceDirectory): + if sourceDirectory != '' and not os.path.isabs(sourceDirectory): sourceDirectory = sourceDir + "/" + sourceDirectory cmakelib.handshake(proc, major, minor, sourceDirectory, buildDirectory, generator, extraGenerator) @@ -95,26 +95,20 @@ for obj in testData: if not 'generator' in data: data['generator'] = cmakeGenerator if not 'extraGenerator' in data: data['extraGenerator'] = '' cmakelib.validateGlobalSettings(proc, cmakeCommand, data) + elif 'validateCache' in obj: + data = obj['validateCache'] + if not 'isEmpty' in data: data['isEmpty'] = false + cmakelib.validateCache(proc, data) elif 'message' in obj: print("MESSAGE:", obj["message"]) + elif 'reconnect' in obj: + cmakelib.exitProc(proc) + proc = cmakelib.initProc(cmakeCommand) else: print("Unknown command:", json.dumps(obj)) sys.exit(2) print("Completed") -# Tell the server to exit. -proc.stdin.close() -proc.stdout.close() - -# Wait for the server to exit. -# If this version of python supports it, terminate the server after a timeout. -try: - proc.wait(timeout=5) -except TypeError: - proc.wait() -except: - proc.terminate() - raise - -sys.exit(0) +cmakelib.exitProc(proc) +sys.exit(proc.returncode) diff --git a/Tests/Server/tc_cache.json b/Tests/Server/tc_cache.json new file mode 100644 index 0000000..74af6d9 --- /dev/null +++ b/Tests/Server/tc_cache.json @@ -0,0 +1,24 @@ +[ +{ "message": "Testing cache" }, + +{ "message": "Cache after first handshake is empty:" }, +{ "handshake": {"major": 1, "sourceDirectory": "buildsystem1", "buildDirectory": "buildsystem1"} }, +{ "send": { "type": "cache" } }, +{ "validateCache": { "isEmpty": true } }, + +{ "message": "Cache after configure is populated:" }, +{ "send": { "type": "configure" } }, +{ "reply": { "type": "configure", "skipProgress":true } }, +{ "send": { "type": "cache" } }, +{ "validateCache": { "isEmpty": false } }, + +{ "message": "Handshake for existing cache requires buildDirectory only:" }, +{ "reconnect": {} }, +{ "handshake": {"major": 1, "sourceDirectory": "", "buildDirectory": "buildsystem1"} }, + +{ "message": "Cache after reconnect is again populated:" }, +{ "send": { "type": "cache" } }, +{ "validateCache": { "isEmpty": false } }, + +{ "message": "Everything ok." } +] diff --git a/Tests/Server/tc_handshake.json b/Tests/Server/tc_handshake.json index 975bb3d..4bb7fa7 100644 --- a/Tests/Server/tc_handshake.json +++ b/Tests/Server/tc_handshake.json @@ -11,6 +11,10 @@ { "send": {"test": "sometext","cookie":"monster"} }, { "recv": {"cookie":"monster","errorMessage":"No type given in request.","inReplyTo":"","type":"error"} }, +{ "message": "Testing commands before handshake" }, +{ "send": {"type": "cache","cookie":"monster"} }, +{ "recv": {"cookie":"monster","errorMessage":"Waiting for type \"handshake\".","inReplyTo":"cache","type":"error"} }, + { "message": "Testing handshake" }, { "send": {"type": "sometype","cookie":"monster2"} }, { "recv": {"cookie":"monster2","errorMessage":"Waiting for type \"handshake\".","inReplyTo":"sometype","type":"error"} }, diff --git a/Tests/XCTest/CMakeLists.txt b/Tests/XCTest/CMakeLists.txt index d40c40e..d0b07ea 100644 --- a/Tests/XCTest/CMakeLists.txt +++ b/Tests/XCTest/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.1) -project(XCTest) +project(XCTest C) enable_testing() find_package(XCTest REQUIRED) diff --git a/Utilities/Doxygen/CMakeLists.txt b/Utilities/Doxygen/CMakeLists.txt index f1e8f95..6a90c84 100644 --- a/Utilities/Doxygen/CMakeLists.txt +++ b/Utilities/Doxygen/CMakeLists.txt @@ -3,7 +3,7 @@ if(NOT CMake_SOURCE_DIR) set(CMakeDeveloperReference_STANDALONE 1) - cmake_minimum_required(VERSION 2.8.12.2 FATAL_ERROR) + cmake_minimum_required(VERSION 3.1 FATAL_ERROR) get_filename_component(tmp "${CMAKE_CURRENT_SOURCE_DIR}" PATH) get_filename_component(CMake_SOURCE_DIR "${tmp}" PATH) include(${CMake_SOURCE_DIR}/Modules/CTestUseLaunchers.cmake) diff --git a/Utilities/IWYU/mapping.imp b/Utilities/IWYU/mapping.imp index fe0f7df..23ca091 100644 --- a/Utilities/IWYU/mapping.imp +++ b/Utilities/IWYU/mapping.imp @@ -21,6 +21,7 @@ { include: [ "<wctype.h>", public, "<cwctype>", public ] }, # HACK: check whether this can be removed with next iwyu release. + { include: [ "<bits/shared_ptr.h>", private, "<memory>", public ] }, { include: [ "<bits/std_function.h>", private, "<functional>", public ] }, { include: [ "<bits/time.h>", private, "<time.h>", public ] }, { include: [ "<bits/types/clock_t.h>", private, "<time.h>", public ] }, diff --git a/Utilities/Scripts/clang-format.bash b/Utilities/Scripts/clang-format.bash index edcda77..428a9e4 100755 --- a/Utilities/Scripts/clang-format.bash +++ b/Utilities/Scripts/clang-format.bash @@ -92,7 +92,7 @@ fi # Verify that we have a tool. if ! type -p "$clang_format" >/dev/null; then - echo "Unable to locate '$clang_format'" + echo "Unable to locate a 'clang-format' tool." exit 1 fi diff --git a/Utilities/Scripts/update-libarchive.bash b/Utilities/Scripts/update-libarchive.bash index 41c6a66..7534f94 100755 --- a/Utilities/Scripts/update-libarchive.bash +++ b/Utilities/Scripts/update-libarchive.bash @@ -8,7 +8,7 @@ readonly name="LibArchive" readonly ownership="LibArchive Upstream <libarchive-discuss@googlegroups.com>" readonly subtree="Utilities/cmlibarchive" readonly repo="https://github.com/libarchive/libarchive.git" -readonly tag="v3.3.1" +readonly tag="v3.3.2" readonly shortlog=false readonly paths=" CMakeLists.txt diff --git a/Utilities/Sphinx/CMakeLists.txt b/Utilities/Sphinx/CMakeLists.txt index a29380c..2de821c 100644 --- a/Utilities/Sphinx/CMakeLists.txt +++ b/Utilities/Sphinx/CMakeLists.txt @@ -3,7 +3,7 @@ if(NOT CMake_SOURCE_DIR) set(CMakeHelp_STANDALONE 1) - cmake_minimum_required(VERSION 2.8.12.2 FATAL_ERROR) + cmake_minimum_required(VERSION 3.1 FATAL_ERROR) get_filename_component(tmp "${CMAKE_CURRENT_SOURCE_DIR}" PATH) get_filename_component(CMake_SOURCE_DIR "${tmp}" PATH) include(${CMake_SOURCE_DIR}/Modules/CTestUseLaunchers.cmake) diff --git a/Utilities/cmlibarchive/CMakeLists.txt b/Utilities/cmlibarchive/CMakeLists.txt index bfe6b13..206f3c6 100644 --- a/Utilities/cmlibarchive/CMakeLists.txt +++ b/Utilities/cmlibarchive/CMakeLists.txt @@ -422,6 +422,7 @@ int main(void) { return FS_IOC_GETFLAGS; }" HAVE_WORKING_FS_IOC_GETFLAGS) LA_CHECK_INCLUDE_FILE("linux/magic.h" HAVE_LINUX_MAGIC_H) LA_CHECK_INCLUDE_FILE("locale.h" HAVE_LOCALE_H) +LA_CHECK_INCLUDE_FILE("membership.h" HAVE_MEMBERSHIP_H) LA_CHECK_INCLUDE_FILE("memory.h" HAVE_MEMORY_H) LA_CHECK_INCLUDE_FILE("paths.h" HAVE_PATHS_H) LA_CHECK_INCLUDE_FILE("poll.h" HAVE_POLL_H) @@ -439,11 +440,13 @@ LA_CHECK_INCLUDE_FILE("string.h" HAVE_STRING_H) LA_CHECK_INCLUDE_FILE("strings.h" HAVE_STRINGS_H) LA_CHECK_INCLUDE_FILE("sys/acl.h" HAVE_SYS_ACL_H) LA_CHECK_INCLUDE_FILE("sys/cdefs.h" HAVE_SYS_CDEFS_H) +LA_CHECK_INCLUDE_FILE("sys/extattr.h" HAVE_SYS_EXTATTR_H) LA_CHECK_INCLUDE_FILE("sys/ioctl.h" HAVE_SYS_IOCTL_H) LA_CHECK_INCLUDE_FILE("sys/mkdev.h" HAVE_SYS_MKDEV_H) LA_CHECK_INCLUDE_FILE("sys/mount.h" HAVE_SYS_MOUNT_H) LA_CHECK_INCLUDE_FILE("sys/param.h" HAVE_SYS_PARAM_H) LA_CHECK_INCLUDE_FILE("sys/poll.h" HAVE_SYS_POLL_H) +LA_CHECK_INCLUDE_FILE("sys/richacl.h" HAVE_SYS_RICHACL_H) LA_CHECK_INCLUDE_FILE("sys/select.h" HAVE_SYS_SELECT_H) LA_CHECK_INCLUDE_FILE("sys/stat.h" HAVE_SYS_STAT_H) LA_CHECK_INCLUDE_FILE("sys/statfs.h" HAVE_SYS_STATFS_H) @@ -453,6 +456,7 @@ LA_CHECK_INCLUDE_FILE("sys/utime.h" HAVE_SYS_UTIME_H) LA_CHECK_INCLUDE_FILE("sys/utsname.h" HAVE_SYS_UTSNAME_H) LA_CHECK_INCLUDE_FILE("sys/vfs.h" HAVE_SYS_VFS_H) LA_CHECK_INCLUDE_FILE("sys/wait.h" HAVE_SYS_WAIT_H) +LA_CHECK_INCLUDE_FILE("sys/xattr.h" HAVE_SYS_XATTR_H) LA_CHECK_INCLUDE_FILE("time.h" HAVE_TIME_H) LA_CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H) LA_CHECK_INCLUDE_FILE("utime.h" HAVE_UTIME_H) @@ -461,6 +465,9 @@ LA_CHECK_INCLUDE_FILE("wctype.h" HAVE_WCTYPE_H) LA_CHECK_INCLUDE_FILE("windows.h" HAVE_WINDOWS_H) IF(ENABLE_CNG) LA_CHECK_INCLUDE_FILE("Bcrypt.h" HAVE_BCRYPT_H) + IF(HAVE_BCRYPT_H) + LIST(APPEND ADDITIONAL_LIBS "Bcrypt") + ENDIF(HAVE_BCRYPT_H) ELSE(ENABLE_CNG) UNSET(HAVE_BCRYPT_H CACHE) ENDIF(ENABLE_CNG) @@ -924,7 +931,6 @@ CHECK_FUNCTION_EXISTS_GLIBC(chflags HAVE_CHFLAGS) CHECK_FUNCTION_EXISTS_GLIBC(chown HAVE_CHOWN) CHECK_FUNCTION_EXISTS_GLIBC(chroot HAVE_CHROOT) CHECK_FUNCTION_EXISTS_GLIBC(ctime_r HAVE_CTIME_R) -CHECK_FUNCTION_EXISTS_GLIBC(dirfd HAVE_DIRFD) CHECK_FUNCTION_EXISTS_GLIBC(fchdir HAVE_FCHDIR) CHECK_FUNCTION_EXISTS_GLIBC(fchflags HAVE_FCHFLAGS) CHECK_FUNCTION_EXISTS_GLIBC(fchmod HAVE_FCHMOD) @@ -1024,6 +1030,10 @@ CHECK_C_SOURCE_COMPILES( "#include <dirent.h>\nint main() {DIR *d = opendir(\".\"); struct dirent e,*r; return readdir_r(d,&e,&r);}" HAVE_READDIR_R) +# dirfd can be either a function or a macro. +CHECK_C_SOURCE_COMPILES( + "#include <dirent.h>\nint main() {DIR *d = opendir(\".\"); return dirfd(d);}" + HAVE_DIRFD) # Only detect readlinkat() if we also have AT_FDCWD in unistd.h. # NOTE: linux requires fcntl.h for AT_FDCWD. @@ -1256,60 +1266,105 @@ CHECK_FILE_OFFSET_BITS() # Check for Extended Attribute libraries, headers, and functions # IF(ENABLE_XATTR) - LA_CHECK_INCLUDE_FILE(attr/xattr.h HAVE_ATTR_XATTR_H) - LA_CHECK_INCLUDE_FILE(sys/xattr.h HAVE_SYS_XATTR_H) - LA_CHECK_INCLUDE_FILE(sys/extattr.h HAVE_SYS_EXTATTR_H) CHECK_LIBRARY_EXISTS(attr "setxattr" "" HAVE_LIBATTR) IF(HAVE_LIBATTR) SET(CMAKE_REQUIRED_LIBRARIES "attr") ENDIF(HAVE_LIBATTR) CHECK_SYMBOL_EXISTS(EXTATTR_NAMESPACE_USER "sys/types.h;sys/extattr.h" HAVE_DECL_EXTATTR_NAMESPACE_USER) - CHECK_FUNCTION_EXISTS_GLIBC(extattr_get_file HAVE_EXTATTR_GET_FILE) - CHECK_FUNCTION_EXISTS_GLIBC(extattr_list_file HAVE_EXTATTR_LIST_FILE) - CHECK_FUNCTION_EXISTS_GLIBC(extattr_set_fd HAVE_EXTATTR_SET_FD) - CHECK_FUNCTION_EXISTS_GLIBC(extattr_set_file HAVE_EXTATTR_SET_FILE) - CHECK_FUNCTION_EXISTS_GLIBC(fgetxattr HAVE_FGETXATTR) - CHECK_FUNCTION_EXISTS_GLIBC(flistxattr HAVE_FLISTXATTR) - CHECK_FUNCTION_EXISTS_GLIBC(fsetxattr HAVE_FSETXATTR) - CHECK_FUNCTION_EXISTS_GLIBC(getxattr HAVE_GETXATTR) - CHECK_FUNCTION_EXISTS_GLIBC(lgetxattr HAVE_LGETXATTR) - CHECK_FUNCTION_EXISTS_GLIBC(listxattr HAVE_LISTXATTR) - CHECK_FUNCTION_EXISTS_GLIBC(llistxattr HAVE_LLISTXATTR) - CHECK_FUNCTION_EXISTS_GLIBC(lsetxattr HAVE_LSETXATTR) - CHECK_FUNCTION_EXISTS_GLIBC(fgetea HAVE_FGETEA) - CHECK_FUNCTION_EXISTS_GLIBC(flistea HAVE_FLISTEA) - CHECK_FUNCTION_EXISTS_GLIBC(fsetea HAVE_FSETEA) - CHECK_FUNCTION_EXISTS_GLIBC(getea HAVE_GETEA) - CHECK_FUNCTION_EXISTS_GLIBC(lgetea HAVE_LGETEA) - CHECK_FUNCTION_EXISTS_GLIBC(listea HAVE_LISTEA) - CHECK_FUNCTION_EXISTS_GLIBC(llistea HAVE_LLISTEA) - CHECK_FUNCTION_EXISTS_GLIBC(lsetea HAVE_LSETEA) + CHECK_SYMBOL_EXISTS(XATTR_NOFOLLOW "sys/xattr.h" HAVE_DECL_XATTR_NOFOLLOW) + IF(HAVE_SYS_XATTR_H AND HAVE_DECL_XATTR_NOFOLLOW) + CHECK_FUNCTION_EXISTS(fgetxattr HAVE_FGETXATTR) + CHECK_FUNCTION_EXISTS(flistxattr HAVE_FLISTXATTR) + CHECK_FUNCTION_EXISTS(fsetxattr HAVE_FSETXATTR) + CHECK_FUNCTION_EXISTS(getxattr HAVE_GETXATTR) + CHECK_FUNCTION_EXISTS(listxattr HAVE_LISTXATTR) + CHECK_FUNCTION_EXISTS(setxattr HAVE_SETXATTR) + IF(HAVE_FGETXATTR AND + HAVE_FLISTXATTR AND + HAVE_FSETXATTR AND + HAVE_GETXATTR AND + HAVE_LISTXATTR AND + HAVE_SETXATTR) + SET(ARCHIVE_XATTR_DARWIN TRUE) + ENDIF() + ELSEIF(HAVE_SYS_EXTATTR_H AND HAVE_DECL_EXTATTR_NAMESPACE_USER) + # FreeBSD xattr support + CHECK_FUNCTION_EXISTS(extattr_get_fd HAVE_EXTATTR_GET_FD) + CHECK_FUNCTION_EXISTS(extattr_get_file HAVE_EXTATTR_GET_FILE) + CHECK_FUNCTION_EXISTS(extattr_get_link HAVE_EXTATTR_GET_LINK) + CHECK_FUNCTION_EXISTS(extattr_list_fd HAVE_EXTATTR_LIST_FD) + CHECK_FUNCTION_EXISTS(extattr_list_file HAVE_EXTATTR_LIST_FILE) + CHECK_FUNCTION_EXISTS(extattr_list_link HAVE_EXTATTR_LIST_LINK) + CHECK_FUNCTION_EXISTS(extattr_set_fd HAVE_EXTATTR_SET_FD) + CHECK_FUNCTION_EXISTS(extattr_set_link HAVE_EXTATTR_SET_LINK) + IF(HAVE_EXTATTR_GET_FD AND + HAVE_EXTATTR_GET_FILE AND + HAVE_EXTATTR_GET_LINK AND + HAVE_EXTATTR_LIST_FD AND + HAVE_EXTATTR_LIST_FILE AND + HAVE_EXTATTR_LIST_LINK AND + HAVE_EXTATTR_SET_FD AND + HAVE_EXTATTR_SET_LINK) + SET(ARCHIVE_XATTR_FREEBSD TRUE) + ENDIF() + ELSEIF(HAVE_SYS_XATTR_H OR HAVE_ATTR_XATTR_H) + # Linux xattr support + CHECK_FUNCTION_EXISTS_GLIBC(fgetxattr HAVE_FGETXATTR) + CHECK_FUNCTION_EXISTS_GLIBC(flistxattr HAVE_FLISTXATTR) + CHECK_FUNCTION_EXISTS_GLIBC(fsetxattr HAVE_FSETXATTR) + CHECK_FUNCTION_EXISTS_GLIBC(getxattr HAVE_GETXATTR) + CHECK_FUNCTION_EXISTS_GLIBC(lgetxattr HAVE_LGETXATTR) + CHECK_FUNCTION_EXISTS_GLIBC(listxattr HAVE_LISTXATTR) + CHECK_FUNCTION_EXISTS_GLIBC(llistxattr HAVE_LLISTXATTR) + CHECK_FUNCTION_EXISTS_GLIBC(lsetxattr HAVE_LSETXATTR) + IF(HAVE_FGETXATTR AND + HAVE_FLISTXATTR AND + HAVE_FSETXATTR AND + HAVE_GETXATTR AND + HAVE_LGETXATTR AND + HAVE_LISTXATTR AND + HAVE_LLISTXATTR AND + HAVE_LSETXATTR) + SET(ARCHIVE_XATTR_LINUX TRUE) + ENDIF() + ELSEIF(HAVE_SYS_EA_H) + # AIX xattr support + CHECK_FUNCTION_EXISTS(fgetea HAVE_FGETEA) + CHECK_FUNCTION_EXISTS(flistea HAVE_FLISTEA) + CHECK_FUNCTION_EXISTS(fsetea HAVE_FSETEA) + CHECK_FUNCTION_EXISTS(getea HAVE_GETEA) + CHECK_FUNCTION_EXISTS(lgetea HAVE_LGETEA) + CHECK_FUNCTION_EXISTS(listea HAVE_LISTEA) + CHECK_FUNCTION_EXISTS(llistea HAVE_LLISTEA) + CHECK_FUNCTION_EXISTS(lsetea HAVE_LSETEA) + IF(HAVE_FGETEA AND + HAVE_FLISTEA AND + HAVE_FSETEA AND + HAVE_GETEA AND + HAVE_LGETEA AND + HAVE_LISTEA AND + HAVE_LLISTEA AND + HAVE_LSETEA) + SET(ARCHIVE_XATTR_AIX TRUE) + ENDIF() + ENDIF() + + IF(ARCHIVE_XATTR_DARWIN) + MESSAGE(STATUS "Extended attributes support: Darwin") + ELSEIF(ARCHIVE_XATTR_FREEBSD) + MESSAGE(STATUS "Extended attributes support: FreeBSD") + ELSEIF(ARCHIVE_XATTR_LINUX) + MESSAGE(STATUS "Extended attributes support: Linux") + ELSEIF(ARCHIVE_XATTR_AIX) + MESSAGE(STATUS "Extended attributes support: AIX") + ELSE() + MESSAGE(STATUS "Extended attributes support: none") + ENDIF() ELSE(ENABLE_XATTR) - SET(HAVE_ATTR_LIB FALSE) - SET(HAVE_ATTR_XATTR_H FALSE) - SET(HAVE_DECL_EXTATTR_NAMESPACE_USER FALSE) - SET(HAVE_EXTATTR_GET_FILE FALSE) - SET(HAVE_EXTATTR_LIST_FILE FALSE) - SET(HAVE_EXTATTR_SET_FD FALSE) - SET(HAVE_EXTATTR_SET_FILE FALSE) - SET(HAVE_FGETEA FALSE) - SET(HAVE_FGETXATTR FALSE) - SET(HAVE_FLISTEA FALSE) - SET(HAVE_FLISTXATTR FALSE) - SET(HAVE_FSETEA FALSE) - SET(HAVE_FSETXATTR FALSE) - SET(HAVE_GETEA FALSE) - SET(HAVE_GETXATTR FALSE) - SET(HAVE_LGETEA FALSE) - SET(HAVE_LGETXATTR FALSE) - SET(HAVE_LISTEA FALSE) - SET(HAVE_LISTXATTR FALSE) - SET(HAVE_LLISTEA FALSE) - SET(HAVE_LLISTXATTR FALSE) - SET(HAVE_LSETEA FALSE) - SET(HAVE_LSETXATTR FALSE) - SET(HAVE_SYS_EXTATTR_H FALSE) - SET(HAVE_SYS_XATTR_H FALSE) + SET(ARCHIVE_XATTR_DARWIN FALSE) + SET(ARCHIVE_XATTR_FREEBSD FALSE) + SET(ARCHIVE_XATTR_LINUX FALSE) + SET(ARCHIVE_XATTR_AIX FALSE) ENDIF(ENABLE_XATTR) # @@ -1321,78 +1376,212 @@ ENDIF(ENABLE_XATTR) # which makes the following checks rather more complex than I would like. # IF(ENABLE_ACL) + # Solaris and derivates ACLs + CHECK_FUNCTION_EXISTS(acl HAVE_ACL) + CHECK_FUNCTION_EXISTS(facl HAVE_FACL) + + # Libacl CHECK_LIBRARY_EXISTS(acl "acl_get_file" "" HAVE_LIBACL) IF(HAVE_LIBACL) SET(CMAKE_REQUIRED_LIBRARIES "acl") FIND_LIBRARY(ACL_LIBRARY NAMES acl) LIST(APPEND ADDITIONAL_LIBS ${ACL_LIBRARY}) ENDIF(HAVE_LIBACL) - # - CHECK_FUNCTION_EXISTS_GLIBC(acl_create_entry HAVE_ACL_CREATE_ENTRY) - CHECK_FUNCTION_EXISTS_GLIBC(acl_init HAVE_ACL_INIT) - CHECK_FUNCTION_EXISTS_GLIBC(acl_set_fd HAVE_ACL_SET_FD) - CHECK_FUNCTION_EXISTS_GLIBC(acl_set_fd_np HAVE_ACL_SET_FD_NP) - CHECK_FUNCTION_EXISTS_GLIBC(acl_set_file HAVE_ACL_SET_FILE) - CHECK_TYPE_EXISTS(acl_permset_t "${INCLUDES}" HAVE_ACL_PERMSET_T) - - # The "acl_get_perm()" function was omitted from the POSIX draft. - # (It's a pretty obvious oversight; otherwise, there's no way to - # test for specific permissions in a permset.) Linux uses the obvious - # name, FreeBSD adds _np to mark it as "non-Posix extension." - # Test for both as a double-check that we really have POSIX-style ACL support. - CHECK_FUNCTION_EXISTS(acl_get_fd_np HAVE_ACL_GET_FD_NP) - CHECK_FUNCTION_EXISTS(acl_get_perm HAVE_ACL_GET_PERM) - CHECK_FUNCTION_EXISTS(acl_get_perm_np HAVE_ACL_GET_PERM_NP) - CHECK_FUNCTION_EXISTS(acl_get_link HAVE_ACL_GET_LINK) - CHECK_FUNCTION_EXISTS(acl_get_link_np HAVE_ACL_GET_LINK_NP) - CHECK_FUNCTION_EXISTS(acl_is_trivial_np HAVE_ACL_IS_TRIVIAL_NP) - CHECK_FUNCTION_EXISTS(acl_set_link_np HAVE_ACL_SET_LINK_NP) - CHECK_SYMBOL_EXISTS(ACL_TYPE_NFS4 "${INCLUDES}" HAVE_ACL_TYPE_NFS4) - - # MacOS has an acl.h that isn't POSIX. It can be detected by - # checking for ACL_USER - CHECK_SYMBOL_EXISTS(ACL_USER "${INCLUDES}" HAVE_ACL_USER) - CHECK_C_SOURCE_COMPILES("#include <sys/types.h> + + CHECK_TYPE_EXISTS(acl_t "sys/types.h;sys/acl.h" HAVE_ACL_T) + CHECK_TYPE_EXISTS(acl_entry_t "sys/types.h;sys/acl.h" HAVE_ACL_ENTRY_T) + CHECK_TYPE_EXISTS(acl_permset_t "sys/types.h;sys/acl.h" HAVE_ACL_PERMSET_T) + CHECK_TYPE_EXISTS(acl_tag_t "sys/types.h;sys/acl.h" HAVE_ACL_TAG_T) + + IF(HAVE_ACL AND HAVE_FACL) + CHECK_TYPE_EXISTS(aclent_t "sys/acl.h" HAVE_ACLENT_T) + IF(HAVE_ACLENT_T) + CHECK_SYMBOL_EXISTS(GETACL "sys/acl.h" HAVE_DECL_GETACL) + CHECK_SYMBOL_EXISTS(GETACLCNT "sys/acl.h" HAVE_DECL_GETACLCNT) + CHECK_SYMBOL_EXISTS(SETACL "sys/acl.h" HAVE_DECL_SETACL) + IF(HAVE_DECL_GETACL AND + HAVE_DECL_GETACLCNT AND + HAVE_DECL_SETACL) + SET(ARCHIVE_ACL_SUNOS TRUE) + ENDIF() + CHECK_TYPE_EXISTS(ace_t "sys/acl.h" HAVE_ACE_T) + IF(HAVE_ACE_T) + CHECK_SYMBOL_EXISTS(ACE_GETACL "sys/acl.h" HAVE_DECL_ACE_GETACL) + CHECK_SYMBOL_EXISTS(ACE_GETACLCNT "sys/acl.h" HAVE_DECL_ACE_GETACLCNT) + CHECK_SYMBOL_EXISTS(ACE_SETACL "sys/acl.h" HAVE_DECL_ACE_SETACL) + IF(HAVE_DECL_ACE_GETACL AND + HAVE_DECL_ACE_GETACLCNT AND + HAVE_DECL_ACE_SETACL) + SET(ARCHIVE_ACL_SUNOS_NFS4 TRUE) + ENDIF() + ENDIF(HAVE_ACE_T) + ENDIF(HAVE_ACLENT_T) + ENDIF(HAVE_ACL AND HAVE_FACL) + + IF(HAVE_ACL_T AND HAVE_ACL_ENTRY_T AND HAVE_ACL_PERMSET_T AND HAVE_ACL_TAG_T) + CHECK_FUNCTION_EXISTS_GLIBC(acl_add_perm HAVE_ACL_ADD_PERM) + CHECK_FUNCTION_EXISTS_GLIBC(acl_clear_perms HAVE_ACL_CLEAR_PERMS) + CHECK_FUNCTION_EXISTS_GLIBC(acl_create_entry HAVE_ACL_CREATE_ENTRY) + CHECK_FUNCTION_EXISTS_GLIBC(acl_delete_def_file HAVE_ACL_DELETE_DEF_FILE) + CHECK_FUNCTION_EXISTS_GLIBC(acl_free HAVE_ACL_FREE) + CHECK_FUNCTION_EXISTS_GLIBC(acl_get_entry HAVE_ACL_GET_ENTRY) + CHECK_FUNCTION_EXISTS_GLIBC(acl_get_fd HAVE_ACL_GET_FD) + CHECK_FUNCTION_EXISTS_GLIBC(acl_get_file HAVE_ACL_GET_FILE) + CHECK_FUNCTION_EXISTS_GLIBC(acl_get_permset HAVE_ACL_GET_PERMSET) + CHECK_FUNCTION_EXISTS_GLIBC(acl_get_qualifier HAVE_ACL_GET_QUALIFIER) + CHECK_FUNCTION_EXISTS_GLIBC(acl_get_tag_type HAVE_ACL_GET_TAG_TYPE) + CHECK_FUNCTION_EXISTS_GLIBC(acl_init HAVE_ACL_INIT) + CHECK_FUNCTION_EXISTS_GLIBC(acl_set_fd HAVE_ACL_SET_FD) + CHECK_FUNCTION_EXISTS_GLIBC(acl_set_file HAVE_ACL_SET_FILE) + CHECK_FUNCTION_EXISTS_GLIBC(acl_set_qualifier HAVE_ACL_SET_QUALIFIER) + CHECK_FUNCTION_EXISTS_GLIBC(acl_set_tag_type HAVE_ACL_SET_TAG_TYPE) + IF(HAVE_ACL_ADD_PERM AND + HAVE_ACL_CLEAR_PERMS AND + HAVE_ACL_CREATE_ENTRY AND + HAVE_ACL_DELETE_DEF_FILE AND + HAVE_ACL_FREE AND + HAVE_ACL_GET_ENTRY AND + HAVE_ACL_GET_FD AND + HAVE_ACL_GET_FILE AND + HAVE_ACL_GET_PERMSET AND + HAVE_ACL_GET_QUALIFIER AND + HAVE_ACL_GET_TAG_TYPE AND + HAVE_ACL_INIT AND + HAVE_ACL_SET_FD AND + HAVE_ACL_SET_FILE AND + HAVE_ACL_SET_QUALIFIER AND + HAVE_ACL_SET_TAG_TYPE) + SET(HAVE_POSIX_ACL_FUNCS 1) + ENDIF() + + CHECK_FUNCTION_EXISTS_GLIBC(acl_get_perm HAVE_ACL_GET_PERM) + + IF(HAVE_POSIX_ACL_FUNCS AND HAVE_ACL_LIBACL_H AND HAVE_LIBACL AND + HAVE_ACL_GET_PERM) + SET(ARCHIVE_ACL_LIBACL TRUE) + ELSE() + CHECK_FUNCTION_EXISTS(acl_add_flag_np HAVE_ACL_ADD_FLAG_NP) + CHECK_FUNCTION_EXISTS(acl_clear_flags_np HAVE_ACL_CLEAR_FLAGS_NP) + CHECK_FUNCTION_EXISTS(acl_get_brand_np HAVE_ACL_GET_BRAND_NP) + CHECK_FUNCTION_EXISTS(acl_get_entry_type_np HAVE_ACL_GET_ENTRY_TYPE_NP) + CHECK_FUNCTION_EXISTS(acl_get_flag_np HAVE_ACL_GET_FLAG_NP) + CHECK_FUNCTION_EXISTS(acl_get_flagset_np HAVE_ACL_GET_FLAGSET_NP) + CHECK_FUNCTION_EXISTS(acl_get_fd_np HAVE_ACL_GET_FD_NP) + CHECK_FUNCTION_EXISTS(acl_get_link_np HAVE_ACL_GET_LINK_NP) + CHECK_FUNCTION_EXISTS(acl_get_perm_np HAVE_ACL_GET_PERM_NP) + CHECK_FUNCTION_EXISTS(acl_is_trivial_np HAVE_ACL_IS_TRIVIAL_NP) + CHECK_FUNCTION_EXISTS(acl_set_entry_type_np HAVE_ACL_SET_ENTRY_TYPE_NP) + CHECK_FUNCTION_EXISTS(acl_set_fd_np HAVE_ACL_SET_FD_NP) + CHECK_FUNCTION_EXISTS(acl_set_link_np HAVE_ACL_SET_LINK_NP) + CHECK_FUNCTION_EXISTS(mbr_gid_to_uuid HAVE_MBR_GID_TO_UUID) + CHECK_FUNCTION_EXISTS(mbr_uid_to_uuid HAVE_MBR_UID_TO_UUID) + CHECK_FUNCTION_EXISTS(mbr_uuid_to_id HAVE_MBR_UUID_TO_ID) + + CHECK_C_SOURCE_COMPILES("#include <sys/types.h> #include <sys/acl.h> -int main(void) { return ACL_TYPE_EXTENDED; }" HAVE_ACL_TYPE_EXTENDED) +int main(void) { return ACL_TYPE_EXTENDED; }" HAVE_DECL_ACL_TYPE_EXTENDED) + CHECK_C_SOURCE_COMPILES("#include <sys/types.h> +#include <sys/acl.h> +int main(void) { return ACL_SYNCHRONIZE; }" HAVE_DECL_ACL_SYNCHRONIZE) + CHECK_SYMBOL_EXISTS(ACL_TYPE_NFS4 "sys/acl.h" HAVE_DECL_ACL_TYPE_NFS4) + CHECK_SYMBOL_EXISTS(ACL_USER "sys/acl.h" HAVE_DECL_ACL_USER) + + IF(HAVE_POSIX_ACL_FUNCS AND + HAVE_ACL_GET_FD_NP AND + HAVE_ACL_GET_PERM_NP AND + NOT HAVE_ACL_GET_PERM AND + HAVE_ACL_SET_FD_NP) + IF(HAVE_DECL_ACL_USER) + SET(ARCHIVE_ACL_FREEBSD TRUE) + IF(HAVE_DECL_ACL_TYPE_NFS4 AND + HAVE_ACL_ADD_FLAG_NP AND + HAVE_ACL_CLEAR_FLAGS_NP AND + HAVE_ACL_GET_BRAND_NP AND + HAVE_ACL_GET_ENTRY_TYPE_NP AND + HAVE_ACL_GET_FLAGSET_NP AND + HAVE_ACL_SET_ENTRY_TYPE_NP) + SET(ARCHIVE_ACL_FREEBSD_NFS4 TRUE) + ENDIF() + ELSEIF(HAVE_DECL_ACL_TYPE_EXTENDED AND + HAVE_MEMBERSHIP_H AND + HAVE_ACL_ADD_FLAG_NP AND + HAVE_ACL_CLEAR_FLAGS_NP AND + HAVE_ACL_GET_FLAGSET_NP AND + HAVE_ACL_GET_LINK_NP AND + HAVE_ACL_SET_LINK_NP AND + HAVE_MBR_UID_TO_UUID AND + HAVE_MBR_GID_TO_UUID AND + HAVE_MBR_UUID_TO_ID) + SET(ARCHIVE_ACL_DARWIN TRUE) + ENDIF() + ENDIF() + ENDIF() + ENDIF(HAVE_ACL_T AND HAVE_ACL_ENTRY_T AND HAVE_ACL_PERMSET_T AND + HAVE_ACL_TAG_T) + + # Richacl + CHECK_LIBRARY_EXISTS(richacl "richacl_get_file" "" HAVE_LIBRICHACL) + IF(HAVE_LIBRICHACL) + SET(CMAKE_REQUIRED_LIBRARIES "richacl") + FIND_LIBRARY(RICHACL_LIBRARY NAMES richacl) + LIST(APPEND ADDITIONAL_LIBS ${RICHACL_LIBRARY}) + ENDIF(HAVE_LIBRICHACL) + + CHECK_STRUCT_HAS_MEMBER("struct richace" e_type "sys/richacl.h" + HAVE_STRUCT_RICHACE) + CHECK_STRUCT_HAS_MEMBER("struct richacl" a_flags "sys/richacl.h" + HAVE_STRUCT_RICHACL) + + IF(HAVE_LIBRICHACL AND HAVE_STRUCT_RICHACL AND HAVE_STRUCT_RICHACE) + CHECK_FUNCTION_EXISTS_GLIBC(richacl_alloc HAVE_RICHACL_ALLOC) + CHECK_FUNCTION_EXISTS_GLIBC(richacl_equiv_mode HAVE_RICHACL_EQUIV_MODE) + CHECK_FUNCTION_EXISTS_GLIBC(richacl_free HAVE_RICHACL_FREE) + CHECK_FUNCTION_EXISTS_GLIBC(richacl_get_fd HAVE_RICHACL_GET_FD) + CHECK_FUNCTION_EXISTS_GLIBC(richacl_get_file HAVE_RICHACL_GET_FILE) + CHECK_FUNCTION_EXISTS_GLIBC(richacl_set_fd HAVE_RICHACL_SET_FD) + CHECK_FUNCTION_EXISTS_GLIBC(richacl_set_file HAVE_RICHACL_SET_FILE) + IF(HAVE_RICHACL_ALLOC AND + HAVE_RICHACL_EQUIV_MODE AND + HAVE_RICHACL_FREE AND + HAVE_RICHACL_GET_FD AND + HAVE_RICHACL_GET_FILE AND + HAVE_RICHACL_SET_FD AND + HAVE_RICHACL_SET_FILE) + SET(ARCHIVE_ACL_LIBRICHACL TRUE) + ENDIF() + ENDIF(HAVE_LIBRICHACL AND HAVE_STRUCT_RICHACL AND HAVE_STRUCT_RICHACE) + + IF(ARCHIVE_ACL_DARWIN) + MESSAGE(STATUS "ACL support: Darwin (limited NFSv4)") + ELSEIF(ARCHIVE_ACL_FREEBSD_NFS4) + MESSAGE(STATUS "ACL support: FreeBSD (POSIX.1e and NFSv4)") + ELSEIF(ARCHIVE_ACL_FREEBSD) + MESSAGE(STATUS "ACL support: FreeBSD (POSIX.1e)") + ELSEIF(ARCHIVE_ACL_LIBACL OR ARCHIVE_ACL_LIBRICHACL) + IF(ARCHIVE_ACL_LIBACL AND ARCHIVE_ACL_LIBRICHACL) + MESSAGE(STATUS "ACL support: libacl (POSIX.1e) + librichacl (NFSv4)") + ELSEIF(ARCHIVE_ACL_LIBRICHACL) + MESSAGE(STATUS "ACL support: librichacl (NFSv4)") + ELSE() + MESSAGE(STATUS "ACL support: libacl (POSIX.1e)") + ENDIF() + ELSEIF(ARCHIVE_ACL_SUNOS_NFS4) + MESSAGE(STATUS "ACL support: Solaris (POSIX.1e and NFSv4)") + ELSEIF(ARCHIVE_ACL_SUNOS) + MESSAGE(STATUS "ACL support: Solaris (POSIX.1e)") + ELSE() + MESSAGE(STATUS "ACL support: none") + ENDIF() - # Solaris and derivates ACLs - CHECK_LIBRARY_EXISTS(sec "acl_get" "" HAVE_LIBSEC) - IF(HAVE_LIBSEC) - SET(CMAKE_REQUIRED_LIBRARIES "sec") - FIND_LIBRARY(SEC_LIBRARY NAMES sec) - LIST(APPEND ADDITIONAL_LIBS ${SEC_LIBRARY}) - ENDIF(HAVE_LIBSEC) - # - CHECK_TYPE_EXISTS(aclent_t "${INCLUDES}" HAVE_ACLENT_T) - CHECK_TYPE_EXISTS(ace_t "${INCLUDES}" HAVE_ACE_T) - CHECK_FUNCTION_EXISTS(acl_get HAVE_FACL_GET) - CHECK_FUNCTION_EXISTS(facl_get HAVE_FACL_GET) - CHECK_FUNCTION_EXISTS(acl_set HAVE_FACL_SET) - CHECK_FUNCTION_EXISTS(facl_set HAVE_FACL_SET) ELSE(ENABLE_ACL) # If someone runs cmake, then disables ACL support, we need # to forcibly override the cached values for these. - SET(HAVE_ACL_CREATE_ENTRY FALSE) - SET(HAVE_ACL_GET_LINK FALSE) - SET(HAVE_ACL_GET_LINK_NP FALSE) - SET(HAVE_ACL_GET_PERM FALSE) - SET(HAVE_ACL_GET_PERM_NP FALSE) - SET(HAVE_ACL_INIT FALSE) - SET(HAVE_ACL_LIB FALSE) - SET(HAVE_ACL_PERMSET_T FALSE) - SET(HAVE_ACL_SET_FD FALSE) - SET(HAVE_ACL_SET_FD_NP FALSE) - SET(HAVE_ACL_SET_FILE FALSE) - SET(HAVE_ACL_TYPE_NFS4 FALSE) - SET(HAVE_ACL_USER FALSE) - SET(HAVE_ACL_TYPE_EXTENDED FALSE) - SET(HAVE_ACL_GET FALSE) - SET(HAVE_ACLENT_T FALSE) - SET(HAVE_ACE_T FALSE) - SET(HAVE_FACL_GET FALSE) - SET(HAVE_ACL_SET FALSE) - SET(HAVE_FACL_SET FALSE) + SET(ARCHIVE_ACL_DARWIN FALSE) + SET(ARCHIVE_ACL_FREEBSD FALSE) + SET(ARCHIVE_ACL_FREEBSD_NFS4 FALSE) + SET(ARCHIVE_ACL_LIBACL FALSE) + SET(ARCHIVE_ACL_SUNOS FALSE) + SET(ARCHIVE_ACL_SUNOS_NFS4 FALSE) ENDIF(ENABLE_ACL) # diff --git a/Utilities/cmlibarchive/build/cmake/config.h.in b/Utilities/cmlibarchive/build/cmake/config.h.in index 55e04b9..368a451 100644 --- a/Utilities/cmlibarchive/build/cmake/config.h.in +++ b/Utilities/cmlibarchive/build/cmake/config.h.in @@ -182,6 +182,27 @@ typedef uint64_t uintmax_t; /* Define ZLIB_WINAPI if zlib was built on Visual Studio. */ #cmakedefine ZLIB_WINAPI 1 +/* Darwin ACL support */ +#cmakedefine ARCHIVE_ACL_DARWIN 1 + +/* FreeBSD ACL support */ +#cmakedefine ARCHIVE_ACL_FREEBSD 1 + +/* FreeBSD NFSv4 ACL support */ +#cmakedefine ARCHIVE_ACL_FREEBSD_NFS4 1 + +/* Linux POSIX.1e ACL support via libacl */ +#cmakedefine ARCHIVE_ACL_LIBACL 1 + +/* Linux NFSv4 ACL support via librichacl */ +#cmakedefine ARCHIVE_ACL_LIBRICHACL 1 + +/* Solaris ACL support */ +#cmakedefine ARCHIVE_ACL_SUNOS 1 + +/* Solaris NFSv4 ACL support */ +#cmakedefine ARCHIVE_ACL_SUNOS_NFS4 1 + /* MD5 via ARCHIVE_CRYPTO_MD5_LIBC supported. */ #cmakedefine ARCHIVE_CRYPTO_MD5_LIBC 1 @@ -284,6 +305,18 @@ typedef uint64_t uintmax_t; /* SHA512 via ARCHIVE_CRYPTO_SHA512_WIN supported. */ #cmakedefine ARCHIVE_CRYPTO_SHA512_WIN 1 +/* AIX xattr support */ +#cmakedefine ARCHIVE_XATTR_AIX 1 + +/* Darwin xattr support */ +#cmakedefine ARCHIVE_XATTR_DARWIN 1 + +/* FreeBSD xattr support */ +#cmakedefine ARCHIVE_XATTR_FREEBSD 1 + +/* Linux xattr support */ +#cmakedefine ARCHIVE_XATTR_LINUX 1 + /* Version number of bsdcpio */ #cmakedefine BSDCPIO_VERSION_STRING "${BSDCPIO_VERSION_STRING}" @@ -329,15 +362,6 @@ typedef uint64_t uintmax_t; /* Define to 1 if you have the `acl_set_file' function. */ #cmakedefine HAVE_ACL_SET_FILE 1 -/* True for FreeBSD with NFSv4 ACL support */ -#cmakedefine HAVE_ACL_TYPE_NFS4 1 - -/* True for MacOS ACL support */ -#cmakedefine HAVE_ACL_TYPE_EXTENDED 1 - -/* True for systems with POSIX ACL support */ -#cmakedefine HAVE_ACL_USER 1 - /* Define to 1 if you have the `arc4random_buf' function. */ #cmakedefine HAVE_ARC4RANDOM_BUF 1 @@ -374,6 +398,34 @@ typedef uint64_t uintmax_t; /* Define to 1 if you have the `cygwin_conv_path' function. */ #cmakedefine HAVE_CYGWIN_CONV_PATH 1 +/* Define to 1 if you have the declaration of `ACE_GETACL', and to 0 if you + don't. */ +#cmakedefine HAVE_DECL_ACE_GETACL 1 + +/* Define to 1 if you have the declaration of `ACE_GETACLCNT', and to 0 if you + don't. */ +#cmakedefine HAVE_DECL_ACE_GETACLCNT 1 + +/* Define to 1 if you have the declaration of `ACE_SETACL', and to 0 if you + don't. */ +#cmakedefine HAVE_DECL_ACE_SETACL 1 + +/* Define to 1 if you have the declaration of `ACL_SYNCHRONIZE', and to 0 if + you don't. */ +#cmakedefine HAVE_DECL_ACL_SYNCHRONIZE 1 + +/* Define to 1 if you have the declaration of `ACL_TYPE_EXTENDED', and to 0 if + you don't. */ +#cmakedefine HAVE_DECL_ACL_TYPE_EXTENDED 1 + +/* Define to 1 if you have the declaration of `ACL_TYPE_NFS4', and to 0 if you + don't. */ +#cmakedefine HAVE_DECL_ACL_TYPE_NFS4 1 + +/* Define to 1 if you have the declaration of `ACL_USER', and to 0 if you + don't. */ +#cmakedefine HAVE_DECL_ACL_USER 1 + /* Define to 1 if you have the declaration of `INT32_MAX', and to 0 if you don't. */ #cmakedefine HAVE_DECL_INT32_MAX 1 @@ -398,6 +450,10 @@ typedef uint64_t uintmax_t; don't. */ #cmakedefine HAVE_DECL_INTMAX_MIN 1 +/* Define to 1 if you have the declaration of `SETACL', and to 0 if you don't. + */ +#cmakedefine HAVE_DECL_SETACL 1 + /* Define to 1 if you have the declaration of `SIZE_MAX', and to 0 if you don't. */ #cmakedefine HAVE_DECL_SIZE_MAX 1 @@ -422,6 +478,10 @@ typedef uint64_t uintmax_t; don't. */ #cmakedefine HAVE_DECL_UINTMAX_MAX 1 +/* Define to 1 if you have the declaration of `XATTR_NOFOLLOW', and to 0 if + you don't. */ +#cmakedefine HAVE_DECL_XATTR_NOFOLLOW 1 + /* Define to 1 if you have the <direct.h> header file. */ #cmakedefine HAVE_DIRECT_H 1 @@ -471,6 +531,14 @@ typedef uint64_t uintmax_t; /* Define to 1 if EXTATTR_NAMESPACE_USER is defined in sys/extattr.h. */ #cmakedefine HAVE_DECL_EXTATTR_NAMESPACE_USER 1 +/* Define to 1 if you have the declaration of `GETACL', and to 0 if you don't. + */ +#cmakedefine HAVE_DECL_GETACL 1 + +/* Define to 1 if you have the declaration of `GETACLCNT', and to 0 if you + don't. */ +#cmakedefine HAVE_DECL_GETACLCNT 1 + /* Define to 1 if you have the `fchdir' function. */ #cmakedefine HAVE_FCHDIR 1 @@ -748,6 +816,9 @@ typedef uint64_t uintmax_t; /* Define to 1 if you have the `mbrtowc' function. */ #cmakedefine HAVE_MBRTOWC 1 +/* Define to 1 if you have the <membership.h> header file. */ +#cmakedefine HAVE_MEMBERSHIP_H 1 + /* Define to 1 if you have the `memmove' function. */ #cmakedefine HAVE_MEMMOVE 1 @@ -985,6 +1056,9 @@ typedef uint64_t uintmax_t; /* Define to 1 if you have the <sys/poll.h> header file. */ #cmakedefine HAVE_SYS_POLL_H 1 +/* Define to 1 if you have the <sys/richacl.h> header file. */ +#cmakedefine HAVE_SYS_RICHACL_H 1 + /* Define to 1 if you have the <sys/select.h> header file. */ #cmakedefine HAVE_SYS_SELECT_H 1 diff --git a/Utilities/cmlibarchive/build/version b/Utilities/cmlibarchive/build/version index ef83457..2dd0839 100644 --- a/Utilities/cmlibarchive/build/version +++ b/Utilities/cmlibarchive/build/version @@ -1 +1 @@ -3003001 +3003002 diff --git a/Utilities/cmlibarchive/libarchive/CMakeLists.txt b/Utilities/cmlibarchive/libarchive/CMakeLists.txt index d412c80..b02ae82 100644 --- a/Utilities/cmlibarchive/libarchive/CMakeLists.txt +++ b/Utilities/cmlibarchive/libarchive/CMakeLists.txt @@ -14,6 +14,7 @@ SET(include_HEADERS # Sources and private headers SET(libarchive_SOURCES archive_acl.c + archive_acl_private.h archive_check_magic.c archive_cmdline.c archive_cmdline_private.h @@ -47,6 +48,8 @@ SET(libarchive_SOURCES archive_pathmatch.c archive_pathmatch.h archive_platform.h + archive_platform_acl.h + archive_platform_xattr.h archive_ppmd_private.h archive_ppmd7.c archive_ppmd7_private.h @@ -106,9 +109,9 @@ SET(libarchive_SOURCES archive_string_composition.h archive_string_sprintf.c archive_util.c + archive_version_details.c archive_virtual.c archive_write.c - archive_write_disk_acl.c archive_write_disk_posix.c archive_write_disk_private.h archive_write_disk_set_standard_lookup.c @@ -210,6 +213,16 @@ IF(WIN32 AND NOT CYGWIN) LIST(APPEND libarchive_SOURCES filter_fork_windows.c) ENDIF(WIN32 AND NOT CYGWIN) +IF(ARCHIVE_ACL_DARWIN) + LIST(APPEND libarchive_SOURCES archive_disk_acl_darwin.c) +ELSEIF(ARCHIVE_ACL_FREEBSD) + LIST(APPEND libarchive_SOURCES archive_disk_acl_freebsd.c) +ELSEIF(ARCHIVE_ACL_LIBACL) + LIST(APPEND libarchive_SOURCES archive_disk_acl_linux.c) +ELSEIF(ARCHIVE_ACL_SUNOS) + LIST(APPEND libarchive_SOURCES archive_disk_acl_sunos.c) +ENDIF() + # CMake needs just one static "cmlibarchive" library. ADD_LIBRARY(cmlibarchive STATIC ${libarchive_SOURCES} ${include_HEADERS}) TARGET_LINK_LIBRARIES(cmlibarchive ${ADDITIONAL_LIBS}) diff --git a/Utilities/cmlibarchive/libarchive/archive.h b/Utilities/cmlibarchive/libarchive/archive.h index cfb5c48..0f94d2e 100644 --- a/Utilities/cmlibarchive/libarchive/archive.h +++ b/Utilities/cmlibarchive/libarchive/archive.h @@ -36,7 +36,7 @@ * assert that ARCHIVE_VERSION_NUMBER >= 2012108. */ /* Note: Compiler will complain if this does not match archive_entry.h! */ -#define ARCHIVE_VERSION_NUMBER 3003001 +#define ARCHIVE_VERSION_NUMBER 3003002 #include <sys/stat.h> #include <stddef.h> /* for wchar_t */ @@ -152,7 +152,7 @@ __LA_DECL int archive_version_number(void); /* * Textual name/version of the library, useful for version displays. */ -#define ARCHIVE_VERSION_ONLY_STRING "3.3.1" +#define ARCHIVE_VERSION_ONLY_STRING "3.3.2" #define ARCHIVE_VERSION_STRING "libarchive " ARCHIVE_VERSION_ONLY_STRING __LA_DECL const char * archive_version_string(void); diff --git a/Utilities/cmlibarchive/libarchive/archive_check_magic.c b/Utilities/cmlibarchive/libarchive/archive_check_magic.c index c695e58..288ce23 100644 --- a/Utilities/cmlibarchive/libarchive/archive_check_magic.c +++ b/Utilities/cmlibarchive/libarchive/archive_check_magic.c @@ -62,7 +62,7 @@ errmsg(const char *m) } } -static void +static __LA_DEAD void diediedie(void) { #if defined(_WIN32) && !defined(__CYGWIN__) && defined(_DEBUG) diff --git a/Utilities/cmlibarchive/libarchive/archive_disk_acl_darwin.c b/Utilities/cmlibarchive/libarchive/archive_disk_acl_darwin.c new file mode 100644 index 0000000..48ad016 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_disk_acl_darwin.c @@ -0,0 +1,559 @@ +/*- + * Copyright (c) 2017 Martin Matuska + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "archive_platform.h" + +#if ARCHIVE_ACL_DARWIN + +#ifdef HAVE_FCNTL_H +#include <fcntl.h> +#endif +#if HAVE_ERRNO_H +#include <errno.h> +#endif +#if HAVE_MEMBERSHIP_H +#include <membership.h> +#endif +#ifdef HAVE_SYS_TYPES_H +#include <sys/types.h> +#endif +#ifdef HAVE_SYS_ACL_H +#define _ACL_PRIVATE /* For debugging */ +#include <sys/acl.h> +#endif + +#include "archive_entry.h" +#include "archive_private.h" +#include "archive_read_disk_private.h" +#include "archive_write_disk_private.h" + +typedef struct { + const int a_perm; /* Libarchive permission or flag */ + const int p_perm; /* Platform permission or flag */ +} acl_perm_map_t; + +static const acl_perm_map_t acl_nfs4_perm_map[] = { + {ARCHIVE_ENTRY_ACL_READ_DATA, ACL_READ_DATA}, + {ARCHIVE_ENTRY_ACL_LIST_DIRECTORY, ACL_LIST_DIRECTORY}, + {ARCHIVE_ENTRY_ACL_WRITE_DATA, ACL_WRITE_DATA}, + {ARCHIVE_ENTRY_ACL_ADD_FILE, ACL_ADD_FILE}, + {ARCHIVE_ENTRY_ACL_EXECUTE, ACL_EXECUTE}, + {ARCHIVE_ENTRY_ACL_DELETE, ACL_DELETE}, + {ARCHIVE_ENTRY_ACL_APPEND_DATA, ACL_APPEND_DATA}, + {ARCHIVE_ENTRY_ACL_ADD_SUBDIRECTORY, ACL_ADD_SUBDIRECTORY}, + {ARCHIVE_ENTRY_ACL_DELETE_CHILD, ACL_DELETE_CHILD}, + {ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES, ACL_READ_ATTRIBUTES}, + {ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES, ACL_WRITE_ATTRIBUTES}, + {ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS, ACL_READ_EXTATTRIBUTES}, + {ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS, ACL_WRITE_EXTATTRIBUTES}, + {ARCHIVE_ENTRY_ACL_READ_ACL, ACL_READ_SECURITY}, + {ARCHIVE_ENTRY_ACL_WRITE_ACL, ACL_WRITE_SECURITY}, + {ARCHIVE_ENTRY_ACL_WRITE_OWNER, ACL_CHANGE_OWNER}, +#if HAVE_DECL_ACL_SYNCHRONIZE + {ARCHIVE_ENTRY_ACL_SYNCHRONIZE, ACL_SYNCHRONIZE} +#endif +}; + +static const int acl_nfs4_perm_map_size = + (int)(sizeof(acl_nfs4_perm_map)/sizeof(acl_nfs4_perm_map[0])); + +static const acl_perm_map_t acl_nfs4_flag_map[] = { + {ARCHIVE_ENTRY_ACL_ENTRY_INHERITED, ACL_ENTRY_INHERITED}, + {ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT, ACL_ENTRY_FILE_INHERIT}, + {ARCHIVE_ENTRY_ACL_ENTRY_DIRECTORY_INHERIT, ACL_ENTRY_DIRECTORY_INHERIT}, + {ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT, ACL_ENTRY_LIMIT_INHERIT}, + {ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY, ACL_ENTRY_ONLY_INHERIT} +}; + +static const int acl_nfs4_flag_map_size = + (int)(sizeof(acl_nfs4_flag_map)/sizeof(acl_nfs4_flag_map[0])); + +static int translate_guid(struct archive *a, acl_entry_t acl_entry, + int *ae_id, int *ae_tag, const char **ae_name) +{ + void *q; + uid_t ugid; + int r, idtype; + + q = acl_get_qualifier(acl_entry); + if (q == NULL) + return (1); + r = mbr_uuid_to_id((const unsigned char *)q, &ugid, &idtype); + if (r != 0) { + acl_free(q); + return (1); + } + if (idtype == ID_TYPE_UID) { + *ae_tag = ARCHIVE_ENTRY_ACL_USER; + *ae_id = ugid; + *ae_name = archive_read_disk_uname(a, *ae_id); + } else if (idtype == ID_TYPE_GID) { + *ae_tag = ARCHIVE_ENTRY_ACL_GROUP; + *ae_id = ugid; + *ae_name = archive_read_disk_gname(a, *ae_id); + } else + r = 1; + + acl_free(q); + return (r); +} + +static void +add_trivial_nfs4_acl(struct archive_entry *entry) +{ + mode_t mode; + int i; + const int rperm = ARCHIVE_ENTRY_ACL_READ_DATA; + const int wperm = ARCHIVE_ENTRY_ACL_WRITE_DATA | + ARCHIVE_ENTRY_ACL_APPEND_DATA; + const int eperm = ARCHIVE_ENTRY_ACL_EXECUTE; + const int pubset = ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES | + ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS | + ARCHIVE_ENTRY_ACL_READ_ACL | + ARCHIVE_ENTRY_ACL_SYNCHRONIZE; + const int ownset = pubset | ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES | + ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS | + ARCHIVE_ENTRY_ACL_WRITE_ACL | + ARCHIVE_ENTRY_ACL_WRITE_OWNER; + + struct { + const int type; + const int tag; + int permset; + } tacl_entry[] = { + {ARCHIVE_ENTRY_ACL_TYPE_ALLOW, ARCHIVE_ENTRY_ACL_USER_OBJ, 0}, + {ARCHIVE_ENTRY_ACL_TYPE_DENY, ARCHIVE_ENTRY_ACL_USER_OBJ, 0}, + {ARCHIVE_ENTRY_ACL_TYPE_DENY, ARCHIVE_ENTRY_ACL_GROUP_OBJ, 0}, + {ARCHIVE_ENTRY_ACL_TYPE_ALLOW, ARCHIVE_ENTRY_ACL_USER_OBJ, ownset}, + {ARCHIVE_ENTRY_ACL_TYPE_ALLOW, ARCHIVE_ENTRY_ACL_GROUP_OBJ, pubset}, + {ARCHIVE_ENTRY_ACL_TYPE_ALLOW, ARCHIVE_ENTRY_ACL_EVERYONE, pubset} + }; + + mode = archive_entry_mode(entry); + + /* Permissions for everyone@ */ + if (mode & 0004) + tacl_entry[5].permset |= rperm; + if (mode & 0002) + tacl_entry[5].permset |= wperm; + if (mode & 0001) + tacl_entry[5].permset |= eperm; + + /* Permissions for group@ */ + if (mode & 0040) + tacl_entry[4].permset |= rperm; + else if (mode & 0004) + tacl_entry[2].permset |= rperm; + if (mode & 0020) + tacl_entry[4].permset |= wperm; + else if (mode & 0002) + tacl_entry[2].permset |= wperm; + if (mode & 0010) + tacl_entry[4].permset |= eperm; + else if (mode & 0001) + tacl_entry[2].permset |= eperm; + + /* Permissions for owner@ */ + if (mode & 0400) { + tacl_entry[3].permset |= rperm; + if (!(mode & 0040) && (mode & 0004)) + tacl_entry[0].permset |= rperm; + } else if ((mode & 0040) || (mode & 0004)) + tacl_entry[1].permset |= rperm; + if (mode & 0200) { + tacl_entry[3].permset |= wperm; + if (!(mode & 0020) && (mode & 0002)) + tacl_entry[0].permset |= wperm; + } else if ((mode & 0020) || (mode & 0002)) + tacl_entry[1].permset |= wperm; + if (mode & 0100) { + tacl_entry[3].permset |= eperm; + if (!(mode & 0010) && (mode & 0001)) + tacl_entry[0].permset |= eperm; + } else if ((mode & 0010) || (mode & 0001)) + tacl_entry[1].permset |= eperm; + + for (i = 0; i < 6; i++) { + if (tacl_entry[i].permset != 0) { + archive_entry_acl_add_entry(entry, + tacl_entry[i].type, tacl_entry[i].permset, + tacl_entry[i].tag, -1, NULL); + } + } + + return; +} + +static int +translate_acl(struct archive_read_disk *a, + struct archive_entry *entry, acl_t acl) +{ + acl_tag_t acl_tag; + acl_flagset_t acl_flagset; + acl_entry_t acl_entry; + acl_permset_t acl_permset; + int i, entry_acl_type; + int r, s, ae_id, ae_tag, ae_perm; + const char *ae_name; + + s = acl_get_entry(acl, ACL_FIRST_ENTRY, &acl_entry); + if (s == -1) { + archive_set_error(&a->archive, errno, + "Failed to get first ACL entry"); + return (ARCHIVE_WARN); + } + + while (s == 0) { + ae_id = -1; + ae_name = NULL; + ae_perm = 0; + + if (acl_get_tag_type(acl_entry, &acl_tag) != 0) { + archive_set_error(&a->archive, errno, + "Failed to get ACL tag type"); + return (ARCHIVE_WARN); + } + switch (acl_tag) { + case ACL_EXTENDED_ALLOW: + entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_ALLOW; + r = translate_guid(&a->archive, acl_entry, + &ae_id, &ae_tag, &ae_name); + break; + case ACL_EXTENDED_DENY: + entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_DENY; + r = translate_guid(&a->archive, acl_entry, + &ae_id, &ae_tag, &ae_name); + break; + default: + /* Skip types that libarchive can't support. */ + s = acl_get_entry(acl, ACL_NEXT_ENTRY, &acl_entry); + continue; + } + + /* Skip if translate_guid() above failed */ + if (r != 0) { + s = acl_get_entry(acl, ACL_NEXT_ENTRY, &acl_entry); + continue; + } + + /* + * Libarchive stores "flag" (NFSv4 inheritance bits) + * in the ae_perm bitmap. + * + * acl_get_flagset_np() fails with non-NFSv4 ACLs + */ + if (acl_get_flagset_np(acl_entry, &acl_flagset) != 0) { + archive_set_error(&a->archive, errno, + "Failed to get flagset from a NFSv4 ACL entry"); + return (ARCHIVE_WARN); + } + for (i = 0; i < acl_nfs4_flag_map_size; ++i) { + r = acl_get_flag_np(acl_flagset, + acl_nfs4_flag_map[i].p_perm); + if (r == -1) { + archive_set_error(&a->archive, errno, + "Failed to check flag in a NFSv4 " + "ACL flagset"); + return (ARCHIVE_WARN); + } else if (r) + ae_perm |= acl_nfs4_flag_map[i].a_perm; + } + + if (acl_get_permset(acl_entry, &acl_permset) != 0) { + archive_set_error(&a->archive, errno, + "Failed to get ACL permission set"); + return (ARCHIVE_WARN); + } + + for (i = 0; i < acl_nfs4_perm_map_size; ++i) { + /* + * acl_get_perm() is spelled differently on different + * platforms; see above. + */ + r = acl_get_perm_np(acl_permset, + acl_nfs4_perm_map[i].p_perm); + if (r == -1) { + archive_set_error(&a->archive, errno, + "Failed to check permission in an ACL " + "permission set"); + return (ARCHIVE_WARN); + } else if (r) + ae_perm |= acl_nfs4_perm_map[i].a_perm; + } + +#if !HAVE_DECL_ACL_SYNCHRONIZE + /* On Mac OS X without ACL_SYNCHRONIZE assume it is set */ + ae_perm |= ARCHIVE_ENTRY_ACL_SYNCHRONIZE; +#endif + + archive_entry_acl_add_entry(entry, entry_acl_type, + ae_perm, ae_tag, + ae_id, ae_name); + + s = acl_get_entry(acl, ACL_NEXT_ENTRY, &acl_entry); + } + return (ARCHIVE_OK); +} + +static int +set_acl(struct archive *a, int fd, const char *name, + struct archive_acl *abstract_acl, + int ae_requested_type, const char *tname) +{ + acl_t acl; + acl_entry_t acl_entry; + acl_permset_t acl_permset; + acl_flagset_t acl_flagset; + int ret; + int ae_type, ae_permset, ae_tag, ae_id; + uuid_t ae_uuid; + uid_t ae_uid; + gid_t ae_gid; + const char *ae_name; + int entries; + int i; + + ret = ARCHIVE_OK; + entries = archive_acl_reset(abstract_acl, ae_requested_type); + if (entries == 0) + return (ARCHIVE_OK); + + if (ae_requested_type != ARCHIVE_ENTRY_ACL_TYPE_NFS4) { + errno = ENOENT; + archive_set_error(a, errno, "Unsupported ACL type"); + return (ARCHIVE_FAILED); + } + + acl = acl_init(entries); + if (acl == (acl_t)NULL) { + archive_set_error(a, errno, + "Failed to initialize ACL working storage"); + return (ARCHIVE_FAILED); + } + + while (archive_acl_next(a, abstract_acl, ae_requested_type, &ae_type, + &ae_permset, &ae_tag, &ae_id, &ae_name) == ARCHIVE_OK) { + /* + * Mac OS doesn't support NFSv4 ACLs for + * owner@, group@ and everyone@. + * We skip any of these ACLs found. + */ + if (ae_tag == ARCHIVE_ENTRY_ACL_USER_OBJ || + ae_tag == ARCHIVE_ENTRY_ACL_GROUP_OBJ || + ae_tag == ARCHIVE_ENTRY_ACL_EVERYONE) + continue; + + if (acl_create_entry(&acl, &acl_entry) != 0) { + archive_set_error(a, errno, + "Failed to create a new ACL entry"); + ret = ARCHIVE_FAILED; + goto exit_free; + } + + switch (ae_type) { + case ARCHIVE_ENTRY_ACL_TYPE_ALLOW: + acl_set_tag_type(acl_entry, ACL_EXTENDED_ALLOW); + break; + case ARCHIVE_ENTRY_ACL_TYPE_DENY: + acl_set_tag_type(acl_entry, ACL_EXTENDED_DENY); + break; + default: + /* We don't support any other types on MacOS */ + continue; + } + + switch (ae_tag) { + case ARCHIVE_ENTRY_ACL_USER: + ae_uid = archive_write_disk_uid(a, ae_name, ae_id); + if (mbr_uid_to_uuid(ae_uid, ae_uuid) != 0) + continue; + if (acl_set_qualifier(acl_entry, &ae_uuid) != 0) + continue; + break; + case ARCHIVE_ENTRY_ACL_GROUP: + ae_gid = archive_write_disk_gid(a, ae_name, ae_id); + if (mbr_gid_to_uuid(ae_gid, ae_uuid) != 0) + continue; + if (acl_set_qualifier(acl_entry, &ae_uuid) != 0) + continue; + break; + default: + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "Unsupported ACL tag"); + ret = ARCHIVE_FAILED; + goto exit_free; + } + + if (acl_get_permset(acl_entry, &acl_permset) != 0) { + archive_set_error(a, errno, + "Failed to get ACL permission set"); + ret = ARCHIVE_FAILED; + goto exit_free; + } + if (acl_clear_perms(acl_permset) != 0) { + archive_set_error(a, errno, + "Failed to clear ACL permissions"); + ret = ARCHIVE_FAILED; + goto exit_free; + } + + for (i = 0; i < acl_nfs4_perm_map_size; ++i) { + if (ae_permset & acl_nfs4_perm_map[i].a_perm) { + if (acl_add_perm(acl_permset, + acl_nfs4_perm_map[i].p_perm) != 0) { + archive_set_error(a, errno, + "Failed to add ACL permission"); + ret = ARCHIVE_FAILED; + goto exit_free; + } + } + } + + /* + * acl_get_flagset_np() fails with non-NFSv4 ACLs + */ + if (acl_get_flagset_np(acl_entry, &acl_flagset) != 0) { + archive_set_error(a, errno, + "Failed to get flagset from an NFSv4 ACL entry"); + ret = ARCHIVE_FAILED; + goto exit_free; + } + if (acl_clear_flags_np(acl_flagset) != 0) { + archive_set_error(a, errno, + "Failed to clear flags from an NFSv4 ACL flagset"); + ret = ARCHIVE_FAILED; + goto exit_free; + } + + for (i = 0; i < acl_nfs4_flag_map_size; ++i) { + if (ae_permset & acl_nfs4_flag_map[i].a_perm) { + if (acl_add_flag_np(acl_flagset, + acl_nfs4_flag_map[i].p_perm) != 0) { + archive_set_error(a, errno, + "Failed to add flag to " + "NFSv4 ACL flagset"); + ret = ARCHIVE_FAILED; + goto exit_free; + } + } + } + } + + if (fd >= 0) { + if (acl_set_fd_np(fd, acl, ACL_TYPE_EXTENDED) == 0) + ret = ARCHIVE_OK; + else { + if (errno == EOPNOTSUPP) { + /* Filesystem doesn't support ACLs */ + ret = ARCHIVE_OK; + } else { + archive_set_error(a, errno, + "Failed to set acl on fd: %s", tname); + ret = ARCHIVE_WARN; + } + } + } else if (acl_set_link_np(name, ACL_TYPE_EXTENDED, acl) != 0) { + if (errno == EOPNOTSUPP) { + /* Filesystem doesn't support ACLs */ + ret = ARCHIVE_OK; + } else { + archive_set_error(a, errno, "Failed to set acl: %s", + tname); + ret = ARCHIVE_WARN; + } + } +exit_free: + acl_free(acl); + return (ret); +} + +int +archive_read_disk_entry_setup_acls(struct archive_read_disk *a, + struct archive_entry *entry, int *fd) +{ + const char *accpath; + acl_t acl; + int r; + + accpath = NULL; + + if (*fd < 0) { + accpath = archive_read_disk_entry_setup_path(a, entry, fd); + if (accpath == NULL) + return (ARCHIVE_WARN); + } + + archive_entry_acl_clear(entry); + + acl = NULL; + + if (*fd >= 0) + acl = acl_get_fd_np(*fd, ACL_TYPE_EXTENDED); + else if (!a->follow_symlinks) + acl = acl_get_link_np(accpath, ACL_TYPE_EXTENDED); + else + acl = acl_get_file(accpath, ACL_TYPE_EXTENDED); + + if (acl != NULL) { + r = translate_acl(a, entry, acl); + acl_free(acl); + acl = NULL; + + if (r != ARCHIVE_OK) { + archive_set_error(&a->archive, errno, + "Couldn't translate NFSv4 ACLs"); + } + + /* + * Because Mac OS doesn't support owner@, group@ and everyone@ + * ACLs we need to add NFSv4 ACLs mirroring the file mode to + * the archive entry. Otherwise extraction on non-Mac platforms + * would lead to an invalid file mode. + */ + if ((archive_entry_acl_types(entry) & + ARCHIVE_ENTRY_ACL_TYPE_NFS4) != 0) + add_trivial_nfs4_acl(entry); + + return (r); + } + return (ARCHIVE_OK); +} + +int +archive_write_disk_set_acls(struct archive *a, int fd, const char *name, + struct archive_acl *abstract_acl, __LA_MODE_T mode) +{ + int ret = ARCHIVE_OK; + + (void)mode; /* UNUSED */ + + if ((archive_acl_types(abstract_acl) & + ARCHIVE_ENTRY_ACL_TYPE_NFS4) != 0) { + ret = set_acl(a, fd, name, abstract_acl, + ARCHIVE_ENTRY_ACL_TYPE_NFS4, "nfs4"); + } + return (ret); +} +#endif /* ARCHIVE_ACL_DARWIN */ diff --git a/Utilities/cmlibarchive/libarchive/archive_disk_acl_freebsd.c b/Utilities/cmlibarchive/libarchive/archive_disk_acl_freebsd.c new file mode 100644 index 0000000..07d08ff --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_disk_acl_freebsd.c @@ -0,0 +1,700 @@ +/*- + * Copyright (c) 2003-2009 Tim Kientzle + * Copyright (c) 2010-2012 Michihiro NAKAJIMA + * Copyright (c) 2017 Martin Matuska + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "archive_platform.h" + +#if ARCHIVE_ACL_FREEBSD + +#ifdef HAVE_ERRNO_H +#include <errno.h> +#endif +#ifdef HAVE_FCNTL_H +#include <fcntl.h> +#endif +#ifdef HAVE_SYS_TYPES_H +#include <sys/types.h> +#endif +#ifdef HAVE_SYS_ACL_H +#define _ACL_PRIVATE /* For debugging */ +#include <sys/acl.h> +#endif + +#include "archive_entry.h" +#include "archive_private.h" +#include "archive_read_disk_private.h" +#include "archive_write_disk_private.h" + +typedef struct { + const int a_perm; /* Libarchive permission or flag */ + const int p_perm; /* Platform permission or flag */ +} acl_perm_map_t; + +static const acl_perm_map_t acl_posix_perm_map[] = { + {ARCHIVE_ENTRY_ACL_EXECUTE, ACL_EXECUTE}, + {ARCHIVE_ENTRY_ACL_WRITE, ACL_WRITE}, + {ARCHIVE_ENTRY_ACL_READ, ACL_READ}, +}; + +static const int acl_posix_perm_map_size = + (int)(sizeof(acl_posix_perm_map)/sizeof(acl_posix_perm_map[0])); + +#if ARCHIVE_ACL_FREEBSD_NFS4 +static const acl_perm_map_t acl_nfs4_perm_map[] = { + {ARCHIVE_ENTRY_ACL_EXECUTE, ACL_EXECUTE}, + {ARCHIVE_ENTRY_ACL_READ_DATA, ACL_READ_DATA}, + {ARCHIVE_ENTRY_ACL_LIST_DIRECTORY, ACL_LIST_DIRECTORY}, + {ARCHIVE_ENTRY_ACL_WRITE_DATA, ACL_WRITE_DATA}, + {ARCHIVE_ENTRY_ACL_ADD_FILE, ACL_ADD_FILE}, + {ARCHIVE_ENTRY_ACL_APPEND_DATA, ACL_APPEND_DATA}, + {ARCHIVE_ENTRY_ACL_ADD_SUBDIRECTORY, ACL_ADD_SUBDIRECTORY}, + {ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS, ACL_READ_NAMED_ATTRS}, + {ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS, ACL_WRITE_NAMED_ATTRS}, + {ARCHIVE_ENTRY_ACL_DELETE_CHILD, ACL_DELETE_CHILD}, + {ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES, ACL_READ_ATTRIBUTES}, + {ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES, ACL_WRITE_ATTRIBUTES}, + {ARCHIVE_ENTRY_ACL_DELETE, ACL_DELETE}, + {ARCHIVE_ENTRY_ACL_READ_ACL, ACL_READ_ACL}, + {ARCHIVE_ENTRY_ACL_WRITE_ACL, ACL_WRITE_ACL}, + {ARCHIVE_ENTRY_ACL_WRITE_OWNER, ACL_WRITE_OWNER}, + {ARCHIVE_ENTRY_ACL_SYNCHRONIZE, ACL_SYNCHRONIZE} +}; + +static const int acl_nfs4_perm_map_size = + (int)(sizeof(acl_nfs4_perm_map)/sizeof(acl_nfs4_perm_map[0])); + +static const acl_perm_map_t acl_nfs4_flag_map[] = { + {ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT, ACL_ENTRY_FILE_INHERIT}, + {ARCHIVE_ENTRY_ACL_ENTRY_DIRECTORY_INHERIT, ACL_ENTRY_DIRECTORY_INHERIT}, + {ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT, ACL_ENTRY_NO_PROPAGATE_INHERIT}, + {ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY, ACL_ENTRY_INHERIT_ONLY}, + {ARCHIVE_ENTRY_ACL_ENTRY_SUCCESSFUL_ACCESS, ACL_ENTRY_SUCCESSFUL_ACCESS}, + {ARCHIVE_ENTRY_ACL_ENTRY_FAILED_ACCESS, ACL_ENTRY_FAILED_ACCESS}, + {ARCHIVE_ENTRY_ACL_ENTRY_INHERITED, ACL_ENTRY_INHERITED} +}; + +static const int acl_nfs4_flag_map_size = + (int)(sizeof(acl_nfs4_flag_map)/sizeof(acl_nfs4_flag_map[0])); +#endif /* ARCHIVE_ACL_FREEBSD_NFS4 */ + +static int +translate_acl(struct archive_read_disk *a, + struct archive_entry *entry, acl_t acl, int default_entry_acl_type) +{ +#if ARCHIVE_ACL_FREEBSD_NFS4 + int brand; + acl_flagset_t acl_flagset; + acl_entry_type_t acl_type; +#endif + acl_tag_t acl_tag; + acl_entry_t acl_entry; + acl_permset_t acl_permset; + int i, entry_acl_type, perm_map_size; + const acl_perm_map_t *perm_map; + int r, s, ae_id, ae_tag, ae_perm; + void *q; + const char *ae_name; + +#if ARCHIVE_ACL_FREEBSD_NFS4 + // FreeBSD "brands" ACLs as POSIX.1e or NFSv4 + // Make sure the "brand" on this ACL is consistent + // with the default_entry_acl_type bits provided. + if (acl_get_brand_np(acl, &brand) != 0) { + archive_set_error(&a->archive, errno, + "Failed to read ACL brand"); + return (ARCHIVE_WARN); + } + switch (brand) { + case ACL_BRAND_POSIX: + switch (default_entry_acl_type) { + case ARCHIVE_ENTRY_ACL_TYPE_ACCESS: + case ARCHIVE_ENTRY_ACL_TYPE_DEFAULT: + break; + default: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Invalid ACL entry type for POSIX.1e ACL"); + return (ARCHIVE_WARN); + } + break; + case ACL_BRAND_NFS4: + if (default_entry_acl_type & ~ARCHIVE_ENTRY_ACL_TYPE_NFS4) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Invalid ACL entry type for NFSv4 ACL"); + return (ARCHIVE_WARN); + } + break; + default: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Unknown ACL brand"); + return (ARCHIVE_WARN); + } +#endif + + s = acl_get_entry(acl, ACL_FIRST_ENTRY, &acl_entry); + if (s == -1) { + archive_set_error(&a->archive, errno, + "Failed to get first ACL entry"); + return (ARCHIVE_WARN); + } + + while (s == 1) { + ae_id = -1; + ae_name = NULL; + ae_perm = 0; + + if (acl_get_tag_type(acl_entry, &acl_tag) != 0) { + archive_set_error(&a->archive, errno, + "Failed to get ACL tag type"); + return (ARCHIVE_WARN); + } + switch (acl_tag) { + case ACL_USER: + q = acl_get_qualifier(acl_entry); + if (q != NULL) { + ae_id = (int)*(uid_t *)q; + acl_free(q); + ae_name = archive_read_disk_uname(&a->archive, + ae_id); + } + ae_tag = ARCHIVE_ENTRY_ACL_USER; + break; + case ACL_GROUP: + q = acl_get_qualifier(acl_entry); + if (q != NULL) { + ae_id = (int)*(gid_t *)q; + acl_free(q); + ae_name = archive_read_disk_gname(&a->archive, + ae_id); + } + ae_tag = ARCHIVE_ENTRY_ACL_GROUP; + break; + case ACL_MASK: + ae_tag = ARCHIVE_ENTRY_ACL_MASK; + break; + case ACL_USER_OBJ: + ae_tag = ARCHIVE_ENTRY_ACL_USER_OBJ; + break; + case ACL_GROUP_OBJ: + ae_tag = ARCHIVE_ENTRY_ACL_GROUP_OBJ; + break; + case ACL_OTHER: + ae_tag = ARCHIVE_ENTRY_ACL_OTHER; + break; +#if ARCHIVE_ACL_FREEBSD_NFS4 + case ACL_EVERYONE: + ae_tag = ARCHIVE_ENTRY_ACL_EVERYONE; + break; +#endif + default: + /* Skip types that libarchive can't support. */ + s = acl_get_entry(acl, ACL_NEXT_ENTRY, &acl_entry); + continue; + } + + // XXX acl_type maps to allow/deny/audit/YYYY bits + entry_acl_type = default_entry_acl_type; + +#if ARCHIVE_ACL_FREEBSD_NFS4 + if (default_entry_acl_type & ARCHIVE_ENTRY_ACL_TYPE_NFS4) { + /* + * acl_get_entry_type_np() fails with non-NFSv4 ACLs + */ + if (acl_get_entry_type_np(acl_entry, &acl_type) != 0) { + archive_set_error(&a->archive, errno, "Failed " + "to get ACL type from a NFSv4 ACL entry"); + return (ARCHIVE_WARN); + } + switch (acl_type) { + case ACL_ENTRY_TYPE_ALLOW: + entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_ALLOW; + break; + case ACL_ENTRY_TYPE_DENY: + entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_DENY; + break; + case ACL_ENTRY_TYPE_AUDIT: + entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_AUDIT; + break; + case ACL_ENTRY_TYPE_ALARM: + entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_ALARM; + break; + default: + archive_set_error(&a->archive, errno, + "Invalid NFSv4 ACL entry type"); + return (ARCHIVE_WARN); + } + + /* + * Libarchive stores "flag" (NFSv4 inheritance bits) + * in the ae_perm bitmap. + * + * acl_get_flagset_np() fails with non-NFSv4 ACLs + */ + if (acl_get_flagset_np(acl_entry, &acl_flagset) != 0) { + archive_set_error(&a->archive, errno, + "Failed to get flagset from a NFSv4 " + "ACL entry"); + return (ARCHIVE_WARN); + } + for (i = 0; i < acl_nfs4_flag_map_size; ++i) { + r = acl_get_flag_np(acl_flagset, + acl_nfs4_flag_map[i].p_perm); + if (r == -1) { + archive_set_error(&a->archive, errno, + "Failed to check flag in a NFSv4 " + "ACL flagset"); + return (ARCHIVE_WARN); + } else if (r) + ae_perm |= acl_nfs4_flag_map[i].a_perm; + } + } +#endif + + if (acl_get_permset(acl_entry, &acl_permset) != 0) { + archive_set_error(&a->archive, errno, + "Failed to get ACL permission set"); + return (ARCHIVE_WARN); + } + +#if ARCHIVE_ACL_FREEBSD_NFS4 + if (default_entry_acl_type & ARCHIVE_ENTRY_ACL_TYPE_NFS4) { + perm_map_size = acl_nfs4_perm_map_size; + perm_map = acl_nfs4_perm_map; + } else { +#endif + perm_map_size = acl_posix_perm_map_size; + perm_map = acl_posix_perm_map; +#if ARCHIVE_ACL_FREEBSD_NFS4 + } +#endif + + for (i = 0; i < perm_map_size; ++i) { + r = acl_get_perm_np(acl_permset, perm_map[i].p_perm); + if (r == -1) { + archive_set_error(&a->archive, errno, + "Failed to check permission in an ACL " + "permission set"); + return (ARCHIVE_WARN); + } else if (r) + ae_perm |= perm_map[i].a_perm; + } + + archive_entry_acl_add_entry(entry, entry_acl_type, + ae_perm, ae_tag, + ae_id, ae_name); + + s = acl_get_entry(acl, ACL_NEXT_ENTRY, &acl_entry); + if (s == -1) { + archive_set_error(&a->archive, errno, + "Failed to get next ACL entry"); + return (ARCHIVE_WARN); + } + } + return (ARCHIVE_OK); +} + +static int +set_acl(struct archive *a, int fd, const char *name, + struct archive_acl *abstract_acl, + int ae_requested_type, const char *tname) +{ + int acl_type = 0; + acl_t acl; + acl_entry_t acl_entry; + acl_permset_t acl_permset; +#if ARCHIVE_ACL_FREEBSD_NFS4 + acl_flagset_t acl_flagset; + int r; +#endif + int ret; + int ae_type, ae_permset, ae_tag, ae_id; + int perm_map_size; + const acl_perm_map_t *perm_map; + uid_t ae_uid; + gid_t ae_gid; + const char *ae_name; + int entries; + int i; + + ret = ARCHIVE_OK; + entries = archive_acl_reset(abstract_acl, ae_requested_type); + if (entries == 0) + return (ARCHIVE_OK); + + + switch (ae_requested_type) { + case ARCHIVE_ENTRY_ACL_TYPE_ACCESS: + acl_type = ACL_TYPE_ACCESS; + break; + case ARCHIVE_ENTRY_ACL_TYPE_DEFAULT: + acl_type = ACL_TYPE_DEFAULT; + break; +#if ARCHIVE_ACL_FREEBSD_NFS4 + case ARCHIVE_ENTRY_ACL_TYPE_NFS4: + acl_type = ACL_TYPE_NFS4; + break; +#endif + default: + errno = ENOENT; + archive_set_error(a, errno, "Unsupported ACL type"); + return (ARCHIVE_FAILED); + } + + acl = acl_init(entries); + if (acl == (acl_t)NULL) { + archive_set_error(a, errno, + "Failed to initialize ACL working storage"); + return (ARCHIVE_FAILED); + } + + while (archive_acl_next(a, abstract_acl, ae_requested_type, &ae_type, + &ae_permset, &ae_tag, &ae_id, &ae_name) == ARCHIVE_OK) { + if (acl_create_entry(&acl, &acl_entry) != 0) { + archive_set_error(a, errno, + "Failed to create a new ACL entry"); + ret = ARCHIVE_FAILED; + goto exit_free; + } + switch (ae_tag) { + case ARCHIVE_ENTRY_ACL_USER: + ae_uid = archive_write_disk_uid(a, ae_name, ae_id); + acl_set_tag_type(acl_entry, ACL_USER); + acl_set_qualifier(acl_entry, &ae_uid); + break; + case ARCHIVE_ENTRY_ACL_GROUP: + ae_gid = archive_write_disk_gid(a, ae_name, ae_id); + acl_set_tag_type(acl_entry, ACL_GROUP); + acl_set_qualifier(acl_entry, &ae_gid); + break; + case ARCHIVE_ENTRY_ACL_USER_OBJ: + acl_set_tag_type(acl_entry, ACL_USER_OBJ); + break; + case ARCHIVE_ENTRY_ACL_GROUP_OBJ: + acl_set_tag_type(acl_entry, ACL_GROUP_OBJ); + break; + case ARCHIVE_ENTRY_ACL_MASK: + acl_set_tag_type(acl_entry, ACL_MASK); + break; + case ARCHIVE_ENTRY_ACL_OTHER: + acl_set_tag_type(acl_entry, ACL_OTHER); + break; +#if ARCHIVE_ACL_FREEBSD_NFS4 + case ARCHIVE_ENTRY_ACL_EVERYONE: + acl_set_tag_type(acl_entry, ACL_EVERYONE); + break; +#endif + default: + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "Unsupported ACL tag"); + ret = ARCHIVE_FAILED; + goto exit_free; + } + +#if ARCHIVE_ACL_FREEBSD_NFS4 + r = 0; + switch (ae_type) { + case ARCHIVE_ENTRY_ACL_TYPE_ALLOW: + r = acl_set_entry_type_np(acl_entry, + ACL_ENTRY_TYPE_ALLOW); + break; + case ARCHIVE_ENTRY_ACL_TYPE_DENY: + r = acl_set_entry_type_np(acl_entry, + ACL_ENTRY_TYPE_DENY); + break; + case ARCHIVE_ENTRY_ACL_TYPE_AUDIT: + r = acl_set_entry_type_np(acl_entry, + ACL_ENTRY_TYPE_AUDIT); + break; + case ARCHIVE_ENTRY_ACL_TYPE_ALARM: + r = acl_set_entry_type_np(acl_entry, + ACL_ENTRY_TYPE_ALARM); + break; + case ARCHIVE_ENTRY_ACL_TYPE_ACCESS: + case ARCHIVE_ENTRY_ACL_TYPE_DEFAULT: + // These don't translate directly into the system ACL. + break; + default: + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "Unsupported ACL entry type"); + ret = ARCHIVE_FAILED; + goto exit_free; + } + + if (r != 0) { + archive_set_error(a, errno, + "Failed to set ACL entry type"); + ret = ARCHIVE_FAILED; + goto exit_free; + } +#endif + + if (acl_get_permset(acl_entry, &acl_permset) != 0) { + archive_set_error(a, errno, + "Failed to get ACL permission set"); + ret = ARCHIVE_FAILED; + goto exit_free; + } + if (acl_clear_perms(acl_permset) != 0) { + archive_set_error(a, errno, + "Failed to clear ACL permissions"); + ret = ARCHIVE_FAILED; + goto exit_free; + } +#if ARCHIVE_ACL_FREEBSD_NFS4 + if (ae_requested_type == ARCHIVE_ENTRY_ACL_TYPE_NFS4) { + perm_map_size = acl_nfs4_perm_map_size; + perm_map = acl_nfs4_perm_map; + } else { +#endif + perm_map_size = acl_posix_perm_map_size; + perm_map = acl_posix_perm_map; +#if ARCHIVE_ACL_FREEBSD_NFS4 + } +#endif + + for (i = 0; i < perm_map_size; ++i) { + if (ae_permset & perm_map[i].a_perm) { + if (acl_add_perm(acl_permset, + perm_map[i].p_perm) != 0) { + archive_set_error(a, errno, + "Failed to add ACL permission"); + ret = ARCHIVE_FAILED; + goto exit_free; + } + } + } + +#if ARCHIVE_ACL_FREEBSD_NFS4 + if (ae_requested_type == ARCHIVE_ENTRY_ACL_TYPE_NFS4) { + /* + * acl_get_flagset_np() fails with non-NFSv4 ACLs + */ + if (acl_get_flagset_np(acl_entry, &acl_flagset) != 0) { + archive_set_error(a, errno, + "Failed to get flagset from an NFSv4 " + "ACL entry"); + ret = ARCHIVE_FAILED; + goto exit_free; + } + if (acl_clear_flags_np(acl_flagset) != 0) { + archive_set_error(a, errno, + "Failed to clear flags from an NFSv4 " + "ACL flagset"); + ret = ARCHIVE_FAILED; + goto exit_free; + } + for (i = 0; i < acl_nfs4_flag_map_size; ++i) { + if (ae_permset & acl_nfs4_flag_map[i].a_perm) { + if (acl_add_flag_np(acl_flagset, + acl_nfs4_flag_map[i].p_perm) != 0) { + archive_set_error(a, errno, + "Failed to add flag to " + "NFSv4 ACL flagset"); + ret = ARCHIVE_FAILED; + goto exit_free; + } + } + } + } +#endif + } + + /* Try restoring the ACL through 'fd' if we can. */ + if (fd >= 0) { + if (acl_set_fd_np(fd, acl, acl_type) == 0) + ret = ARCHIVE_OK; + else { + if (errno == EOPNOTSUPP) { + /* Filesystem doesn't support ACLs */ + ret = ARCHIVE_OK; + } else { + archive_set_error(a, errno, + "Failed to set acl on fd: %s", tname); + ret = ARCHIVE_WARN; + } + } + } +#if HAVE_ACL_SET_LINK_NP + else if (acl_set_link_np(name, acl_type, acl) != 0) +#else + /* FreeBSD older than 8.0 */ + else if (acl_set_file(name, acl_type, acl) != 0) +#endif + { + if (errno == EOPNOTSUPP) { + /* Filesystem doesn't support ACLs */ + ret = ARCHIVE_OK; + } else { + archive_set_error(a, errno, "Failed to set acl: %s", + tname); + ret = ARCHIVE_WARN; + } + } +exit_free: + acl_free(acl); + return (ret); +} + +int +archive_read_disk_entry_setup_acls(struct archive_read_disk *a, + struct archive_entry *entry, int *fd) +{ + const char *accpath; + acl_t acl; + int r; + + accpath = NULL; + + if (*fd < 0) { + accpath = archive_read_disk_entry_setup_path(a, entry, fd); + if (accpath == NULL) + return (ARCHIVE_WARN); + } + + archive_entry_acl_clear(entry); + + acl = NULL; + +#if ARCHIVE_ACL_FREEBSD_NFS4 + /* Try NFSv4 ACL first. */ + if (*fd >= 0) + acl = acl_get_fd_np(*fd, ACL_TYPE_NFS4); + else if (!a->follow_symlinks) + acl = acl_get_link_np(accpath, ACL_TYPE_NFS4); + else + acl = acl_get_file(accpath, ACL_TYPE_NFS4); + + /* Ignore "trivial" ACLs that just mirror the file mode. */ + if (acl != NULL && acl_is_trivial_np(acl, &r) == 0 && r == 1) { + acl_free(acl); + acl = NULL; + return (ARCHIVE_OK); + } + + if (acl != NULL) { + r = translate_acl(a, entry, acl, ARCHIVE_ENTRY_ACL_TYPE_NFS4); + acl_free(acl); + acl = NULL; + + if (r != ARCHIVE_OK) { + archive_set_error(&a->archive, errno, + "Couldn't translate NFSv4 ACLs"); + } + + return (r); + } +#endif + + /* Retrieve access ACL from file. */ + if (*fd >= 0) + acl = acl_get_fd_np(*fd, ACL_TYPE_ACCESS); +#if HAVE_ACL_GET_LINK_NP + else if (!a->follow_symlinks) + acl = acl_get_link_np(accpath, ACL_TYPE_ACCESS); +#else + else if ((!a->follow_symlinks) + && (archive_entry_filetype(entry) == AE_IFLNK)) + /* We can't get the ACL of a symlink, so we assume it can't + have one. */ + acl = NULL; +#endif + else + acl = acl_get_file(accpath, ACL_TYPE_ACCESS); + +#if HAVE_ACL_IS_TRIVIAL_NP + /* Ignore "trivial" ACLs that just mirror the file mode. */ + if (acl != NULL && acl_is_trivial_np(acl, &r) == 0 && r == 1) { + acl_free(acl); + acl = NULL; + } +#endif + + if (acl != NULL) { + r = translate_acl(a, entry, acl, ARCHIVE_ENTRY_ACL_TYPE_ACCESS); + acl_free(acl); + acl = NULL; + + if (r != ARCHIVE_OK) { + archive_set_error(&a->archive, errno, + "Couldn't translate access ACLs"); + return (r); + } + } + + /* Only directories can have default ACLs. */ + if (S_ISDIR(archive_entry_mode(entry))) { + if (*fd >= 0) + acl = acl_get_fd_np(*fd, ACL_TYPE_DEFAULT); + else + acl = acl_get_file(accpath, ACL_TYPE_DEFAULT); + if (acl != NULL) { + r = translate_acl(a, entry, acl, + ARCHIVE_ENTRY_ACL_TYPE_DEFAULT); + acl_free(acl); + if (r != ARCHIVE_OK) { + archive_set_error(&a->archive, errno, + "Couldn't translate default ACLs"); + return (r); + } + } + } + return (ARCHIVE_OK); +} + +int +archive_write_disk_set_acls(struct archive *a, int fd, const char *name, + struct archive_acl *abstract_acl, __LA_MODE_T mode) +{ + int ret = ARCHIVE_OK; + + (void)mode; /* UNUSED */ + + if ((archive_acl_types(abstract_acl) + & ARCHIVE_ENTRY_ACL_TYPE_POSIX1E) != 0) { + if ((archive_acl_types(abstract_acl) + & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0) { + ret = set_acl(a, fd, name, abstract_acl, + ARCHIVE_ENTRY_ACL_TYPE_ACCESS, "access"); + if (ret != ARCHIVE_OK) + return (ret); + } + if ((archive_acl_types(abstract_acl) + & ARCHIVE_ENTRY_ACL_TYPE_DEFAULT) != 0) + ret = set_acl(a, fd, name, abstract_acl, + ARCHIVE_ENTRY_ACL_TYPE_DEFAULT, "default"); + + /* Simultaneous POSIX.1e and NFSv4 is not supported */ + return (ret); + } +#if ARCHIVE_ACL_FREEBSD_NFS4 + else if ((archive_acl_types(abstract_acl) & + ARCHIVE_ENTRY_ACL_TYPE_NFS4) != 0) { + ret = set_acl(a, fd, name, abstract_acl, + ARCHIVE_ENTRY_ACL_TYPE_NFS4, "nfs4"); + } +#endif + return (ret); +} +#endif /* ARCHIVE_ACL_FREEBSD */ diff --git a/Utilities/cmlibarchive/libarchive/archive_disk_acl_linux.c b/Utilities/cmlibarchive/libarchive/archive_disk_acl_linux.c new file mode 100644 index 0000000..3928f3d --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_disk_acl_linux.c @@ -0,0 +1,743 @@ +/*- + * Copyright (c) 2003-2009 Tim Kientzle + * Copyright (c) 2010-2012 Michihiro NAKAJIMA + * Copyright (c) 2017 Martin Matuska + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "archive_platform.h" + +#if ARCHIVE_ACL_LIBACL || ARCHIVE_ACL_LIBRICHACL + +#ifdef HAVE_ERRNO_H +#include <errno.h> +#endif +#ifdef HAVE_FCNTL_H +#include <fcntl.h> +#endif +#if HAVE_ACL_LIBACL_H +#include <acl/libacl.h> +#endif +#ifdef HAVE_SYS_ACL_H +#include <sys/acl.h> +#endif +#ifdef HAVE_SYS_RICHACL_H +#include <sys/richacl.h> +#endif + +#include "archive_entry.h" +#include "archive_private.h" +#include "archive_read_disk_private.h" +#include "archive_write_disk_private.h" + +typedef struct { + const int a_perm; /* Libarchive permission or flag */ + const int p_perm; /* Platform permission or flag */ +} acl_perm_map_t; + +#if ARCHIVE_ACL_LIBACL +static const acl_perm_map_t acl_posix_perm_map[] = { + {ARCHIVE_ENTRY_ACL_EXECUTE, ACL_EXECUTE}, + {ARCHIVE_ENTRY_ACL_WRITE, ACL_WRITE}, + {ARCHIVE_ENTRY_ACL_READ, ACL_READ}, +}; + +static const int acl_posix_perm_map_size = + (int)(sizeof(acl_posix_perm_map)/sizeof(acl_posix_perm_map[0])); +#endif /* ARCHIVE_ACL_LIBACL */ + +#if ARCHIVE_ACL_LIBRICHACL +static const acl_perm_map_t acl_nfs4_perm_map[] = { + {ARCHIVE_ENTRY_ACL_EXECUTE, RICHACE_EXECUTE}, + {ARCHIVE_ENTRY_ACL_READ_DATA, RICHACE_READ_DATA}, + {ARCHIVE_ENTRY_ACL_LIST_DIRECTORY, RICHACE_LIST_DIRECTORY}, + {ARCHIVE_ENTRY_ACL_WRITE_DATA, RICHACE_WRITE_DATA}, + {ARCHIVE_ENTRY_ACL_ADD_FILE, RICHACE_ADD_FILE}, + {ARCHIVE_ENTRY_ACL_APPEND_DATA, RICHACE_APPEND_DATA}, + {ARCHIVE_ENTRY_ACL_ADD_SUBDIRECTORY, RICHACE_ADD_SUBDIRECTORY}, + {ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS, RICHACE_READ_NAMED_ATTRS}, + {ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS, RICHACE_WRITE_NAMED_ATTRS}, + {ARCHIVE_ENTRY_ACL_DELETE_CHILD, RICHACE_DELETE_CHILD}, + {ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES, RICHACE_READ_ATTRIBUTES}, + {ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES, RICHACE_WRITE_ATTRIBUTES}, + {ARCHIVE_ENTRY_ACL_DELETE, RICHACE_DELETE}, + {ARCHIVE_ENTRY_ACL_READ_ACL, RICHACE_READ_ACL}, + {ARCHIVE_ENTRY_ACL_WRITE_ACL, RICHACE_WRITE_ACL}, + {ARCHIVE_ENTRY_ACL_WRITE_OWNER, RICHACE_WRITE_OWNER}, + {ARCHIVE_ENTRY_ACL_SYNCHRONIZE, RICHACE_SYNCHRONIZE} +}; + +static const int acl_nfs4_perm_map_size = + (int)(sizeof(acl_nfs4_perm_map)/sizeof(acl_nfs4_perm_map[0])); + +static const acl_perm_map_t acl_nfs4_flag_map[] = { + {ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT, RICHACE_FILE_INHERIT_ACE}, + {ARCHIVE_ENTRY_ACL_ENTRY_DIRECTORY_INHERIT, RICHACE_DIRECTORY_INHERIT_ACE}, + {ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT, RICHACE_NO_PROPAGATE_INHERIT_ACE}, + {ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY, RICHACE_INHERIT_ONLY_ACE}, + {ARCHIVE_ENTRY_ACL_ENTRY_INHERITED, RICHACE_INHERITED_ACE} +}; + +static const int acl_nfs4_flag_map_size = + (int)(sizeof(acl_nfs4_flag_map)/sizeof(acl_nfs4_flag_map[0])); +#endif /* ARCHIVE_ACL_LIBRICHACL */ + +#if ARCHIVE_ACL_LIBACL +/* + * Translate POSIX.1e ACLs into libarchive internal structure + */ +static int +translate_acl(struct archive_read_disk *a, + struct archive_entry *entry, acl_t acl, int default_entry_acl_type) +{ + acl_tag_t acl_tag; + acl_entry_t acl_entry; + acl_permset_t acl_permset; + int i, entry_acl_type; + int r, s, ae_id, ae_tag, ae_perm; + void *q; + const char *ae_name; + + s = acl_get_entry(acl, ACL_FIRST_ENTRY, &acl_entry); + if (s == -1) { + archive_set_error(&a->archive, errno, + "Failed to get first ACL entry"); + return (ARCHIVE_WARN); + } + + while (s == 1) { + ae_id = -1; + ae_name = NULL; + ae_perm = 0; + + if (acl_get_tag_type(acl_entry, &acl_tag) != 0) { + archive_set_error(&a->archive, errno, + "Failed to get ACL tag type"); + return (ARCHIVE_WARN); + } + switch (acl_tag) { + case ACL_USER: + q = acl_get_qualifier(acl_entry); + if (q != NULL) { + ae_id = (int)*(uid_t *)q; + acl_free(q); + ae_name = archive_read_disk_uname(&a->archive, + ae_id); + } + ae_tag = ARCHIVE_ENTRY_ACL_USER; + break; + case ACL_GROUP: + q = acl_get_qualifier(acl_entry); + if (q != NULL) { + ae_id = (int)*(gid_t *)q; + acl_free(q); + ae_name = archive_read_disk_gname(&a->archive, + ae_id); + } + ae_tag = ARCHIVE_ENTRY_ACL_GROUP; + break; + case ACL_MASK: + ae_tag = ARCHIVE_ENTRY_ACL_MASK; + break; + case ACL_USER_OBJ: + ae_tag = ARCHIVE_ENTRY_ACL_USER_OBJ; + break; + case ACL_GROUP_OBJ: + ae_tag = ARCHIVE_ENTRY_ACL_GROUP_OBJ; + break; + case ACL_OTHER: + ae_tag = ARCHIVE_ENTRY_ACL_OTHER; + break; + default: + /* Skip types that libarchive can't support. */ + s = acl_get_entry(acl, ACL_NEXT_ENTRY, &acl_entry); + continue; + } + + // XXX acl_type maps to allow/deny/audit/YYYY bits + entry_acl_type = default_entry_acl_type; + + if (acl_get_permset(acl_entry, &acl_permset) != 0) { + archive_set_error(&a->archive, errno, + "Failed to get ACL permission set"); + return (ARCHIVE_WARN); + } + + for (i = 0; i < acl_posix_perm_map_size; ++i) { + r = acl_get_perm(acl_permset, + acl_posix_perm_map[i].p_perm); + if (r == -1) { + archive_set_error(&a->archive, errno, + "Failed to check permission in an ACL " + "permission set"); + return (ARCHIVE_WARN); + } else if (r) + ae_perm |= acl_posix_perm_map[i].a_perm; + } + + archive_entry_acl_add_entry(entry, entry_acl_type, + ae_perm, ae_tag, + ae_id, ae_name); + + s = acl_get_entry(acl, ACL_NEXT_ENTRY, &acl_entry); + if (s == -1) { + archive_set_error(&a->archive, errno, + "Failed to get next ACL entry"); + return (ARCHIVE_WARN); + } + } + return (ARCHIVE_OK); +} +#endif /* ARCHIVE_ACL_LIBACL */ + +#if ARCHIVE_ACL_LIBRICHACL +/* + * Translate RichACL into libarchive internal ACL + */ +static int +translate_richacl(struct archive_read_disk *a, struct archive_entry *entry, + struct richacl *richacl) +{ + int ae_id, ae_tag, ae_perm; + int entry_acl_type, i; + const char *ae_name; + + struct richace *richace; + + richacl_for_each_entry(richace, richacl) { + ae_name = NULL; + ae_tag = 0; + ae_perm = 0; + ae_id = -1; + + switch (richace->e_type) { + case RICHACE_ACCESS_ALLOWED_ACE_TYPE: + entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_ALLOW; + break; + case RICHACE_ACCESS_DENIED_ACE_TYPE: + entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_DENY; + break; + default: /* Unknown entry type, skip */ + continue; + } + + /* Unsupported */ + if (richace->e_flags & RICHACE_UNMAPPED_WHO) + continue; + + if (richace->e_flags & RICHACE_SPECIAL_WHO) { + switch (richace->e_id) { + case RICHACE_OWNER_SPECIAL_ID: + ae_tag = ARCHIVE_ENTRY_ACL_USER_OBJ; + break; + case RICHACE_GROUP_SPECIAL_ID: + ae_tag = ARCHIVE_ENTRY_ACL_GROUP_OBJ; + break; + case RICHACE_EVERYONE_SPECIAL_ID: + ae_tag = ARCHIVE_ENTRY_ACL_EVERYONE; + break; + default: /* Unknown special ID type */ + continue; + } + } else { + ae_id = richace->e_id; + if (richace->e_flags & RICHACE_IDENTIFIER_GROUP) { + ae_tag = ARCHIVE_ENTRY_ACL_GROUP; + ae_name = archive_read_disk_gname(&a->archive, + (gid_t)(richace->e_id)); + } else { + ae_tag = ARCHIVE_ENTRY_ACL_USER; + ae_name = archive_read_disk_uname(&a->archive, + (uid_t)(richace->e_id)); + } + } + for (i = 0; i < acl_nfs4_flag_map_size; ++i) { + if ((richace->e_flags & + acl_nfs4_flag_map[i].p_perm) != 0) + ae_perm |= acl_nfs4_flag_map[i].a_perm; + } + for (i = 0; i < acl_nfs4_perm_map_size; ++i) { + if ((richace->e_mask & + acl_nfs4_perm_map[i].p_perm) != 0) + ae_perm |= + acl_nfs4_perm_map[i].a_perm; + } + + archive_entry_acl_add_entry(entry, entry_acl_type, + ae_perm, ae_tag, ae_id, ae_name); + } + return (ARCHIVE_OK); +} +#endif /* ARCHIVE_ACL_LIBRICHACL */ + +#if ARCHIVE_ACL_LIBRICHACL +static int +_richacl_mode_to_mask(short mode) +{ + int mask = 0; + + if (mode & S_IROTH) + mask |= RICHACE_POSIX_MODE_READ; + if (mode & S_IWOTH) + mask |= RICHACE_POSIX_MODE_WRITE; + if (mode & S_IXOTH) + mask |= RICHACE_POSIX_MODE_EXEC; + + return (mask); +} + +static void +_richacl_mode_to_masks(struct richacl *richacl, __LA_MODE_T mode) +{ + richacl->a_owner_mask = _richacl_mode_to_mask((mode & 0700) >> 6); + richacl->a_group_mask = _richacl_mode_to_mask((mode & 0070) >> 3); + richacl->a_other_mask = _richacl_mode_to_mask(mode & 0007); +} +#endif /* ARCHIVE_ACL_LIBRICHACL */ + +#if ARCHIVE_ACL_LIBRICHACL +static int +set_richacl(struct archive *a, int fd, const char *name, + struct archive_acl *abstract_acl, __LA_MODE_T mode, + int ae_requested_type, const char *tname) +{ + int ae_type, ae_permset, ae_tag, ae_id; + uid_t ae_uid; + gid_t ae_gid; + const char *ae_name; + int entries; + int i; + int ret; + int e = 0; + struct richacl *richacl = NULL; + struct richace *richace; + + ret = ARCHIVE_OK; + entries = archive_acl_reset(abstract_acl, ae_requested_type); + if (entries == 0) + return (ARCHIVE_OK); + + if (ae_requested_type != ARCHIVE_ENTRY_ACL_TYPE_NFS4) { + errno = ENOENT; + archive_set_error(a, errno, "Unsupported ACL type"); + return (ARCHIVE_FAILED); + } + + richacl = richacl_alloc(entries); + if (richacl == NULL) { + archive_set_error(a, errno, + "Failed to initialize RichACL working storage"); + return (ARCHIVE_FAILED); + } + + e = 0; + + while (archive_acl_next(a, abstract_acl, ae_requested_type, &ae_type, + &ae_permset, &ae_tag, &ae_id, &ae_name) == ARCHIVE_OK) { + richace = &(richacl->a_entries[e]); + + richace->e_flags = 0; + richace->e_mask = 0; + + switch (ae_tag) { + case ARCHIVE_ENTRY_ACL_USER: + ae_uid = archive_write_disk_uid(a, ae_name, ae_id); + richace->e_id = ae_uid; + break; + case ARCHIVE_ENTRY_ACL_GROUP: + ae_gid = archive_write_disk_gid(a, ae_name, ae_id); + richace->e_id = ae_gid; + richace->e_flags |= RICHACE_IDENTIFIER_GROUP; + break; + case ARCHIVE_ENTRY_ACL_USER_OBJ: + richace->e_flags |= RICHACE_SPECIAL_WHO; + richace->e_id = RICHACE_OWNER_SPECIAL_ID; + break; + case ARCHIVE_ENTRY_ACL_GROUP_OBJ: + richace->e_flags |= RICHACE_SPECIAL_WHO; + richace->e_id = RICHACE_GROUP_SPECIAL_ID; + break; + case ARCHIVE_ENTRY_ACL_EVERYONE: + richace->e_flags |= RICHACE_SPECIAL_WHO; + richace->e_id = RICHACE_EVERYONE_SPECIAL_ID; + break; + default: + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "Unsupported ACL tag"); + ret = ARCHIVE_FAILED; + goto exit_free; + } + + switch (ae_type) { + case ARCHIVE_ENTRY_ACL_TYPE_ALLOW: + richace->e_type = + RICHACE_ACCESS_ALLOWED_ACE_TYPE; + break; + case ARCHIVE_ENTRY_ACL_TYPE_DENY: + richace->e_type = + RICHACE_ACCESS_DENIED_ACE_TYPE; + break; + case ARCHIVE_ENTRY_ACL_TYPE_AUDIT: + case ARCHIVE_ENTRY_ACL_TYPE_ALARM: + break; + default: + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "Unsupported ACL entry type"); + ret = ARCHIVE_FAILED; + goto exit_free; + } + + for (i = 0; i < acl_nfs4_perm_map_size; ++i) { + if (ae_permset & acl_nfs4_perm_map[i].a_perm) + richace->e_mask |= acl_nfs4_perm_map[i].p_perm; + } + + for (i = 0; i < acl_nfs4_flag_map_size; ++i) { + if (ae_permset & + acl_nfs4_flag_map[i].a_perm) + richace->e_flags |= acl_nfs4_flag_map[i].p_perm; + } + e++; + } + + /* Fill RichACL masks */ + _richacl_mode_to_masks(richacl, mode); + + if (fd >= 0) { + if (richacl_set_fd(fd, richacl) == 0) + ret = ARCHIVE_OK; + else { + if (errno == EOPNOTSUPP) { + /* Filesystem doesn't support ACLs */ + ret = ARCHIVE_OK; + } else { + archive_set_error(a, errno, + "Failed to set richacl on fd: %s", tname); + ret = ARCHIVE_WARN; + } + } + } else if (richacl_set_file(name, richacl) != 0) { + if (errno == EOPNOTSUPP) { + /* Filesystem doesn't support ACLs */ + ret = ARCHIVE_OK; + } else { + archive_set_error(a, errno, "Failed to set richacl: %s", + tname); + ret = ARCHIVE_WARN; + } + } +exit_free: + richacl_free(richacl); + return (ret); +} +#endif /* ARCHIVE_ACL_RICHACL */ + +#if ARCHIVE_ACL_LIBACL +static int +set_acl(struct archive *a, int fd, const char *name, + struct archive_acl *abstract_acl, + int ae_requested_type, const char *tname) +{ + int acl_type = 0; + int ae_type, ae_permset, ae_tag, ae_id; + uid_t ae_uid; + gid_t ae_gid; + const char *ae_name; + int entries; + int i; + int ret; + acl_t acl = NULL; + acl_entry_t acl_entry; + acl_permset_t acl_permset; + + ret = ARCHIVE_OK; + entries = archive_acl_reset(abstract_acl, ae_requested_type); + if (entries == 0) + return (ARCHIVE_OK); + + switch (ae_requested_type) { + case ARCHIVE_ENTRY_ACL_TYPE_ACCESS: + acl_type = ACL_TYPE_ACCESS; + break; + case ARCHIVE_ENTRY_ACL_TYPE_DEFAULT: + acl_type = ACL_TYPE_DEFAULT; + break; + default: + errno = ENOENT; + archive_set_error(a, errno, "Unsupported ACL type"); + return (ARCHIVE_FAILED); + } + + acl = acl_init(entries); + if (acl == (acl_t)NULL) { + archive_set_error(a, errno, + "Failed to initialize ACL working storage"); + return (ARCHIVE_FAILED); + } + + while (archive_acl_next(a, abstract_acl, ae_requested_type, &ae_type, + &ae_permset, &ae_tag, &ae_id, &ae_name) == ARCHIVE_OK) { + + if (acl_create_entry(&acl, &acl_entry) != 0) { + archive_set_error(a, errno, + "Failed to create a new ACL entry"); + ret = ARCHIVE_FAILED; + goto exit_free; + } + + switch (ae_tag) { + case ARCHIVE_ENTRY_ACL_USER: + ae_uid = archive_write_disk_uid(a, ae_name, ae_id); + acl_set_tag_type(acl_entry, ACL_USER); + acl_set_qualifier(acl_entry, &ae_uid); + break; + case ARCHIVE_ENTRY_ACL_GROUP: + ae_gid = archive_write_disk_gid(a, ae_name, ae_id); + acl_set_tag_type(acl_entry, ACL_GROUP); + acl_set_qualifier(acl_entry, &ae_gid); + break; + case ARCHIVE_ENTRY_ACL_USER_OBJ: + acl_set_tag_type(acl_entry, ACL_USER_OBJ); + break; + case ARCHIVE_ENTRY_ACL_GROUP_OBJ: + acl_set_tag_type(acl_entry, ACL_GROUP_OBJ); + break; + case ARCHIVE_ENTRY_ACL_MASK: + acl_set_tag_type(acl_entry, ACL_MASK); + break; + case ARCHIVE_ENTRY_ACL_OTHER: + acl_set_tag_type(acl_entry, ACL_OTHER); + break; + default: + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "Unsupported ACL tag"); + ret = ARCHIVE_FAILED; + goto exit_free; + } + + if (acl_get_permset(acl_entry, &acl_permset) != 0) { + archive_set_error(a, errno, + "Failed to get ACL permission set"); + ret = ARCHIVE_FAILED; + goto exit_free; + } + if (acl_clear_perms(acl_permset) != 0) { + archive_set_error(a, errno, + "Failed to clear ACL permissions"); + ret = ARCHIVE_FAILED; + goto exit_free; + } + + for (i = 0; i < acl_posix_perm_map_size; ++i) { + if (ae_permset & acl_posix_perm_map[i].a_perm) { + if (acl_add_perm(acl_permset, + acl_posix_perm_map[i].p_perm) != 0) { + archive_set_error(a, errno, + "Failed to add ACL permission"); + ret = ARCHIVE_FAILED; + goto exit_free; + } + } + } + + } + + if (fd >= 0 && ae_requested_type == ARCHIVE_ENTRY_ACL_TYPE_ACCESS) { + if (acl_set_fd(fd, acl) == 0) + ret = ARCHIVE_OK; + else { + if (errno == EOPNOTSUPP) { + /* Filesystem doesn't support ACLs */ + ret = ARCHIVE_OK; + } else { + archive_set_error(a, errno, + "Failed to set acl on fd: %s", tname); + ret = ARCHIVE_WARN; + } + } + } else if (acl_set_file(name, acl_type, acl) != 0) { + if (errno == EOPNOTSUPP) { + /* Filesystem doesn't support ACLs */ + ret = ARCHIVE_OK; + } else { + archive_set_error(a, errno, "Failed to set acl: %s", + tname); + ret = ARCHIVE_WARN; + } + } +exit_free: + acl_free(acl); + return (ret); +} +#endif /* ARCHIVE_ACL_LIBACL */ + +int +archive_read_disk_entry_setup_acls(struct archive_read_disk *a, + struct archive_entry *entry, int *fd) +{ + const char *accpath; + int r; +#if ARCHIVE_ACL_LIBACL + acl_t acl; +#endif +#if ARCHIVE_ACL_LIBRICHACL + struct richacl *richacl; + mode_t mode; +#endif + + accpath = NULL; + r = ARCHIVE_OK; + + /* For default ACLs we need reachable accpath */ + if (*fd < 0 || S_ISDIR(archive_entry_mode(entry))) { + accpath = archive_read_disk_entry_setup_path(a, entry, fd); + if (accpath == NULL) + return (ARCHIVE_WARN); + } + + archive_entry_acl_clear(entry); + +#if ARCHIVE_ACL_LIBACL + acl = NULL; +#endif +#if ARCHIVE_ACL_LIBRICHACL + richacl = NULL; +#endif + +#if ARCHIVE_ACL_LIBRICHACL + /* Try NFSv4 ACL first. */ + if (*fd >= 0) + richacl = richacl_get_fd(*fd); + else if ((!a->follow_symlinks) + && (archive_entry_filetype(entry) == AE_IFLNK)) + /* We can't get the ACL of a symlink, so we assume it can't + have one */ + richacl = NULL; + else + richacl = richacl_get_file(accpath); + + /* Ignore "trivial" ACLs that just mirror the file mode. */ + if (richacl != NULL) { + mode = archive_entry_mode(entry); + if (richacl_equiv_mode(richacl, &mode) == 0) { + richacl_free(richacl); + richacl = NULL; + return (ARCHIVE_OK); + } + } + + if (richacl != NULL) { + r = translate_richacl(a, entry, richacl); + richacl_free(richacl); + richacl = NULL; + + if (r != ARCHIVE_OK) { + archive_set_error(&a->archive, errno, + "Couldn't translate NFSv4 ACLs"); + } + + return (r); + } +#endif /* ARCHIVE_ACL_LIBRICHACL */ + +#if ARCHIVE_ACL_LIBACL + /* Retrieve access ACL from file. */ + if (*fd >= 0) + acl = acl_get_fd(*fd); + else if ((!a->follow_symlinks) + && (archive_entry_filetype(entry) == AE_IFLNK)) + /* We can't get the ACL of a symlink, so we assume it can't + have one. */ + acl = NULL; + else + acl = acl_get_file(accpath, ACL_TYPE_ACCESS); + + if (acl != NULL) { + r = translate_acl(a, entry, acl, ARCHIVE_ENTRY_ACL_TYPE_ACCESS); + acl_free(acl); + acl = NULL; + + if (r != ARCHIVE_OK) { + archive_set_error(&a->archive, errno, + "Couldn't translate access ACLs"); + return (r); + } + } + + /* Only directories can have default ACLs. */ + if (S_ISDIR(archive_entry_mode(entry))) { + acl = acl_get_file(accpath, ACL_TYPE_DEFAULT); + if (acl != NULL) { + r = translate_acl(a, entry, acl, + ARCHIVE_ENTRY_ACL_TYPE_DEFAULT); + acl_free(acl); + if (r != ARCHIVE_OK) { + archive_set_error(&a->archive, errno, + "Couldn't translate default ACLs"); + return (r); + } + } + } +#endif /* ARCHIVE_ACL_LIBACL */ + return (r); +} + +int +archive_write_disk_set_acls(struct archive *a, int fd, const char *name, + struct archive_acl *abstract_acl, __LA_MODE_T mode) +{ + int ret = ARCHIVE_OK; + +#if !ARCHIVE_ACL_LIBRICHACL + (void)mode; /* UNUSED */ +#endif + +#if ARCHIVE_ACL_LIBRICHACL + if ((archive_acl_types(abstract_acl) + & ARCHIVE_ENTRY_ACL_TYPE_NFS4) != 0) { + ret = set_richacl(a, fd, name, abstract_acl, mode, + ARCHIVE_ENTRY_ACL_TYPE_NFS4, "nfs4"); + } +#if ARCHIVE_ACL_LIBACL + else +#endif +#endif /* ARCHIVE_ACL_LIBRICHACL */ +#if ARCHIVE_ACL_LIBACL + if ((archive_acl_types(abstract_acl) + & ARCHIVE_ENTRY_ACL_TYPE_POSIX1E) != 0) { + if ((archive_acl_types(abstract_acl) + & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0) { + ret = set_acl(a, fd, name, abstract_acl, + ARCHIVE_ENTRY_ACL_TYPE_ACCESS, "access"); + if (ret != ARCHIVE_OK) + return (ret); + } + if ((archive_acl_types(abstract_acl) + & ARCHIVE_ENTRY_ACL_TYPE_DEFAULT) != 0) + ret = set_acl(a, fd, name, abstract_acl, + ARCHIVE_ENTRY_ACL_TYPE_DEFAULT, "default"); + } +#endif /* ARCHIVE_ACL_LIBACL */ + return (ret); +} +#endif /* ARCHIVE_ACL_LIBACL || ARCHIVE_ACL_LIBRICHACL */ diff --git a/Utilities/cmlibarchive/libarchive/archive_disk_acl_sunos.c b/Utilities/cmlibarchive/libarchive/archive_disk_acl_sunos.c new file mode 100644 index 0000000..bc84fd6 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_disk_acl_sunos.c @@ -0,0 +1,821 @@ +/*- + * Copyright (c) 2017 Martin Matuska + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "archive_platform.h" + +#if ARCHIVE_ACL_SUNOS + +#ifdef HAVE_ERRNO_H +#include <errno.h> +#endif +#ifdef HAVE_FCNTL_H +#include <fcntl.h> +#endif +#ifdef HAVE_SYS_TYPES_H +#include <sys/types.h> +#endif +#ifdef HAVE_SYS_ACL_H +#define _ACL_PRIVATE /* For debugging */ +#include <sys/acl.h> +#endif + +#include "archive_entry.h" +#include "archive_private.h" +#include "archive_read_disk_private.h" +#include "archive_write_disk_private.h" + +typedef struct { + const int a_perm; /* Libarchive permission or flag */ + const int p_perm; /* Platform permission or flag */ +} acl_perm_map_t; + +static const acl_perm_map_t acl_posix_perm_map[] = { + {ARCHIVE_ENTRY_ACL_EXECUTE, S_IXOTH }, + {ARCHIVE_ENTRY_ACL_WRITE, S_IWOTH }, + {ARCHIVE_ENTRY_ACL_READ, S_IROTH } +}; + +static const int acl_posix_perm_map_size = + (int)(sizeof(acl_posix_perm_map)/sizeof(acl_posix_perm_map[0])); + +#if ARCHIVE_ACL_SUNOS_NFS4 +static const acl_perm_map_t acl_nfs4_perm_map[] = { + {ARCHIVE_ENTRY_ACL_EXECUTE, ACE_EXECUTE}, + {ARCHIVE_ENTRY_ACL_READ_DATA, ACE_READ_DATA}, + {ARCHIVE_ENTRY_ACL_LIST_DIRECTORY, ACE_LIST_DIRECTORY}, + {ARCHIVE_ENTRY_ACL_WRITE_DATA, ACE_WRITE_DATA}, + {ARCHIVE_ENTRY_ACL_ADD_FILE, ACE_ADD_FILE}, + {ARCHIVE_ENTRY_ACL_APPEND_DATA, ACE_APPEND_DATA}, + {ARCHIVE_ENTRY_ACL_ADD_SUBDIRECTORY, ACE_ADD_SUBDIRECTORY}, + {ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS, ACE_READ_NAMED_ATTRS}, + {ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS, ACE_WRITE_NAMED_ATTRS}, + {ARCHIVE_ENTRY_ACL_DELETE_CHILD, ACE_DELETE_CHILD}, + {ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES, ACE_READ_ATTRIBUTES}, + {ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES, ACE_WRITE_ATTRIBUTES}, + {ARCHIVE_ENTRY_ACL_DELETE, ACE_DELETE}, + {ARCHIVE_ENTRY_ACL_READ_ACL, ACE_READ_ACL}, + {ARCHIVE_ENTRY_ACL_WRITE_ACL, ACE_WRITE_ACL}, + {ARCHIVE_ENTRY_ACL_WRITE_OWNER, ACE_WRITE_OWNER}, + {ARCHIVE_ENTRY_ACL_SYNCHRONIZE, ACE_SYNCHRONIZE} +}; + +static const int acl_nfs4_perm_map_size = + (int)(sizeof(acl_nfs4_perm_map)/sizeof(acl_nfs4_perm_map[0])); + +static const acl_perm_map_t acl_nfs4_flag_map[] = { + {ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT, ACE_FILE_INHERIT_ACE}, + {ARCHIVE_ENTRY_ACL_ENTRY_DIRECTORY_INHERIT, ACE_DIRECTORY_INHERIT_ACE}, + {ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT, ACE_NO_PROPAGATE_INHERIT_ACE}, + {ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY, ACE_INHERIT_ONLY_ACE}, + {ARCHIVE_ENTRY_ACL_ENTRY_SUCCESSFUL_ACCESS, ACE_SUCCESSFUL_ACCESS_ACE_FLAG}, + {ARCHIVE_ENTRY_ACL_ENTRY_FAILED_ACCESS, ACE_FAILED_ACCESS_ACE_FLAG}, +#ifdef ACE_INHERITED_ACE + {ARCHIVE_ENTRY_ACL_ENTRY_INHERITED, ACE_INHERITED_ACE} +#endif +}; + +const int acl_nfs4_flag_map_size = + (int)(sizeof(acl_nfs4_flag_map)/sizeof(acl_nfs4_flag_map[0])); + +#endif /* ARCHIVE_ACL_SUNOS_NFS4 */ + +static void * +sunacl_get(int cmd, int *aclcnt, int fd, const char *path) +{ + int cnt, cntcmd; + size_t size; + void *aclp; + + if (cmd == GETACL) { + cntcmd = GETACLCNT; + size = sizeof(aclent_t); + } +#if ARCHIVE_ACL_SUNOS_NFS4 + else if (cmd == ACE_GETACL) { + cntcmd = ACE_GETACLCNT; + size = sizeof(ace_t); + } +#endif + else { + errno = EINVAL; + *aclcnt = -1; + return (NULL); + } + + aclp = NULL; + cnt = -2; + + while (cnt == -2 || (cnt == -1 && errno == ENOSPC)) { + if (path != NULL) + cnt = acl(path, cntcmd, 0, NULL); + else + cnt = facl(fd, cntcmd, 0, NULL); + + if (cnt > 0) { + if (aclp == NULL) + aclp = malloc(cnt * size); + else + aclp = realloc(NULL, cnt * size); + if (aclp != NULL) { + if (path != NULL) + cnt = acl(path, cmd, cnt, aclp); + else + cnt = facl(fd, cmd, cnt, aclp); + } + } else { + if (aclp != NULL) { + free(aclp); + aclp = NULL; + } + break; + } + } + + *aclcnt = cnt; + return (aclp); +} + +/* + * Check if acl is trivial + * This is a FreeBSD acl_is_trivial_np() implementation for Solaris + */ +static int +sun_acl_is_trivial(void *aclp, int aclcnt, mode_t mode, int is_nfs4, + int is_dir, int *trivialp) +{ +#if ARCHIVE_ACL_SUNOS_NFS4 + int i, p; + const uint32_t rperm = ACE_READ_DATA; + const uint32_t wperm = ACE_WRITE_DATA | ACE_APPEND_DATA; + const uint32_t eperm = ACE_EXECUTE; + const uint32_t pubset = ACE_READ_ATTRIBUTES | ACE_READ_NAMED_ATTRS | + ACE_READ_ACL | ACE_SYNCHRONIZE; + const uint32_t ownset = pubset | ACE_WRITE_ATTRIBUTES | + ACE_WRITE_NAMED_ATTRS | ACE_WRITE_ACL | ACE_WRITE_OWNER; + + ace_t *ace; + ace_t tace[6]; +#endif + + if (aclp == NULL || trivialp == NULL) + return (-1); + + *trivialp = 0; + + /* + * POSIX.1e ACLs marked with ACL_IS_TRIVIAL are compatible with + * FreeBSD acl_is_trivial_np(). On Solaris they have 4 entries, + * including mask. + */ + if (!is_nfs4) { + if (aclcnt == 4) + *trivialp = 1; + return (0); + } + +#if ARCHIVE_ACL_SUNOS_NFS4 + /* + * Continue with checking NFSv4 ACLs + * + * Create list of trivial ace's to be compared + */ + + /* owner@ allow pre */ + tace[0].a_flags = ACE_OWNER; + tace[0].a_type = ACE_ACCESS_ALLOWED_ACE_TYPE; + tace[0].a_access_mask = 0; + + /* owner@ deny */ + tace[1].a_flags = ACE_OWNER; + tace[1].a_type = ACE_ACCESS_DENIED_ACE_TYPE; + tace[1].a_access_mask = 0; + + /* group@ deny */ + tace[2].a_flags = ACE_GROUP | ACE_IDENTIFIER_GROUP; + tace[2].a_type = ACE_ACCESS_DENIED_ACE_TYPE; + tace[2].a_access_mask = 0; + + /* owner@ allow */ + tace[3].a_flags = ACE_OWNER; + tace[3].a_type = ACE_ACCESS_ALLOWED_ACE_TYPE; + tace[3].a_access_mask = ownset; + + /* group@ allow */ + tace[4].a_flags = ACE_GROUP | ACE_IDENTIFIER_GROUP; + tace[4].a_type = ACE_ACCESS_ALLOWED_ACE_TYPE; + tace[4].a_access_mask = pubset; + + /* everyone@ allow */ + tace[5].a_flags = ACE_EVERYONE; + tace[5].a_type = ACE_ACCESS_ALLOWED_ACE_TYPE; + tace[5].a_access_mask = pubset; + + /* Permissions for everyone@ */ + if (mode & 0004) + tace[5].a_access_mask |= rperm; + if (mode & 0002) + tace[5].a_access_mask |= wperm; + if (mode & 0001) + tace[5].a_access_mask |= eperm; + + /* Permissions for group@ */ + if (mode & 0040) + tace[4].a_access_mask |= rperm; + else if (mode & 0004) + tace[2].a_access_mask |= rperm; + if (mode & 0020) + tace[4].a_access_mask |= wperm; + else if (mode & 0002) + tace[2].a_access_mask |= wperm; + if (mode & 0010) + tace[4].a_access_mask |= eperm; + else if (mode & 0001) + tace[2].a_access_mask |= eperm; + + /* Permissions for owner@ */ + if (mode & 0400) { + tace[3].a_access_mask |= rperm; + if (!(mode & 0040) && (mode & 0004)) + tace[0].a_access_mask |= rperm; + } else if ((mode & 0040) || (mode & 0004)) + tace[1].a_access_mask |= rperm; + if (mode & 0200) { + tace[3].a_access_mask |= wperm; + if (!(mode & 0020) && (mode & 0002)) + tace[0].a_access_mask |= wperm; + } else if ((mode & 0020) || (mode & 0002)) + tace[1].a_access_mask |= wperm; + if (mode & 0100) { + tace[3].a_access_mask |= eperm; + if (!(mode & 0010) && (mode & 0001)) + tace[0].a_access_mask |= eperm; + } else if ((mode & 0010) || (mode & 0001)) + tace[1].a_access_mask |= eperm; + + /* Check if the acl count matches */ + p = 3; + for (i = 0; i < 3; i++) { + if (tace[i].a_access_mask != 0) + p++; + } + if (aclcnt != p) + return (0); + + p = 0; + for (i = 0; i < 6; i++) { + if (tace[i].a_access_mask != 0) { + ace = &((ace_t *)aclp)[p]; + /* + * Illumos added ACE_DELETE_CHILD to write perms for + * directories. We have to check against that, too. + */ + if (ace->a_flags != tace[i].a_flags || + ace->a_type != tace[i].a_type || + (ace->a_access_mask != tace[i].a_access_mask && + (!is_dir || (tace[i].a_access_mask & wperm) == 0 || + ace->a_access_mask != + (tace[i].a_access_mask | ACE_DELETE_CHILD)))) + return (0); + p++; + } + } + + *trivialp = 1; +#else /* !ARCHIVE_ACL_SUNOS_NFS4 */ + (void)is_dir; /* UNUSED */ + (void)aclp; /* UNUSED */ +#endif /* !ARCHIVE_ACL_SUNOS_NFS4 */ + return (0); +} + +/* + * Translate Solaris POSIX.1e and NFSv4 ACLs into libarchive internal ACL + */ +static int +translate_acl(struct archive_read_disk *a, + struct archive_entry *entry, void *aclp, int aclcnt, + int default_entry_acl_type) +{ + int e, i; + int ae_id, ae_tag, ae_perm; + int entry_acl_type; + const char *ae_name; + aclent_t *aclent; +#if ARCHIVE_ACL_SUNOS_NFS4 + ace_t *ace; +#endif + + if (aclcnt <= 0) + return (ARCHIVE_OK); + + for (e = 0; e < aclcnt; e++) { + ae_name = NULL; + ae_tag = 0; + ae_perm = 0; + +#if ARCHIVE_ACL_SUNOS_NFS4 + if (default_entry_acl_type == ARCHIVE_ENTRY_ACL_TYPE_NFS4) { + ace = &((ace_t *)aclp)[e]; + ae_id = ace->a_who; + + switch(ace->a_type) { + case ACE_ACCESS_ALLOWED_ACE_TYPE: + entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_ALLOW; + break; + case ACE_ACCESS_DENIED_ACE_TYPE: + entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_DENY; + break; + case ACE_SYSTEM_AUDIT_ACE_TYPE: + entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_ACCESS; + break; + case ACE_SYSTEM_ALARM_ACE_TYPE: + entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_ALARM; + break; + default: + /* Unknown entry type, skip */ + continue; + } + + if ((ace->a_flags & ACE_OWNER) != 0) + ae_tag = ARCHIVE_ENTRY_ACL_USER_OBJ; + else if ((ace->a_flags & ACE_GROUP) != 0) + ae_tag = ARCHIVE_ENTRY_ACL_GROUP_OBJ; + else if ((ace->a_flags & ACE_EVERYONE) != 0) + ae_tag = ARCHIVE_ENTRY_ACL_EVERYONE; + else if ((ace->a_flags & ACE_IDENTIFIER_GROUP) != 0) { + ae_tag = ARCHIVE_ENTRY_ACL_GROUP; + ae_name = archive_read_disk_gname(&a->archive, + ae_id); + } else { + ae_tag = ARCHIVE_ENTRY_ACL_USER; + ae_name = archive_read_disk_uname(&a->archive, + ae_id); + } + + for (i = 0; i < acl_nfs4_flag_map_size; ++i) { + if ((ace->a_flags & + acl_nfs4_flag_map[i].p_perm) != 0) + ae_perm |= acl_nfs4_flag_map[i].a_perm; + } + + for (i = 0; i < acl_nfs4_perm_map_size; ++i) { + if ((ace->a_access_mask & + acl_nfs4_perm_map[i].p_perm) != 0) + ae_perm |= acl_nfs4_perm_map[i].a_perm; + } + } else +#endif /* ARCHIVE_ACL_SUNOS_NFS4 */ + if (default_entry_acl_type == ARCHIVE_ENTRY_ACL_TYPE_ACCESS) { + aclent = &((aclent_t *)aclp)[e]; + if ((aclent->a_type & ACL_DEFAULT) != 0) + entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_DEFAULT; + else + entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_ACCESS; + ae_id = aclent->a_id; + + switch(aclent->a_type) { + case DEF_USER: + case USER: + ae_name = archive_read_disk_uname(&a->archive, + ae_id); + ae_tag = ARCHIVE_ENTRY_ACL_USER; + break; + case DEF_GROUP: + case GROUP: + ae_name = archive_read_disk_gname(&a->archive, + ae_id); + ae_tag = ARCHIVE_ENTRY_ACL_GROUP; + break; + case DEF_CLASS_OBJ: + case CLASS_OBJ: + ae_tag = ARCHIVE_ENTRY_ACL_MASK; + break; + case DEF_USER_OBJ: + case USER_OBJ: + ae_tag = ARCHIVE_ENTRY_ACL_USER_OBJ; + break; + case DEF_GROUP_OBJ: + case GROUP_OBJ: + ae_tag = ARCHIVE_ENTRY_ACL_GROUP_OBJ; + break; + case DEF_OTHER_OBJ: + case OTHER_OBJ: + ae_tag = ARCHIVE_ENTRY_ACL_OTHER; + break; + default: + /* Unknown tag type, skip */ + continue; + } + + for (i = 0; i < acl_posix_perm_map_size; ++i) { + if ((aclent->a_perm & + acl_posix_perm_map[i].p_perm) != 0) + ae_perm |= acl_posix_perm_map[i].a_perm; + } + } else + return (ARCHIVE_WARN); + + archive_entry_acl_add_entry(entry, entry_acl_type, + ae_perm, ae_tag, ae_id, ae_name); + } + return (ARCHIVE_OK); +} + +static int +set_acl(struct archive *a, int fd, const char *name, + struct archive_acl *abstract_acl, + int ae_requested_type, const char *tname) +{ + aclent_t *aclent; +#if ARCHIVE_ACL_SUNOS_NFS4 + ace_t *ace; +#endif + int cmd, e, r; + void *aclp; + int ret; + int ae_type, ae_permset, ae_tag, ae_id; + int perm_map_size; + const acl_perm_map_t *perm_map; + uid_t ae_uid; + gid_t ae_gid; + const char *ae_name; + int entries; + int i; + + ret = ARCHIVE_OK; + entries = archive_acl_reset(abstract_acl, ae_requested_type); + if (entries == 0) + return (ARCHIVE_OK); + + + switch (ae_requested_type) { + case ARCHIVE_ENTRY_ACL_TYPE_POSIX1E: + cmd = SETACL; + aclp = malloc(entries * sizeof(aclent_t)); + break; +#if ARCHIVE_ACL_SUNOS_NFS4 + case ARCHIVE_ENTRY_ACL_TYPE_NFS4: + cmd = ACE_SETACL; + aclp = malloc(entries * sizeof(ace_t)); + + break; +#endif + default: + errno = ENOENT; + archive_set_error(a, errno, "Unsupported ACL type"); + return (ARCHIVE_FAILED); + } + + if (aclp == NULL) { + archive_set_error(a, errno, + "Can't allocate memory for acl buffer"); + return (ARCHIVE_FAILED); + } + + e = 0; + + while (archive_acl_next(a, abstract_acl, ae_requested_type, &ae_type, + &ae_permset, &ae_tag, &ae_id, &ae_name) == ARCHIVE_OK) { + aclent = NULL; +#if ARCHIVE_ACL_SUNOS_NFS4 + ace = NULL; +#endif + if (cmd == SETACL) { + aclent = &((aclent_t *)aclp)[e]; + aclent->a_id = -1; + aclent->a_type = 0; + aclent->a_perm = 0; + } +#if ARCHIVE_ACL_SUNOS_NFS4 + else { /* cmd == ACE_SETACL */ + ace = &((ace_t *)aclp)[e]; + ace->a_who = -1; + ace->a_access_mask = 0; + ace->a_flags = 0; + } +#endif /* ARCHIVE_ACL_SUNOS_NFS4 */ + + switch (ae_tag) { + case ARCHIVE_ENTRY_ACL_USER: + ae_uid = archive_write_disk_uid(a, ae_name, ae_id); + if (aclent != NULL) { + aclent->a_id = ae_uid; + aclent->a_type |= USER; + } +#if ARCHIVE_ACL_SUNOS_NFS4 + else { + ace->a_who = ae_uid; + } +#endif + break; + case ARCHIVE_ENTRY_ACL_GROUP: + ae_gid = archive_write_disk_gid(a, ae_name, ae_id); + if (aclent != NULL) { + aclent->a_id = ae_gid; + aclent->a_type |= GROUP; + } +#if ARCHIVE_ACL_SUNOS_NFS4 + else { + ace->a_who = ae_gid; + ace->a_flags |= ACE_IDENTIFIER_GROUP; + } +#endif + break; + case ARCHIVE_ENTRY_ACL_USER_OBJ: + if (aclent != NULL) + aclent->a_type |= USER_OBJ; +#if ARCHIVE_ACL_SUNOS_NFS4 + else { + ace->a_flags |= ACE_OWNER; + } +#endif + break; + case ARCHIVE_ENTRY_ACL_GROUP_OBJ: + if (aclent != NULL) + aclent->a_type |= GROUP_OBJ; +#if ARCHIVE_ACL_SUNOS_NFS4 + else { + ace->a_flags |= ACE_GROUP; + ace->a_flags |= ACE_IDENTIFIER_GROUP; + } +#endif + break; + case ARCHIVE_ENTRY_ACL_MASK: + if (aclent != NULL) + aclent->a_type |= CLASS_OBJ; + break; + case ARCHIVE_ENTRY_ACL_OTHER: + if (aclent != NULL) + aclent->a_type |= OTHER_OBJ; + break; +#if ARCHIVE_ACL_SUNOS_NFS4 + case ARCHIVE_ENTRY_ACL_EVERYONE: + if (ace != NULL) + ace->a_flags |= ACE_EVERYONE; + break; +#endif + default: + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "Unsupported ACL tag"); + ret = ARCHIVE_FAILED; + goto exit_free; + } + + r = 0; + switch (ae_type) { +#if ARCHIVE_ACL_SUNOS_NFS4 + case ARCHIVE_ENTRY_ACL_TYPE_ALLOW: + if (ace != NULL) + ace->a_type = ACE_ACCESS_ALLOWED_ACE_TYPE; + else + r = -1; + break; + case ARCHIVE_ENTRY_ACL_TYPE_DENY: + if (ace != NULL) + ace->a_type = ACE_ACCESS_DENIED_ACE_TYPE; + else + r = -1; + break; + case ARCHIVE_ENTRY_ACL_TYPE_AUDIT: + if (ace != NULL) + ace->a_type = ACE_SYSTEM_AUDIT_ACE_TYPE; + else + r = -1; + break; + case ARCHIVE_ENTRY_ACL_TYPE_ALARM: + if (ace != NULL) + ace->a_type = ACE_SYSTEM_ALARM_ACE_TYPE; + else + r = -1; + break; +#endif + case ARCHIVE_ENTRY_ACL_TYPE_ACCESS: + if (aclent == NULL) + r = -1; + break; + case ARCHIVE_ENTRY_ACL_TYPE_DEFAULT: + if (aclent != NULL) + aclent->a_type |= ACL_DEFAULT; + else + r = -1; + break; + default: + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "Unsupported ACL entry type"); + ret = ARCHIVE_FAILED; + goto exit_free; + } + + if (r != 0) { + errno = EINVAL; + archive_set_error(a, errno, + "Failed to set ACL entry type"); + ret = ARCHIVE_FAILED; + goto exit_free; + } + +#if ARCHIVE_ACL_SUNOS_NFS4 + if (ae_requested_type == ARCHIVE_ENTRY_ACL_TYPE_NFS4) { + perm_map_size = acl_nfs4_perm_map_size; + perm_map = acl_nfs4_perm_map; + } else { +#endif + perm_map_size = acl_posix_perm_map_size; + perm_map = acl_posix_perm_map; +#if ARCHIVE_ACL_SUNOS_NFS4 + } +#endif + for (i = 0; i < perm_map_size; ++i) { + if (ae_permset & perm_map[i].a_perm) { +#if ARCHIVE_ACL_SUNOS_NFS4 + if (ae_requested_type == + ARCHIVE_ENTRY_ACL_TYPE_NFS4) + ace->a_access_mask |= + perm_map[i].p_perm; + else +#endif + aclent->a_perm |= perm_map[i].p_perm; + } + } + +#if ARCHIVE_ACL_SUNOS_NFS4 + if (ae_requested_type == ARCHIVE_ENTRY_ACL_TYPE_NFS4) { + for (i = 0; i < acl_nfs4_flag_map_size; ++i) { + if (ae_permset & acl_nfs4_flag_map[i].a_perm) { + ace->a_flags |= + acl_nfs4_flag_map[i].p_perm; + } + } + } +#endif + e++; + } + + /* Try restoring the ACL through 'fd' if we can. */ + if (fd >= 0) { + if (facl(fd, cmd, entries, aclp) == 0) + ret = ARCHIVE_OK; + else { + if (errno == EOPNOTSUPP) { + /* Filesystem doesn't support ACLs */ + ret = ARCHIVE_OK; + } else { + archive_set_error(a, errno, + "Failed to set acl on fd: %s", tname); + ret = ARCHIVE_WARN; + } + } + } else if (acl(name, cmd, entries, aclp) != 0) { + if (errno == EOPNOTSUPP) { + /* Filesystem doesn't support ACLs */ + ret = ARCHIVE_OK; + } else { + archive_set_error(a, errno, "Failed to set acl: %s", + tname); + ret = ARCHIVE_WARN; + } + } +exit_free: + free(aclp); + return (ret); +} + +int +archive_read_disk_entry_setup_acls(struct archive_read_disk *a, + struct archive_entry *entry, int *fd) +{ + const char *accpath; + void *aclp; + int aclcnt; + int r; + + accpath = NULL; + + if (*fd < 0) { + accpath = archive_read_disk_entry_setup_path(a, entry, fd); + if (accpath == NULL) + return (ARCHIVE_WARN); + } + + archive_entry_acl_clear(entry); + + aclp = NULL; + +#if ARCHIVE_ACL_SUNOS_NFS4 + if (*fd >= 0) + aclp = sunacl_get(ACE_GETACL, &aclcnt, *fd, NULL); + else if ((!a->follow_symlinks) + && (archive_entry_filetype(entry) == AE_IFLNK)) + /* We can't get the ACL of a symlink, so we assume it can't + have one. */ + aclp = NULL; + else + aclp = sunacl_get(ACE_GETACL, &aclcnt, 0, accpath); + + if (aclp != NULL && sun_acl_is_trivial(aclp, aclcnt, + archive_entry_mode(entry), 1, S_ISDIR(archive_entry_mode(entry)), + &r) == 0 && r == 1) { + free(aclp); + aclp = NULL; + return (ARCHIVE_OK); + } + + if (aclp != NULL) { + r = translate_acl(a, entry, aclp, aclcnt, + ARCHIVE_ENTRY_ACL_TYPE_NFS4); + free(aclp); + aclp = NULL; + + if (r != ARCHIVE_OK) { + archive_set_error(&a->archive, errno, + "Couldn't translate NFSv4 ACLs"); + } + return (r); + } +#endif /* ARCHIVE_ACL_SUNOS_NFS4 */ + + /* Retrieve POSIX.1e ACLs from file. */ + if (*fd >= 0) + aclp = sunacl_get(GETACL, &aclcnt, *fd, NULL); + else if ((!a->follow_symlinks) + && (archive_entry_filetype(entry) == AE_IFLNK)) + /* We can't get the ACL of a symlink, so we assume it can't + have one. */ + aclp = NULL; + else + aclp = sunacl_get(GETACL, &aclcnt, 0, accpath); + + /* Ignore "trivial" ACLs that just mirror the file mode. */ + if (aclp != NULL && sun_acl_is_trivial(aclp, aclcnt, + archive_entry_mode(entry), 0, S_ISDIR(archive_entry_mode(entry)), + &r) == 0 && r == 1) { + free(aclp); + aclp = NULL; + } + + if (aclp != NULL) + { + r = translate_acl(a, entry, aclp, aclcnt, + ARCHIVE_ENTRY_ACL_TYPE_ACCESS); + free(aclp); + aclp = NULL; + + if (r != ARCHIVE_OK) { + archive_set_error(&a->archive, errno, + "Couldn't translate access ACLs"); + return (r); + } + } + + return (ARCHIVE_OK); +} + +int +archive_write_disk_set_acls(struct archive *a, int fd, const char *name, + struct archive_acl *abstract_acl, __LA_MODE_T mode) +{ + int ret = ARCHIVE_OK; + + (void)mode; /* UNUSED */ + + if ((archive_acl_types(abstract_acl) + & ARCHIVE_ENTRY_ACL_TYPE_POSIX1E) != 0) { + /* Solaris writes POSIX.1e access and default ACLs together */ + ret = set_acl(a, fd, name, abstract_acl, + ARCHIVE_ENTRY_ACL_TYPE_POSIX1E, "posix1e"); + + /* Simultaneous POSIX.1e and NFSv4 is not supported */ + return (ret); + } +#if ARCHIVE_ACL_SUNOS_NFS4 + else if ((archive_acl_types(abstract_acl) & + ARCHIVE_ENTRY_ACL_TYPE_NFS4) != 0) { + ret = set_acl(a, fd, name, abstract_acl, + ARCHIVE_ENTRY_ACL_TYPE_NFS4, "nfs4"); + } +#endif + return (ret); +} +#endif /* ARCHIVE_ACL_SUNOS */ diff --git a/Utilities/cmlibarchive/libarchive/archive_entry.3 b/Utilities/cmlibarchive/libarchive/archive_entry.3 index f5e22af..f75916c 100644 --- a/Utilities/cmlibarchive/libarchive/archive_entry.3 +++ b/Utilities/cmlibarchive/libarchive/archive_entry.3 @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd Feburary 2, 2012 +.Dd February 2, 2012 .Dt ARCHIVE_ENTRY 3 .Os .Sh NAME diff --git a/Utilities/cmlibarchive/libarchive/archive_entry.c b/Utilities/cmlibarchive/libarchive/archive_entry.c index 10eff11..30fb456 100644 --- a/Utilities/cmlibarchive/libarchive/archive_entry.c +++ b/Utilities/cmlibarchive/libarchive/archive_entry.c @@ -401,7 +401,7 @@ archive_entry_fflags_text(struct archive_entry *entry) return (NULL); } -int64_t +la_int64_t archive_entry_gid(struct archive_entry *entry) { return (entry->ae_stat.aest_gid); @@ -502,7 +502,7 @@ _archive_entry_hardlink_l(struct archive_entry *entry, return (archive_mstring_get_mbs_l(&entry->ae_hardlink, p, len, sc)); } -int64_t +la_int64_t archive_entry_ino(struct archive_entry *entry) { return (entry->ae_stat.aest_ino); @@ -514,7 +514,7 @@ archive_entry_ino_is_set(struct archive_entry *entry) return (entry->ae_set & AE_SET_INO); } -int64_t +la_int64_t archive_entry_ino64(struct archive_entry *entry) { return (entry->ae_stat.aest_ino); @@ -627,7 +627,7 @@ archive_entry_rdevminor(struct archive_entry *entry) return minor(entry->ae_stat.aest_rdev); } -int64_t +la_int64_t archive_entry_size(struct archive_entry *entry) { return (entry->ae_stat.aest_size); @@ -715,7 +715,7 @@ _archive_entry_symlink_l(struct archive_entry *entry, return (archive_mstring_get_mbs_l( &entry->ae_symlink, p, len, sc)); } -int64_t +la_int64_t archive_entry_uid(struct archive_entry *entry) { return (entry->ae_stat.aest_uid); @@ -819,7 +819,7 @@ archive_entry_copy_fflags_text_w(struct archive_entry *entry, } void -archive_entry_set_gid(struct archive_entry *entry, int64_t g) +archive_entry_set_gid(struct archive_entry *entry, la_int64_t g) { entry->stat_valid = 0; entry->ae_stat.aest_gid = g; @@ -868,7 +868,7 @@ _archive_entry_copy_gname_l(struct archive_entry *entry, } void -archive_entry_set_ino(struct archive_entry *entry, int64_t ino) +archive_entry_set_ino(struct archive_entry *entry, la_int64_t ino) { entry->stat_valid = 0; entry->ae_set |= AE_SET_INO; @@ -876,7 +876,7 @@ archive_entry_set_ino(struct archive_entry *entry, int64_t ino) } void -archive_entry_set_ino64(struct archive_entry *entry, int64_t ino) +archive_entry_set_ino64(struct archive_entry *entry, la_int64_t ino) { entry->stat_valid = 0; entry->ae_set |= AE_SET_INO; @@ -1209,7 +1209,7 @@ archive_entry_set_rdevminor(struct archive_entry *entry, dev_t m) } void -archive_entry_set_size(struct archive_entry *entry, int64_t s) +archive_entry_set_size(struct archive_entry *entry, la_int64_t s) { entry->stat_valid = 0; entry->ae_stat.aest_size = s; @@ -1306,7 +1306,7 @@ _archive_entry_copy_symlink_l(struct archive_entry *entry, } void -archive_entry_set_uid(struct archive_entry *entry, int64_t u) +archive_entry_set_uid(struct archive_entry *entry, la_int64_t u) { entry->stat_valid = 0; entry->ae_stat.aest_uid = u; @@ -1638,7 +1638,7 @@ _archive_entry_acl_text_l(struct archive_entry *entry, int flags, * SUCH DAMAGE. */ -static struct flag { +static const struct flag { const char *name; const wchar_t *wname; unsigned long set; @@ -1708,6 +1708,9 @@ static struct flag { #ifdef UF_COMPRESSED { "nocompressed",L"nocompressed", UF_COMPRESSED, 0 }, #endif +#ifdef UF_HIDDEN + { "nohidden", L"nohidden", UF_HIDDEN, 0 }, +#endif #if defined(FS_UNRM_FL) { "nouunlink", L"nouunlink", FS_UNRM_FL, 0}, #elif defined(EXT2_UNRM_FL) @@ -1840,7 +1843,7 @@ ae_fflagstostr(unsigned long bitset, unsigned long bitclear) char *string, *dp; const char *sp; unsigned long bits; - struct flag *flag; + const struct flag *flag; size_t length; bits = bitset | bitclear; @@ -1892,7 +1895,7 @@ static const char * ae_strtofflags(const char *s, unsigned long *setp, unsigned long *clrp) { const char *start, *end; - struct flag *flag; + const struct flag *flag; unsigned long set, clear; const char *failed; @@ -1960,7 +1963,7 @@ static const wchar_t * ae_wcstofflags(const wchar_t *s, unsigned long *setp, unsigned long *clrp) { const wchar_t *start, *end; - struct flag *flag; + const struct flag *flag; unsigned long set, clear; const wchar_t *failed; diff --git a/Utilities/cmlibarchive/libarchive/archive_entry.h b/Utilities/cmlibarchive/libarchive/archive_entry.h index 6e0225b..8c8e75a 100644 --- a/Utilities/cmlibarchive/libarchive/archive_entry.h +++ b/Utilities/cmlibarchive/libarchive/archive_entry.h @@ -30,7 +30,7 @@ #define ARCHIVE_ENTRY_H_INCLUDED /* Note: Compiler will complain if this does not match archive.h! */ -#define ARCHIVE_VERSION_NUMBER 3003001 +#define ARCHIVE_VERSION_NUMBER 3003002 /* * Note: archive_entry.h is for use outside of libarchive; the diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_acl.3 b/Utilities/cmlibarchive/libarchive/archive_entry_acl.3 index c5115f7..534dbfa 100644 --- a/Utilities/cmlibarchive/libarchive/archive_entry_acl.3 +++ b/Utilities/cmlibarchive/libarchive/archive_entry_acl.3 @@ -32,7 +32,7 @@ .Nm archive_entry_acl_clear , .Nm archive_entry_acl_count , .Nm archive_entry_acl_from_text , -.Nm archive_entry_acl_from_text_w, +.Nm archive_entry_acl_from_text_w , .Nm archive_entry_acl_next , .Nm archive_entry_acl_next_w , .Nm archive_entry_acl_reset , @@ -267,7 +267,7 @@ Only inherit, do not apply the permission on the directory itself. .It Dv ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT ( Sy n ) Do not propagate inherit flags. Only first-level entries inherit ACLs. .It Dv ARCHIVE_ENTRY_ACL_ENTRY_SUCCESSFUL_ACCESS ( Sy S ) -Trigger alarm or audit on succesful access. +Trigger alarm or audit on successful access. .It Dv ARCHIVE_ENTRY_ACL_ENTRY_FAILED_ACCESS ( Sy F ) Trigger alarm or audit on failed access. .It Dv ARCHIVE_ENTRY_ACL_ENTRY_INHERITED ( Sy I ) @@ -279,7 +279,7 @@ and .Fn archive_entry_acl_add_entry_w add a single ACL entry. For the access ACL and non-extended principals, the classic Unix permissions -are updated. An archive enry cannot contain both POSIX.1e and NFSv4 ACL +are updated. An archive entry cannot contain both POSIX.1e and NFSv4 ACL entries. .Pp .Fn archive_entry_acl_clear @@ -303,7 +303,7 @@ for POSIX.1e ACLs and for NFSv4 ACLs. For POSIX.1e ACLs if .Dv ARCHIVE_ENTRY_ACL_TYPE_ACCESS is included and at least one extended ACL entry is found, -the three non-extened ACLs are added. +the three non-extended ACLs are added. .Pp .Fn archive_entry_acl_from_text and @@ -367,7 +367,7 @@ and .Fn archive_entry_acl_to_text_w convert the ACL entries for the given type into a .Pq wide -string of ACL entries separated by newline. If the the pointer +string of ACL entries separated by newline. If the pointer .Fa len_p is not NULL, then the function shall return the length of the string .Pq not including the NULL terminator diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_paths.3 b/Utilities/cmlibarchive/libarchive/archive_entry_paths.3 index fd22cf7..f647212 100644 --- a/Utilities/cmlibarchive/libarchive/archive_entry_paths.3 +++ b/Utilities/cmlibarchive/libarchive/archive_entry_paths.3 @@ -31,25 +31,25 @@ .Nm archive_entry_set_hardlink , .Nm archive_entry_copy_hardlink , .Nm archive_entry_copy_hardlink_w , -.Nm archve_entry_update_hardlink_utf8 , +.Nm archive_entry_update_hardlink_utf8 , .Nm archive_entry_set_link , .Nm archive_entry_copy_link , .Nm archive_entry_copy_link_w , -.Nm archve_entry_update_link_utf8 , +.Nm archive_entry_update_link_utf8 , .Nm archive_entry_pathname , .Nm archive_entry_pathname_w , .Nm archive_entry_set_pathname , .Nm archive_entry_copy_pathname , .Nm archive_entry_copy_pathname_w , -.Nm archve_entry_update_pathname_utf8 , +.Nm archive_entry_update_pathname_utf8 , .Nm archive_entry_sourcepath , .Nm archive_entry_copy_sourcepath , -.Nm archive_entry_symlink, -.Nm archive_entry_symlink_w, +.Nm archive_entry_symlink , +.Nm archive_entry_symlink_w , .Nm archive_entry_set_symlink , .Nm archive_entry_copy_symlink , .Nm archive_entry_copy_symlink_w , -.Nm archve_entry_update_symlink_utf8 +.Nm archive_entry_update_symlink_utf8 .Nd functions for manipulating path names in archive entry descriptions .Sh LIBRARY Streaming Archive Library (libarchive, -larchive) diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_perms.3 b/Utilities/cmlibarchive/libarchive/archive_entry_perms.3 index 340c5ea..aae3648 100644 --- a/Utilities/cmlibarchive/libarchive/archive_entry_perms.3 +++ b/Utilities/cmlibarchive/libarchive/archive_entry_perms.3 @@ -34,8 +34,8 @@ .Nm archive_entry_perm , .Nm archive_entry_set_perm , .Nm archive_entry_strmode , -.Nm archive_entry_uname -.Nm archive_entry_uname_w +.Nm archive_entry_uname , +.Nm archive_entry_uname_w , .Nm archive_entry_set_uname , .Nm archive_entry_copy_uname , .Nm archive_entry_copy_uname_w , diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_sparse.c b/Utilities/cmlibarchive/libarchive/archive_entry_sparse.c index fed74f5..74917b3 100644 --- a/Utilities/cmlibarchive/libarchive/archive_entry_sparse.c +++ b/Utilities/cmlibarchive/libarchive/archive_entry_sparse.c @@ -51,7 +51,7 @@ archive_entry_sparse_clear(struct archive_entry *entry) void archive_entry_sparse_add_entry(struct archive_entry *entry, - int64_t offset, int64_t length) + la_int64_t offset, la_int64_t length) { struct ae_sparse *sp; @@ -135,7 +135,7 @@ archive_entry_sparse_reset(struct archive_entry * entry) int archive_entry_sparse_next(struct archive_entry * entry, - int64_t *offset, int64_t *length) + la_int64_t *offset, la_int64_t *length) { if (entry->sparse_p) { *offset = entry->sparse_p->offset; diff --git a/Utilities/cmlibarchive/libarchive/archive_getdate.c b/Utilities/cmlibarchive/libarchive/archive_getdate.c index beb0cba..030c083 100644 --- a/Utilities/cmlibarchive/libarchive/archive_getdate.c +++ b/Utilities/cmlibarchive/libarchive/archive_getdate.c @@ -691,7 +691,7 @@ Convert(time_t Month, time_t Day, time_t Year, time_t Hours, time_t Minutes, time_t Seconds, time_t Timezone, enum DSTMODE DSTmode) { - static int DaysInMonth[12] = { + signed char DaysInMonth[12] = { 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; time_t Julian; diff --git a/Utilities/cmlibarchive/libarchive/archive_openssl_hmac_private.h b/Utilities/cmlibarchive/libarchive/archive_openssl_hmac_private.h index 2deeb5f..59f95b8 100644 --- a/Utilities/cmlibarchive/libarchive/archive_openssl_hmac_private.h +++ b/Utilities/cmlibarchive/libarchive/archive_openssl_hmac_private.h @@ -28,7 +28,7 @@ #include <openssl/hmac.h> #include <openssl/opensslv.h> -#if OPENSSL_VERSION_NUMBER < 0x10100000L +#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER) #include <stdlib.h> /* malloc, free */ #include <string.h> /* memset */ static inline HMAC_CTX *HMAC_CTX_new(void) diff --git a/Utilities/cmlibarchive/libarchive/archive_pack_dev.c b/Utilities/cmlibarchive/libarchive/archive_pack_dev.c index 6b7b472..098881b 100644 --- a/Utilities/cmlibarchive/libarchive/archive_pack_dev.c +++ b/Utilities/cmlibarchive/libarchive/archive_pack_dev.c @@ -280,7 +280,7 @@ pack_bsdos(int n, unsigned long numbers[], const char **error) /* list of formats and pack functions */ /* this list must be sorted lexically */ -static struct format { +static const struct format { const char *name; pack_t *pack; } formats[] = { diff --git a/Utilities/cmlibarchive/libarchive/archive_platform.h b/Utilities/cmlibarchive/libarchive/archive_platform.h index 47d144b..4cb8f81 100644 --- a/Utilities/cmlibarchive/libarchive/archive_platform.h +++ b/Utilities/cmlibarchive/libarchive/archive_platform.h @@ -148,32 +148,6 @@ #endif /* - * If this platform has <sys/acl.h>, acl_create(), acl_init(), - * acl_set_file(), and ACL_USER, we assume it has the rest of the - * POSIX.1e draft functions used in archive_read_extract.c. - */ -#if HAVE_SYS_ACL_H && HAVE_ACL_CREATE_ENTRY && HAVE_ACL_INIT && HAVE_ACL_SET_FILE -#if HAVE_ACL_USER -#define HAVE_POSIX_ACL 1 -#elif HAVE_ACL_TYPE_EXTENDED -#define HAVE_DARWIN_ACL 1 -#endif -#endif - -/* - * If this platform has <sys/acl.h>, acl_get(), facl_get(), acl_set(), - * facl_set() and types aclent_t and ace_t it uses Solaris-style ACL functions - */ -#if HAVE_SYS_ACL_H && HAVE_ACL_GET && HAVE_FACL_GET && HAVE_ACL_SET && HAVE_FACL_SET && HAVE_ACLENT_T && HAVE_ACE_T -#define HAVE_SUN_ACL 1 -#endif - -/* Define if platform supports NFSv4 ACLs */ -#if (HAVE_POSIX_ACL && HAVE_ACL_TYPE_NFS4) || HAVE_SUN_ACL || HAVE_DARWIN_ACL -#define HAVE_NFS4_ACL 1 -#endif - -/* * If we can't restore metadata using a file descriptor, then * for compatibility's sake, close files before trying to restore metadata. */ diff --git a/Utilities/cmlibarchive/libarchive/archive_platform_acl.h b/Utilities/cmlibarchive/libarchive/archive_platform_acl.h new file mode 100644 index 0000000..3498f78 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_platform_acl.h @@ -0,0 +1,49 @@ +/*- + * Copyright (c) 2017 Martin Matuska + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* !!ONLY FOR USE INTERNALLY TO LIBARCHIVE!! */ + +#ifndef ARCHIVE_PLATFORM_ACL_H_INCLUDED +#define ARCHIVE_PLATFORM_ACL_H_INCLUDED + +/* + * Determine what ACL types are supported + */ +#if ARCHIVE_ACL_FREEBSD || ARCHIVE_ACL_SUNOS || ARCHIVE_ACL_LIBACL +#define ARCHIVE_ACL_POSIX1E 1 +#endif + +#if ARCHIVE_ACL_FREEBSD_NFS4 || ARCHIVE_ACL_SUNOS_NFS4 || \ + ARCHIVE_ACL_DARWIN || ARCHIVE_ACL_LIBRICHACL +#define ARCHIVE_ACL_NFS4 1 +#endif + +#if ARCHIVE_ACL_POSIX1E || ARCHIVE_ACL_NFS4 +#define ARCHIVE_ACL_SUPPORT 1 +#endif + +#endif /* ARCHIVE_PLATFORM_ACL_H_INCLUDED */ diff --git a/Utilities/cmlibarchive/libarchive/archive_platform_xattr.h b/Utilities/cmlibarchive/libarchive/archive_platform_xattr.h new file mode 100644 index 0000000..4edfecf --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_platform_xattr.h @@ -0,0 +1,41 @@ +/*- + * Copyright (c) 2017 Martin Matuska + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* !!ONLY FOR USE INTERNALLY TO LIBARCHIVE!! */ + +#ifndef ARCHIVE_PLATFORM_XATTR_H_INCLUDED +#define ARCHIVE_PLATFORM_XATTR_H_INCLUDED + +/* + * Determine if we support extended attributes + */ +#if ARCHIVE_XATTR_LINUX || ARCHIVE_XATTR_DARWIN || ARCHIVE_XATTR_FREEBSD || \ + ARCHIVE_XATTR_AIX +#define ARCHIVE_XATTR_SUPPORT 1 +#endif + +#endif /* ARCHIVE_PLATFORM_XATTR_H_INCLUDED */ diff --git a/Utilities/cmlibarchive/libarchive/archive_random.c b/Utilities/cmlibarchive/libarchive/archive_random.c index 90ee7c6..65ea691 100644 --- a/Utilities/cmlibarchive/libarchive/archive_random.c +++ b/Utilities/cmlibarchive/libarchive/archive_random.c @@ -221,7 +221,10 @@ arc4_stir(void) /* * Discard early keystream, as per recommendations in: * "(Not So) Random Shuffles of RC4" by Ilya Mironov. + * As per the Network Operations Division, cryptographic requirements + * published on wikileaks on March 2017. */ + for (i = 0; i < 3072; i++) (void)arc4_getbyte(); arc4_count = 1600000; diff --git a/Utilities/cmlibarchive/libarchive/archive_read.c b/Utilities/cmlibarchive/libarchive/archive_read.c index d1feceb..a642a33 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read.c +++ b/Utilities/cmlibarchive/libarchive/archive_read.c @@ -881,7 +881,8 @@ archive_read_data(struct archive *_a, void *buff, size_t s) len = a->read_data_remaining; if (len > s) len = s; - memcpy(dest, a->read_data_block, len); + if (len) + memcpy(dest, a->read_data_block, len); s -= len; a->read_data_block += len; a->read_data_remaining -= len; diff --git a/Utilities/cmlibarchive/libarchive/archive_read_disk.3 b/Utilities/cmlibarchive/libarchive/archive_read_disk.3 index 2a5c130..027f63c 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_disk.3 +++ b/Utilities/cmlibarchive/libarchive/archive_read_disk.3 @@ -24,11 +24,12 @@ .\" .\" $FreeBSD$ .\" -.Dd December 30, 2016 +.Dd April 3, 2017 .Dt ARCHIVE_READ_DISK 3 .Os .Sh NAME .Nm archive_read_disk_new , +.Nm archive_read_disk_set_behavior , .Nm archive_read_disk_set_symlink_logical , .Nm archive_read_disk_set_symlink_physical , .Nm archive_read_disk_set_symlink_hybrid , @@ -37,10 +38,7 @@ .Nm archive_read_disk_uname , .Nm archive_read_disk_set_uname_lookup , .Nm archive_read_disk_set_gname_lookup , -.Nm archive_read_disk_set_standard_lookup , -.Nm archive_read_close , -.Nm archive_read_finish , -.Nm archive_read_free +.Nm archive_read_disk_set_standard_lookup .Nd functions for reading objects from disk .Sh LIBRARY Streaming Archive Library (libarchive, -larchive) @@ -49,6 +47,8 @@ Streaming Archive Library (libarchive, -larchive) .Ft struct archive * .Fn archive_read_disk_new "void" .Ft int +.Fn archive_read_disk_set_behavior "struct archive *" "int" +.Ft int .Fn archive_read_disk_set_symlink_logical "struct archive *" .Ft int .Fn archive_read_disk_set_symlink_physical "struct archive *" @@ -81,12 +81,6 @@ Streaming Archive Library (libarchive, -larchive) .Fa "int fd" .Fa "const struct stat *" .Fc -.Ft int -.Fn archive_read_close "struct archive *" -.Ft int -.Fn archive_read_finish "struct archive *" -.Ft int -.Fn archive_read_free "struct archive *" .Sh DESCRIPTION These functions provide an API for reading information about objects on disk. @@ -98,6 +92,51 @@ objects. Allocates and initializes a .Tn struct archive object suitable for reading object information from disk. +.It Fn archive_read_disk_set_behavior +Configures various behavior options when reading entries from disk. +The flags field consists of a bitwise OR of one or more of the +following values: +.Bl -tag -compact -width "indent" +.It Cm ARCHIVE_READDISK_HONOR_NODUMP +Skip files and directories with the nodump file attribute (file flag) set. +By default, the nodump file atrribute is ignored. +.It Cm ARCHIVE_READDISK_MAC_COPYFILE +Mac OS X specific. Read metadata (ACLs and extended attributes) with +.Xr copyfile 3 . +By default, metadata is read using +.Xr copyfile 3 . +.It Cm ARCHIVE_READDISK_NO_ACL +Do not read Access Control Lists. +By default, ACLs are read from disk. +.It Cm ARCHIVE_READDISK_NO_FFLAGS +Do not read file attributes (file flags). +By default, file attributes are read from disk. +See +.Xr chattr 1 +.Pq Linux +or +.Xr chflags 1 +.Pq FreeBSD, Mac OS X +for more information on file attributes. +.It Cm ARCHIVE_READDISK_NO_TRAVERSE_MOUNTS +Do not traverse mount points. +By defaut, moint points are traversed. +.It Cm ARCHIVE_READDISK_NO_XATTR +Do not read extended file attributes (xattrs). +By default, extended file attributes are read from disk. +See +.Xr xattr 7 +.Pq Linux , +.Xr xattr 2 +.Pq Mac OS X , +or +.Xr getextattr 8 +.Pq FreeBSD +for more information on extended file attributes. +.It Cm ARCHIVE_READDISK_RESTORE_ATIME +Restore access time of traversed files. +By default, access time of traversed files is not restored. +.El .It Xo .Fn archive_read_disk_set_symlink_logical , .Fn archive_read_disk_set_symlink_physical , @@ -181,17 +220,6 @@ using the currently registered lookup functions above. This affects the file ownership fields and ACL values in the .Tn struct archive_entry object. -.It Fn archive_read_close -Does nothing for -.Tn archive_read_disk -handles. -.It Fn archive_read_finish -This is a deprecated synonym for -.Fn archive_read_free . -.It Fn archive_read_free -Invokes -.Fn archive_read_close -if it was not invoked manually, then releases all resources. .El More information about the .Va struct archive diff --git a/Utilities/cmlibarchive/libarchive/archive_read_disk_entry_from_file.c b/Utilities/cmlibarchive/libarchive/archive_read_disk_entry_from_file.c index b2f1d17..548ba89 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_disk_entry_from_file.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_disk_entry_from_file.c @@ -26,23 +26,14 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_disk_entry_from_file.c 201084 2009-12-28 02:14:09Z kientzle $"); +__FBSDID("$FreeBSD"); /* This is the tree-walking code for POSIX systems. */ #if !defined(_WIN32) || defined(__CYGWIN__) #ifdef HAVE_SYS_TYPES_H -/* Mac OSX requires sys/types.h before sys/acl.h. */ #include <sys/types.h> #endif -#ifdef HAVE_SYS_ACL_H -#include <sys/acl.h> -#endif -#ifdef HAVE_DARWIN_ACL -#include <membership.h> -#include <grp.h> -#include <pwd.h> -#endif #ifdef HAVE_SYS_EXTATTR_H #include <sys/extattr.h> #endif @@ -63,9 +54,6 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_read_disk_entry_from_file.c 2010 #ifdef HAVE_SYS_EA_H #include <sys/ea.h> #endif -#ifdef HAVE_ACL_LIBACL_H -#include <acl/libacl.h> -#endif #ifdef HAVE_COPYFILE_H #include <copyfile.h> #endif @@ -113,27 +101,6 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_read_disk_entry_from_file.c 2010 #define O_CLOEXEC 0 #endif -/* - * Linux and FreeBSD plug this obvious hole in POSIX.1e in - * different ways. - */ -#if HAVE_ACL_GET_PERM -#define ACL_GET_PERM acl_get_perm -#elif HAVE_ACL_GET_PERM_NP -#define ACL_GET_PERM acl_get_perm_np -#endif - -/* NFSv4 platform ACL type */ -#if HAVE_SUN_ACL -#define ARCHIVE_PLATFORM_ACL_TYPE_NFS4 ACE_T -#elif HAVE_DARWIN_ACL -#define ARCHIVE_PLATFORM_ACL_TYPE_NFS4 ACL_TYPE_EXTENDED -#elif HAVE_ACL_TYPE_NFS4 -#define ARCHIVE_PLATFORM_ACL_TYPE_NFS4 ACL_TYPE_NFS4 -#endif - -static int setup_acls(struct archive_read_disk *, - struct archive_entry *, int *fd); static int setup_mac_metadata(struct archive_read_disk *, struct archive_entry *, int *fd); static int setup_xattrs(struct archive_read_disk *, @@ -145,6 +112,45 @@ static int setup_sparse_fiemap(struct archive_read_disk *, struct archive_entry *, int *fd); #endif +#if !ARCHIVE_ACL_SUPPORT +int +archive_read_disk_entry_setup_acls(struct archive_read_disk *a, + struct archive_entry *entry, int *fd) +{ + (void)a; /* UNUSED */ + (void)entry; /* UNUSED */ + (void)fd; /* UNUSED */ + return (ARCHIVE_OK); +} +#endif + +/* + * Enter working directory and return working pathname of archive_entry. + * If a pointer to an integer is provided and its value is below zero + * open a file descriptor on this pahtname. + */ +const char * +archive_read_disk_entry_setup_path(struct archive_read_disk *a, + struct archive_entry *entry, int *fd) +{ + const char *path; + + path = archive_entry_sourcepath(entry); + + if (path == NULL || (a->tree != NULL && + a->tree_enter_working_dir(a->tree) != 0)) + path = archive_entry_pathname(entry); + if (path == NULL) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Couldn't determine path"); + } else if (fd != NULL && *fd < 0 && a->tree != NULL && + (a->follow_symlinks || archive_entry_filetype(entry) != AE_IFLNK)) { + *fd = a->open_on_current_dir(a->tree, path, + O_RDONLY | O_NONBLOCK); + } + return (path); +} + int archive_read_disk_entry_from_file(struct archive *_a, struct archive_entry *entry, @@ -279,7 +285,7 @@ archive_read_disk_entry_from_file(struct archive *_a, r = 0; if ((a->flags & ARCHIVE_READDISK_NO_ACL) == 0) - r = setup_acls(a, entry, &fd); + r = archive_read_disk_entry_setup_acls(a, entry, &fd); if ((a->flags & ARCHIVE_READDISK_NO_XATTR) == 0) { r1 = setup_xattrs(a, entry, &fd); if (r1 < r) @@ -328,19 +334,10 @@ setup_mac_metadata(struct archive_read_disk *a, struct archive_string tempfile; (void)fd; /* UNUSED */ - name = archive_entry_sourcepath(entry); + + name = archive_read_disk_entry_setup_path(a, entry, NULL); if (name == NULL) - name = archive_entry_pathname(entry); - else if (a->tree != NULL && a->tree_enter_working_dir(a->tree) != 0) { - archive_set_error(&a->archive, errno, - "Can't change dir to read extended attributes"); - return (ARCHIVE_FAILED); - } - if (name == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Can't open file to read extended attributes: No name"); return (ARCHIVE_WARN); - } /* Short-circuit if there's nothing to do. */ have_attrs = copyfile(name, NULL, 0, copyfile_flags | COPYFILE_CHECK); @@ -426,996 +423,10 @@ setup_mac_metadata(struct archive_read_disk *a, } #endif -#if HAVE_DARWIN_ACL -static int translate_guid(struct archive *, acl_entry_t, - int *, int *, const char **); - -static void add_trivial_nfs4_acl(struct archive_entry *); -#endif - -#if HAVE_SUN_ACL -static int -sun_acl_is_trivial(acl_t *, mode_t, int *trivialp); -#endif - -#if HAVE_POSIX_ACL || HAVE_NFS4_ACL -static int translate_acl(struct archive_read_disk *a, - struct archive_entry *entry, -#if HAVE_SUN_ACL - acl_t *acl, -#else - acl_t acl, -#endif - int archive_entry_acl_type); - -static int -setup_acls(struct archive_read_disk *a, - struct archive_entry *entry, int *fd) -{ - const char *accpath; -#if HAVE_SUN_ACL - acl_t *acl; -#else - acl_t acl; -#endif - int r; - - accpath = NULL; - -#if HAVE_SUN_ACL || HAVE_DARWIN_ACL || HAVE_ACL_GET_FD_NP - if (*fd < 0) -#else - /* For default ACLs on Linux we need reachable accpath */ - if (*fd < 0 || S_ISDIR(archive_entry_mode(entry))) -#endif - { - accpath = archive_entry_sourcepath(entry); - if (accpath == NULL || (a->tree != NULL && - a->tree_enter_working_dir(a->tree) != 0)) - accpath = archive_entry_pathname(entry); - if (accpath == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Couldn't determine file path to read ACLs"); - return (ARCHIVE_WARN); - } - if (a->tree != NULL && -#if !HAVE_SUN_ACL && !HAVE_DARWIN_ACL && !HAVE_ACL_GET_FD_NP - *fd < 0 && -#endif - (a->follow_symlinks || - archive_entry_filetype(entry) != AE_IFLNK)) { - *fd = a->open_on_current_dir(a->tree, - accpath, O_RDONLY | O_NONBLOCK); - } - } - - archive_entry_acl_clear(entry); - - acl = NULL; - -#if HAVE_NFS4_ACL - /* Try NFSv4 ACL first. */ - if (*fd >= 0) -#if HAVE_SUN_ACL - /* Solaris reads both POSIX.1e and NFSv4 ACL here */ - facl_get(*fd, 0, &acl); -#elif HAVE_ACL_GET_FD_NP - acl = acl_get_fd_np(*fd, ARCHIVE_PLATFORM_ACL_TYPE_NFS4); -#else - acl = acl_get_fd(*fd); -#endif -#if HAVE_ACL_GET_LINK_NP - else if (!a->follow_symlinks) - acl = acl_get_link_np(accpath, ARCHIVE_PLATFORM_ACL_TYPE_NFS4); -#else - else if ((!a->follow_symlinks) - && (archive_entry_filetype(entry) == AE_IFLNK)) - /* We can't get the ACL of a symlink, so we assume it can't - have one. */ - acl = NULL; -#endif - else -#if HAVE_SUN_ACL - /* Solaris reads both POSIX.1e and NFSv4 ACLs here */ - acl_get(accpath, 0, &acl); -#else - acl = acl_get_file(accpath, ARCHIVE_PLATFORM_ACL_TYPE_NFS4); -#endif - - -#if HAVE_ACL_IS_TRIVIAL_NP || HAVE_SUN_ACL - /* Ignore "trivial" ACLs that just mirror the file mode. */ - if (acl != NULL) { -#if HAVE_SUN_ACL - if (sun_acl_is_trivial(acl, archive_entry_mode(entry), - &r) == 0 && r == 1) -#elif HAVE_ACL_IS_TRIVIAL_NP - if (acl_is_trivial_np(acl, &r) == 0 && r == 1) -#endif - { - acl_free(acl); - acl = NULL; - /* - * Simultaneous NFSv4 and POSIX.1e ACLs for the same - * entry are not allowed, so we should return here - */ - return (ARCHIVE_OK); - } - } -#endif /* HAVE_ACL_IS_TRIVIAL_NP || HAVE_SUN_ACL */ - if (acl != NULL) { - r = translate_acl(a, entry, acl, ARCHIVE_ENTRY_ACL_TYPE_NFS4); - acl_free(acl); - if (r != ARCHIVE_OK) { - archive_set_error(&a->archive, errno, - "Couldn't translate " -#if !HAVE_SUN_ACL - "NFSv4 " -#endif - "ACLs"); - } -#if HAVE_DARWIN_ACL - /* - * Because Mac OS doesn't support owner@, group@ and everyone@ - * ACLs we need to add NFSv4 ACLs mirroring the file mode to - * the archive entry. Otherwise extraction on non-Mac platforms - * would lead to an invalid file mode. - */ - if ((archive_entry_acl_types(entry) & - ARCHIVE_ENTRY_ACL_TYPE_NFS4) != 0) - add_trivial_nfs4_acl(entry); -#endif - return (r); - } -#endif /* HAVE_NFS4_ACL */ - -#if HAVE_POSIX_ACL - /* This code path is skipped on MacOS and Solaris */ +#if ARCHIVE_XATTR_LINUX || ARCHIVE_XATTR_DARWIN || ARCHIVE_XATTR_AIX - /* Retrieve access ACL from file. */ - if (*fd >= 0) - acl = acl_get_fd(*fd); -#if HAVE_ACL_GET_LINK_NP - else if (!a->follow_symlinks) - acl = acl_get_link_np(accpath, ACL_TYPE_ACCESS); -#else - else if ((!a->follow_symlinks) - && (archive_entry_filetype(entry) == AE_IFLNK)) - /* We can't get the ACL of a symlink, so we assume it can't - have one. */ - acl = NULL; -#endif - else - acl = acl_get_file(accpath, ACL_TYPE_ACCESS); - -#if HAVE_ACL_IS_TRIVIAL_NP - /* Ignore "trivial" ACLs that just mirror the file mode. */ - if (acl != NULL && acl_is_trivial_np(acl, &r) == 0) { - if (r) { - acl_free(acl); - acl = NULL; - } - } -#endif - - if (acl != NULL) { - r = translate_acl(a, entry, acl, ARCHIVE_ENTRY_ACL_TYPE_ACCESS); - acl_free(acl); - acl = NULL; - if (r != ARCHIVE_OK) { - archive_set_error(&a->archive, errno, - "Couldn't translate access ACLs"); - return (r); - } - } - - /* Only directories can have default ACLs. */ - if (S_ISDIR(archive_entry_mode(entry))) { -#if HAVE_ACL_GET_FD_NP - if (*fd >= 0) - acl = acl_get_fd_np(*fd, ACL_TYPE_DEFAULT); - else -#endif - acl = acl_get_file(accpath, ACL_TYPE_DEFAULT); - if (acl != NULL) { - r = translate_acl(a, entry, acl, - ARCHIVE_ENTRY_ACL_TYPE_DEFAULT); - acl_free(acl); - if (r != ARCHIVE_OK) { - archive_set_error(&a->archive, errno, - "Couldn't translate default ACLs"); - return (r); - } - } - } -#endif /* HAVE_POSIX_ACL */ - return (ARCHIVE_OK); -} - -/* - * Translate system ACL permissions into libarchive internal structure - */ -static const struct { - const int archive_perm; - const int platform_perm; -} acl_perm_map[] = { -#if HAVE_SUN_ACL /* Solaris NFSv4 ACL permissions */ - {ARCHIVE_ENTRY_ACL_EXECUTE, ACE_EXECUTE}, - {ARCHIVE_ENTRY_ACL_READ_DATA, ACE_READ_DATA}, - {ARCHIVE_ENTRY_ACL_LIST_DIRECTORY, ACE_LIST_DIRECTORY}, - {ARCHIVE_ENTRY_ACL_WRITE_DATA, ACE_WRITE_DATA}, - {ARCHIVE_ENTRY_ACL_ADD_FILE, ACE_ADD_FILE}, - {ARCHIVE_ENTRY_ACL_APPEND_DATA, ACE_APPEND_DATA}, - {ARCHIVE_ENTRY_ACL_ADD_SUBDIRECTORY, ACE_ADD_SUBDIRECTORY}, - {ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS, ACE_READ_NAMED_ATTRS}, - {ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS, ACE_WRITE_NAMED_ATTRS}, - {ARCHIVE_ENTRY_ACL_DELETE_CHILD, ACE_DELETE_CHILD}, - {ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES, ACE_READ_ATTRIBUTES}, - {ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES, ACE_WRITE_ATTRIBUTES}, - {ARCHIVE_ENTRY_ACL_DELETE, ACE_DELETE}, - {ARCHIVE_ENTRY_ACL_READ_ACL, ACE_READ_ACL}, - {ARCHIVE_ENTRY_ACL_WRITE_ACL, ACE_WRITE_ACL}, - {ARCHIVE_ENTRY_ACL_WRITE_OWNER, ACE_WRITE_OWNER}, - {ARCHIVE_ENTRY_ACL_SYNCHRONIZE, ACE_SYNCHRONIZE} -#elif HAVE_DARWIN_ACL /* MacOS ACL permissions */ - {ARCHIVE_ENTRY_ACL_READ_DATA, ACL_READ_DATA}, - {ARCHIVE_ENTRY_ACL_LIST_DIRECTORY, ACL_LIST_DIRECTORY}, - {ARCHIVE_ENTRY_ACL_WRITE_DATA, ACL_WRITE_DATA}, - {ARCHIVE_ENTRY_ACL_ADD_FILE, ACL_ADD_FILE}, - {ARCHIVE_ENTRY_ACL_EXECUTE, ACL_EXECUTE}, - {ARCHIVE_ENTRY_ACL_DELETE, ACL_DELETE}, - {ARCHIVE_ENTRY_ACL_APPEND_DATA, ACL_APPEND_DATA}, - {ARCHIVE_ENTRY_ACL_ADD_SUBDIRECTORY, ACL_ADD_SUBDIRECTORY}, - {ARCHIVE_ENTRY_ACL_DELETE_CHILD, ACL_DELETE_CHILD}, - {ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES, ACL_READ_ATTRIBUTES}, - {ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES, ACL_WRITE_ATTRIBUTES}, - {ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS, ACL_READ_EXTATTRIBUTES}, - {ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS, ACL_WRITE_EXTATTRIBUTES}, - {ARCHIVE_ENTRY_ACL_READ_ACL, ACL_READ_SECURITY}, - {ARCHIVE_ENTRY_ACL_WRITE_ACL, ACL_WRITE_SECURITY}, - {ARCHIVE_ENTRY_ACL_WRITE_OWNER, ACL_CHANGE_OWNER}, - {ARCHIVE_ENTRY_ACL_SYNCHRONIZE, ACL_SYNCHRONIZE} -#else /* POSIX.1e ACL permissions */ - {ARCHIVE_ENTRY_ACL_EXECUTE, ACL_EXECUTE}, - {ARCHIVE_ENTRY_ACL_WRITE, ACL_WRITE}, - {ARCHIVE_ENTRY_ACL_READ, ACL_READ}, -#if HAVE_ACL_TYPE_NFS4 /* FreeBSD NFSv4 ACL permissions */ - {ARCHIVE_ENTRY_ACL_READ_DATA, ACL_READ_DATA}, - {ARCHIVE_ENTRY_ACL_LIST_DIRECTORY, ACL_LIST_DIRECTORY}, - {ARCHIVE_ENTRY_ACL_WRITE_DATA, ACL_WRITE_DATA}, - {ARCHIVE_ENTRY_ACL_ADD_FILE, ACL_ADD_FILE}, - {ARCHIVE_ENTRY_ACL_APPEND_DATA, ACL_APPEND_DATA}, - {ARCHIVE_ENTRY_ACL_ADD_SUBDIRECTORY, ACL_ADD_SUBDIRECTORY}, - {ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS, ACL_READ_NAMED_ATTRS}, - {ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS, ACL_WRITE_NAMED_ATTRS}, - {ARCHIVE_ENTRY_ACL_DELETE_CHILD, ACL_DELETE_CHILD}, - {ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES, ACL_READ_ATTRIBUTES}, - {ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES, ACL_WRITE_ATTRIBUTES}, - {ARCHIVE_ENTRY_ACL_DELETE, ACL_DELETE}, - {ARCHIVE_ENTRY_ACL_READ_ACL, ACL_READ_ACL}, - {ARCHIVE_ENTRY_ACL_WRITE_ACL, ACL_WRITE_ACL}, - {ARCHIVE_ENTRY_ACL_WRITE_OWNER, ACL_WRITE_OWNER}, - {ARCHIVE_ENTRY_ACL_SYNCHRONIZE, ACL_SYNCHRONIZE} -#endif -#endif /* !HAVE_SUN_ACL && !HAVE_DARWIN_ACL */ -}; - -#if HAVE_NFS4_ACL -/* - * Translate system NFSv4 inheritance flags into libarchive internal structure - */ -static const struct { - const int archive_inherit; - const int platform_inherit; -} acl_inherit_map[] = { -#if HAVE_SUN_ACL /* Solaris ACL inheritance flags */ - {ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT, ACE_FILE_INHERIT_ACE}, - {ARCHIVE_ENTRY_ACL_ENTRY_DIRECTORY_INHERIT, ACE_DIRECTORY_INHERIT_ACE}, - {ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT, ACE_NO_PROPAGATE_INHERIT_ACE}, - {ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY, ACE_INHERIT_ONLY_ACE}, - {ARCHIVE_ENTRY_ACL_ENTRY_SUCCESSFUL_ACCESS, ACE_SUCCESSFUL_ACCESS_ACE_FLAG}, - {ARCHIVE_ENTRY_ACL_ENTRY_FAILED_ACCESS, ACE_FAILED_ACCESS_ACE_FLAG}, - {ARCHIVE_ENTRY_ACL_ENTRY_INHERITED, ACE_INHERITED_ACE} -#elif HAVE_DARWIN_ACL /* MacOS NFSv4 inheritance flags */ - {ARCHIVE_ENTRY_ACL_ENTRY_INHERITED, ACL_ENTRY_INHERITED}, - {ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT, ACL_ENTRY_FILE_INHERIT}, - {ARCHIVE_ENTRY_ACL_ENTRY_DIRECTORY_INHERIT, ACL_ENTRY_DIRECTORY_INHERIT}, - {ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT, ACL_ENTRY_LIMIT_INHERIT}, - {ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY, ACL_ENTRY_ONLY_INHERIT} -#else /* FreeBSD NFSv4 ACL inheritance flags */ - {ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT, ACL_ENTRY_FILE_INHERIT}, - {ARCHIVE_ENTRY_ACL_ENTRY_DIRECTORY_INHERIT, ACL_ENTRY_DIRECTORY_INHERIT}, - {ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT, ACL_ENTRY_NO_PROPAGATE_INHERIT}, - {ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY, ACL_ENTRY_INHERIT_ONLY}, - {ARCHIVE_ENTRY_ACL_ENTRY_SUCCESSFUL_ACCESS, ACL_ENTRY_SUCCESSFUL_ACCESS}, - {ARCHIVE_ENTRY_ACL_ENTRY_FAILED_ACCESS, ACL_ENTRY_FAILED_ACCESS}, - {ARCHIVE_ENTRY_ACL_ENTRY_INHERITED, ACL_ENTRY_INHERITED} -#endif /* !HAVE_SUN_ACL && !HAVE_DARWIN_ACL */ -}; -#endif /* HAVE_NFS4_ACL */ - -#if HAVE_DARWIN_ACL -static int translate_guid(struct archive *a, acl_entry_t acl_entry, - int *ae_id, int *ae_tag, const char **ae_name) -{ - void *q; - uid_t ugid; - int r, idtype; - struct passwd *pwd; - struct group *grp; - - q = acl_get_qualifier(acl_entry); - if (q == NULL) - return (1); - r = mbr_uuid_to_id((const unsigned char *)q, &ugid, &idtype); - if (r != 0) { - acl_free(q); - return (1); - } - if (idtype == ID_TYPE_UID) { - *ae_tag = ARCHIVE_ENTRY_ACL_USER; - pwd = getpwuuid(q); - if (pwd == NULL) { - *ae_id = ugid; - *ae_name = NULL; - } else { - *ae_id = pwd->pw_uid; - *ae_name = archive_read_disk_uname(a, *ae_id); - } - } else if (idtype == ID_TYPE_GID) { - *ae_tag = ARCHIVE_ENTRY_ACL_GROUP; - grp = getgruuid(q); - if (grp == NULL) { - *ae_id = ugid; - *ae_name = NULL; - } else { - *ae_id = grp->gr_gid; - *ae_name = archive_read_disk_gname(a, *ae_id); - } - } else - r = 1; - - acl_free(q); - return (r); -} - -/* - * Add trivial NFSv4 ACL entries from mode - */ -static void -add_trivial_nfs4_acl(struct archive_entry *entry) -{ - mode_t mode; - int i; - const int rperm = ARCHIVE_ENTRY_ACL_READ_DATA; - const int wperm = ARCHIVE_ENTRY_ACL_WRITE_DATA | - ARCHIVE_ENTRY_ACL_APPEND_DATA; - const int eperm = ARCHIVE_ENTRY_ACL_EXECUTE; - const int pubset = ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES | - ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS | - ARCHIVE_ENTRY_ACL_READ_ACL | - ARCHIVE_ENTRY_ACL_SYNCHRONIZE; - const int ownset = pubset | ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES | - ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS | - ARCHIVE_ENTRY_ACL_WRITE_ACL | - ARCHIVE_ENTRY_ACL_WRITE_OWNER; - - struct { - const int type; - const int tag; - int permset; - } tacl_entry[] = { - {ARCHIVE_ENTRY_ACL_TYPE_ALLOW, ARCHIVE_ENTRY_ACL_USER_OBJ, 0}, - {ARCHIVE_ENTRY_ACL_TYPE_DENY, ARCHIVE_ENTRY_ACL_USER_OBJ, 0}, - {ARCHIVE_ENTRY_ACL_TYPE_DENY, ARCHIVE_ENTRY_ACL_GROUP_OBJ, 0}, - {ARCHIVE_ENTRY_ACL_TYPE_ALLOW, ARCHIVE_ENTRY_ACL_USER_OBJ, ownset}, - {ARCHIVE_ENTRY_ACL_TYPE_ALLOW, ARCHIVE_ENTRY_ACL_GROUP_OBJ, pubset}, - {ARCHIVE_ENTRY_ACL_TYPE_ALLOW, ARCHIVE_ENTRY_ACL_EVERYONE, pubset} - }; - - mode = archive_entry_mode(entry); - - /* Permissions for everyone@ */ - if (mode & 0004) - tacl_entry[5].permset |= rperm; - if (mode & 0002) - tacl_entry[5].permset |= wperm; - if (mode & 0001) - tacl_entry[5].permset |= eperm; - - /* Permissions for group@ */ - if (mode & 0040) - tacl_entry[4].permset |= rperm; - else if (mode & 0004) - tacl_entry[2].permset |= rperm; - if (mode & 0020) - tacl_entry[4].permset |= wperm; - else if (mode & 0002) - tacl_entry[2].permset |= wperm; - if (mode & 0010) - tacl_entry[4].permset |= eperm; - else if (mode & 0001) - tacl_entry[2].permset |= eperm; - - /* Permissions for owner@ */ - if (mode & 0400) { - tacl_entry[3].permset |= rperm; - if (!(mode & 0040) && (mode & 0004)) - tacl_entry[0].permset |= rperm; - } else if ((mode & 0040) || (mode & 0004)) - tacl_entry[1].permset |= rperm; - if (mode & 0200) { - tacl_entry[3].permset |= wperm; - if (!(mode & 0020) && (mode & 0002)) - tacl_entry[0].permset |= wperm; - } else if ((mode & 0020) || (mode & 0002)) - tacl_entry[1].permset |= wperm; - if (mode & 0100) { - tacl_entry[3].permset |= eperm; - if (!(mode & 0010) && (mode & 0001)) - tacl_entry[0].permset |= eperm; - } else if ((mode & 0010) || (mode & 0001)) - tacl_entry[1].permset |= eperm; - - for (i = 0; i < 6; i++) { - if (tacl_entry[i].permset != 0) { - archive_entry_acl_add_entry(entry, - tacl_entry[i].type, tacl_entry[i].permset, - tacl_entry[i].tag, -1, NULL); - } - } - - return; -} -#elif HAVE_SUN_ACL -/* - * Check if acl is trivial - * This is a FreeBSD acl_is_trivial_np() implementation for Solaris - */ -static int -sun_acl_is_trivial(acl_t *acl, mode_t mode, int *trivialp) -{ - int i, p; - const uint32_t rperm = ACE_READ_DATA; - const uint32_t wperm = ACE_WRITE_DATA | ACE_APPEND_DATA; - const uint32_t eperm = ACE_EXECUTE; - const uint32_t pubset = ACE_READ_ATTRIBUTES | ACE_READ_NAMED_ATTRS | - ACE_READ_ACL | ACE_SYNCHRONIZE; - const uint32_t ownset = pubset | ACE_WRITE_ATTRIBUTES | - ACE_WRITE_NAMED_ATTRS | ACE_WRITE_ACL | ACE_WRITE_OWNER; - - ace_t *ace; - ace_t tace[6]; - - if (acl == NULL || trivialp == NULL) - return (-1); - - *trivialp = 0; - - /* ACL_IS_TRIVIAL flag must be set for both POSIX.1e and NFSv4 ACLs */ - if ((acl->acl_flags & ACL_IS_TRIVIAL) == 0) - return (0); - - /* - * POSIX.1e ACLs marked with ACL_IS_TRIVIAL are compatible with - * FreeBSD acl_is_trivial_np(). On Solaris they have 4 entries, - * including mask. - */ - if (acl->acl_type == ACLENT_T) { - if (acl->acl_cnt == 4) - *trivialp = 1; - return (0); - } - - if (acl->acl_type != ACE_T || acl->acl_entry_size != sizeof(ace_t)) - return (-1); - - /* - * Continue with checking NFSv4 ACLs - * - * Create list of trivial ace's to be compared - */ - - /* owner@ allow pre */ - tace[0].a_flags = ACE_OWNER; - tace[0].a_type = ACE_ACCESS_ALLOWED_ACE_TYPE; - tace[0].a_access_mask = 0; - - /* owner@ deny */ - tace[1].a_flags = ACE_OWNER; - tace[1].a_type = ACE_ACCESS_DENIED_ACE_TYPE; - tace[1].a_access_mask = 0; - - /* group@ deny */ - tace[2].a_flags = ACE_GROUP | ACE_IDENTIFIER_GROUP; - tace[2].a_type = ACE_ACCESS_DENIED_ACE_TYPE; - tace[2].a_access_mask = 0; - - /* owner@ allow */ - tace[3].a_flags = ACE_OWNER; - tace[3].a_type = ACE_ACCESS_ALLOWED_ACE_TYPE; - tace[3].a_access_mask = ownset; - - /* group@ allow */ - tace[4].a_flags = ACE_GROUP | ACE_IDENTIFIER_GROUP; - tace[4].a_type = ACE_ACCESS_ALLOWED_ACE_TYPE; - tace[4].a_access_mask = pubset; - - /* everyone@ allow */ - tace[5].a_flags = ACE_EVERYONE; - tace[5].a_type = ACE_ACCESS_ALLOWED_ACE_TYPE; - tace[5].a_access_mask = pubset; - - /* Permissions for everyone@ */ - if (mode & 0004) - tace[5].a_access_mask |= rperm; - if (mode & 0002) - tace[5].a_access_mask |= wperm; - if (mode & 0001) - tace[5].a_access_mask |= eperm; - - /* Permissions for group@ */ - if (mode & 0040) - tace[4].a_access_mask |= rperm; - else if (mode & 0004) - tace[2].a_access_mask |= rperm; - if (mode & 0020) - tace[4].a_access_mask |= wperm; - else if (mode & 0002) - tace[2].a_access_mask |= wperm; - if (mode & 0010) - tace[4].a_access_mask |= eperm; - else if (mode & 0001) - tace[2].a_access_mask |= eperm; - - /* Permissions for owner@ */ - if (mode & 0400) { - tace[3].a_access_mask |= rperm; - if (!(mode & 0040) && (mode & 0004)) - tace[0].a_access_mask |= rperm; - } else if ((mode & 0040) || (mode & 0004)) - tace[1].a_access_mask |= rperm; - if (mode & 0200) { - tace[3].a_access_mask |= wperm; - if (!(mode & 0020) && (mode & 0002)) - tace[0].a_access_mask |= wperm; - } else if ((mode & 0020) || (mode & 0002)) - tace[1].a_access_mask |= wperm; - if (mode & 0100) { - tace[3].a_access_mask |= eperm; - if (!(mode & 0010) && (mode & 0001)) - tace[0].a_access_mask |= eperm; - } else if ((mode & 0010) || (mode & 0001)) - tace[1].a_access_mask |= eperm; - - /* Check if the acl count matches */ - p = 3; - for (i = 0; i < 3; i++) { - if (tace[i].a_access_mask != 0) - p++; - } - if (acl->acl_cnt != p) - return (0); - - p = 0; - for (i = 0; i < 6; i++) { - if (tace[i].a_access_mask != 0) { - ace = &((ace_t *)acl->acl_aclp)[p]; - /* - * Illumos added ACE_DELETE_CHILD to write perms for - * directories. We have to check against that, too. - */ - if (ace->a_flags != tace[i].a_flags || - ace->a_type != tace[i].a_type || - (ace->a_access_mask != tace[i].a_access_mask && - ((acl->acl_flags & ACL_IS_DIR) == 0 || - (tace[i].a_access_mask & wperm) == 0 || - ace->a_access_mask != - (tace[i].a_access_mask | ACE_DELETE_CHILD)))) - return (0); - p++; - } - } - - *trivialp = 1; - return (0); -} -#endif /* HAVE_SUN_ACL */ - -#if HAVE_SUN_ACL /* - * Translate Solaris POSIX.1e and NFSv4 ACLs into libarchive internal ACL - */ -static int -translate_acl(struct archive_read_disk *a, - struct archive_entry *entry, acl_t *acl, int default_entry_acl_type) -{ - int e, i; - int ae_id, ae_tag, ae_perm; - int entry_acl_type; - const char *ae_name; - aclent_t *aclent; - ace_t *ace; - - (void)default_entry_acl_type; - - if (acl->acl_cnt <= 0) - return (ARCHIVE_OK); - - for (e = 0; e < acl->acl_cnt; e++) { - ae_name = NULL; - ae_tag = 0; - ae_perm = 0; - - if (acl->acl_type == ACE_T) { - ace = &((ace_t *)acl->acl_aclp)[e]; - ae_id = ace->a_who; - - switch(ace->a_type) { - case ACE_ACCESS_ALLOWED_ACE_TYPE: - entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_ALLOW; - break; - case ACE_ACCESS_DENIED_ACE_TYPE: - entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_DENY; - break; - case ACE_SYSTEM_AUDIT_ACE_TYPE: - entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_ACCESS; - break; - case ACE_SYSTEM_ALARM_ACE_TYPE: - entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_ALARM; - break; - default: - /* Unknown entry type, skip */ - continue; - } - - if ((ace->a_flags & ACE_OWNER) != 0) - ae_tag = ARCHIVE_ENTRY_ACL_USER_OBJ; - else if ((ace->a_flags & ACE_GROUP) != 0) - ae_tag = ARCHIVE_ENTRY_ACL_GROUP_OBJ; - else if ((ace->a_flags & ACE_EVERYONE) != 0) - ae_tag = ARCHIVE_ENTRY_ACL_EVERYONE; - else if ((ace->a_flags & ACE_IDENTIFIER_GROUP) != 0) { - ae_tag = ARCHIVE_ENTRY_ACL_GROUP; - ae_name = archive_read_disk_gname(&a->archive, - ae_id); - } else { - ae_tag = ARCHIVE_ENTRY_ACL_USER; - ae_name = archive_read_disk_uname(&a->archive, - ae_id); - } - - for (i = 0; i < (int)(sizeof(acl_inherit_map) / - sizeof(acl_inherit_map[0])); ++i) { - if ((ace->a_flags & - acl_inherit_map[i].platform_inherit) != 0) - ae_perm |= - acl_inherit_map[i].archive_inherit; - } - - for (i = 0; i < (int)(sizeof(acl_perm_map) / - sizeof(acl_perm_map[0])); ++i) { - if ((ace->a_access_mask & - acl_perm_map[i].platform_perm) != 0) - ae_perm |= - acl_perm_map[i].archive_perm; - } - } else { - aclent = &((aclent_t *)acl->acl_aclp)[e]; - if ((aclent->a_type & ACL_DEFAULT) != 0) - entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_DEFAULT; - else - entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_ACCESS; - ae_id = aclent->a_id; - - switch(aclent->a_type) { - case DEF_USER: - case USER: - ae_name = archive_read_disk_uname(&a->archive, - ae_id); - ae_tag = ARCHIVE_ENTRY_ACL_USER; - break; - case DEF_GROUP: - case GROUP: - ae_name = archive_read_disk_gname(&a->archive, - ae_id); - ae_tag = ARCHIVE_ENTRY_ACL_GROUP; - break; - case DEF_CLASS_OBJ: - case CLASS_OBJ: - ae_tag = ARCHIVE_ENTRY_ACL_MASK; - break; - case DEF_USER_OBJ: - case USER_OBJ: - ae_tag = ARCHIVE_ENTRY_ACL_USER_OBJ; - break; - case DEF_GROUP_OBJ: - case GROUP_OBJ: - ae_tag = ARCHIVE_ENTRY_ACL_GROUP_OBJ; - break; - case DEF_OTHER_OBJ: - case OTHER_OBJ: - ae_tag = ARCHIVE_ENTRY_ACL_OTHER; - break; - default: - /* Unknown tag type, skip */ - continue; - } - - if ((aclent->a_perm & 1) != 0) - ae_perm |= ARCHIVE_ENTRY_ACL_EXECUTE; - if ((aclent->a_perm & 2) != 0) - ae_perm |= ARCHIVE_ENTRY_ACL_WRITE; - if ((aclent->a_perm & 4) != 0) - ae_perm |= ARCHIVE_ENTRY_ACL_READ; - } /* default_entry_acl_type != ARCHIVE_ENTRY_ACL_TYPE_NFS4 */ - - archive_entry_acl_add_entry(entry, entry_acl_type, - ae_perm, ae_tag, ae_id, ae_name); - } - return (ARCHIVE_OK); -} -#else /* !HAVE_SUN_ACL */ -/* - * Translate POSIX.1e (Linux), FreeBSD (both POSIX.1e and NFSv4) and - * MacOS (NFSv4 only) ACLs into libarchive internal structure - */ -static int -translate_acl(struct archive_read_disk *a, - struct archive_entry *entry, acl_t acl, int default_entry_acl_type) -{ - acl_tag_t acl_tag; -#if HAVE_ACL_TYPE_NFS4 - acl_entry_type_t acl_type; - int brand; -#endif -#if HAVE_ACL_TYPE_NFS4 || HAVE_DARWIN_ACL - acl_flagset_t acl_flagset; -#endif - acl_entry_t acl_entry; - acl_permset_t acl_permset; - int i, entry_acl_type; - int r, s, ae_id, ae_tag, ae_perm; -#if !HAVE_DARWIN_ACL - void *q; -#endif - const char *ae_name; - -#if HAVE_ACL_TYPE_NFS4 - // FreeBSD "brands" ACLs as POSIX.1e or NFSv4 - // Make sure the "brand" on this ACL is consistent - // with the default_entry_acl_type bits provided. - if (acl_get_brand_np(acl, &brand) != 0) { - archive_set_error(&a->archive, errno, - "Failed to read ACL brand"); - return (ARCHIVE_WARN); - } - switch (brand) { - case ACL_BRAND_POSIX: - switch (default_entry_acl_type) { - case ARCHIVE_ENTRY_ACL_TYPE_ACCESS: - case ARCHIVE_ENTRY_ACL_TYPE_DEFAULT: - break; - default: - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Invalid ACL entry type for POSIX.1e ACL"); - return (ARCHIVE_WARN); - } - break; - case ACL_BRAND_NFS4: - if (default_entry_acl_type & ~ARCHIVE_ENTRY_ACL_TYPE_NFS4) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Invalid ACL entry type for NFSv4 ACL"); - return (ARCHIVE_WARN); - } - break; - default: - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Unknown ACL brand"); - return (ARCHIVE_WARN); - } -#endif - - s = acl_get_entry(acl, ACL_FIRST_ENTRY, &acl_entry); - if (s == -1) { - archive_set_error(&a->archive, errno, - "Failed to get first ACL entry"); - return (ARCHIVE_WARN); - } - -#if HAVE_DARWIN_ACL - while (s == 0) -#else /* FreeBSD, Linux */ - while (s == 1) -#endif - { - ae_id = -1; - ae_name = NULL; - ae_perm = 0; - - if (acl_get_tag_type(acl_entry, &acl_tag) != 0) { - archive_set_error(&a->archive, errno, - "Failed to get ACL tag type"); - return (ARCHIVE_WARN); - } - switch (acl_tag) { -#if !HAVE_DARWIN_ACL /* FreeBSD, Linux */ - case ACL_USER: - q = acl_get_qualifier(acl_entry); - if (q != NULL) { - ae_id = (int)*(uid_t *)q; - acl_free(q); - ae_name = archive_read_disk_uname(&a->archive, - ae_id); - } - ae_tag = ARCHIVE_ENTRY_ACL_USER; - break; - case ACL_GROUP: - q = acl_get_qualifier(acl_entry); - if (q != NULL) { - ae_id = (int)*(gid_t *)q; - acl_free(q); - ae_name = archive_read_disk_gname(&a->archive, - ae_id); - } - ae_tag = ARCHIVE_ENTRY_ACL_GROUP; - break; - case ACL_MASK: - ae_tag = ARCHIVE_ENTRY_ACL_MASK; - break; - case ACL_USER_OBJ: - ae_tag = ARCHIVE_ENTRY_ACL_USER_OBJ; - break; - case ACL_GROUP_OBJ: - ae_tag = ARCHIVE_ENTRY_ACL_GROUP_OBJ; - break; - case ACL_OTHER: - ae_tag = ARCHIVE_ENTRY_ACL_OTHER; - break; -#if HAVE_ACL_TYPE_NFS4 - case ACL_EVERYONE: - ae_tag = ARCHIVE_ENTRY_ACL_EVERYONE; - break; -#endif -#else /* HAVE_DARWIN_ACL */ - case ACL_EXTENDED_ALLOW: - entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_ALLOW; - r = translate_guid(&a->archive, acl_entry, &ae_id, - &ae_tag, &ae_name); - break; - case ACL_EXTENDED_DENY: - entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_DENY; - r = translate_guid(&a->archive, acl_entry, &ae_id, - &ae_tag, &ae_name); - break; -#endif /* HAVE_DARWIN_ACL */ - default: - /* Skip types that libarchive can't support. */ - s = acl_get_entry(acl, ACL_NEXT_ENTRY, &acl_entry); - continue; - } - -#if HAVE_DARWIN_ACL - /* Skip if translate_guid() above failed */ - if (r != 0) { - s = acl_get_entry(acl, ACL_NEXT_ENTRY, &acl_entry); - continue; - } -#endif - -#if !HAVE_DARWIN_ACL - // XXX acl_type maps to allow/deny/audit/YYYY bits - entry_acl_type = default_entry_acl_type; -#endif -#if HAVE_ACL_TYPE_NFS4 || HAVE_DARWIN_ACL - if (default_entry_acl_type & ARCHIVE_ENTRY_ACL_TYPE_NFS4) { -#if HAVE_ACL_TYPE_NFS4 - /* - * acl_get_entry_type_np() fails with non-NFSv4 ACLs - */ - if (acl_get_entry_type_np(acl_entry, &acl_type) != 0) { - archive_set_error(&a->archive, errno, "Failed " - "to get ACL type from a NFSv4 ACL entry"); - return (ARCHIVE_WARN); - } - switch (acl_type) { - case ACL_ENTRY_TYPE_ALLOW: - entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_ALLOW; - break; - case ACL_ENTRY_TYPE_DENY: - entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_DENY; - break; - case ACL_ENTRY_TYPE_AUDIT: - entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_AUDIT; - break; - case ACL_ENTRY_TYPE_ALARM: - entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_ALARM; - break; - default: - archive_set_error(&a->archive, errno, - "Invalid NFSv4 ACL entry type"); - return (ARCHIVE_WARN); - } -#endif /* HAVE_ACL_TYPE_NFS4 */ - - /* - * Libarchive stores "flag" (NFSv4 inheritance bits) - * in the ae_perm bitmap. - * - * acl_get_flagset_np() fails with non-NFSv4 ACLs - */ - if (acl_get_flagset_np(acl_entry, &acl_flagset) != 0) { - archive_set_error(&a->archive, errno, - "Failed to get flagset from a NFSv4 ACL entry"); - return (ARCHIVE_WARN); - } - for (i = 0; i < (int)(sizeof(acl_inherit_map) / sizeof(acl_inherit_map[0])); ++i) { - r = acl_get_flag_np(acl_flagset, - acl_inherit_map[i].platform_inherit); - if (r == -1) { - archive_set_error(&a->archive, errno, - "Failed to check flag in a NFSv4 " - "ACL flagset"); - return (ARCHIVE_WARN); - } else if (r) - ae_perm |= acl_inherit_map[i].archive_inherit; - } - } -#endif /* HAVE_ACL_TYPE_NFS4 || HAVE_DARWIN_ACL */ - - if (acl_get_permset(acl_entry, &acl_permset) != 0) { - archive_set_error(&a->archive, errno, - "Failed to get ACL permission set"); - return (ARCHIVE_WARN); - } - for (i = 0; i < (int)(sizeof(acl_perm_map) / sizeof(acl_perm_map[0])); ++i) { - /* - * acl_get_perm() is spelled differently on different - * platforms; see above. - */ - r = ACL_GET_PERM(acl_permset, acl_perm_map[i].platform_perm); - if (r == -1) { - archive_set_error(&a->archive, errno, - "Failed to check permission in an ACL permission set"); - return (ARCHIVE_WARN); - } else if (r) - ae_perm |= acl_perm_map[i].archive_perm; - } - - archive_entry_acl_add_entry(entry, entry_acl_type, - ae_perm, ae_tag, - ae_id, ae_name); - - s = acl_get_entry(acl, ACL_NEXT_ENTRY, &acl_entry); -#if !HAVE_DARWIN_ACL - if (s == -1) { - archive_set_error(&a->archive, errno, - "Failed to get next ACL entry"); - return (ARCHIVE_WARN); - } -#endif - } - return (ARCHIVE_OK); -} -#endif /* !HAVE_SUN_ACL */ -#else /* !HAVE_POSIX_ACL && !HAVE_NFS4_ACL */ -static int -setup_acls(struct archive_read_disk *a, - struct archive_entry *entry, int *fd) -{ - (void)a; /* UNUSED */ - (void)entry; /* UNUSED */ - (void)fd; /* UNUSED */ - return (ARCHIVE_OK); -} -#endif /* !HAVE_POSIX_ACL && !HAVE_NFS4_ACL */ - -#if (HAVE_FGETXATTR && HAVE_FLISTXATTR && HAVE_LISTXATTR && \ - HAVE_LLISTXATTR && HAVE_GETXATTR && HAVE_LGETXATTR) || \ - (HAVE_FGETEA && HAVE_FLISTEA && HAVE_LISTEA) - -/* - * Linux and AIX extended attribute support. + * Linux, Darwin and AIX extended attribute support. * * TODO: By using a stack-allocated buffer for the first * call to getxattr(), we might be able to avoid the second @@ -1433,21 +444,32 @@ setup_xattr(struct archive_read_disk *a, ssize_t size; void *value = NULL; -#if HAVE_FGETXATTR - if (fd >= 0) + + if (fd >= 0) { +#if ARCHIVE_XATTR_LINUX size = fgetxattr(fd, name, NULL, 0); - else if (!a->follow_symlinks) - size = lgetxattr(accpath, name, NULL, 0); - else - size = getxattr(accpath, name, NULL, 0); -#elif HAVE_FGETEA - if (fd >= 0) +#elif ARCHIVE_XATTR_DARWIN + size = fgetxattr(fd, name, NULL, 0, 0, 0); +#elif ARCHIVE_XATTR_AIX size = fgetea(fd, name, NULL, 0); - else if (!a->follow_symlinks) +#endif + } else if (!a->follow_symlinks) { +#if ARCHIVE_XATTR_LINUX + size = lgetxattr(accpath, name, NULL, 0); +#elif ARCHIVE_XATTR_DARWIN + size = getxattr(accpath, name, NULL, 0, 0, XATTR_NOFOLLOW); +#elif ARCHIVE_XATTR_AIX size = lgetea(accpath, name, NULL, 0); - else +#endif + } else { +#if ARCHIVE_XATTR_LINUX + size = getxattr(accpath, name, NULL, 0); +#elif ARCHIVE_XATTR_DARWIN + size = getxattr(accpath, name, NULL, 0, 0, 0); +#elif ARCHIVE_XATTR_AIX size = getea(accpath, name, NULL, 0); #endif + } if (size == -1) { archive_set_error(&a->archive, errno, @@ -1460,21 +482,32 @@ setup_xattr(struct archive_read_disk *a, return (ARCHIVE_FATAL); } -#if HAVE_FGETXATTR - if (fd >= 0) + + if (fd >= 0) { +#if ARCHIVE_XATTR_LINUX size = fgetxattr(fd, name, value, size); - else if (!a->follow_symlinks) - size = lgetxattr(accpath, name, value, size); - else - size = getxattr(accpath, name, value, size); -#elif HAVE_FGETEA - if (fd >= 0) +#elif ARCHIVE_XATTR_DARWIN + size = fgetxattr(fd, name, value, size, 0, 0); +#elif ARCHIVE_XATTR_AIX size = fgetea(fd, name, value, size); - else if (!a->follow_symlinks) +#endif + } else if (!a->follow_symlinks) { +#if ARCHIVE_XATTR_LINUX + size = lgetxattr(accpath, name, value, size); +#elif ARCHIVE_XATTR_DARWIN + size = getxattr(accpath, name, value, size, 0, XATTR_NOFOLLOW); +#elif ARCHIVE_XATTR_AIX size = lgetea(accpath, name, value, size); - else +#endif + } else { +#if ARCHIVE_XATTR_LINUX + size = getxattr(accpath, name, value, size); +#elif ARCHIVE_XATTR_DARWIN + size = getxattr(accpath, name, value, size, 0, 0); +#elif ARCHIVE_XATTR_AIX size = getea(accpath, name, value, size); #endif + } if (size == -1) { archive_set_error(&a->archive, errno, @@ -1499,38 +532,36 @@ setup_xattrs(struct archive_read_disk *a, path = NULL; if (*fd < 0) { - path = archive_entry_sourcepath(entry); - if (path == NULL || (a->tree != NULL && - a->tree_enter_working_dir(a->tree) != 0)) - path = archive_entry_pathname(entry); - if (path == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Couldn't determine file path to read " - "extended attributes"); + path = archive_read_disk_entry_setup_path(a, entry, fd); + if (path == NULL) return (ARCHIVE_WARN); - } - if (a->tree != NULL && (a->follow_symlinks || - archive_entry_filetype(entry) != AE_IFLNK)) { - *fd = a->open_on_current_dir(a->tree, - path, O_RDONLY | O_NONBLOCK); - } } -#if HAVE_FLISTXATTR - if (*fd >= 0) + if (*fd >= 0) { +#if ARCHIVE_XATTR_LINUX list_size = flistxattr(*fd, NULL, 0); - else if (!a->follow_symlinks) - list_size = llistxattr(path, NULL, 0); - else - list_size = listxattr(path, NULL, 0); -#elif HAVE_FLISTEA - if (*fd >= 0) +#elif ARCHIVE_XATTR_DARWIN + list_size = flistxattr(*fd, NULL, 0, 0); +#elif ARCHIVE_XATTR_AIX list_size = flistea(*fd, NULL, 0); - else if (!a->follow_symlinks) +#endif + } else if (!a->follow_symlinks) { +#if ARCHIVE_XATTR_LINUX + list_size = llistxattr(path, NULL, 0); +#elif ARCHIVE_XATTR_DARWIN + list_size = listxattr(path, NULL, 0, XATTR_NOFOLLOW); +#elif ARCHIVE_XATTR_AIX list_size = llistea(path, NULL, 0); - else +#endif + } else { +#if ARCHIVE_XATTR_LINUX + list_size = listxattr(path, NULL, 0); +#elif ARCHIVE_XATTR_DARWIN + list_size = listxattr(path, NULL, 0, 0); +#elif ARCHIVE_XATTR_AIX list_size = listea(path, NULL, 0); #endif + } if (list_size == -1) { if (errno == ENOTSUP || errno == ENOSYS) @@ -1548,21 +579,31 @@ setup_xattrs(struct archive_read_disk *a, return (ARCHIVE_FATAL); } -#if HAVE_FLISTXATTR - if (*fd >= 0) + if (*fd >= 0) { +#if ARCHIVE_XATTR_LINUX list_size = flistxattr(*fd, list, list_size); - else if (!a->follow_symlinks) - list_size = llistxattr(path, list, list_size); - else - list_size = listxattr(path, list, list_size); -#elif HAVE_FLISTEA - if (*fd >= 0) +#elif ARCHIVE_XATTR_DARWIN + list_size = flistxattr(*fd, list, list_size, 0); +#elif ARCHIVE_XATTR_AIX list_size = flistea(*fd, list, list_size); - else if (!a->follow_symlinks) +#endif + } else if (!a->follow_symlinks) { +#if ARCHIVE_XATTR_LINUX + list_size = llistxattr(path, list, list_size); +#elif ARCHIVE_XATTR_DARWIN + list_size = listxattr(path, list, list_size, XATTR_NOFOLLOW); +#elif ARCHIVE_XATTR_AIX list_size = llistea(path, list, list_size); - else +#endif + } else { +#if ARCHIVE_XATTR_LINUX + list_size = listxattr(path, list, list_size); +#elif ARCHIVE_XATTR_DARWIN + list_size = listxattr(path, list, list_size, 0); +#elif ARCHIVE_XATTR_AIX list_size = listea(path, list, list_size); #endif + } if (list_size == -1) { archive_set_error(&a->archive, errno, @@ -1572,9 +613,21 @@ setup_xattrs(struct archive_read_disk *a, } for (p = list; (p - list) < list_size; p += strlen(p) + 1) { - if (strncmp(p, "system.", 7) == 0 || - strncmp(p, "xfsroot.", 8) == 0) +#if ARCHIVE_XATTR_LINUX + /* Linux: skip POSIX.1e ACL extended attributes */ + if (strncmp(p, "system.", 7) == 0 && + (strcmp(p + 7, "posix_acl_access") == 0 || + strcmp(p + 7, "posix_acl_default") == 0)) + continue; + if (strncmp(p, "trusted.SGI_", 12) == 0 && + (strcmp(p + 12, "ACL_DEFAULT") == 0 || + strcmp(p + 12, "ACL_FILE") == 0)) + continue; + + /* Linux: xfsroot namespace is obsolete and unsupported */ + if (strncmp(p, "xfsroot.", 8) == 0) continue; +#endif setup_xattr(a, entry, p, *fd, path); } @@ -1582,8 +635,7 @@ setup_xattrs(struct archive_read_disk *a, return (ARCHIVE_OK); } -#elif HAVE_EXTATTR_GET_FILE && HAVE_EXTATTR_LIST_FILE && \ - HAVE_DECL_EXTATTR_NAMESPACE_USER +#elif ARCHIVE_XATTR_FREEBSD /* * FreeBSD extattr interface. @@ -1658,21 +710,9 @@ setup_xattrs(struct archive_read_disk *a, path = NULL; if (*fd < 0) { - path = archive_entry_sourcepath(entry); - if (path == NULL || (a->tree != NULL && - a->tree_enter_working_dir(a->tree) != 0)) - path = archive_entry_pathname(entry); - if (path == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Couldn't determine file path to read " - "extended attributes"); + path = archive_read_disk_entry_setup_path(a, entry, fd); + if (path == NULL) return (ARCHIVE_WARN); - } - if (a->tree != NULL && (a->follow_symlinks || - archive_entry_filetype(entry) != AE_IFLNK)) { - *fd = a->open_on_current_dir(a->tree, - path, O_RDONLY | O_NONBLOCK); - } } if (*fd >= 0) @@ -1773,6 +813,7 @@ setup_sparse_fiemap(struct archive_read_disk *a, int64_t size; int count, do_fiemap, iters; int exit_sts = ARCHIVE_OK; + const char *path; if (archive_entry_filetype(entry) != AE_IFREG || archive_entry_size(entry) <= 0 @@ -1780,11 +821,10 @@ setup_sparse_fiemap(struct archive_read_disk *a, return (ARCHIVE_OK); if (*fd < 0) { - const char *path; - - path = archive_entry_sourcepath(entry); + path = archive_read_disk_entry_setup_path(a, entry, NULL); if (path == NULL) - path = archive_entry_pathname(entry); + return (ARCHIVE_FAILED); + if (a->tree != NULL) *fd = a->open_on_current_dir(a->tree, path, O_RDONLY | O_NONBLOCK | O_CLOEXEC); @@ -1880,6 +920,7 @@ setup_sparse(struct archive_read_disk *a, off_t off_s, off_e; int exit_sts = ARCHIVE_OK; int check_fully_sparse = 0; + const char *path; if (archive_entry_filetype(entry) != AE_IFREG || archive_entry_size(entry) <= 0 @@ -1887,20 +928,10 @@ setup_sparse(struct archive_read_disk *a, return (ARCHIVE_OK); /* Does filesystem support the reporting of hole ? */ - if (*fd < 0 && a->tree != NULL) { - const char *path; - - path = archive_entry_sourcepath(entry); - if (path == NULL) - path = archive_entry_pathname(entry); - *fd = a->open_on_current_dir(a->tree, path, - O_RDONLY | O_NONBLOCK); - if (*fd < 0) { - archive_set_error(&a->archive, errno, - "Can't open `%s'", path); - return (ARCHIVE_FAILED); - } - } + if (*fd < 0) + path = archive_read_disk_entry_setup_path(a, entry, fd); + else + path = NULL; if (*fd >= 0) { #ifdef _PC_MIN_HOLE_SIZE @@ -1911,12 +942,8 @@ setup_sparse(struct archive_read_disk *a, if (initial_off != 0) lseek(*fd, 0, SEEK_SET); } else { - const char *path; - - path = archive_entry_sourcepath(entry); if (path == NULL) - path = archive_entry_pathname(entry); - + return (ARCHIVE_FAILED); #ifdef _PC_MIN_HOLE_SIZE if (pathconf(path, _PC_MIN_HOLE_SIZE) <= 0) return (ARCHIVE_OK); diff --git a/Utilities/cmlibarchive/libarchive/archive_read_disk_private.h b/Utilities/cmlibarchive/libarchive/archive_read_disk_private.h index b5a8328..f03a0a9 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_disk_private.h +++ b/Utilities/cmlibarchive/libarchive/archive_read_disk_private.h @@ -33,6 +33,8 @@ #ifndef ARCHIVE_READ_DISK_PRIVATE_H_INCLUDED #define ARCHIVE_READ_DISK_PRIVATE_H_INCLUDED +#include "archive_platform_acl.h" + struct tree; struct archive_entry; @@ -86,4 +88,11 @@ struct archive_read_disk { void *excluded_cb_data; }; +const char * +archive_read_disk_entry_setup_path(struct archive_read_disk *, + struct archive_entry *, int *); + +int +archive_read_disk_entry_setup_acls(struct archive_read_disk *, + struct archive_entry *, int *); #endif diff --git a/Utilities/cmlibarchive/libarchive/archive_read_format.3 b/Utilities/cmlibarchive/libarchive/archive_read_format.3 index 53b9a7e..91c5d2c 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_format.3 +++ b/Utilities/cmlibarchive/libarchive/archive_read_format.3 @@ -37,9 +37,9 @@ .Nm archive_read_support_format_empty , .Nm archive_read_support_format_iso9660 , .Nm archive_read_support_format_lha , -.Nm archive_read_support_format_mtree, -.Nm archive_read_support_format_rar, -.Nm archive_read_support_format_raw, +.Nm archive_read_support_format_mtree , +.Nm archive_read_support_format_rar , +.Nm archive_read_support_format_raw , .Nm archive_read_support_format_tar , .Nm archive_read_support_format_xar , .Nm archive_read_support_format_zip diff --git a/Utilities/cmlibarchive/libarchive/archive_read_open.3 b/Utilities/cmlibarchive/libarchive/archive_read_open.3 index 4d8272c..2278ebc 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_open.3 +++ b/Utilities/cmlibarchive/libarchive/archive_read_open.3 @@ -33,7 +33,7 @@ .Nm archive_read_open_fd , .Nm archive_read_open_FILE , .Nm archive_read_open_filename , -.Nm archive_read_open_memory , +.Nm archive_read_open_memory .Nd functions for reading streaming archives .Sh LIBRARY Streaming Archive Library (libarchive, -larchive) @@ -67,7 +67,7 @@ Streaming Archive Library (libarchive, -larchive) .Fa "size_t block_size" .Fc .Ft int -.Fn archive_read_open_memory "struct archive *" "void *buff" "size_t size" +.Fn archive_read_open_memory "struct archive *" "const void *buff" "size_t size" .Sh DESCRIPTION .Bl -tag -compact -width indent .It Fn archive_read_open diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_lz4.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_lz4.c index 663e2d3..147f502 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_lz4.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_lz4.c @@ -494,7 +494,7 @@ lz4_filter_read_data_block(struct archive_read_filter *self, const void **p) if (read_buf == NULL) goto truncated_error; compressed_size = archive_le32dec(read_buf); - if ((compressed_size & ~(1 << 31)) > state->flags.block_maximum_size) + if ((compressed_size & 0x7fffffff) > state->flags.block_maximum_size) goto malformed_error; /* A compressed size == 0 means the end of stream blocks. */ if (compressed_size == 0) { @@ -504,8 +504,8 @@ lz4_filter_read_data_block(struct archive_read_filter *self, const void **p) checksum_size = state->flags.block_checksum; /* Check if the block is uncompressed. */ - if (compressed_size & (1 << 31)) { - compressed_size &= ~(1 << 31); + if (compressed_size & 0x80000000U) { + compressed_size &= 0x7fffffff; uncompressed_size = compressed_size; } else uncompressed_size = 0;/* Unknown yet. */ diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_cab.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_cab.c index 20eb157..51f79fa 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_cab.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_cab.c @@ -116,19 +116,11 @@ struct lzx_dec { * coding tree, which is a binary tree. But a use of a large * index table causes L1 cache read miss many times. */ -#define HTBL_BITS 10 int max_bits; - int shift_bits; int tbl_bits; int tree_used; - int tree_avail; /* Direct access table. */ uint16_t *tbl; - /* Binary tree table for extra bits over the direct access. */ - struct htree_t { - uint16_t left; - uint16_t right; - } *tree; } at, lt, mt, pt; int loop; @@ -187,7 +179,7 @@ struct lzx_stream { #define CFDATA_cbData 4 #define CFDATA_cbUncomp 6 -static const char *compression_name[] = { +static const char * const compression_name[] = { "NONE", "MSZIP", "Quantum", @@ -352,7 +344,6 @@ static int lzx_huffman_init(struct huffman *, size_t, int); static void lzx_huffman_free(struct huffman *); static int lzx_make_huffman_table(struct huffman *); static inline int lzx_decode_huffman(struct huffman *, unsigned); -static int lzx_decode_huffman_tree(struct huffman *, unsigned, int); int @@ -3127,7 +3118,6 @@ getdata: static int lzx_huffman_init(struct huffman *hf, size_t len_size, int tbl_bits) { - int bits; if (hf->bitlen == NULL || hf->len_size != (int)len_size) { free(hf->bitlen); @@ -3138,21 +3128,11 @@ lzx_huffman_init(struct huffman *hf, size_t len_size, int tbl_bits) } else memset(hf->bitlen, 0, len_size * sizeof(hf->bitlen[0])); if (hf->tbl == NULL) { - if (tbl_bits < HTBL_BITS) - bits = tbl_bits; - else - bits = HTBL_BITS; - hf->tbl = malloc(((size_t)1 << bits) * sizeof(hf->tbl[0])); + hf->tbl = malloc(((size_t)1 << tbl_bits) * sizeof(hf->tbl[0])); if (hf->tbl == NULL) return (ARCHIVE_FATAL); hf->tbl_bits = tbl_bits; } - if (hf->tree == NULL && tbl_bits > HTBL_BITS) { - hf->tree_avail = 1 << (tbl_bits - HTBL_BITS + 4); - hf->tree = malloc(hf->tree_avail * sizeof(hf->tree[0])); - if (hf->tree == NULL) - return (ARCHIVE_FATAL); - } return (ARCHIVE_OK); } @@ -3161,7 +3141,6 @@ lzx_huffman_free(struct huffman *hf) { free(hf->bitlen); free(hf->tbl); - free(hf->tree); } /* @@ -3174,7 +3153,7 @@ lzx_make_huffman_table(struct huffman *hf) const unsigned char *bitlen; int bitptn[17], weight[17]; int i, maxbits = 0, ptn, tbl_size, w; - int diffbits, len_avail; + int len_avail; /* * Initialize bit patterns. @@ -3205,28 +3184,11 @@ lzx_make_huffman_table(struct huffman *hf) weight[i] >>= ebits; } } - if (maxbits > HTBL_BITS) { - int htbl_max; - uint16_t *p; - - diffbits = maxbits - HTBL_BITS; - for (i = 1; i <= HTBL_BITS; i++) { - bitptn[i] >>= diffbits; - weight[i] >>= diffbits; - } - htbl_max = bitptn[HTBL_BITS] + - weight[HTBL_BITS] * hf->freq[HTBL_BITS]; - p = &(hf->tbl[htbl_max]); - while (p < &hf->tbl[1U<<HTBL_BITS]) - *p++ = 0; - } else - diffbits = 0; - hf->shift_bits = diffbits; /* * Make the table. */ - tbl_size = 1 << HTBL_BITS; + tbl_size = 1 << hf->tbl_bits; tbl = hf->tbl; bitlen = hf->bitlen; len_avail = hf->len_size; @@ -3234,120 +3196,32 @@ lzx_make_huffman_table(struct huffman *hf) for (i = 0; i < len_avail; i++) { uint16_t *p; int len, cnt; - uint16_t bit; - int extlen; - struct htree_t *ht; if (bitlen[i] == 0) continue; /* Get a bit pattern */ len = bitlen[i]; + if (len > tbl_size) + return (0); ptn = bitptn[len]; cnt = weight[len]; - if (len <= HTBL_BITS) { - /* Calculate next bit pattern */ - if ((bitptn[len] = ptn + cnt) > tbl_size) - return (0);/* Invalid */ - /* Update the table */ - p = &(tbl[ptn]); - while (--cnt >= 0) - p[cnt] = (uint16_t)i; - continue; - } - - /* - * A bit length is too big to be housed to a direct table, - * so we use a tree model for its extra bits. - */ - bitptn[len] = ptn + cnt; - bit = 1U << (diffbits -1); - extlen = len - HTBL_BITS; - - p = &(tbl[ptn >> diffbits]); - if (*p == 0) { - *p = len_avail + hf->tree_used; - ht = &(hf->tree[hf->tree_used++]); - if (hf->tree_used > hf->tree_avail) - return (0);/* Invalid */ - ht->left = 0; - ht->right = 0; - } else { - if (*p < len_avail || - *p >= (len_avail + hf->tree_used)) - return (0);/* Invalid */ - ht = &(hf->tree[*p - len_avail]); - } - while (--extlen > 0) { - if (ptn & bit) { - if (ht->left < len_avail) { - ht->left = len_avail + hf->tree_used; - ht = &(hf->tree[hf->tree_used++]); - if (hf->tree_used > hf->tree_avail) - return (0);/* Invalid */ - ht->left = 0; - ht->right = 0; - } else { - ht = &(hf->tree[ht->left - len_avail]); - } - } else { - if (ht->right < len_avail) { - ht->right = len_avail + hf->tree_used; - ht = &(hf->tree[hf->tree_used++]); - if (hf->tree_used > hf->tree_avail) - return (0);/* Invalid */ - ht->left = 0; - ht->right = 0; - } else { - ht = &(hf->tree[ht->right - len_avail]); - } - } - bit >>= 1; - } - if (ptn & bit) { - if (ht->left != 0) - return (0);/* Invalid */ - ht->left = (uint16_t)i; - } else { - if (ht->right != 0) - return (0);/* Invalid */ - ht->right = (uint16_t)i; - } + /* Calculate next bit pattern */ + if ((bitptn[len] = ptn + cnt) > tbl_size) + return (0);/* Invalid */ + /* Update the table */ + p = &(tbl[ptn]); + while (--cnt >= 0) + p[cnt] = (uint16_t)i; } return (1); } -static int -lzx_decode_huffman_tree(struct huffman *hf, unsigned rbits, int c) -{ - struct htree_t *ht; - int extlen; - - ht = hf->tree; - extlen = hf->shift_bits; - while (c >= hf->len_size) { - c -= hf->len_size; - if (extlen-- <= 0 || c >= hf->tree_used) - return (0); - if (rbits & (1U << extlen)) - c = ht[c].left; - else - c = ht[c].right; - } - return (c); -} - static inline int lzx_decode_huffman(struct huffman *hf, unsigned rbits) { int c; - /* - * At first search an index table for a bit pattern. - * If it fails, search a huffman tree for. - */ - c = hf->tbl[rbits >> hf->shift_bits]; + c = hf->tbl[rbits]; if (c < hf->len_size) return (c); - /* This bit pattern needs to be found out at a huffman tree. */ - return (lzx_decode_huffman_tree(hf, rbits, c)); + return (0); } - diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_cpio.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_cpio.c index ffd4a85..ad9f782 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_cpio.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_cpio.c @@ -165,7 +165,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_cpio.c 20116 struct links_entry { struct links_entry *next; struct links_entry *previous; - int links; + unsigned int links; dev_t dev; int64_t ino; char *name; diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_iso9660.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_iso9660.c index 3541330..4b436d1 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_iso9660.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_iso9660.c @@ -3021,8 +3021,9 @@ heap_add_entry(struct archive_read *a, struct heap_queue *heap, ENOMEM, "Out of memory"); return (ARCHIVE_FATAL); } - memcpy(new_pending_files, heap->files, - heap->allocated * sizeof(new_pending_files[0])); + if (heap->allocated) + memcpy(new_pending_files, heap->files, + heap->allocated * sizeof(new_pending_files[0])); if (heap->files != NULL) free(heap->files); heap->files = new_pending_files; diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_lha.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_lha.c index ebd7f2c..1995e9c 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_lha.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_lha.c @@ -2480,7 +2480,7 @@ lzh_huffman_free(struct huffman *hf) free(hf->tree); } -static char bitlen_tbl[0x400] = { +static const char bitlen_tbl[0x400] = { 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_mtree.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_mtree.c index 4231ff5..44b6083 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_mtree.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_mtree.c @@ -130,9 +130,7 @@ static ssize_t readline(struct archive_read *, struct mtree *, char **, ssize_t) static int skip(struct archive_read *a); static int read_header(struct archive_read *, struct archive_entry *); -static int64_t mtree_atol10(char **); -static int64_t mtree_atol8(char **); -static int64_t mtree_atol(char **); +static int64_t mtree_atol(char **, int base); /* * There's no standard for TIME_T_MAX/TIME_T_MIN. So we compute them @@ -399,41 +397,41 @@ bid_keycmp(const char *p, const char *key, ssize_t len) static int bid_keyword(const char *p, ssize_t len) { - static const char *keys_c[] = { + static const char * const keys_c[] = { "content", "contents", "cksum", NULL }; - static const char *keys_df[] = { + static const char * const keys_df[] = { "device", "flags", NULL }; - static const char *keys_g[] = { + static const char * const keys_g[] = { "gid", "gname", NULL }; - static const char *keys_il[] = { + static const char * const keys_il[] = { "ignore", "inode", "link", NULL }; - static const char *keys_m[] = { + static const char * const keys_m[] = { "md5", "md5digest", "mode", NULL }; - static const char *keys_no[] = { + static const char * const keys_no[] = { "nlink", "nochange", "optional", NULL }; - static const char *keys_r[] = { + static const char * const keys_r[] = { "resdevice", "rmd160", "rmd160digest", NULL }; - static const char *keys_s[] = { + static const char * const keys_s[] = { "sha1", "sha1digest", "sha256", "sha256digest", "sha384", "sha384digest", "sha512", "sha512digest", "size", NULL }; - static const char *keys_t[] = { + static const char * const keys_t[] = { "tags", "time", "type", NULL }; - static const char *keys_u[] = { + static const char * const keys_u[] = { "uid", "uname", NULL }; - const char **keys; + const char * const *keys; int i; switch (*p) { @@ -1418,7 +1416,7 @@ parse_device(dev_t *pdev, struct archive *a, char *val) "Too many arguments"); return ARCHIVE_WARN; } - numbers[argc++] = (unsigned long)mtree_atol(&p); + numbers[argc++] = (unsigned long)mtree_atol(&p, 0); } if (argc < 2) { archive_set_error(a, ARCHIVE_ERRNO_FILE_FORMAT, @@ -1433,7 +1431,7 @@ parse_device(dev_t *pdev, struct archive *a, char *val) } } else { /* file system raw value. */ - result = (dev_t)mtree_atol(&val); + result = (dev_t)mtree_atol(&val, 0); } *pdev = result; return ARCHIVE_OK; @@ -1513,7 +1511,7 @@ parse_keyword(struct archive_read *a, struct mtree *mtree, case 'g': if (strcmp(key, "gid") == 0) { *parsed_kws |= MTREE_HAS_GID; - archive_entry_set_gid(entry, mtree_atol10(&val)); + archive_entry_set_gid(entry, mtree_atol(&val, 10)); break; } if (strcmp(key, "gname") == 0) { @@ -1523,7 +1521,7 @@ parse_keyword(struct archive_read *a, struct mtree *mtree, } case 'i': if (strcmp(key, "inode") == 0) { - archive_entry_set_ino(entry, mtree_atol10(&val)); + archive_entry_set_ino(entry, mtree_atol(&val, 10)); break; } case 'l': @@ -1535,14 +1533,14 @@ parse_keyword(struct archive_read *a, struct mtree *mtree, if (strcmp(key, "md5") == 0 || strcmp(key, "md5digest") == 0) break; if (strcmp(key, "mode") == 0) { - if (val[0] >= '0' && val[0] <= '9') { + if (val[0] >= '0' && val[0] <= '7') { *parsed_kws |= MTREE_HAS_PERM; archive_entry_set_perm(entry, - (mode_t)mtree_atol8(&val)); + (mode_t)mtree_atol(&val, 8)); } else { archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Symbolic mode \"%s\" unsupported", val); + "Symbolic or non-octal mode \"%s\" unsupported", val); return ARCHIVE_WARN; } break; @@ -1551,7 +1549,7 @@ parse_keyword(struct archive_read *a, struct mtree *mtree, if (strcmp(key, "nlink") == 0) { *parsed_kws |= MTREE_HAS_NLINK; archive_entry_set_nlink(entry, - (unsigned int)mtree_atol10(&val)); + (unsigned int)mtree_atol(&val, 10)); break; } case 'r': @@ -1582,7 +1580,7 @@ parse_keyword(struct archive_read *a, struct mtree *mtree, strcmp(key, "sha512digest") == 0) break; if (strcmp(key, "size") == 0) { - archive_entry_set_size(entry, mtree_atol10(&val)); + archive_entry_set_size(entry, mtree_atol(&val, 10)); break; } case 't': @@ -1601,13 +1599,13 @@ parse_keyword(struct archive_read *a, struct mtree *mtree, long ns = 0; *parsed_kws |= MTREE_HAS_MTIME; - m = mtree_atol10(&val); + m = mtree_atol(&val, 10); /* Replicate an old mtree bug: * 123456789.1 represents 123456789 * seconds and 1 nanosecond. */ if (*val == '.') { ++val; - ns = (long)mtree_atol10(&val); + ns = (long)mtree_atol(&val, 10); if (ns < 0) ns = 0; else if (ns > 999999999) @@ -1670,7 +1668,7 @@ parse_keyword(struct archive_read *a, struct mtree *mtree, case 'u': if (strcmp(key, "uid") == 0) { *parsed_kws |= MTREE_HAS_UID; - archive_entry_set_uid(entry, mtree_atol10(&val)); + archive_entry_set_uid(entry, mtree_atol(&val, 10)); break; } if (strcmp(key, "uname") == 0) { @@ -1825,72 +1823,9 @@ parse_escapes(char *src, struct mtree_entry *mentry) *dest = '\0'; } -/* - * Note that this implementation does not (and should not!) obey - * locale settings; you cannot simply substitute strtol here, since - * it does obey locale. - */ -static int64_t -mtree_atol8(char **p) -{ - int64_t l, limit, last_digit_limit; - int digit, base; - - base = 8; - limit = INT64_MAX / base; - last_digit_limit = INT64_MAX % base; - - l = 0; - digit = **p - '0'; - while (digit >= 0 && digit < base) { - if (l>limit || (l == limit && digit > last_digit_limit)) { - l = INT64_MAX; /* Truncate on overflow. */ - break; - } - l = (l * base) + digit; - digit = *++(*p) - '0'; - } - return (l); -} - -/* - * Note that this implementation does not (and should not!) obey - * locale settings; you cannot simply substitute strtol here, since - * it does obey locale. - */ -static int64_t -mtree_atol10(char **p) -{ - int64_t l, limit, last_digit_limit; - int base, digit, sign; - - base = 10; - - if (**p == '-') { - sign = -1; - limit = ((uint64_t)(INT64_MAX) + 1) / base; - last_digit_limit = ((uint64_t)(INT64_MAX) + 1) % base; - ++(*p); - } else { - sign = 1; - limit = INT64_MAX / base; - last_digit_limit = INT64_MAX % base; - } - - l = 0; - digit = **p - '0'; - while (digit >= 0 && digit < base) { - if (l > limit || (l == limit && digit > last_digit_limit)) - return (sign < 0) ? INT64_MIN : INT64_MAX; - l = (l * base) + digit; - digit = *++(*p) - '0'; - } - return (sign < 0) ? -l : l; -} - /* Parse a hex digit. */ static int -parsehex(char c) +parsedigit(char c) { if (c >= '0' && c <= '9') return c - '0'; @@ -1908,45 +1843,50 @@ parsehex(char c) * it does obey locale. */ static int64_t -mtree_atol16(char **p) +mtree_atol(char **p, int base) { - int64_t l, limit, last_digit_limit; - int base, digit, sign; - - base = 16; + int64_t l, limit; + int digit, last_digit_limit; + + if (base == 0) { + if (**p != '0') + base = 10; + else if ((*p)[1] == 'x' || (*p)[1] == 'X') { + *p += 2; + base = 16; + } else { + base = 8; + } + } if (**p == '-') { - sign = -1; - limit = ((uint64_t)(INT64_MAX) + 1) / base; - last_digit_limit = ((uint64_t)(INT64_MAX) + 1) % base; + limit = INT64_MIN / base; + last_digit_limit = INT64_MIN % base; ++(*p); + + l = 0; + digit = parsedigit(**p); + while (digit >= 0 && digit < base) { + if (l < limit || (l == limit && digit > last_digit_limit)) + return INT64_MIN; + l = (l * base) - digit; + digit = parsedigit(*++(*p)); + } + return l; } else { - sign = 1; limit = INT64_MAX / base; last_digit_limit = INT64_MAX % base; - } - l = 0; - digit = parsehex(**p); - while (digit >= 0 && digit < base) { - if (l > limit || (l == limit && digit > last_digit_limit)) - return (sign < 0) ? INT64_MIN : INT64_MAX; - l = (l * base) + digit; - digit = parsehex(*++(*p)); - } - return (sign < 0) ? -l : l; -} - -static int64_t -mtree_atol(char **p) -{ - if (**p != '0') - return mtree_atol10(p); - if ((*p)[1] == 'x' || (*p)[1] == 'X') { - *p += 2; - return mtree_atol16(p); + l = 0; + digit = parsedigit(**p); + while (digit >= 0 && digit < base) { + if (l > limit || (l == limit && digit > last_digit_limit)) + return INT64_MAX; + l = (l * base) + digit; + digit = parsedigit(*++(*p)); + } + return l; } - return mtree_atol8(p); } /* diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_rar.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_rar.c index 658d49d..a0e641e 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_rar.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_rar.c @@ -1750,7 +1750,7 @@ read_exttime(const char *p, struct rar *rar, const char *endp) return (-1); for (j = 0; j < count; j++) { - rem = ((*p) << 16) | (rem >> 8); + rem = (((unsigned)(unsigned char)*p) << 16) | (rem >> 8); p++; } tm = localtime(&t); diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c index bd7f13d..30d5bc8 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c @@ -155,6 +155,7 @@ struct tar { int compat_2x; int process_mac_extensions; int read_concatenated_archives; + int realsize_override; }; static int archive_block_is_null(const char *p); @@ -527,6 +528,7 @@ archive_read_format_tar_read_header(struct archive_read *a, tar->entry_offset = 0; gnu_clear_sparse_list(tar); tar->realsize = -1; /* Mark this as "unset" */ + tar->realsize_override = 0; /* Setup default string conversion. */ tar->sconv = tar->opt_sconv; @@ -1894,6 +1896,7 @@ pax_attribute(struct archive_read *a, struct tar *tar, if (strcmp(key, "GNU.sparse.size") == 0) { tar->realsize = tar_atol10(value, strlen(value)); archive_entry_set_size(entry, tar->realsize); + tar->realsize_override = 1; } /* GNU "0.1" sparse pax format. */ @@ -1925,6 +1928,7 @@ pax_attribute(struct archive_read *a, struct tar *tar, if (strcmp(key, "GNU.sparse.realsize") == 0) { tar->realsize = tar_atol10(value, strlen(value)); archive_entry_set_size(entry, tar->realsize); + tar->realsize_override = 1; } break; case 'L': @@ -1977,6 +1981,7 @@ pax_attribute(struct archive_read *a, struct tar *tar, tar_atol10(value, strlen(value))); } else if (strcmp(key, "SCHILY.realsize") == 0) { tar->realsize = tar_atol10(value, strlen(value)); + tar->realsize_override = 1; archive_entry_set_size(entry, tar->realsize); } else if (strncmp(key, "SCHILY.xattr.", 13) == 0) { pax_attribute_schily_xattr(entry, key, value, @@ -2055,14 +2060,12 @@ pax_attribute(struct archive_read *a, struct tar *tar, tar->entry_bytes_remaining = tar_atol10(value, strlen(value)); /* - * But, "size" is not necessarily the size of - * the file on disk; if this is a sparse file, - * the disk size may have already been set from - * GNU.sparse.realsize or GNU.sparse.size or - * an old GNU header field or SCHILY.realsize - * or .... + * The "size" pax header keyword always overrides the + * "size" field in the tar header. + * GNU.sparse.realsize, GNU.sparse.size and + * SCHILY.realsize override this value. */ - if (tar->realsize < 0) { + if (!tar->realsize_override) { archive_entry_set_size(entry, tar->entry_bytes_remaining); tar->realsize @@ -2206,6 +2209,7 @@ header_gnutar(struct archive_read *a, struct tar *tar, tar->realsize = tar_atol(header->realsize, sizeof(header->realsize)); archive_entry_set_size(entry, tar->realsize); + tar->realsize_override = 1; } if (header->sparse[0].offset[0] != 0) { diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_warc.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_warc.c index b162465..e875385 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_warc.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_warc.c @@ -600,9 +600,10 @@ _warc_rdver(const char *buf, size_t bsz) /* looks good so far, read the version number for a laugh */ buf += sizeof(magic) - 1U; - if (isdigit(buf[0U]) && (buf[1U] == '.') && isdigit(buf[2U])) { + if (isdigit((unsigned char)buf[0U]) && (buf[1U] == '.') && + isdigit((unsigned char)buf[2U])) { /* we support a maximum of 2 digits in the minor version */ - if (isdigit(buf[3U])) + if (isdigit((unsigned char)buf[3U])) end = 1U; /* set up major version */ ver = (buf[0U] - '0') * 10000U; @@ -686,7 +687,7 @@ _warc_rduri(const char *buf, size_t bsz) /* spaces inside uri are not allowed, CRLF should follow */ for (p = val; p < eol; p++) { - if (isspace(*p)) + if (isspace((unsigned char)*p)) return res; } @@ -736,7 +737,7 @@ _warc_rdlen(const char *buf, size_t bsz) while (val < eol && (*val == ' ' || *val == '\t')) val++; /* there must be at least one digit */ - if (!isdigit(*val)) + if (!isdigit((unsigned char)*val)) return -1; len = strtol(val, &on, 10); if (on != eol) { diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_zip.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_zip.c index e56bd63..ddd4458 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_zip.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_zip.c @@ -347,7 +347,7 @@ fake_crc32(unsigned long crc, const void *buff, size_t len) return 0; } -static struct { +static const struct { int id; const char * name; } compression_methods[] = { @@ -2407,7 +2407,7 @@ read_eocd(struct zip *zip, const char *p, int64_t current_offset) * Examine Zip64 EOCD locator: If it's valid, store the information * from it. */ -static void +static int read_zip64_eocd(struct archive_read *a, struct zip *zip, const char *p) { int64_t eocd64_offset; @@ -2417,35 +2417,37 @@ read_zip64_eocd(struct archive_read *a, struct zip *zip, const char *p) /* Central dir must be on first volume. */ if (archive_le32dec(p + 4) != 0) - return; + return 0; /* Must be only a single volume. */ if (archive_le32dec(p + 16) != 1) - return; + return 0; /* Find the Zip64 EOCD record. */ eocd64_offset = archive_le64dec(p + 8); if (__archive_read_seek(a, eocd64_offset, SEEK_SET) < 0) - return; + return 0; if ((p = __archive_read_ahead(a, 56, NULL)) == NULL) - return; + return 0; /* Make sure we can read all of it. */ eocd64_size = archive_le64dec(p + 4) + 12; if (eocd64_size < 56 || eocd64_size > 16384) - return; + return 0; if ((p = __archive_read_ahead(a, (size_t)eocd64_size, NULL)) == NULL) - return; + return 0; /* Sanity-check the EOCD64 */ if (archive_le32dec(p + 16) != 0) /* Must be disk #0 */ - return; + return 0; if (archive_le32dec(p + 20) != 0) /* CD must be on disk #0 */ - return; + return 0; /* CD can't be split. */ if (archive_le64dec(p + 24) != archive_le64dec(p + 32)) - return; + return 0; /* Save the central directory offset for later use. */ zip->central_directory_offset = archive_le64dec(p + 48); + + return 32; } static int @@ -2483,15 +2485,14 @@ archive_read_format_zip_seekable_bid(struct archive_read *a, int best_bid) if (memcmp(p + i, "PK\005\006", 4) == 0) { int ret = read_eocd(zip, p + i, current_offset + i); - if (ret > 0) { - /* Zip64 EOCD locator precedes - * regular EOCD if present. */ - if (i >= 20 - && memcmp(p + i - 20, "PK\006\007", 4) == 0) { - read_zip64_eocd(a, zip, p + i - 20); - } - return (ret); + /* Zip64 EOCD locator precedes + * regular EOCD if present. */ + if (i >= 20 && memcmp(p + i - 20, "PK\006\007", 4) == 0) { + int ret_zip64 = read_zip64_eocd(a, zip, p + i - 20); + if (ret_zip64 > ret) + ret = ret_zip64; } + return (ret); } i -= 4; break; diff --git a/Utilities/cmlibarchive/libarchive/archive_string.c b/Utilities/cmlibarchive/libarchive/archive_string.c index 592ead2..5ae09b6 100644 --- a/Utilities/cmlibarchive/libarchive/archive_string.c +++ b/Utilities/cmlibarchive/libarchive/archive_string.c @@ -202,7 +202,8 @@ archive_string_append(struct archive_string *as, const char *p, size_t s) { if (archive_string_ensure(as, as->length + s + 1) == NULL) return (NULL); - memmove(as->s + as->length, p, s); + if (s) + memmove(as->s + as->length, p, s); as->length += s; as->s[as->length] = 0; return (as); diff --git a/Utilities/cmlibarchive/libarchive/archive_string_sprintf.c b/Utilities/cmlibarchive/libarchive/archive_string_sprintf.c index 964ea2b..969a560 100644 --- a/Utilities/cmlibarchive/libarchive/archive_string_sprintf.c +++ b/Utilities/cmlibarchive/libarchive/archive_string_sprintf.c @@ -53,7 +53,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_string_sprintf.c 189435 2009-03- static void append_uint(struct archive_string *as, uintmax_t d, unsigned base) { - static const char *digits = "0123456789abcdef"; + static const char digits[] = "0123456789abcdef"; if (d >= base) append_uint(as, d/base, base); archive_strappend_char(as, digits[d % base]); diff --git a/Utilities/cmlibarchive/libarchive/archive_util.c b/Utilities/cmlibarchive/libarchive/archive_util.c index f56ca33..1e36ad7 100644 --- a/Utilities/cmlibarchive/libarchive/archive_util.c +++ b/Utilities/cmlibarchive/libarchive/archive_util.c @@ -89,88 +89,6 @@ archive_version_string(void) return (ARCHIVE_VERSION_STRING); } -const char * -archive_version_details(void) -{ - static struct archive_string str; - static int init = 0; - const char *zlib = archive_zlib_version(); - const char *liblzma = archive_liblzma_version(); - const char *bzlib = archive_bzlib_version(); - const char *liblz4 = archive_liblz4_version(); - - if (!init) { - archive_string_init(&str); - - archive_strcat(&str, ARCHIVE_VERSION_STRING); - if (zlib != NULL) { - archive_strcat(&str, " zlib/"); - archive_strcat(&str, zlib); - } - if (liblzma) { - archive_strcat(&str, " liblzma/"); - archive_strcat(&str, liblzma); - } - if (bzlib) { - const char *p = bzlib; - const char *sep = strchr(p, ','); - if (sep == NULL) - sep = p + strlen(p); - archive_strcat(&str, " bz2lib/"); - archive_strncat(&str, p, sep - p); - } - if (liblz4) { - archive_strcat(&str, " liblz4/"); - archive_strcat(&str, liblz4); - } - } - return str.s; -} - -const char * -archive_zlib_version(void) -{ -#ifdef HAVE_ZLIB_H - return ZLIB_VERSION; -#else - return NULL; -#endif -} - -const char * -archive_liblzma_version(void) -{ -#ifdef HAVE_LZMA_H - return LZMA_VERSION_STRING; -#else - return NULL; -#endif -} - -const char * -archive_bzlib_version(void) -{ -#ifdef HAVE_BZLIB_H - return BZ2_bzlibVersion(); -#else - return NULL; -#endif -} - -const char * -archive_liblz4_version(void) -{ -#if defined(HAVE_LZ4_H) && defined(HAVE_LIBLZ4) -#define str(s) #s -#define NUMBER(x) str(x) - return NUMBER(LZ4_VERSION_MAJOR) "." NUMBER(LZ4_VERSION_MINOR) "." NUMBER(LZ4_VERSION_RELEASE); -#undef NUMBER -#undef str -#else - return NULL; -#endif -} - int archive_errno(struct archive *a) { @@ -275,7 +193,7 @@ archive_copy_error(struct archive *dest, struct archive *src) void __archive_errx(int retvalue, const char *msg) { - static const char *msg1 = "Fatal Internal Error in libarchive: "; + static const char msg1[] = "Fatal Internal Error in libarchive: "; size_t s; s = write(2, msg1, strlen(msg1)); @@ -303,8 +221,8 @@ __archive_errx(int retvalue, const char *msg) int __archive_mktemp(const char *tmpdir) { - static const wchar_t *prefix = L"libarchive_"; - static const wchar_t *suffix = L"XXXXXXXXXX"; + static const wchar_t prefix[] = L"libarchive_"; + static const wchar_t suffix[] = L"XXXXXXXXXX"; static const wchar_t num[] = { L'0', L'1', L'2', L'3', L'4', L'5', L'6', L'7', L'8', L'9', L'A', L'B', L'C', L'D', L'E', L'F', diff --git a/Utilities/cmlibarchive/libarchive/archive_version_details.c b/Utilities/cmlibarchive/libarchive/archive_version_details.c new file mode 100644 index 0000000..9289bf1 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_version_details.c @@ -0,0 +1,133 @@ +/*- + * Copyright (c) 2009-2012,2014 Michihiro NAKAJIMA + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "archive_platform.h" +__FBSDID("$FreeBSD: head/lib/libarchive/archive_util.c 201098 2009-12-28 02:58:14Z kientzle $"); + +#ifdef HAVE_STDLIB_H +#include <stdlib.h> +#endif +#ifdef HAVE_STRING_H +#include <string.h> +#endif +#ifdef HAVE_ZLIB_H +#include <cm_zlib.h> +#endif +#ifdef HAVE_LZMA_H +#include <cm_lzma.h> +#endif +#ifdef HAVE_BZLIB_H +#include <cm_bzlib.h> +#endif +#ifdef HAVE_LZ4_H +#include <lz4.h> +#endif + +#include "archive.h" +#include "archive_private.h" +#include "archive_string.h" + +const char * +archive_version_details(void) +{ + static struct archive_string str; + static int init = 0; + const char *zlib = archive_zlib_version(); + const char *liblzma = archive_liblzma_version(); + const char *bzlib = archive_bzlib_version(); + const char *liblz4 = archive_liblz4_version(); + + if (!init) { + archive_string_init(&str); + + archive_strcat(&str, ARCHIVE_VERSION_STRING); + if (zlib != NULL) { + archive_strcat(&str, " zlib/"); + archive_strcat(&str, zlib); + } + if (liblzma) { + archive_strcat(&str, " liblzma/"); + archive_strcat(&str, liblzma); + } + if (bzlib) { + const char *p = bzlib; + const char *sep = strchr(p, ','); + if (sep == NULL) + sep = p + strlen(p); + archive_strcat(&str, " bz2lib/"); + archive_strncat(&str, p, sep - p); + } + if (liblz4) { + archive_strcat(&str, " liblz4/"); + archive_strcat(&str, liblz4); + } + } + return str.s; +} + +const char * +archive_zlib_version(void) +{ +#ifdef HAVE_ZLIB_H + return ZLIB_VERSION; +#else + return NULL; +#endif +} + +const char * +archive_liblzma_version(void) +{ +#ifdef HAVE_LZMA_H + return LZMA_VERSION_STRING; +#else + return NULL; +#endif +} + +const char * +archive_bzlib_version(void) +{ +#ifdef HAVE_BZLIB_H + return BZ2_bzlibVersion(); +#else + return NULL; +#endif +} + +const char * +archive_liblz4_version(void) +{ +#if defined(HAVE_LZ4_H) && defined(HAVE_LIBLZ4) +#define str(s) #s +#define NUMBER(x) str(x) + return NUMBER(LZ4_VERSION_MAJOR) "." NUMBER(LZ4_VERSION_MINOR) "." NUMBER(LZ4_VERSION_RELEASE); +#undef NUMBER +#undef str +#else + return NULL; +#endif +} diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter.c index ad5dc83..08f518a 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_add_filter.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter.c @@ -38,7 +38,7 @@ __FBSDID("$FreeBSD$"); #include "archive_private.h" /* A table that maps filter codes to functions. */ -static +static const struct { int code; int (*setter)(struct archive *); } codes[] = { { ARCHIVE_FILTER_NONE, archive_write_add_filter_none }, diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_by_name.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_by_name.c index eac4011..85a8d47 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_by_name.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_by_name.c @@ -42,7 +42,7 @@ __FBSDID("$FreeBSD$"); #include "archive_private.h" /* A table that maps names to functions. */ -static +static const struct { const char *name; int (*setter)(struct archive *); } names[] = { { "b64encode", archive_write_add_filter_b64encode }, diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_lz4.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_lz4.c index e655185..15fd494 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_lz4.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_lz4.c @@ -225,7 +225,7 @@ archive_filter_lz4_open(struct archive_write_filter *f) struct private_data *data = (struct private_data *)f->data; int ret; size_t required_size; - static size_t bkmap[] = { 64 * 1024, 256 * 1024, 1 * 1024 * 1024, + static size_t const bkmap[] = { 64 * 1024, 256 * 1024, 1 * 1024 * 1024, 4 * 1024 * 1024 }; size_t pre_block_size; diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_program.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_program.c index 55b5e8e..660f693 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_program.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_program.c @@ -92,7 +92,7 @@ archive_write_add_filter_program(struct archive *_a, const char *cmd) { struct archive_write_filter *f = __archive_write_allocate_filter(_a); struct private_data *data; - static const char *prefix = "Program: "; + static const char prefix[] = "Program: "; archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, ARCHIVE_STATE_NEW, "archive_write_add_filter_program"); diff --git a/Utilities/cmlibarchive/libarchive/archive_write_data.3 b/Utilities/cmlibarchive/libarchive/archive_write_data.3 index 0cdd25f..9c16cd9 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_data.3 +++ b/Utilities/cmlibarchive/libarchive/archive_write_data.3 @@ -24,11 +24,12 @@ .\" .\" $FreeBSD$ .\" -.Dd February 2, 2012 +.Dd February 28, 2017 .Dt ARCHIVE_WRITE_DATA 3 .Os .Sh NAME -.Nm archive_write_data +.Nm archive_write_data , +.Nm archive_write_data_block .Nd functions for creating archives .Sh LIBRARY Streaming Archive Library (libarchive, -larchive) @@ -36,8 +37,27 @@ Streaming Archive Library (libarchive, -larchive) .In archive.h .Ft la_ssize_t .Fn archive_write_data "struct archive *" "const void *" "size_t" +.Ft la_ssize_t +.Fn archive_write_data_block "struct archive *" "const void *" "size_t size" "int64_t offset" .Sh DESCRIPTION +.Bl -tag -width indent +.It Fn archive_write_data +Write data corresponding to the header just written. +.It Fn archive_write_data_block Write data corresponding to the header just written. +This is like +.Fn archive_write_data +except that it performs a seek on the file being +written to the specified offset before writing the data. +This is useful when restoring sparse files from archive +formats that support sparse files. +Returns number of bytes written or -1 on error. +(Note: This is currently not supported for +.Tn archive_write +handles, only for +.Tn archive_write_disk +handles. +.El .\" .Sh EXAMPLE .\" .Sh RETURN VALUES diff --git a/Utilities/cmlibarchive/libarchive/archive_write_disk.3 b/Utilities/cmlibarchive/libarchive/archive_write_disk.3 index ba6c970..949c9ef 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_disk.3 +++ b/Utilities/cmlibarchive/libarchive/archive_write_disk.3 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd February 2, 2012 +.Dd April 3, 2017 .Dt ARCHIVE_WRITE_DISK 3 .Os .Sh NAME @@ -33,14 +33,7 @@ .Nm archive_write_disk_set_skip_file , .Nm archive_write_disk_set_group_lookup , .Nm archive_write_disk_set_standard_lookup , -.Nm archive_write_disk_set_user_lookup , -.Nm archive_write_header , -.Nm archive_write_data , -.Nm archive_write_data_block , -.Nm archive_write_finish_entry , -.Nm archive_write_close , -.Nm archive_write_finish -.Nm archive_write_free +.Nm archive_write_disk_set_user_lookup .Nd functions for creating objects on disk .Sh LIBRARY Streaming Archive Library (libarchive, -larchive) @@ -68,20 +61,6 @@ Streaming Archive Library (libarchive, -larchive) .Fa "uid_t (*)(void *, const char *uname, uid_t uid)" .Fa "void (*cleanup)(void *)" .Fc -.Ft int -.Fn archive_write_header "struct archive *" "struct archive_entry *" -.Ft la_ssize_t -.Fn archive_write_data "struct archive *" "const void *" "size_t" -.Ft la_ssize_t -.Fn archive_write_data_block "struct archive *" "const void *" "size_t size" "int64_t offset" -.Ft int -.Fn archive_write_finish_entry "struct archive *" -.Ft int -.Fn archive_write_close "struct archive *" -.Ft int -.Fn archive_write_finish "struct archive *" -.Ft int -.Fn archive_write_free "struct archive *" .Sh DESCRIPTION These functions provide a complete API for creating objects on disk from @@ -117,6 +96,33 @@ performance optimization in practice. The options field consists of a bitwise OR of one or more of the following values: .Bl -tag -compact -width "indent" +.It Cm ARCHIVE_EXTRACT_ACL +Attempt to restore Access Control Lists. +By default, extended ACLs are ignored. +.It Cm ARCHIVE_EXTRACT_CLEAR_NOCHANGE_FFLAGS +Before removing a file system object prior to replacing it, clear +platform-specific file flags which might prevent its removal. +.It Cm ARCHIVE_EXTRACT_FFLAGS +Attempt to restore file attributes (file flags). +By default, file attributes are ignored. +See +.Xr chattr 1 +.Pq Linux +or +.Xr chflags 1 +.Pq FreeBSD, Mac OS X +for more information on file attributes. +.It Cm ARCHIVE_EXTRACT_MAC_METADATA +Mac OS X specific. Restore metadata using +.Xr copyfile 3 . +By default, +.Xr copyfile 3 +metadata is ignored. +.It Cm ARCHIVE_EXTRACT_NO_OVERWRITE +Existing files on disk will not be overwritten. +By default, existing regular files are truncated and overwritten; +existing directories will have their permissions updated; +other pre-existing objects are unlinked and recreated from scratch. .It Cm ARCHIVE_EXTRACT_OWNER The user and group IDs should be set on the restored file. By default, the user and group IDs are not restored. @@ -132,15 +138,37 @@ is not specified, then SUID and SGID bits will only be restored if the default user and group IDs of newly-created objects on disk happen to match those specified in the archive entry. By default, only basic permissions are restored, and umask is obeyed. +.It Cm ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS +Refuse to extract an absolute path. +The default is to not refuse such paths. +.It Cm ARCHIVE_EXTRACT_SECURE_NODOTDOT +Refuse to extract a path that contains a +.Pa .. +element anywhere within it. +The default is to not refuse such paths. +Note that paths ending in +.Pa .. +always cause an error, regardless of this flag. +.It Cm ARCHIVE_EXTRACT_SECURE_SYMLINKS +Refuse to extract any object whose final location would be altered +by a symlink on disk. +This is intended to help guard against a variety of mischief +caused by archives that (deliberately or otherwise) extract +files outside of the current directory. +The default is not to perform this check. +If +.It Cm ARCHIVE_EXTRACT_SPARSE +Scan data for blocks of NUL bytes and try to recreate them with holes. +This results in sparse files, independent of whether the archive format +supports or uses them. +.Cm ARCHIVE_EXTRACT_UNLINK +is specified together with this option, the library will +remove any intermediate symlinks it finds and return an +error only if such symlink could not be removed. .It Cm ARCHIVE_EXTRACT_TIME The timestamps (mtime, ctime, and atime) should be restored. By default, they are ignored. Note that restoring of atime is not currently supported. -.It Cm ARCHIVE_EXTRACT_NO_OVERWRITE -Existing files on disk will not be overwritten. -By default, existing regular files are truncated and overwritten; -existing directories will have their permissions updated; -other pre-existing objects are unlinked and recreated from scratch. .It Cm ARCHIVE_EXTRACT_UNLINK Existing files on disk will be unlinked before any attempt to create them. @@ -148,45 +176,18 @@ In some cases, this can prove to be a significant performance improvement. By default, existing files are truncated and rewritten, but the file is not recreated. In particular, the default behavior does not break existing hard links. -.It Cm ARCHIVE_EXTRACT_ACL -Attempt to restore ACLs. -By default, extended ACLs are ignored. -.It Cm ARCHIVE_EXTRACT_FFLAGS -Attempt to restore extended file flags. -By default, file flags are ignored. .It Cm ARCHIVE_EXTRACT_XATTR -Attempt to restore POSIX.1e extended attributes. +Attempt to restore extended file attributes. By default, they are ignored. -.It Cm ARCHIVE_EXTRACT_SECURE_SYMLINKS -Refuse to extract any object whose final location would be altered -by a symlink on disk. -This is intended to help guard against a variety of mischief -caused by archives that (deliberately or otherwise) extract -files outside of the current directory. -The default is not to perform this check. -If -.Cm ARCHIVE_EXTRACT_UNLINK -is specified together with this option, the library will -remove any intermediate symlinks it finds and return an -error only if such symlink could not be removed. -.It Cm ARCHIVE_EXTRACT_SECURE_NODOTDOT -Refuse to extract a path that contains a -.Pa .. -element anywhere within it. -The default is to not refuse such paths. -Note that paths ending in -.Pa .. -always cause an error, regardless of this flag. -.It Cm ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS -Refuse to extract an absolute path. -The default is to not refuse such paths. -.It Cm ARCHIVE_EXTRACT_SPARSE -Scan data for blocks of NUL bytes and try to recreate them with holes. -This results in sparse files, independent of whether the archive format -supports or uses them. -.It Cm ARCHIVE_EXTRACT_CLEAR_NOCHANGE_FFLAGS -Before removing a file system object prior to replacing it, clear -platform-specific file flags which might prevent its removal. +See +.Xr xattr 7 +.Pq Linux , +.Xr xattr 2 +.Pq Mac OS X , +or +.Xr getextattr 8 +.Pq FreeBSD +for more information on extended file attributes. .El .It Xo .Fn archive_write_disk_set_group_lookup , @@ -223,60 +224,6 @@ the number of calls to .Xr getpwnam 3 and .Xr getgrnam 3 . -.It Fn archive_write_header -Build and write a header using the data in the provided -.Tn struct archive_entry -structure. -See -.Xr archive_entry 3 -for information on creating and populating -.Tn struct archive_entry -objects. -.It Fn archive_write_data -Write data corresponding to the header just written. -Returns number of bytes written or -1 on error. -.It Fn archive_write_data_block -Write data corresponding to the header just written. -This is like -.Fn archive_write_data -except that it performs a seek on the file being -written to the specified offset before writing the data. -This is useful when restoring sparse files from archive -formats that support sparse files. -Returns number of bytes written or -1 on error. -(Note: This is currently not supported for -.Tn archive_write -handles, only for -.Tn archive_write_disk -handles.) -.It Fn archive_write_finish_entry -Close out the entry just written. -Ordinarily, clients never need to call this, as it -is called automatically by -.Fn archive_write_next_header -and -.Fn archive_write_close -as needed. -However, some file attributes are written to disk only -after the file is closed, so this can be necessary -if you need to work with the file on disk right away. -.It Fn archive_write_close -Set any attributes that could not be set during the initial restore. -For example, directory timestamps are not restored initially because -restoring a subsequent file would alter that timestamp. -Similarly, non-writable directories are initially created with -write permissions (so that their contents can be restored). -The -.Nm -library maintains a list of all such deferred attributes and -sets them when this function is invoked. -.It Fn archive_write_finish -This is a deprecated synonym for -.Fn archive_write_free . -.It Fn archive_write_free -Invokes -.Fn archive_write_close -if it was not invoked manually, then releases all resources. .El More information about the .Va struct archive diff --git a/Utilities/cmlibarchive/libarchive/archive_write_disk_acl.c b/Utilities/cmlibarchive/libarchive/archive_write_disk_acl.c deleted file mode 100644 index 144ab7e..0000000 --- a/Utilities/cmlibarchive/libarchive/archive_write_disk_acl.c +++ /dev/null @@ -1,654 +0,0 @@ -/*- - * Copyright (c) 2003-2010 Tim Kientzle - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer - * in this position and unchanged. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_disk.c 201159 2009-12-29 05:35:40Z kientzle $"); - -#ifdef HAVE_SYS_TYPES_H -#include <sys/types.h> -#endif -#ifdef HAVE_SYS_ACL_H -#define _ACL_PRIVATE /* For debugging */ -#include <sys/acl.h> -#endif -#if HAVE_DARWIN_ACL -#include <membership.h> -#endif -#ifdef HAVE_ERRNO_H -#include <errno.h> -#endif - -#include "archive.h" -#include "archive_entry.h" -#include "archive_acl_private.h" -#include "archive_write_disk_private.h" - -#if !HAVE_POSIX_ACL && !HAVE_NFS4_ACL -/* Default empty function body to satisfy mainline code. */ -int -archive_write_disk_set_acls(struct archive *a, int fd, const char *name, - struct archive_acl *abstract_acl) -{ - (void)a; /* UNUSED */ - (void)fd; /* UNUSED */ - (void)name; /* UNUSED */ - (void)abstract_acl; /* UNUSED */ - return (ARCHIVE_OK); -} - -#else /* HAVE_POSIX_ACL || HAVE_NFS4_ACL */ - -#if HAVE_SUN_ACL -#define ARCHIVE_PLATFORM_ACL_TYPE_NFS4 ACE_T -#elif HAVE_DARWIN_ACL -#define ARCHIVE_PLATFORM_ACL_TYPE_NFS4 ACL_TYPE_EXTENDED -#elif HAVE_ACL_TYPE_NFS4 -#define ARCHIVE_PLATFORM_ACL_TYPE_NFS4 ACL_TYPE_NFS4 -#endif - -static int set_acl(struct archive *, int fd, const char *, - struct archive_acl *, - acl_type_t, int archive_entry_acl_type, const char *tn); - -int -archive_write_disk_set_acls(struct archive *a, int fd, const char *name, - struct archive_acl *abstract_acl) -{ - int ret = ARCHIVE_OK; - -#if !HAVE_DARWIN_ACL - if ((archive_acl_types(abstract_acl) - & ARCHIVE_ENTRY_ACL_TYPE_POSIX1E) != 0) { -#if HAVE_SUN_ACL - /* Solaris writes POSIX.1e access and default ACLs together */ - ret = set_acl(a, fd, name, abstract_acl, ACLENT_T, - ARCHIVE_ENTRY_ACL_TYPE_POSIX1E, "posix1e"); -#else /* HAVE_POSIX_ACL */ - if ((archive_acl_types(abstract_acl) - & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0) { - ret = set_acl(a, fd, name, abstract_acl, - ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - "access"); - if (ret != ARCHIVE_OK) - return (ret); - } - if ((archive_acl_types(abstract_acl) - & ARCHIVE_ENTRY_ACL_TYPE_DEFAULT) != 0) - ret = set_acl(a, fd, name, abstract_acl, - ACL_TYPE_DEFAULT, ARCHIVE_ENTRY_ACL_TYPE_DEFAULT, - "default"); -#endif /* !HAVE_SUN_ACL */ - /* Simultaneous POSIX.1e and NFSv4 is not supported */ - return (ret); - } -#endif /* !HAVE_DARWIN_ACL */ -#if HAVE_NFS4_ACL - if ((archive_acl_types(abstract_acl) & - ARCHIVE_ENTRY_ACL_TYPE_NFS4) != 0) { - ret = set_acl(a, fd, name, abstract_acl, - ARCHIVE_PLATFORM_ACL_TYPE_NFS4, - ARCHIVE_ENTRY_ACL_TYPE_NFS4, "nfs4"); - } -#endif /* HAVE_NFS4_ACL */ - return (ret); -} - -/* - * Translate system ACL permissions into libarchive internal structure - */ -static const struct { - const int archive_perm; - const int platform_perm; -} acl_perm_map[] = { -#if HAVE_SUN_ACL /* Solaris NFSv4 ACL permissions */ - {ARCHIVE_ENTRY_ACL_EXECUTE, ACE_EXECUTE}, - {ARCHIVE_ENTRY_ACL_READ_DATA, ACE_READ_DATA}, - {ARCHIVE_ENTRY_ACL_LIST_DIRECTORY, ACE_LIST_DIRECTORY}, - {ARCHIVE_ENTRY_ACL_WRITE_DATA, ACE_WRITE_DATA}, - {ARCHIVE_ENTRY_ACL_ADD_FILE, ACE_ADD_FILE}, - {ARCHIVE_ENTRY_ACL_APPEND_DATA, ACE_APPEND_DATA}, - {ARCHIVE_ENTRY_ACL_ADD_SUBDIRECTORY, ACE_ADD_SUBDIRECTORY}, - {ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS, ACE_READ_NAMED_ATTRS}, - {ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS, ACE_WRITE_NAMED_ATTRS}, - {ARCHIVE_ENTRY_ACL_DELETE_CHILD, ACE_DELETE_CHILD}, - {ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES, ACE_READ_ATTRIBUTES}, - {ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES, ACE_WRITE_ATTRIBUTES}, - {ARCHIVE_ENTRY_ACL_DELETE, ACE_DELETE}, - {ARCHIVE_ENTRY_ACL_READ_ACL, ACE_READ_ACL}, - {ARCHIVE_ENTRY_ACL_WRITE_ACL, ACE_WRITE_ACL}, - {ARCHIVE_ENTRY_ACL_WRITE_OWNER, ACE_WRITE_OWNER}, - {ARCHIVE_ENTRY_ACL_SYNCHRONIZE, ACE_SYNCHRONIZE} -#elif HAVE_DARWIN_ACL /* MacOS ACL permissions */ - {ARCHIVE_ENTRY_ACL_READ_DATA, ACL_READ_DATA}, - {ARCHIVE_ENTRY_ACL_LIST_DIRECTORY, ACL_LIST_DIRECTORY}, - {ARCHIVE_ENTRY_ACL_WRITE_DATA, ACL_WRITE_DATA}, - {ARCHIVE_ENTRY_ACL_ADD_FILE, ACL_ADD_FILE}, - {ARCHIVE_ENTRY_ACL_EXECUTE, ACL_EXECUTE}, - {ARCHIVE_ENTRY_ACL_DELETE, ACL_DELETE}, - {ARCHIVE_ENTRY_ACL_APPEND_DATA, ACL_APPEND_DATA}, - {ARCHIVE_ENTRY_ACL_ADD_SUBDIRECTORY, ACL_ADD_SUBDIRECTORY}, - {ARCHIVE_ENTRY_ACL_DELETE_CHILD, ACL_DELETE_CHILD}, - {ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES, ACL_READ_ATTRIBUTES}, - {ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES, ACL_WRITE_ATTRIBUTES}, - {ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS, ACL_READ_EXTATTRIBUTES}, - {ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS, ACL_WRITE_EXTATTRIBUTES}, - {ARCHIVE_ENTRY_ACL_READ_ACL, ACL_READ_SECURITY}, - {ARCHIVE_ENTRY_ACL_WRITE_ACL, ACL_WRITE_SECURITY}, - {ARCHIVE_ENTRY_ACL_WRITE_OWNER, ACL_CHANGE_OWNER}, - {ARCHIVE_ENTRY_ACL_SYNCHRONIZE, ACL_SYNCHRONIZE} -#else /* POSIX.1e ACL permissions */ - {ARCHIVE_ENTRY_ACL_EXECUTE, ACL_EXECUTE}, - {ARCHIVE_ENTRY_ACL_WRITE, ACL_WRITE}, - {ARCHIVE_ENTRY_ACL_READ, ACL_READ}, -#if HAVE_ACL_TYPE_NFS4 /* FreeBSD NFSv4 ACL permissions */ - {ARCHIVE_ENTRY_ACL_READ_DATA, ACL_READ_DATA}, - {ARCHIVE_ENTRY_ACL_LIST_DIRECTORY, ACL_LIST_DIRECTORY}, - {ARCHIVE_ENTRY_ACL_WRITE_DATA, ACL_WRITE_DATA}, - {ARCHIVE_ENTRY_ACL_ADD_FILE, ACL_ADD_FILE}, - {ARCHIVE_ENTRY_ACL_APPEND_DATA, ACL_APPEND_DATA}, - {ARCHIVE_ENTRY_ACL_ADD_SUBDIRECTORY, ACL_ADD_SUBDIRECTORY}, - {ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS, ACL_READ_NAMED_ATTRS}, - {ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS, ACL_WRITE_NAMED_ATTRS}, - {ARCHIVE_ENTRY_ACL_DELETE_CHILD, ACL_DELETE_CHILD}, - {ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES, ACL_READ_ATTRIBUTES}, - {ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES, ACL_WRITE_ATTRIBUTES}, - {ARCHIVE_ENTRY_ACL_DELETE, ACL_DELETE}, - {ARCHIVE_ENTRY_ACL_READ_ACL, ACL_READ_ACL}, - {ARCHIVE_ENTRY_ACL_WRITE_ACL, ACL_WRITE_ACL}, - {ARCHIVE_ENTRY_ACL_WRITE_OWNER, ACL_WRITE_OWNER}, - {ARCHIVE_ENTRY_ACL_SYNCHRONIZE, ACL_SYNCHRONIZE} -#endif -#endif /* !HAVE_SUN_ACL && !HAVE_DARWIN_ACL */ -}; - -#if HAVE_NFS4_ACL -/* - * Translate system NFSv4 inheritance flags into libarchive internal structure - */ -static const struct { - const int archive_inherit; - const int platform_inherit; -} acl_inherit_map[] = { -#if HAVE_SUN_ACL /* Solaris NFSv4 inheritance flags */ - {ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT, ACE_FILE_INHERIT_ACE}, - {ARCHIVE_ENTRY_ACL_ENTRY_DIRECTORY_INHERIT, ACE_DIRECTORY_INHERIT_ACE}, - {ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT, ACE_NO_PROPAGATE_INHERIT_ACE}, - {ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY, ACE_INHERIT_ONLY_ACE}, - {ARCHIVE_ENTRY_ACL_ENTRY_SUCCESSFUL_ACCESS, ACE_SUCCESSFUL_ACCESS_ACE_FLAG}, - {ARCHIVE_ENTRY_ACL_ENTRY_FAILED_ACCESS, ACE_FAILED_ACCESS_ACE_FLAG}, - {ARCHIVE_ENTRY_ACL_ENTRY_INHERITED, ACE_INHERITED_ACE} -#elif HAVE_DARWIN_ACL /* MacOS NFSv4 inheritance flags */ - {ARCHIVE_ENTRY_ACL_ENTRY_INHERITED, ACL_ENTRY_INHERITED}, - {ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT, ACL_ENTRY_FILE_INHERIT}, - {ARCHIVE_ENTRY_ACL_ENTRY_DIRECTORY_INHERIT, ACL_ENTRY_DIRECTORY_INHERIT}, - {ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT, ACL_ENTRY_LIMIT_INHERIT}, - {ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY, ACL_ENTRY_ONLY_INHERIT} -#else /* FreeBSD NFSv4 ACL inheritance flags */ - {ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT, ACL_ENTRY_FILE_INHERIT}, - {ARCHIVE_ENTRY_ACL_ENTRY_DIRECTORY_INHERIT, ACL_ENTRY_DIRECTORY_INHERIT}, - {ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT, ACL_ENTRY_NO_PROPAGATE_INHERIT}, - {ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY, ACL_ENTRY_INHERIT_ONLY}, - {ARCHIVE_ENTRY_ACL_ENTRY_SUCCESSFUL_ACCESS, ACL_ENTRY_SUCCESSFUL_ACCESS}, - {ARCHIVE_ENTRY_ACL_ENTRY_FAILED_ACCESS, ACL_ENTRY_FAILED_ACCESS}, - {ARCHIVE_ENTRY_ACL_ENTRY_INHERITED, ACL_ENTRY_INHERITED} -#endif /* !HAVE_SUN_ACL && !HAVE_DARWIN_ACL */ -}; -#endif /* HAVE_NFS4_ACL */ - -static int -set_acl(struct archive *a, int fd, const char *name, - struct archive_acl *abstract_acl, - acl_type_t acl_type, int ae_requested_type, const char *tname) -{ -#if HAVE_SUN_ACL - aclent_t *aclent; - ace_t *ace; - int e, r; - acl_t *acl; -#else - acl_t acl; - acl_entry_t acl_entry; - acl_permset_t acl_permset; -#if HAVE_ACL_TYPE_NFS4 || HAVE_DARWIN_ACL - acl_flagset_t acl_flagset; -#endif -#endif /* HAVE_SUN_ACL */ -#if HAVE_ACL_TYPE_NFS4 - int r; -#endif - int ret; - int ae_type, ae_permset, ae_tag, ae_id; -#if HAVE_DARWIN_ACL - uuid_t ae_uuid; -#endif - uid_t ae_uid; - gid_t ae_gid; - const char *ae_name; - int entries; - int i; - - ret = ARCHIVE_OK; - entries = archive_acl_reset(abstract_acl, ae_requested_type); - if (entries == 0) - return (ARCHIVE_OK); - -#if HAVE_SUN_ACL - acl = NULL; - acl = malloc(sizeof(acl_t)); - if (acl == NULL) { - archive_set_error(a, ARCHIVE_ERRNO_MISC, - "Invalid ACL type"); - return (ARCHIVE_FAILED); - } - if (acl_type == ACE_T) - acl->acl_entry_size = sizeof(ace_t); - else if (acl_type == ACLENT_T) - acl->acl_entry_size = sizeof(aclent_t); - else { - archive_set_error(a, ARCHIVE_ERRNO_MISC, - "Invalid ACL type"); - acl_free(acl); - return (ARCHIVE_FAILED); - } - acl->acl_type = acl_type; - acl->acl_cnt = entries; - - acl->acl_aclp = malloc(entries * acl->acl_entry_size); - if (acl->acl_aclp == NULL) { - archive_set_error(a, errno, - "Can't allocate memory for acl buffer"); - acl_free(acl); - return (ARCHIVE_FAILED); - } -#else /* !HAVE_SUN_ACL */ - acl = acl_init(entries); - if (acl == (acl_t)NULL) { - archive_set_error(a, errno, - "Failed to initialize ACL working storage"); - return (ARCHIVE_FAILED); - } -#endif /* !HAVE_SUN_ACL */ -#if HAVE_SUN_ACL - e = 0; -#endif - while (archive_acl_next(a, abstract_acl, ae_requested_type, &ae_type, - &ae_permset, &ae_tag, &ae_id, &ae_name) == ARCHIVE_OK) { -#if HAVE_SUN_ACL - ace = NULL; - aclent = NULL; - if (acl->acl_type == ACE_T) { - ace = &((ace_t *)acl->acl_aclp)[e]; - ace->a_who = -1; - ace->a_access_mask = 0; - ace->a_flags = 0; - } else { - aclent = &((aclent_t *)acl->acl_aclp)[e]; - aclent->a_id = -1; - aclent->a_type = 0; - aclent->a_perm = 0; - } -#else /* !HAVE_SUN_ACL */ -#if HAVE_DARWIN_ACL - /* - * Mac OS doesn't support NFSv4 ACLs for - * owner@, group@ and everyone@. - * We skip any of these ACLs found. - */ - if (ae_tag == ARCHIVE_ENTRY_ACL_USER_OBJ || - ae_tag == ARCHIVE_ENTRY_ACL_GROUP_OBJ || - ae_tag == ARCHIVE_ENTRY_ACL_EVERYONE) - continue; -#endif - if (acl_create_entry(&acl, &acl_entry) != 0) { - archive_set_error(a, errno, - "Failed to create a new ACL entry"); - ret = ARCHIVE_FAILED; - goto exit_free; - } -#endif /* !HAVE_SUN_ACL */ -#if HAVE_DARWIN_ACL - switch (ae_type) { - case ARCHIVE_ENTRY_ACL_TYPE_ALLOW: - acl_set_tag_type(acl_entry, ACL_EXTENDED_ALLOW); - break; - case ARCHIVE_ENTRY_ACL_TYPE_DENY: - acl_set_tag_type(acl_entry, ACL_EXTENDED_DENY); - break; - default: - /* We don't support any other types on MacOS */ - continue; - } -#endif - switch (ae_tag) { -#if HAVE_SUN_ACL - case ARCHIVE_ENTRY_ACL_USER: - ae_uid = archive_write_disk_uid(a, ae_name, ae_id); - if (acl->acl_type == ACE_T) - ace->a_who = ae_uid; - else { - aclent->a_id = ae_uid; - aclent->a_type |= USER; - } - break; - case ARCHIVE_ENTRY_ACL_GROUP: - ae_gid = archive_write_disk_gid(a, ae_name, ae_id); - if (acl->acl_type == ACE_T) { - ace->a_who = ae_gid; - ace->a_flags |= ACE_IDENTIFIER_GROUP; - } else { - aclent->a_id = ae_gid; - aclent->a_type |= GROUP; - } - break; - case ARCHIVE_ENTRY_ACL_USER_OBJ: - if (acl->acl_type == ACE_T) - ace->a_flags |= ACE_OWNER; - else - aclent->a_type |= USER_OBJ; - break; - case ARCHIVE_ENTRY_ACL_GROUP_OBJ: - if (acl->acl_type == ACE_T) { - ace->a_flags |= ACE_GROUP; - ace->a_flags |= ACE_IDENTIFIER_GROUP; - } else - aclent->a_type |= GROUP_OBJ; - break; - case ARCHIVE_ENTRY_ACL_MASK: - aclent->a_type |= CLASS_OBJ; - break; - case ARCHIVE_ENTRY_ACL_OTHER: - aclent->a_type |= OTHER_OBJ; - break; - case ARCHIVE_ENTRY_ACL_EVERYONE: - ace->a_flags |= ACE_EVERYONE; - break; -#else /* !HAVE_SUN_ACL */ - case ARCHIVE_ENTRY_ACL_USER: - ae_uid = archive_write_disk_uid(a, ae_name, ae_id); -#if !HAVE_DARWIN_ACL /* FreeBSD, Linux */ - acl_set_tag_type(acl_entry, ACL_USER); - acl_set_qualifier(acl_entry, &ae_uid); -#else /* MacOS */ - if (mbr_identifier_to_uuid(ID_TYPE_UID, &ae_uid, - sizeof(uid_t), ae_uuid) != 0) - continue; - if (acl_set_qualifier(acl_entry, &ae_uuid) != 0) - continue; -#endif /* HAVE_DARWIN_ACL */ - break; - case ARCHIVE_ENTRY_ACL_GROUP: - ae_gid = archive_write_disk_gid(a, ae_name, ae_id); -#if !HAVE_DARWIN_ACL /* FreeBSD, Linux */ - acl_set_tag_type(acl_entry, ACL_GROUP); - acl_set_qualifier(acl_entry, &ae_gid); -#else /* MacOS */ - if (mbr_identifier_to_uuid(ID_TYPE_GID, &ae_gid, - sizeof(gid_t), ae_uuid) != 0) - continue; - if (acl_set_qualifier(acl_entry, &ae_uuid) != 0) - continue; -#endif /* HAVE_DARWIN_ACL */ - break; -#if !HAVE_DARWIN_ACL /* FreeBSD, Linux */ - case ARCHIVE_ENTRY_ACL_USER_OBJ: - acl_set_tag_type(acl_entry, ACL_USER_OBJ); - break; - case ARCHIVE_ENTRY_ACL_GROUP_OBJ: - acl_set_tag_type(acl_entry, ACL_GROUP_OBJ); - break; - case ARCHIVE_ENTRY_ACL_MASK: - acl_set_tag_type(acl_entry, ACL_MASK); - break; - case ARCHIVE_ENTRY_ACL_OTHER: - acl_set_tag_type(acl_entry, ACL_OTHER); - break; -#if HAVE_ACL_TYPE_NFS4 /* FreeBSD only */ - case ARCHIVE_ENTRY_ACL_EVERYONE: - acl_set_tag_type(acl_entry, ACL_EVERYONE); - break; -#endif -#endif /* !HAVE_DARWIN_ACL */ -#endif /* !HAVE_SUN_ACL */ - default: - archive_set_error(a, ARCHIVE_ERRNO_MISC, - "Unknown ACL tag"); - ret = ARCHIVE_FAILED; - goto exit_free; - } - -#if HAVE_ACL_TYPE_NFS4 || HAVE_SUN_ACL - r = 0; - switch (ae_type) { -#if HAVE_SUN_ACL - case ARCHIVE_ENTRY_ACL_TYPE_ALLOW: - if (ace != NULL) - ace->a_type = ACE_ACCESS_ALLOWED_ACE_TYPE; - else - r = -1; - break; - case ARCHIVE_ENTRY_ACL_TYPE_DENY: - if (ace != NULL) - ace->a_type = ACE_ACCESS_DENIED_ACE_TYPE; - else - r = -1; - break; - case ARCHIVE_ENTRY_ACL_TYPE_AUDIT: - if (ace != NULL) - ace->a_type = ACE_SYSTEM_AUDIT_ACE_TYPE; - else - r = -1; - break; - case ARCHIVE_ENTRY_ACL_TYPE_ALARM: - if (ace != NULL) - ace->a_type = ACE_SYSTEM_ALARM_ACE_TYPE; - else - r = -1; - break; - case ARCHIVE_ENTRY_ACL_TYPE_ACCESS: - if (aclent == NULL) - r = -1; - break; - case ARCHIVE_ENTRY_ACL_TYPE_DEFAULT: - if (aclent != NULL) - aclent->a_type |= ACL_DEFAULT; - else - r = -1; - break; -#else /* !HAVE_SUN_ACL */ - case ARCHIVE_ENTRY_ACL_TYPE_ALLOW: - r = acl_set_entry_type_np(acl_entry, ACL_ENTRY_TYPE_ALLOW); - break; - case ARCHIVE_ENTRY_ACL_TYPE_DENY: - r = acl_set_entry_type_np(acl_entry, ACL_ENTRY_TYPE_DENY); - break; - case ARCHIVE_ENTRY_ACL_TYPE_AUDIT: - r = acl_set_entry_type_np(acl_entry, ACL_ENTRY_TYPE_AUDIT); - break; - case ARCHIVE_ENTRY_ACL_TYPE_ALARM: - r = acl_set_entry_type_np(acl_entry, ACL_ENTRY_TYPE_ALARM); - break; - case ARCHIVE_ENTRY_ACL_TYPE_ACCESS: - case ARCHIVE_ENTRY_ACL_TYPE_DEFAULT: - // These don't translate directly into the system ACL. - break; -#endif /* !HAVE_SUN_ACL */ - default: - archive_set_error(a, ARCHIVE_ERRNO_MISC, - "Unknown ACL entry type"); - ret = ARCHIVE_FAILED; - goto exit_free; - } - - if (r != 0) { -#if HAVE_SUN_ACL - errno = EINVAL; -#endif - archive_set_error(a, errno, - "Failed to set ACL entry type"); - ret = ARCHIVE_FAILED; - goto exit_free; - } -#endif /* HAVE_ACL_TYPE_NFS4 || HAVE_SUN_ACL */ - -#if HAVE_SUN_ACL - if (acl->acl_type == ACLENT_T) { - if (ae_permset & ARCHIVE_ENTRY_ACL_EXECUTE) - aclent->a_perm |= 1; - if (ae_permset & ARCHIVE_ENTRY_ACL_WRITE) - aclent->a_perm |= 2; - if (ae_permset & ARCHIVE_ENTRY_ACL_READ) - aclent->a_perm |= 4; - } else -#else - if (acl_get_permset(acl_entry, &acl_permset) != 0) { - archive_set_error(a, errno, - "Failed to get ACL permission set"); - ret = ARCHIVE_FAILED; - goto exit_free; - } - if (acl_clear_perms(acl_permset) != 0) { - archive_set_error(a, errno, - "Failed to clear ACL permissions"); - ret = ARCHIVE_FAILED; - goto exit_free; - } -#endif /* !HAVE_SUN_ACL */ - for (i = 0; i < (int)(sizeof(acl_perm_map) / sizeof(acl_perm_map[0])); ++i) { - if (ae_permset & acl_perm_map[i].archive_perm) { -#if HAVE_SUN_ACL - ace->a_access_mask |= - acl_perm_map[i].platform_perm; -#else - if (acl_add_perm(acl_permset, - acl_perm_map[i].platform_perm) != 0) { - archive_set_error(a, errno, - "Failed to add ACL permission"); - ret = ARCHIVE_FAILED; - goto exit_free; - } -#endif - } - } - -#if HAVE_NFS4_ACL -#if HAVE_SUN_ACL - if (acl_type == ACE_T) -#elif HAVE_DARWIN_ACL - if (acl_type == ACL_TYPE_EXTENDED) -#else /* FreeBSD */ - if (acl_type == ACL_TYPE_NFS4) -#endif - { -#if HAVE_POSIX_ACL || HAVE_DARWIN_ACL - /* - * acl_get_flagset_np() fails with non-NFSv4 ACLs - */ - if (acl_get_flagset_np(acl_entry, &acl_flagset) != 0) { - archive_set_error(a, errno, - "Failed to get flagset from an NFSv4 ACL entry"); - ret = ARCHIVE_FAILED; - goto exit_free; - } - if (acl_clear_flags_np(acl_flagset) != 0) { - archive_set_error(a, errno, - "Failed to clear flags from an NFSv4 ACL flagset"); - ret = ARCHIVE_FAILED; - goto exit_free; - } -#endif /* HAVE_POSIX_ACL || HAVE_DARWIN_ACL */ - for (i = 0; i < (int)(sizeof(acl_inherit_map) /sizeof(acl_inherit_map[0])); ++i) { - if (ae_permset & acl_inherit_map[i].archive_inherit) { -#if HAVE_SUN_ACL - ace->a_flags |= - acl_inherit_map[i].platform_inherit; -#else /* !HAVE_SUN_ACL */ - if (acl_add_flag_np(acl_flagset, - acl_inherit_map[i].platform_inherit) != 0) { - archive_set_error(a, errno, - "Failed to add flag to NFSv4 ACL flagset"); - ret = ARCHIVE_FAILED; - goto exit_free; - } -#endif /* HAVE_SUN_ACL */ - } - } - } -#endif /* HAVE_NFS4_ACL */ -#if HAVE_SUN_ACL - e++; -#endif - } - -#if HAVE_ACL_SET_FD_NP || HAVE_ACL_SET_FD || HAVE_SUN_ACL - /* Try restoring the ACL through 'fd' if we can. */ -#if HAVE_SUN_ACL || HAVE_ACL_SET_FD_NP - if (fd >= 0) -#else /* !HAVE_SUN_ACL && !HAVE_ACL_SET_FD_NP */ - if (fd >= 0 && acl_type == ACL_TYPE_ACCESS) -#endif - { -#if HAVE_SUN_ACL - if (facl_set(fd, acl) == 0) -#elif HAVE_ACL_SET_FD_NP - if (acl_set_fd_np(fd, acl, acl_type) == 0) -#else /* !HAVE_SUN_ACL && !HAVE_ACL_SET_FD_NP */ - if (acl_set_fd(fd, acl) == 0) -#endif - ret = ARCHIVE_OK; - else { - if (errno == EOPNOTSUPP) { - /* Filesystem doesn't support ACLs */ - ret = ARCHIVE_OK; - } else { - archive_set_error(a, errno, - "Failed to set %s acl on fd", tname); - } - } - } else -#endif /* HAVE_ACL_SET_FD_NP || HAVE_ACL_SET_FD || HAVE_SUN_ACL */ -#if HAVE_SUN_ACL - if (acl_set(name, acl) != 0) -#elif HAVE_ACL_SET_LINK_NP - if (acl_set_link_np(name, acl_type, acl) != 0) -#else - /* TODO: Skip this if 'name' is a symlink. */ - if (acl_set_file(name, acl_type, acl) != 0) -#endif - { - if (errno == EOPNOTSUPP) { - /* Filesystem doesn't support ACLs */ - ret = ARCHIVE_OK; - } else { - archive_set_error(a, errno, "Failed to set %s acl", - tname); - ret = ARCHIVE_WARN; - } - } -exit_free: - acl_free(acl); - return (ret); -} -#endif /* HAVE_POSIX_ACL || HAVE_NFS4_ACL */ diff --git a/Utilities/cmlibarchive/libarchive/archive_write_disk_posix.c b/Utilities/cmlibarchive/libarchive/archive_write_disk_posix.c index a5f3067..4a42a3b 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_disk_posix.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_disk_posix.c @@ -39,9 +39,9 @@ __FBSDID("$FreeBSD$"); #ifdef HAVE_SYS_EXTATTR_H #include <sys/extattr.h> #endif -#if defined(HAVE_SYS_XATTR_H) +#if HAVE_SYS_XATTR_H #include <sys/xattr.h> -#elif defined(HAVE_ATTR_XATTR_H) +#elif HAVE_ATTR_XATTR_H #include <attr/xattr.h> #endif #ifdef HAVE_SYS_EA_H @@ -575,10 +575,55 @@ _archive_write_disk_header(struct archive *_a, struct archive_entry *entry) if (a->flags & ARCHIVE_EXTRACT_TIME) a->todo |= TODO_TIMES; if (a->flags & ARCHIVE_EXTRACT_ACL) { +#if ARCHIVE_ACL_DARWIN + /* + * On MacOS, platform ACLs get stored in mac_metadata, too. + * If we intend to extract mac_metadata and it is present + * we skip extracting libarchive NFSv4 ACLs. + */ + size_t metadata_size; + + if ((a->flags & ARCHIVE_EXTRACT_MAC_METADATA) == 0 || + archive_entry_mac_metadata(a->entry, + &metadata_size) == NULL || metadata_size == 0) +#endif +#if ARCHIVE_ACL_LIBRICHACL + /* + * RichACLs are stored in an extended attribute. + * If we intend to extract extended attributes and have this + * attribute we skip extracting libarchive NFSv4 ACLs. + */ + short extract_acls = 1; + if (a->flags & ARCHIVE_EXTRACT_XATTR && ( + archive_entry_acl_types(a->entry) & + ARCHIVE_ENTRY_ACL_TYPE_NFS4)) { + const char *attr_name; + const void *attr_value; + size_t attr_size; + int i = archive_entry_xattr_reset(a->entry); + while (i--) { + archive_entry_xattr_next(a->entry, &attr_name, + &attr_value, &attr_size); + if (attr_name != NULL && attr_value != NULL && + attr_size > 0 && strcmp(attr_name, + "trusted.richacl") == 0) { + extract_acls = 0; + break; + } + } + } + if (extract_acls) +#endif +#if ARCHIVE_ACL_DARWIN || ARCHIVE_ACL_LIBRICHACL + { +#endif if (archive_entry_filetype(a->entry) == AE_IFDIR) a->deferred |= TODO_ACLS; else a->todo |= TODO_ACLS; +#if ARCHIVE_ACL_DARWIN || ARCHIVE_ACL_LIBRICHACL + } +#endif } if (a->flags & ARCHIVE_EXTRACT_MAC_METADATA) { if (archive_entry_filetype(a->entry) == AE_IFDIR) @@ -619,8 +664,21 @@ _archive_write_disk_header(struct archive *_a, struct archive_entry *entry) } #endif - if (a->flags & ARCHIVE_EXTRACT_XATTR) + if (a->flags & ARCHIVE_EXTRACT_XATTR) { +#if ARCHIVE_XATTR_DARWIN + /* + * On MacOS, extended attributes get stored in mac_metadata, + * too. If we intend to extract mac_metadata and it is present + * we skip extracting extended attributes. + */ + size_t metadata_size; + + if ((a->flags & ARCHIVE_EXTRACT_MAC_METADATA) == 0 || + archive_entry_mac_metadata(a->entry, + &metadata_size) == NULL || metadata_size == 0) +#endif a->todo |= TODO_XATTR; + } if (a->flags & ARCHIVE_EXTRACT_FFLAGS) a->todo |= TODO_FFLAGS; if (a->flags & ARCHIVE_EXTRACT_SECURE_SYMLINKS) { @@ -1703,25 +1761,11 @@ _archive_write_disk_finish_entry(struct archive *_a) */ if (a->todo & TODO_ACLS) { int r2; -#ifdef HAVE_DARWIN_ACL - /* - * On Mac OS, platform ACLs are stored also in mac_metadata by - * the operating system. If mac_metadata is present it takes - * precedence and we skip extracting libarchive NFSv4 ACLs - */ - const void *metadata; - size_t metadata_size; - metadata = archive_entry_mac_metadata(a->entry, &metadata_size); - if ((a->todo & TODO_MAC_METADATA) == 0 || - metadata == NULL || metadata_size == 0) { -#endif r2 = archive_write_disk_set_acls(&a->archive, a->fd, archive_entry_pathname(a->entry), - archive_entry_acl(a->entry)); + archive_entry_acl(a->entry), + archive_entry_mode(a->entry)); if (r2 < ret) ret = r2; -#ifdef HAVE_DARWIN_ACL - } -#endif } finish_metadata: @@ -2293,13 +2337,8 @@ _archive_write_disk_close(struct archive *_a) if (p->fixup & TODO_MODE_BASE) chmod(p->name, p->mode); if (p->fixup & TODO_ACLS) -#ifdef HAVE_DARWIN_ACL - if ((p->fixup & TODO_MAC_METADATA) == 0 || - p->mac_metadata == NULL || - p->mac_metadata_size == 0) -#endif - archive_write_disk_set_acls(&a->archive, - -1, p->name, &p->acl); + archive_write_disk_set_acls(&a->archive, -1, p->name, + &p->acl, p->mode); if (p->fixup & TODO_FFLAGS) set_fflags_platform(a, -1, p->name, p->mode, p->fflags_set, 0); @@ -2467,7 +2506,7 @@ fsobj_error(int *a_eno, struct archive_string *a_estr, if (a_eno) *a_eno = err; if (a_estr) - archive_string_sprintf(a_estr, errstr, path); + archive_string_sprintf(a_estr, "%s%s", errstr, path); } /* @@ -2573,7 +2612,7 @@ check_symlinks_fsobj(char *path, int *a_eno, struct archive_string *a_estr, * with the deep-directory editing. */ fsobj_error(a_eno, a_estr, errno, - "Could not stat %s", path); + "Could not stat ", path); res = ARCHIVE_FAILED; break; } @@ -2582,7 +2621,7 @@ check_symlinks_fsobj(char *path, int *a_eno, struct archive_string *a_estr, if (chdir(head) != 0) { tail[0] = c; fsobj_error(a_eno, a_estr, errno, - "Could not chdir %s", path); + "Could not chdir ", path); res = (ARCHIVE_FATAL); break; } @@ -2599,7 +2638,7 @@ check_symlinks_fsobj(char *path, int *a_eno, struct archive_string *a_estr, if (unlink(head)) { tail[0] = c; fsobj_error(a_eno, a_estr, errno, - "Could not remove symlink %s", + "Could not remove symlink ", path); res = ARCHIVE_FAILED; break; @@ -2618,7 +2657,7 @@ check_symlinks_fsobj(char *path, int *a_eno, struct archive_string *a_estr, /* if (!S_ISLNK(path)) { fsobj_error(a_eno, a_estr, 0, - "Removing symlink %s", path); + "Removing symlink ", path); } */ /* Symlink gone. No more problem! */ @@ -2630,7 +2669,7 @@ check_symlinks_fsobj(char *path, int *a_eno, struct archive_string *a_estr, tail[0] = c; fsobj_error(a_eno, a_estr, 0, "Cannot remove intervening " - "symlink %s", path); + "symlink ", path); res = ARCHIVE_FAILED; break; } @@ -2652,7 +2691,7 @@ check_symlinks_fsobj(char *path, int *a_eno, struct archive_string *a_estr, } else { fsobj_error(a_eno, a_estr, errno, - "Could not stat %s", path); + "Could not stat ", path); res = (ARCHIVE_FAILED); break; } @@ -2661,7 +2700,7 @@ check_symlinks_fsobj(char *path, int *a_eno, struct archive_string *a_estr, tail[0] = c; fsobj_error(a_eno, a_estr, errno, - "Could not chdir %s", path); + "Could not chdir ", path); res = (ARCHIVE_FATAL); break; } @@ -2674,14 +2713,14 @@ check_symlinks_fsobj(char *path, int *a_eno, struct archive_string *a_estr, tail[0] = c; fsobj_error(a_eno, a_estr, 0, "Cannot extract through " - "symlink %s", path); + "symlink ", path); res = ARCHIVE_FAILED; break; } } else { tail[0] = c; fsobj_error(a_eno, a_estr, 0, - "Cannot extract through symlink %s", path); + "Cannot extract through symlink ", path); res = ARCHIVE_FAILED; break; } @@ -4044,71 +4083,98 @@ skip_appledouble: } #endif -#if HAVE_LSETXATTR || HAVE_LSETEA +#if ARCHIVE_XATTR_LINUX || ARCHIVE_XATTR_DARWIN || ARCHIVE_XATTR_AIX /* - * Restore extended attributes - Linux and AIX implementations: + * Restore extended attributes - Linux, Darwin and AIX implementations: * AIX' ea interface is syntaxwise identical to the Linux xattr interface. */ static int set_xattrs(struct archive_write_disk *a) { struct archive_entry *entry = a->entry; - static int warning_done = 0; + struct archive_string errlist; int ret = ARCHIVE_OK; int i = archive_entry_xattr_reset(entry); + short fail = 0; + + archive_string_init(&errlist); while (i--) { const char *name; const void *value; size_t size; + int e; + archive_entry_xattr_next(entry, &name, &value, &size); - if (name != NULL && - strncmp(name, "xfsroot.", 8) != 0 && - strncmp(name, "system.", 7) != 0) { - int e; -#if HAVE_FSETXATTR - if (a->fd >= 0) - e = fsetxattr(a->fd, name, value, size, 0); - else -#elif HAVE_FSETEA - if (a->fd >= 0) - e = fsetea(a->fd, name, value, size, 0); - else + + if (name == NULL) + continue; +#if ARCHIVE_XATTR_LINUX + /* Linux: quietly skip POSIX.1e ACL extended attributes */ + if (strncmp(name, "system.", 7) == 0 && + (strcmp(name + 7, "posix_acl_access") == 0 || + strcmp(name + 7, "posix_acl_default") == 0)) + continue; + if (strncmp(name, "trusted.SGI_", 12) == 0 && + (strcmp(name + 12, "ACL_DEFAULT") == 0 || + strcmp(name + 12, "ACL_FILE") == 0)) + continue; + + /* Linux: xfsroot namespace is obsolete and unsupported */ + if (strncmp(name, "xfsroot.", 8) == 0) { + fail = 1; + archive_strcat(&errlist, name); + archive_strappend_char(&errlist, ' '); + continue; + } #endif - { -#if HAVE_LSETXATTR - e = lsetxattr(archive_entry_pathname(entry), - name, value, size, 0); -#elif HAVE_LSETEA - e = lsetea(archive_entry_pathname(entry), - name, value, size, 0); + + if (a->fd >= 0) { +#if ARCHIVE_XATTR_LINUX + e = fsetxattr(a->fd, name, value, size, 0); +#elif ARCHIVE_XATTR_DARWIN + e = fsetxattr(a->fd, name, value, size, 0, 0); +#elif ARCHIVE_XATTR_AIX + e = fsetea(a->fd, name, value, size, 0); #endif - } - if (e == -1) { - if (errno == ENOTSUP || errno == ENOSYS) { - if (!warning_done) { - warning_done = 1; - archive_set_error(&a->archive, - errno, - "Cannot restore extended " - "attributes on this file " - "system"); - } - } else - archive_set_error(&a->archive, errno, - "Failed to set extended attribute"); - ret = ARCHIVE_WARN; - } } else { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Invalid extended attribute encountered"); +#if ARCHIVE_XATTR_LINUX + e = lsetxattr(archive_entry_pathname(entry), + name, value, size, 0); +#elif ARCHIVE_XATTR_DARWIN + e = setxattr(archive_entry_pathname(entry), + name, value, size, 0, XATTR_NOFOLLOW); +#elif ARCHIVE_XATTR_AIX + e = lsetea(archive_entry_pathname(entry), + name, value, size, 0); +#endif + } + if (e == -1) { ret = ARCHIVE_WARN; + archive_strcat(&errlist, name); + archive_strappend_char(&errlist, ' '); + if (errno != ENOTSUP && errno != ENOSYS) + fail = 1; } } + + if (ret == ARCHIVE_WARN) { + if (fail && errlist.length > 0) { + errlist.length--; + errlist.s[errlist.length] = '\0'; + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Cannot restore extended attributes: %s", + errlist.s); + } else + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Cannot restore extended " + "attributes on this file system."); + } + + archive_string_free(&errlist); return (ret); } -#elif HAVE_EXTATTR_SET_FILE && HAVE_DECL_EXTATTR_NAMESPACE_USER +#elif ARCHIVE_XATTR_FREEBSD /* * Restore extended attributes - FreeBSD implementation */ @@ -4116,9 +4182,12 @@ static int set_xattrs(struct archive_write_disk *a) { struct archive_entry *entry = a->entry; - static int warning_done = 0; + struct archive_string errlist; int ret = ARCHIVE_OK; int i = archive_entry_xattr_reset(entry); + short fail = 0; + + archive_string_init(&errlist); while (i--) { const char *name; @@ -4134,46 +4203,47 @@ set_xattrs(struct archive_write_disk *a) name += 5; namespace = EXTATTR_NAMESPACE_USER; } else { - /* Warn about other extended attributes. */ - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Can't restore extended attribute ``%s''", - name); + /* Other namespaces are unsupported */ + archive_strcat(&errlist, name); + archive_strappend_char(&errlist, ' '); + fail = 1; ret = ARCHIVE_WARN; continue; } - errno = 0; -#if HAVE_EXTATTR_SET_FD - if (a->fd >= 0) + + if (a->fd >= 0) { e = extattr_set_fd(a->fd, namespace, name, value, size); - else -#endif - /* TODO: should we use extattr_set_link() instead? */ - { - e = extattr_set_file( + } else { + e = extattr_set_link( archive_entry_pathname(entry), namespace, name, value, size); } if (e != (int)size) { - if (errno == ENOTSUP || errno == ENOSYS) { - if (!warning_done) { - warning_done = 1; - archive_set_error(&a->archive, - errno, - "Cannot restore extended " - "attributes on this file " - "system"); - } - } else { - archive_set_error(&a->archive, errno, - "Failed to set extended attribute"); - } - + archive_strcat(&errlist, name); + archive_strappend_char(&errlist, ' '); ret = ARCHIVE_WARN; + if (errno != ENOTSUP && errno != ENOSYS) + fail = 1; } } } + + if (ret == ARCHIVE_WARN) { + if (fail && errlist.length > 0) { + errlist.length--; + errlist.s[errlist.length] = '\0'; + + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Cannot restore extended attributes: %s", + errlist.s); + } else + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Cannot restore extended " + "attributes on this file system."); + } + + archive_string_free(&errlist); return (ret); } #else @@ -4239,5 +4309,19 @@ older(struct stat *st, struct archive_entry *entry) return (0); } +#ifndef ARCHIVE_ACL_SUPPORT +int +archive_write_disk_set_acls(struct archive *a, int fd, const char *name, + struct archive_acl *abstract_acl, __LA_MODE_T mode) +{ + (void)a; /* UNUSED */ + (void)fd; /* UNUSED */ + (void)name; /* UNUSED */ + (void)abstract_acl; /* UNUSED */ + (void)mode; /* UNUSED */ + return (ARCHIVE_OK); +} +#endif + #endif /* !_WIN32 || __CYGWIN__ */ diff --git a/Utilities/cmlibarchive/libarchive/archive_write_disk_private.h b/Utilities/cmlibarchive/libarchive/archive_write_disk_private.h index d84e7e1..b655dea 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_disk_private.h +++ b/Utilities/cmlibarchive/libarchive/archive_write_disk_private.h @@ -33,11 +33,13 @@ #ifndef ARCHIVE_WRITE_DISK_PRIVATE_H_INCLUDED #define ARCHIVE_WRITE_DISK_PRIVATE_H_INCLUDED +#include "archive_platform_acl.h" #include "archive_acl_private.h" +#include "archive_entry.h" struct archive_write_disk; -int -archive_write_disk_set_acls(struct archive *, int /* fd */, const char * /* pathname */, struct archive_acl *); +int archive_write_disk_set_acls(struct archive *, int, const char *, + struct archive_acl *, __LA_MODE_T); #endif diff --git a/Utilities/cmlibarchive/libarchive/archive_write_finish_entry.3 b/Utilities/cmlibarchive/libarchive/archive_write_finish_entry.3 index c5ef69e..dc1b94b 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_finish_entry.3 +++ b/Utilities/cmlibarchive/libarchive/archive_write_finish_entry.3 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd February 2, 2012 +.Dd February 28, 2017 .Dt ARCHIVE_WRITE_FINISH_ENTRY 3 .Os .Sh NAME @@ -45,6 +45,9 @@ is called automatically by and .Fn archive_write_close as needed. +For +.Tn archive_write_disk +handles, this flushes pending file attribute changes like modification time. .\" .Sh EXAMPLE .Sh RETURN VALUES This function returns diff --git a/Utilities/cmlibarchive/libarchive/archive_write_format.3 b/Utilities/cmlibarchive/libarchive/archive_write_format.3 index d4ba6ab..aaafb0a 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_format.3 +++ b/Utilities/cmlibarchive/libarchive/archive_write_format.3 @@ -108,7 +108,6 @@ Streaming Archive Library (libarchive, -larchive) These functions set the format that will be used for the archive. .Pp The library can write a variety of common archive formats. - .Bl -tag -width indent .It Fn archive_write_set_format Sets the format based on the format code (see diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format.c index 744302d..0f70623 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_set_format.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format.c @@ -38,7 +38,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format.c 201168 2009-1 #include "archive_private.h" /* A table that maps format codes to functions. */ -static +static const struct { int code; int (*setter)(struct archive *); } codes[] = { { ARCHIVE_FORMAT_7ZIP, archive_write_set_format_7zip }, diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_by_name.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_by_name.c index a2ce7c6..86e8621 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_set_format_by_name.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_by_name.c @@ -41,7 +41,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_by_name.c 20116 #include "archive_private.h" /* A table that maps names to functions. */ -static +static const struct { const char *name; int (*setter)(struct archive *); } names[] = { { "7zip", archive_write_set_format_7zip }, diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_filter_by_ext.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_filter_by_ext.c index adec9b2..9fe21e4 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_set_format_filter_by_ext.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_filter_by_ext.c @@ -42,7 +42,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_by_name.c 20116 #include "archive_private.h" /* A table that maps names to functions. */ -static +static const struct { const char *name; int (*format)(struct archive *); int (*filter)(struct archive *); } names[] = { { ".7z", archive_write_set_format_7zip, archive_write_add_filter_none}, diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_pax.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_pax.c index 6a301ac..0eaf733 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_set_format_pax.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_pax.c @@ -1196,8 +1196,12 @@ archive_write_pax_header(struct archive_write *a, "GNU.sparse.major", 1); add_pax_attr_int(&(pax->pax_header), "GNU.sparse.minor", 0); + /* + * Make sure to store the original path, since + * truncation to ustar limit happened already. + */ add_pax_attr(&(pax->pax_header), - "GNU.sparse.name", entry_name.s); + "GNU.sparse.name", path); add_pax_attr_int(&(pax->pax_header), "GNU.sparse.realsize", archive_entry_size(entry_main)); @@ -1650,13 +1654,14 @@ build_pax_attribute_name(char *dest, const char *src) * GNU PAX Format 1.0 requires the special name, which pattern is: * <dir>/GNUSparseFile.<pid>/<original file name> * + * Since reproducable archives are more important, use 0 as pid. + * * This function is used for only Sparse file, a file type of which * is regular file. */ static char * build_gnu_sparse_name(char *dest, const char *src) { - char buff[64]; const char *p; /* Handle the null filename case. */ @@ -1682,15 +1687,9 @@ build_gnu_sparse_name(char *dest, const char *src) break; } -#if HAVE_GETPID && 0 /* Disable this as pax attribute name. */ - sprintf(buff, "GNUSparseFile.%d", getpid()); -#else - /* If the platform can't fetch the pid, don't include it. */ - strcpy(buff, "GNUSparseFile"); -#endif /* General case: build a ustar-compatible name adding * "/GNUSparseFile/". */ - build_ustar_entry_name(dest, src, p - src, buff); + build_ustar_entry_name(dest, src, p - src, "GNUSparseFile.0"); return (dest); } diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_warc.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_warc.c index 8b6daf9..edad072 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_set_format_warc.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_warc.c @@ -354,7 +354,7 @@ static ssize_t _popul_ehdr(struct archive_string *tgt, size_t tsz, warc_essential_hdr_t hdr) { static const char _ver[] = "WARC/1.0\r\n"; - static const char *_typ[LAST_WT] = { + static const char * const _typ[LAST_WT] = { NULL, "warcinfo", "metadata", "resource", NULL }; char std_uuid[48U]; diff --git a/Utilities/cmlibarchive/libarchive/config_freebsd.h b/Utilities/cmlibarchive/libarchive/config_freebsd.h index 215e886..be25258 100644 --- a/Utilities/cmlibarchive/libarchive/config_freebsd.h +++ b/Utilities/cmlibarchive/libarchive/config_freebsd.h @@ -22,141 +22,238 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD: head/lib/libarchive/config_freebsd.h 201079 2009-12-28 02:01:42Z kientzle $ + * $FreeBSD$ */ -/* FreeBSD 5.0 and later have ACL and extattr support. */ +#include <osreldate.h> + +/* FreeBSD 5.0 and later has ACL and extattr support. */ #if __FreeBSD__ > 4 -#define HAVE_ACL_CREATE_ENTRY 1 -#define HAVE_ACL_GET_FD_NP 1 -#define HAVE_ACL_GET_LINK_NP 1 -#define HAVE_ACL_GET_PERM_NP 1 -#define HAVE_ACL_INIT 1 -#define HAVE_ACL_SET_FD 1 -#define HAVE_ACL_SET_FD_NP 1 -#define HAVE_ACL_SET_FILE 1 -#define HAVE_ACL_USER 1 -#define HAVE_EXTATTR_GET_FILE 1 -#define HAVE_EXTATTR_LIST_FILE 1 -#define HAVE_EXTATTR_SET_FD 1 -#define HAVE_EXTATTR_SET_FILE 1 -#define HAVE_STRUCT_XVFSCONF 1 -#define HAVE_SYS_ACL_H 1 -#define HAVE_SYS_EXTATTR_H 1 -#endif +#define ARCHIVE_ACL_FREEBSD 1 +#define HAVE_ACL_GET_PERM_NP 1 +#define HAVE_ARC4RANDOM_BUF 1 +#define HAVE_EXTATTR_GET_FILE 1 +#define HAVE_EXTATTR_LIST_FILE 1 +#define HAVE_EXTATTR_SET_FD 1 +#define HAVE_EXTATTR_SET_FILE 1 +#define HAVE_STRUCT_XVFSCONF 1 +#define HAVE_SYS_ACL_H 1 +#define HAVE_SYS_EXTATTR_H 1 +#if __FreeBSD__ > 7 +/* FreeBSD 8.0 and later has NFSv4 ACL support */ +#define ARCHIVE_ACL_FREEBSD_NFS4 1 +#define HAVE_ACL_GET_LINK_NP 1 +#define HAVE_ACL_IS_TRIVIAL_NP 1 +#define HAVE_ACL_SET_LINK_NP 1 +#endif /* __FreeBSD__ > 7 */ +#endif /* __FreeBSD__ > 4 */ #ifdef WITH_OPENSSL -#define HAVE_OPENSSL_MD5_H 1 -#define HAVE_OPENSSL_RIPEMD_H 1 -#define HAVE_OPENSSL_SHA_H 1 -#define HAVE_SHA384 1 -#define HAVE_SHA512 1 +#define HAVE_LIBCRYPTO 1 +#define HAVE_OPENSSL_EVP_H 1 +#define HAVE_OPENSSL_MD5_H 1 +#define HAVE_OPENSSL_RIPEMD_H 1 +#define HAVE_OPENSSL_SHA_H 1 +#define HAVE_OPENSSL_SHA256_INIT 1 +#define HAVE_OPENSSL_SHA384_INIT 1 +#define HAVE_OPENSSL_SHA512_INIT 1 +#define HAVE_PKCS5_PBKDF2_HMAC_SHA1 1 +#define HAVE_SHA256 1 +#define HAVE_SHA384 1 +#define HAVE_SHA512 1 +#else +#define HAVE_LIBMD 1 +#define HAVE_MD5_H 1 +#define HAVE_MD5INIT 1 +#define HAVE_RIPEMD_H 1 +#define HAVE_SHA_H 1 +#define HAVE_SHA1 1 +#define HAVE_SHA1_INIT 1 +#define HAVE_SHA256 1 +#define HAVE_SHA256_H 1 +#define HAVE_SHA256_INIT 1 +#define HAVE_SHA512 1 +#define HAVE_SHA512_H 1 +#define HAVE_SHA512_INIT 1 #endif -#define HAVE_BSDXML_H 1 -#define HAVE_BZLIB_H 1 -#define HAVE_CHFLAGS 1 -#define HAVE_CHOWN 1 -#define HAVE_DECL_INT64_MAX 1 -#define HAVE_DECL_INT64_MIN 1 -#define HAVE_DECL_SIZE_MAX 1 -#define HAVE_DECL_SSIZE_MAX 1 -#define HAVE_DECL_STRERROR_R 1 -#define HAVE_DECL_UINT32_MAX 1 -#define HAVE_DECL_UINT64_MAX 1 -#define HAVE_DIRENT_H 1 -#define HAVE_EFTYPE 1 -#define HAVE_EILSEQ 1 -#define HAVE_ERRNO_H 1 -#define HAVE_FCHDIR 1 -#define HAVE_FCHFLAGS 1 -#define HAVE_FCHMOD 1 -#define HAVE_FCHOWN 1 -#define HAVE_FCNTL 1 -#define HAVE_FCNTL_H 1 -#define HAVE_FSEEKO 1 -#define HAVE_FSTAT 1 -#define HAVE_FTRUNCATE 1 -#define HAVE_FUTIMES 1 -#define HAVE_GETEUID 1 -#define HAVE_GETGRGID_R 1 -#define HAVE_GETPID 1 -#define HAVE_GETPWUID_R 1 -#define HAVE_GRP_H 1 -#define HAVE_INTTYPES_H 1 -#define HAVE_LCHFLAGS 1 -#define HAVE_LCHMOD 1 -#define HAVE_LCHOWN 1 -#define HAVE_LIMITS_H 1 -#define HAVE_LINK 1 -#define HAVE_LSTAT 1 -#define HAVE_LUTIMES 1 -#define HAVE_MALLOC 1 -#define HAVE_MD5 1 -#define HAVE_MD5_H 1 -#define HAVE_MEMMOVE 1 -#define HAVE_MKDIR 1 -#define HAVE_MKFIFO 1 -#define HAVE_MKNOD 1 -#define HAVE_PIPE 1 -#define HAVE_POLL 1 -#define HAVE_POLL_H 1 -#define HAVE_PWD_H 1 -#define HAVE_READLINK 1 -#define HAVE_RMD160 1 -#define HAVE_SELECT 1 -#define HAVE_SETENV 1 -#define HAVE_SHA_H 1 -#define HAVE_SHA1 1 -#define HAVE_SHA256 1 -#define HAVE_SHA256_H 1 -#define HAVE_SIGNAL_H 1 -#define HAVE_STDINT_H 1 -#define HAVE_STDLIB_H 1 -#define HAVE_STRCHR 1 -#define HAVE_STRDUP 1 -#define HAVE_STRERROR 1 -#define HAVE_STRERROR_R 1 -#define HAVE_STRINGS_H 1 -#define HAVE_STRING_H 1 -#define HAVE_STRRCHR 1 -#define HAVE_STRUCT_STAT_ST_BLKSIZE 1 -#define HAVE_STRUCT_STAT_ST_BIRTHTIME 1 -#define HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC 1 -#define HAVE_STRUCT_STAT_ST_FLAGS 1 -#define HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC 1 -#define HAVE_STRUCT_TM_TM_GMTOFF 1 -#define HAVE_SYMLINK 1 -#define HAVE_SYS_CDEFS_H 1 -#define HAVE_SYS_IOCTL_H 1 -#define HAVE_SYS_MOUNT_H 1 -#define HAVE_SYS_PARAM_H 1 -#define HAVE_SYS_SELECT_H 1 -#define HAVE_SYS_STAT_H 1 -#define HAVE_SYS_TIME_H 1 -#define HAVE_SYS_TYPES_H 1 -#undef HAVE_SYS_UTIME_H -#define HAVE_SYS_UTSNAME_H 1 -#define HAVE_SYS_WAIT_H 1 -#define HAVE_TIMEGM 1 -#define HAVE_TZSET 1 -#define HAVE_UNISTD_H 1 -#define HAVE_UNSETENV 1 -#define HAVE_UTIME 1 -#define HAVE_UTIMES 1 -#define HAVE_UTIME_H 1 -#define HAVE_VFORK 1 -#define HAVE_WCHAR_H 1 -#define HAVE_WCSCPY 1 -#define HAVE_WCSLEN 1 -#define HAVE_WCTOMB 1 -#define HAVE_WMEMCMP 1 -#define HAVE_WMEMCPY 1 -#define HAVE_ZLIB_H 1 -#define TIME_WITH_SYS_TIME 1 +#define HAVE_BSDXML_H 1 +#define HAVE_BZLIB_H 1 +#define HAVE_CHFLAGS 1 +#define HAVE_CHOWN 1 +#define HAVE_CHROOT 1 +#define HAVE_CTIME_R 1 +#define HAVE_CTYPE_H 1 +#define HAVE_DECL_EXTATTR_NAMESPACE_USER 1 +#define HAVE_DECL_INT32_MAX 1 +#define HAVE_DECL_INT32_MIN 1 +#define HAVE_DECL_INT64_MAX 1 +#define HAVE_DECL_INT64_MIN 1 +#define HAVE_DECL_INTMAX_MAX 1 +#define HAVE_DECL_INTMAX_MIN 1 +#define HAVE_DECL_SIZE_MAX 1 +#define HAVE_DECL_SSIZE_MAX 1 +#define HAVE_DECL_STRERROR_R 1 +#define HAVE_DECL_UINT32_MAX 1 +#define HAVE_DECL_UINT64_MAX 1 +#define HAVE_DECL_UINTMAX_MAX 1 +#define HAVE_DIRENT_H 1 +#define HAVE_DLFCN_H 1 +#define HAVE_D_MD_ORDER 1 +#define HAVE_EFTYPE 1 +#define HAVE_EILSEQ 1 +#define HAVE_ERRNO_H 1 +#define HAVE_FCHDIR 1 +#define HAVE_FCHFLAGS 1 +#define HAVE_FCHMOD 1 +#define HAVE_FCHOWN 1 +#define HAVE_FCNTL 1 +#define HAVE_FCNTL_H 1 +#define HAVE_FDOPENDIR 1 +#define HAVE_FORK 1 +#define HAVE_FSEEKO 1 +#define HAVE_FSTAT 1 +#define HAVE_FSTATAT 1 +#define HAVE_FSTATFS 1 +#define HAVE_FSTATVFS 1 +#define HAVE_FTRUNCATE 1 +#define HAVE_FUTIMES 1 +#define HAVE_FUTIMESAT 1 +#define HAVE_GETEUID 1 +#define HAVE_GETGRGID_R 1 +#define HAVE_GETGRNAM_R 1 +#define HAVE_GETPID 1 +#define HAVE_GETPWNAM_R 1 +#define HAVE_GETPWUID_R 1 +#define HAVE_GETVFSBYNAME 1 +#define HAVE_GMTIME_R 1 +#define HAVE_GRP_H 1 +#define HAVE_INTMAX_T 1 +#define HAVE_INTTYPES_H 1 +#define HAVE_LANGINFO_H 1 +#define HAVE_LCHFLAGS 1 +#define HAVE_LCHMOD 1 +#define HAVE_LCHOWN 1 +#define HAVE_LIBZ 1 +#define HAVE_LIMITS_H 1 +#define HAVE_LINK 1 +#define HAVE_LOCALE_H 1 +#define HAVE_LOCALTIME_R 1 +#define HAVE_LONG_LONG_INT 1 +#define HAVE_LSTAT 1 +#define HAVE_LUTIMES 1 +#define HAVE_MBRTOWC 1 +#define HAVE_MEMMOVE 1 +#define HAVE_MEMORY_H 1 +#define HAVE_MEMSET 1 +#define HAVE_MKDIR 1 +#define HAVE_MKFIFO 1 +#define HAVE_MKNOD 1 +#define HAVE_MKSTEMP 1 +#define HAVE_NL_LANGINFO 1 +#define HAVE_OPENAT 1 +#define HAVE_PATHS_H 1 +#define HAVE_PIPE 1 +#define HAVE_POLL 1 +#define HAVE_POLL_H 1 +#define HAVE_POSIX_SPAWNP 1 +#define HAVE_PTHREAD_H 1 +#define HAVE_PWD_H 1 +#define HAVE_READDIR_R 1 +#define HAVE_READLINK 1 +#define HAVE_READLINKAT 1 +#define HAVE_READPASSPHRASE 1 +#define HAVE_READPASSPHRASE_H 1 +#define HAVE_REGEX_H 1 +#define HAVE_SELECT 1 +#define HAVE_SETENV 1 +#define HAVE_SETLOCALE 1 +#define HAVE_SIGACTION 1 +#define HAVE_SIGNAL_H 1 +#define HAVE_SPAWN_H 1 +#define HAVE_STATFS 1 +#define HAVE_STATVFS 1 +#define HAVE_STDARG_H 1 +#define HAVE_STDINT_H 1 +#define HAVE_STDLIB_H 1 +#define HAVE_STRCHR 1 +#define HAVE_STRDUP 1 +#define HAVE_STRERROR 1 +#define HAVE_STRERROR_R 1 +#define HAVE_STRFTIME 1 +#define HAVE_STRINGS_H 1 +#define HAVE_STRING_H 1 +#define HAVE_STRRCHR 1 +#define HAVE_STRUCT_STATFS_F_NAMEMAX 1 +#define HAVE_STRUCT_STAT_ST_BIRTHTIME 1 +#define HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC 1 +#define HAVE_STRUCT_STAT_ST_BLKSIZE 1 +#define HAVE_STRUCT_STAT_ST_FLAGS 1 +#define HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC 1 +#define HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC 1 +#define HAVE_STRUCT_TM_TM_GMTOFF 1 +#define HAVE_SYMLINK 1 +#define HAVE_SYS_CDEFS_H 1 +#define HAVE_SYS_IOCTL_H 1 +#define HAVE_SYS_MOUNT_H 1 +#define HAVE_SYS_PARAM_H 1 +#define HAVE_SYS_POLL_H 1 +#define HAVE_SYS_SELECT_H 1 +#define HAVE_SYS_STATVFS_H 1 +#define HAVE_SYS_STAT_H 1 +#define HAVE_SYS_TIME_H 1 +#define HAVE_SYS_TYPES_H 1 +#define HAVE_SYS_UTSNAME_H 1 +#define HAVE_SYS_WAIT_H 1 +#define HAVE_TIMEGM 1 +#define HAVE_TIME_H 1 +#define HAVE_TZSET 1 +#define HAVE_UINTMAX_T 1 +#define HAVE_UNISTD_H 1 +#define HAVE_UNSETENV 1 +#define HAVE_UNSIGNED_LONG_LONG 1 +#define HAVE_UNSIGNED_LONG_LONG_INT 1 +#define HAVE_UTIME 1 +#define HAVE_UTIMES 1 +#define HAVE_UTIME_H 1 +#define HAVE_VFORK 1 +#define HAVE_VPRINTF 1 +#define HAVE_WCHAR_H 1 +#define HAVE_WCHAR_T 1 +#define HAVE_WCRTOMB 1 +#define HAVE_WCSCMP 1 +#define HAVE_WCSCPY 1 +#define HAVE_WCSLEN 1 +#define HAVE_WCTOMB 1 +#define HAVE_WCTYPE_H 1 +#define HAVE_WMEMCMP 1 +#define HAVE_WMEMCPY 1 +#define HAVE_WMEMMOVE 1 +#define HAVE_ZLIB_H 1 +#define TIME_WITH_SYS_TIME 1 + +#if __FreeBSD_version >= 1100056 +#define HAVE_FUTIMENS 1 +#define HAVE_UTIMENSAT 1 +#endif /* FreeBSD 4 and earlier lack intmax_t/uintmax_t */ #if __FreeBSD__ < 5 -#define intmax_t int64_t -#define uintmax_t uint64_t +#define intmax_t int64_t +#define uintmax_t uint64_t +#endif + +/* FreeBSD defines for archive_hash.h */ +#ifdef WITH_OPENSSL +#define ARCHIVE_CRYPTO_MD5_OPENSSL 1 +#define ARCHIVE_CRYPTO_RMD160_OPENSSL 1 +#define ARCHIVE_CRYPTO_SHA1_OPENSSL +#define ARCHIVE_CRYPTO_SHA256_OPENSSL 1 +#define ARCHIVE_CRYPTO_SHA384_OPENSSL 1 +#define ARCHIVE_CRYPTO_SHA512_OPENSSL 1 +#else +#define ARCHIVE_CRYPTO_MD5_LIBMD 1 +#define ARCHIVE_CRYPTO_SHA1_LIBMD 1 +#define ARCHIVE_CRYPTO_SHA256_LIBMD 1 +#define ARCHIVE_CRYPTO_SHA512_LIBMD 1 #endif diff --git a/Utilities/cmlibarchive/libarchive/libarchive_changes.3 b/Utilities/cmlibarchive/libarchive/libarchive_changes.3 index 881a67c..adc87fe 100644 --- a/Utilities/cmlibarchive/libarchive/libarchive_changes.3 +++ b/Utilities/cmlibarchive/libarchive/libarchive_changes.3 @@ -28,6 +28,7 @@ .Dt LIBARCHIVE_CHANGES 3 .Os .Sh NAME +.Nm libarchive_changes .Nd changes in libarchive interface .\" .Sh CHANGES IN LIBARCHIVE 3 diff --git a/Utilities/cmlibarchive/libarchive/mtree.5 b/Utilities/cmlibarchive/libarchive/mtree.5 index 16c8abe..e607e4a 100644 --- a/Utilities/cmlibarchive/libarchive/mtree.5 +++ b/Utilities/cmlibarchive/libarchive/mtree.5 @@ -48,7 +48,7 @@ Leading whitespace is always ignored. .Pp When encoding file or pathnames, any backslash character or character outside of the 95 printable ASCII characters must be -encoded as a a backslash followed by three +encoded as a backslash followed by three octal digits. When reading mtree files, any appearance of a backslash followed by three octal digits should be converted into the diff --git a/Utilities/cmlibarchive/libarchive/xxhash.c b/Utilities/cmlibarchive/libarchive/xxhash.c index 6f5ba52..70750ba 100644 --- a/Utilities/cmlibarchive/libarchive/xxhash.c +++ b/Utilities/cmlibarchive/libarchive/xxhash.c @@ -141,13 +141,19 @@ typedef struct _U32_S { U32 v; } _PACKED U32_S; # pragma pack(pop) #endif -#define A32(x) (((const U32_S *)(x))->v) - /**************************************** ** Compiler-specific Functions and Macros *****************************************/ -#define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) +#define GCC_VERSION ((__GNUC__-0) * 100 + (__GNUC_MINOR__ - 0)) + +#if GCC_VERSION >= 409 +__attribute__((__no_sanitize_undefined__)) +#endif +static inline U32 A32(const void * x) +{ + return (((const U32_S *)(x))->v); +} /* Note : although _rotl exists for minGW (GCC under windows), performance seems poor */ #if defined(_MSC_VER) @@ -9,26 +9,22 @@ die() { # Compile flag extraction function. cmake_extract_standard_flags() { - cd "${cmake_source_dir}/Modules/Compiler/" - for file in ${1:-*}-${2}.cmake; do - cat "${file}" \ - | sed -n "s/ *set *( *CMAKE_${2}${3}_EXTENSION_COMPILE_OPTION *\"\{0,1\}\([^\")]*\).*/\1/p" \ - | tr ';' ' ' - done + sed -n "s/ *set *( *CMAKE_${2}${3}_EXTENSION_COMPILE_OPTION *\"\{0,1\}\([^\")]*\).*/\1/p" \ + "${cmake_source_dir}/Modules/Compiler/"${1:-*}-${2}.cmake 2>/dev/null | tr ';' ' ' } # Version number extraction function. cmake_version_component() { - cat "${cmake_source_dir}/Source/CMakeVersion.cmake" | sed -n " + sed -n " /^set(CMake_VERSION_${1}/ {s/set(CMake_VERSION_${1} *\([0-9]*\))/\1/;p;} -" +" "${cmake_source_dir}/Source/CMakeVersion.cmake" } # Install destination extraction function. cmake_install_dest_default() { - cat "${cmake_source_dir}/Source/CMakeInstallDestinations.cmake" | sed -n ' + sed -n ' /^ *set(CMAKE_'"${1}"'_DIR_DEFAULT.*) # '"${2}"'$/ { s/^ *set(CMAKE_'"${1}"'_DIR_DEFAULT *"\([^"]*\)").*$/\1/ s/${CMake_VERSION_MAJOR}/'"${cmake_version_major}"'/ @@ -37,12 +33,12 @@ cmake_install_dest_default() p q } -' +' "${cmake_source_dir}/Source/CMakeInstallDestinations.cmake" } cmake_toupper() { - echo "$1" | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' + echo "$1" | tr '[:lower:]' '[:upper:]' } # Detect system and directory information. @@ -133,6 +129,11 @@ fi # Determine whether this is HP-UX if echo "${cmake_system}" | grep HP-UX >/dev/null 2>&1; then + die 'CMake no longer compiles on HP-UX. See + + https://gitlab.kitware.com/cmake/cmake/issues/17137 + +Use CMake 3.9 or lower instead.' cmake_system_hpux=true else cmake_system_hpux=false @@ -334,6 +335,7 @@ CMAKE_CXX_SOURCES="\ cmHexFileConverter \ cmIfCommand \ cmIncludeCommand \ + cmIncludeGuardCommand \ cmIncludeDirectoryCommand \ cmIncludeRegularExpressionCommand \ cmInstallCommand \ @@ -401,8 +403,14 @@ CMAKE_CXX_SOURCES="\ cmSubdirCommand \ cmSystemTools \ cmTarget \ + cmTargetCompileDefinitionsCommand \ + cmTargetCompileFeaturesCommand \ + cmTargetCompileOptionsCommand \ + cmTargetIncludeDirectoriesCommand \ cmTargetLinkLibrariesCommand \ + cmTargetPropCommandBase \ cmTargetPropertyComputer \ + cmTargetSourcesCommand \ cmTest \ cmTestGenerator \ cmTimestamp \ @@ -581,8 +589,7 @@ cmake_replace_string () SEARCHFOR="$3" REPLACEWITH="$4" if [ -f "${INFILE}" ] || ${cmake_system_openvms}; then - cat "${INFILE}" | - sed "s/\@${SEARCHFOR}\@/${REPLACEWITH}/g" > "${OUTFILE}${_tmp}" + sed "s/\@${SEARCHFOR}\@/${REPLACEWITH}/g" "${INFILE}" > "${OUTFILE}${_tmp}" if [ -f "${OUTFILE}${_tmp}" ]; then if "${_diff}" "${OUTFILE}" "${OUTFILE}${_tmp}" > /dev/null 2> /dev/null ; then #echo "Files are the same" @@ -604,15 +611,14 @@ cmake_kwsys_config_replace_string () APPEND="$*" if [ -f "${INFILE}" ] || ${cmake_system_openvms}; then echo "${APPEND}" > "${OUTFILE}${_tmp}" - cat "${INFILE}" | - sed "/./ {s/\@KWSYS_NAMESPACE\@/cmsys/g; - s/@KWSYS_BUILD_SHARED@/${KWSYS_BUILD_SHARED}/g; - s/@KWSYS_LFS_AVAILABLE@/${KWSYS_LFS_AVAILABLE}/g; - s/@KWSYS_LFS_REQUESTED@/${KWSYS_LFS_REQUESTED}/g; - s/@KWSYS_NAME_IS_KWSYS@/${KWSYS_NAME_IS_KWSYS}/g; - s/@KWSYS_STL_HAS_WSTRING@/${KWSYS_STL_HAS_WSTRING}/g; - s/@KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H@/${KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H}/g; - }" >> "${OUTFILE}${_tmp}" + sed "/./ {s/\@KWSYS_NAMESPACE\@/cmsys/g; + s/@KWSYS_BUILD_SHARED@/${KWSYS_BUILD_SHARED}/g; + s/@KWSYS_LFS_AVAILABLE@/${KWSYS_LFS_AVAILABLE}/g; + s/@KWSYS_LFS_REQUESTED@/${KWSYS_LFS_REQUESTED}/g; + s/@KWSYS_NAME_IS_KWSYS@/${KWSYS_NAME_IS_KWSYS}/g; + s/@KWSYS_STL_HAS_WSTRING@/${KWSYS_STL_HAS_WSTRING}/g; + s/@KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H@/${KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H}/g; + }" "${INFILE}" >> "${OUTFILE}${_tmp}" if [ -f "${OUTFILE}${_tmp}" ]; then if "${_diff}" "${OUTFILE}" "${OUTFILE}${_tmp}" > /dev/null 2> /dev/null ; then #echo "Files are the same" @@ -855,16 +861,6 @@ if ${cmake_system_haiku}; then cmake_ld_flags="${LDFLAGS} -lroot -lbe" fi -# Workaround for short jump tables on PA-RISC -if ${cmake_machine_parisc}; then - if ${cmake_c_compiler_is_gnu}; then - cmake_c_flags="${CFLAGS} -mlong-calls" - fi - if ${cmake_cxx_compiler_is_gnu}; then - cmake_cxx_flags="${CXXFLAGS} -mlong-calls" - fi -fi - #----------------------------------------------------------------------------- # Detect known toolchains on some platforms. cmake_toolchains='' @@ -945,35 +941,26 @@ echo ' # error "The CMAKE_C_COMPILER is set to a C++ compiler" #endif -#include<stdio.h> +#include <stdio.h> -#if defined(__CLASSIC_C__) -int main(argc, argv) - int argc; - char* argv[]; -#else int main(int argc, char* argv[]) -#endif { printf("%d%c", (argv != 0), (char)0x0a); - return argc-1; + return argc - 1; } ' > "${TMPFILE}.c" -for a in ${cmake_c_compilers}; do - if [ -z "${cmake_c_compiler}" ] && \ - cmake_try_run "${a}" "${cmake_c_flags}" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then - cmake_c_compiler="${a}" - fi -done for std in 11 99 90; do try_flags="`cmake_extract_standard_flags \"${cmake_toolchain}\" C \"${std}\"`" - for flag in $try_flags; do - echo "Checking whether ${cmake_c_compiler} supports ${flag}" >> cmake_bootstrap.log 2>&1 - if cmake_try_run "${cmake_c_compiler}" "${cmake_c_flags} ${flag}" \ - "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then - cmake_c_flags="${cmake_c_flags} ${flag}" - break 2 - fi + for compiler in ${cmake_c_compilers}; do + for flag in '' $try_flags; do + echo "Checking whether '${compiler} ${cmake_c_flags} ${flag}' works." >> cmake_bootstrap.log 2>&1 + if cmake_try_run "${compiler}" "${cmake_c_flags} ${flag}" \ + "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then + cmake_c_compiler="${compiler}" + cmake_c_flags="${cmake_c_flags} ${flag}" + break 3 + fi + done done done rm -f "${TMPFILE}.c" @@ -1004,58 +991,45 @@ fi # Check if C++ compiler works TMPFILE=`cmake_tmp_file` echo ' -#if defined(TEST1) -# include <iostream> -#else -# include <iostream.h> -#endif +#include <iostream> +#include <memory> #if __cplusplus >= 201103L && defined(__SUNPRO_CC) && __SUNPRO_CC < 0x5140 #error "SunPro <= 5.13 C++ 11 mode not supported due to bug in move semantics." #endif -class NeedCXX +class Class { public: - NeedCXX() { this->Foo = 1; } - int GetFoo() { return this->Foo; } + int Get() const { return this->Member; } private: - int Foo; + int Member = 1; }; int main() { - NeedCXX c; -#ifdef TEST3 - cout << c.GetFoo() << endl; -#else - std::cout << c.GetFoo() << std::endl; -#endif + auto const c = std::unique_ptr<Class>(new Class); + std::cout << c->Get() << std::endl; return 0; } ' > "${TMPFILE}.cxx" -for a in ${cmake_cxx_compilers}; do - for b in 1 2 3; do - if [ -z "${cmake_cxx_compiler}" ] && \ - cmake_try_run "${a}" "${cmake_cxx_flags} -DTEST${b}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then - cmake_cxx_compiler="${a}" - fi - done -done -for std in 14 11 98; do +for std in 17 14 11; do try_flags="`cmake_extract_standard_flags \"${cmake_toolchain}\" CXX \"${std}\"`" - for flag in $try_flags; do - echo "Checking for wheter ${cmake_cxx_flags} supports ${flag}" >> cmake_bootstrap.log 2>&1 - if cmake_try_run "${cmake_cxx_compiler}" "${cmake_cxx_flags} ${flag} -DTEST1" \ - "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then - cmake_cxx_flags="${cmake_cxx_flags} ${flag} " - break 2 - fi + for compiler in ${cmake_cxx_compilers}; do + for flag in '' $try_flags; do + echo "Checking whether '${compiler} ${cmake_cxx_flags} ${flag}' works." >> cmake_bootstrap.log 2>&1 + if cmake_try_run "${compiler}" "${cmake_cxx_flags} ${flag}" \ + "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then + cmake_cxx_compiler="${compiler}" + cmake_cxx_flags="${cmake_cxx_flags} ${flag} " + break 3 + fi + done done done rm -f "${TMPFILE}.cxx" if [ -z "${cmake_cxx_compiler}" ]; then - cmake_error 7 "Cannot find appropriate C++ compiler on this system. +cmake_error 7 "Cannot find a C++ compiler supporting C++11 on this system. Please specify one using environment variable CXX. See cmake_bootstrap.log for compilers attempted." fi @@ -1120,85 +1094,6 @@ if [ "x${cmake_full_make_flags}" != "x${cmake_make_flags}" ]; then echo "---------------------------------------------" fi -# Ok, we have CC, CXX, and MAKE. - -# Test C++ compiler features - -# Are we GCC? - -TMPFILE=`cmake_tmp_file` -echo ' -#if defined(__GNUC__) && !defined(__INTEL_COMPILER) -#include <iostream> -int main() { std::cout << "This is GNU" << std::endl; return 0;} -#endif -' > ${TMPFILE}.cxx -cmake_cxx_compiler_is_gnu=0 -if cmake_try_run "${cmake_cxx_compiler}" \ - "${cmake_cxx_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then - cmake_cxx_compiler_is_gnu=1 -fi -if [ "x${cmake_cxx_compiler_is_gnu}" = "x1" ]; then - echo "${cmake_cxx_compiler} is GNU compiler" -else - echo "${cmake_cxx_compiler} is not GNU compiler" -fi -rm -f "${TMPFILE}.cxx" - -if [ "x${cmake_cxx_compiler_is_gnu}" != "x1" ]; then - # Check for non-GNU compiler flags - - # If we are on HP-UX, check for -Ae for the C compiler. - if [ "x${cmake_system}" = "xHP-UX" ]; then - cmake_test_flags="-Ae" - TMPFILE=`cmake_tmp_file` - echo ' - int main(int argc, char** argv) { (void)argc; (void)argv; return 0; } -' > ${TMPFILE}.c - cmake_need_Ae=0 - if cmake_try_run "${cmake_c_compiler}" "${cmake_c_flags}" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then - : - else - if cmake_try_run "${cmake_c_compiler}" \ - "${cmake_c_flags} ${cmake_test_flags}" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then - cmake_need_Ae=1 - fi - fi - if [ "x${cmake_need_Ae}" = "x1" ]; then - cmake_c_flags="${cmake_c_flags} ${cmake_test_flags}" - echo "${cmake_c_compiler} needs ${cmake_test_flags}" - else - echo "${cmake_c_compiler} does not need ${cmake_test_flags}" - fi - rm -f "${TMPFILE}.c" - echo ' - #include <iostream> - int main(int argc, char** argv) { - for(int i=0; i < 1; ++i); - for(int i=0; i < 1; ++i); - (void)argc; (void)argv; return 0; } -' > ${TMPFILE}.cxx - cmake_need_AAstd98=0 - cmake_test_flags="-AA +hpxstd98" - if cmake_try_run "${cmake_cxx_compiler}" "${cmake_cxx_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then - : - else - if cmake_try_run "${cmake_cxx_compiler}" \ - "${cmake_cxx_flags} ${cmake_test_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then - cmake_need_AAstd98=1 - fi - fi - if [ "x${cmake_need_AAstd98}" = "x1" ]; then - cmake_cxx_flags="${cmake_cxx_flags} ${cmake_test_flags}" - echo "${cmake_cxx_compiler} needs ${cmake_test_flags}" - else - echo "${cmake_cxx_compiler} does not need ${cmake_test_flags}" - fi - fi - cmake_test_flags= -fi - - # Test for kwsys features KWSYS_NAME_IS_KWSYS=0 KWSYS_BUILD_SHARED=0 |