diff options
155 files changed, 2333 insertions, 1050 deletions
diff --git a/Auxiliary/bash-completion/cmake b/Auxiliary/bash-completion/cmake index 557f243..6061129 100644 --- a/Auxiliary/bash-completion/cmake +++ b/Auxiliary/bash-completion/cmake @@ -121,14 +121,19 @@ _cmake() grep -v "^cmake version " )' -- "$cur" ) ) return ;; + --help-manual) + COMPREPLY=( $( compgen -W '$( cmake --help-manual-list 2>/dev/null| + grep -v "^cmake version " | sed -e "s/([0-9])$//" )' -- "$cur" ) ) + return + ;; --help-module) COMPREPLY=( $( compgen -W '$( cmake --help-module-list 2>/dev/null| grep -v "^cmake version " )' -- "$cur" ) ) return ;; --help-policy) - COMPREPLY=( $( compgen -W '$( cmake --help-policies 2>/dev/null | - grep "^ CMP" 2>/dev/null )' -- "$cur" ) ) + COMPREPLY=( $( compgen -W '$( cmake --help-policy-list 2>/dev/null | + grep -v "^cmake version " )' -- "$cur" ) ) return ;; --help-property) diff --git a/Auxiliary/bash-completion/cpack b/Auxiliary/bash-completion/cpack index 05e0e93..cf5751f 100644 --- a/Auxiliary/bash-completion/cpack +++ b/Auxiliary/bash-completion/cpack @@ -48,6 +48,26 @@ _cpack() grep -v "^cpack version " )' -- "$cur" ) ) return ;; + --help-manual) + COMPREPLY=( $( compgen -W '$( cpack --help-manual-list 2>/dev/null| + grep -v "^cpack version " | sed -e "s/([0-9])$//" )' -- "$cur" ) ) + return + ;; + --help-module) + COMPREPLY=( $( compgen -W '$( cpack --help-module-list 2>/dev/null| + grep -v "^cpack version " )' -- "$cur" ) ) + return + ;; + --help-policy) + COMPREPLY=( $( compgen -W '$( cpack --help-policy-list 2>/dev/null | + grep -v "^cpack version " )' -- "$cur" ) ) + return + ;; + --help-property) + COMPREPLY=( $( compgen -W '$( cpack --help-property-list \ + 2>/dev/null | grep -v "^cpack version " )' -- "$cur" ) ) + return + ;; --help-variable) COMPREPLY=( $( compgen -W '$( cpack --help-variable-list \ 2>/dev/null | grep -v "^cpack version " )' -- "$cur" ) ) diff --git a/Auxiliary/bash-completion/ctest b/Auxiliary/bash-completion/ctest index 387672a..49343bb 100644 --- a/Auxiliary/bash-completion/ctest +++ b/Auxiliary/bash-completion/ctest @@ -72,11 +72,37 @@ _ctest() COMPREPLY=( $( compgen -W '0 1' -- "$cur" ) ) return ;; + --help-command) COMPREPLY=( $( compgen -W '$( ctest --help-command-list 2>/dev/null| grep -v "^ctest version " )' -- "$cur" ) ) return ;; + --help-manual) + COMPREPLY=( $( compgen -W '$( ctest --help-manual-list 2>/dev/null| + grep -v "^ctest version " | sed -e "s/([0-9])$//" )' -- "$cur" ) ) + return + ;; + --help-module) + COMPREPLY=( $( compgen -W '$( ctest --help-module-list 2>/dev/null| + grep -v "^ctest version " )' -- "$cur" ) ) + return + ;; + --help-policy) + COMPREPLY=( $( compgen -W '$( ctest --help-policy-list 2>/dev/null | + grep -v "^ctest version " )' -- "$cur" ) ) + return + ;; + --help-property) + COMPREPLY=( $( compgen -W '$( ctest --help-property-list \ + 2>/dev/null | grep -v "^ctest version " )' -- "$cur" ) ) + return + ;; + --help-variable) + COMPREPLY=( $( compgen -W '$( ctest --help-variable-list \ + 2>/dev/null | grep -v "^ctest version " )' -- "$cur" ) ) + return + ;; esac if [[ "$cur" == -* ]]; then diff --git a/Help/command/ctest_update.rst b/Help/command/ctest_update.rst index 74af1f7..b205bca 100644 --- a/Help/command/ctest_update.rst +++ b/Help/command/ctest_update.rst @@ -25,3 +25,7 @@ The options are: have otherwise printed to the console. CTest will still report the new revision of the repository and any conflicting files that were found. + +The update always follows the version control branch currently checked +out in the source directory. See the :ref:`CTest Update Step` +documentation for more information. diff --git a/Help/command/find_library.rst b/Help/command/find_library.rst index 31e6ec0..1eb50f7 100644 --- a/Help/command/find_library.rst +++ b/Help/command/find_library.rst @@ -49,6 +49,13 @@ path to the framework ``<fullPath>/A.framework``. When a full path to a framework is used as a library, CMake will use a ``-framework A``, and a ``-F<fullPath>`` to link the framework to the target. +If the :prop_gbl:`FIND_LIBRARY_USE_LIB32_PATHS` global property is set +all search paths will be tested as normal, with ``32/`` appended, and +with all matches of ``lib/`` replaced with ``lib32/``. This property is +automatically set for the platforms that are known to need it if at +least one of the languages supported by the :command:`project` command +is enabled. + If the :prop_gbl:`FIND_LIBRARY_USE_LIB64_PATHS` global property is set all search paths will be tested as normal, with ``64/`` appended, and with all matches of ``lib/`` replaced with ``lib64/``. This property is diff --git a/Help/manual/cmake-modules.7.rst b/Help/manual/cmake-modules.7.rst index f911662..6ac5973 100644 --- a/Help/manual/cmake-modules.7.rst +++ b/Help/manual/cmake-modules.7.rst @@ -210,6 +210,7 @@ All Modules /module/FindTIFF /module/FindUnixCommands /module/FindVTK + /module/FindVulkan /module/FindWget /module/FindWish /module/FindwxWidgets diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst index 3403dcd..3574b7f 100644 --- a/Help/manual/cmake-properties.7.rst +++ b/Help/manual/cmake-properties.7.rst @@ -24,6 +24,7 @@ Properties of Global Scope /prop_gbl/DISABLED_FEATURES /prop_gbl/ENABLED_FEATURES /prop_gbl/ENABLED_LANGUAGES + /prop_gbl/FIND_LIBRARY_USE_LIB32_PATHS /prop_gbl/FIND_LIBRARY_USE_LIB64_PATHS /prop_gbl/FIND_LIBRARY_USE_OPENBSD_VERSIONING /prop_gbl/GLOBAL_DEPENDS_DEBUG_MODE diff --git a/Help/manual/ctest.1.rst b/Help/manual/ctest.1.rst index 1179f56..e797333 100644 --- a/Help/manual/ctest.1.rst +++ b/Help/manual/ctest.1.rst @@ -589,6 +589,11 @@ Configuration settings to specify the version control tool include: * `CTest Script`_ variable: :variable:`CTEST_GIT_COMMAND` * :module:`CTest` module variable: ``GITCOMMAND`` + The source tree is updated by ``git fetch`` followed by + ``git reset --hard`` to the ``FETCH_HEAD``. The result is the same + as ``git pull`` except that any local moficiations are overwritten. + Use ``GITUpdateCustom`` to specify a different approach. + ``GITInitSubmodules`` If set, CTest will update the repository's submodules before updating. diff --git a/Help/module/FindVulkan.rst b/Help/module/FindVulkan.rst new file mode 100644 index 0000000..adf824e --- /dev/null +++ b/Help/module/FindVulkan.rst @@ -0,0 +1 @@ +.. cmake-module:: ../../Modules/FindVulkan.cmake diff --git a/Help/prop_gbl/FIND_LIBRARY_USE_LIB32_PATHS.rst b/Help/prop_gbl/FIND_LIBRARY_USE_LIB32_PATHS.rst new file mode 100644 index 0000000..ce18b65 --- /dev/null +++ b/Help/prop_gbl/FIND_LIBRARY_USE_LIB32_PATHS.rst @@ -0,0 +1,10 @@ +FIND_LIBRARY_USE_LIB32_PATHS +---------------------------- + +Whether the :command:`find_library` command should automatically search +``lib32`` directories. + +``FIND_LIBRARY_USE_LIB32_PATHS`` is a boolean specifying whether the +:command:`find_library` command should automatically search the ``lib32`` +variant of directories called ``lib`` in the search path when building 32-bit +binaries. diff --git a/Help/release/dev/FindVulkan.rst b/Help/release/dev/FindVulkan.rst new file mode 100644 index 0000000..bb5447e --- /dev/null +++ b/Help/release/dev/FindVulkan.rst @@ -0,0 +1,4 @@ +FindVulkan +---------- + +* A :module:`FindVulkan` module was added. diff --git a/Help/release/dev/find-lib32.rst b/Help/release/dev/find-lib32.rst new file mode 100644 index 0000000..00818dc --- /dev/null +++ b/Help/release/dev/find-lib32.rst @@ -0,0 +1,7 @@ +find-lib32 +---------- + +* The :command:`find_library` and :command:`find_package` commands learned + to search in ``lib32/`` directories when the build targets a 32-bit + architecture. See the :prop_gbl:`FIND_LIBRARY_USE_LIB32_PATHS` global + property. diff --git a/Help/release/dev/java-export-targets.rst b/Help/release/dev/java-export-targets.rst new file mode 100644 index 0000000..5b70e97 --- /dev/null +++ b/Help/release/dev/java-export-targets.rst @@ -0,0 +1,6 @@ +java-export-targets +------------------- + +* The :module:`UseJava` module gained APIs to "export" jar targets + for use by external CMake projects. See the ``install_jar_exports`` + and ``export_jars`` functions. diff --git a/Modules/FindBZip2.cmake b/Modules/FindBZip2.cmake index 6af42dd..b670025 100644 --- a/Modules/FindBZip2.cmake +++ b/Modules/FindBZip2.cmake @@ -37,7 +37,7 @@ find_path(BZIP2_INCLUDE_DIR bzlib.h ${_BZIP2_PATHS} PATH_SUFFIXES include) if (NOT BZIP2_LIBRARIES) find_library(BZIP2_LIBRARY_RELEASE NAMES bz2 bzip2 ${_BZIP2_PATHS} PATH_SUFFIXES lib) - find_library(BZIP2_LIBRARY_DEBUG NAMES bzip2d ${_BZIP2_PATHS} PATH_SUFFIXES lib) + find_library(BZIP2_LIBRARY_DEBUG NAMES bz2d bzip2d ${_BZIP2_PATHS} PATH_SUFFIXES lib) include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake) SELECT_LIBRARY_CONFIGURATIONS(BZIP2) diff --git a/Modules/FindCUDA.cmake b/Modules/FindCUDA.cmake index 48bb554..86f89d8 100644 --- a/Modules/FindCUDA.cmake +++ b/Modules/FindCUDA.cmake @@ -188,10 +188,8 @@ # files. # # -# # CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS( output_file_var cuda_target # nvcc_flags object_files) -# # -- Generates the link object required by separable compilation from the given # object files. This is called automatically for CUDA_ADD_EXECUTABLE and # CUDA_ADD_LIBRARY, but can be called manually when using CUDA_WRAP_SRCS @@ -201,6 +199,24 @@ # specified by CUDA_64_BIT_DEVICE_CODE. Note that this is a function # instead of a macro. # +# CUDA_SELECT_NVCC_ARCH_FLAGS(out_variable [target_CUDA_architectures]) +# -- Selects GPU arch flags for nvcc based on target_CUDA_architectures +# target_CUDA_architectures : Auto | Common | All | LIST(ARCH_AND_PTX ...) +# - "Auto" detects local machine GPU compute arch at runtime. +# - "Common" and "All" cover common and entire subsets of architectures +# ARCH_AND_PTX : NAME | NUM.NUM | NUM.NUM(NUM.NUM) | NUM.NUM+PTX +# NAME: Fermi Kepler Maxwell Kepler+Tegra Kepler+Tesla Maxwell+Tegra Pascal +# NUM: Any number. Only those pairs are currently accepted by NVCC though: +# 2.0 2.1 3.0 3.2 3.5 3.7 5.0 5.2 5.3 6.0 6.2 +# Returns LIST of flags to be added to CUDA_NVCC_FLAGS in ${out_variable} +# Additionally, sets ${out_variable}_readable to the resulting numeric list +# Example: +# CUDA_SELECT_NVCC_ARCH_FLAGS(ARCH_FLAGS 3.0 3.5+PTX 5.2(5.0) Maxwell) +# LIST(APPEND CUDA_NVCC_FLAGS ${ARCH_FLAGS}) +# +# More info on CUDA architectures: https://en.wikipedia.org/wiki/CUDA +# Note that this is a function instead of a macro. +# # CUDA_WRAP_SRCS ( cuda_target format generated_files file0 file1 ... # [STATIC | SHARED | MODULE] [OPTIONS ...] ) # -- This is where all the magic happens. CUDA_ADD_EXECUTABLE, @@ -563,8 +579,8 @@ 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() # Check to see if the CUDA_TOOLKIT_ROOT_DIR and CUDA_SDK_ROOT_DIR have changed, @@ -580,27 +596,28 @@ if(NOT "${CUDA_TOOLKIT_TARGET_DIR}" STREQUAL "${CUDA_TOOLKIT_TARGET_DIR_INTERNAL cuda_unset_include_and_libraries() endif() -if(NOT "${CUDA_SDK_ROOT_DIR}" STREQUAL "${CUDA_SDK_ROOT_DIR_INTERNAL}") - # No specific variables to catch. Use this kind of code before calling - # find_package(CUDA) to clean up any variables that may depend on this path. +# +# End of unset() +# - # unset(MY_SPECIAL_CUDA_SDK_INCLUDE_DIR CACHE) - # unset(MY_SPECIAL_CUDA_SDK_LIBRARY CACHE) -endif() +# +# Start looking for things +# # Search for the cuda distribution. -if(NOT CUDA_TOOLKIT_ROOT_DIR) - +if(NOT CUDA_TOOLKIT_ROOT_DIR AND NOT CMAKE_CROSSCOMPILING) # Search in the CUDA_BIN_PATH first. find_path(CUDA_TOOLKIT_ROOT_DIR NAMES nvcc nvcc.exe PATHS + ENV CUDA_TOOLKIT_ROOT ENV CUDA_PATH ENV CUDA_BIN_PATH PATH_SUFFIXES bin bin64 DOC "Toolkit location." NO_DEFAULT_PATH ) + # Now search default paths find_path(CUDA_TOOLKIT_ROOT_DIR NAMES nvcc nvcc.exe @@ -613,7 +630,9 @@ if(NOT CUDA_TOOLKIT_ROOT_DIR) string(REGEX REPLACE "[/\\\\]?bin[64]*[/\\\\]?$" "" CUDA_TOOLKIT_ROOT_DIR ${CUDA_TOOLKIT_ROOT_DIR}) # We need to force this back into the cache. set(CUDA_TOOLKIT_ROOT_DIR ${CUDA_TOOLKIT_ROOT_DIR} CACHE PATH "Toolkit location." FORCE) + set(CUDA_TOOLKIT_TARGET_DIR ${CUDA_TOOLKIT_ROOT_DIR}) endif() + if (NOT EXISTS ${CUDA_TOOLKIT_ROOT_DIR}) if(CUDA_FIND_REQUIRED) message(FATAL_ERROR "Specify CUDA_TOOLKIT_ROOT_DIR") @@ -623,8 +642,45 @@ if(NOT CUDA_TOOLKIT_ROOT_DIR) endif () endif () +if(CMAKE_CROSSCOMPILING) + SET (CUDA_TOOLKIT_ROOT $ENV{CUDA_TOOLKIT_ROOT}) + if(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7-a") + # Support for NVPACK + set (CUDA_TOOLKIT_TARGET_NAME "armv7-linux-androideabi") + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm") + # Support for arm cross compilation + set(CUDA_TOOLKIT_TARGET_NAME "armv7-linux-gnueabihf") + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") + # Support for aarch64 cross compilation + if (ANDROID_ARCH_NAME STREQUAL "arm64") + set(CUDA_TOOLKIT_TARGET_NAME "aarch64-linux-androideabi") + else() + set(CUDA_TOOLKIT_TARGET_NAME "aarch64-linux") + endif (ANDROID_ARCH_NAME STREQUAL "arm64") + endif() + + if (EXISTS "${CUDA_TOOLKIT_ROOT}/targets/${CUDA_TOOLKIT_TARGET_NAME}") + set(CUDA_TOOLKIT_TARGET_DIR "${CUDA_TOOLKIT_ROOT}/targets/${CUDA_TOOLKIT_TARGET_NAME}" CACHE PATH "CUDA Toolkit target location.") + SET (CUDA_TOOLKIT_ROOT_DIR ${CUDA_TOOLKIT_ROOT}) + mark_as_advanced(CUDA_TOOLKIT_TARGET_DIR) + endif() + + # 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} ) + endmacro() +else() + # for non-cross-compile, find_host_program == find_program and CUDA_TOOLKIT_TARGET_DIR == CUDA_TOOLKIT_ROOT_DIR + macro( cuda_find_host_program ) + find_program( ${ARGN} ) + endmacro() + SET (CUDA_TOOLKIT_TARGET_DIR ${CUDA_TOOLKIT_ROOT_DIR}) +endif() + + # CUDA_NVCC_EXECUTABLE -find_program(CUDA_NVCC_EXECUTABLE +cuda_find_host_program(CUDA_NVCC_EXECUTABLE NAMES nvcc PATHS "${CUDA_TOOLKIT_ROOT_DIR}" ENV CUDA_PATH @@ -633,7 +689,7 @@ find_program(CUDA_NVCC_EXECUTABLE NO_DEFAULT_PATH ) # Search default search paths, after we search our own set of paths. -find_program(CUDA_NVCC_EXECUTABLE nvcc) +cuda_find_host_program(CUDA_NVCC_EXECUTABLE nvcc) mark_as_advanced(CUDA_NVCC_EXECUTABLE) if(CUDA_NVCC_EXECUTABLE AND NOT CUDA_VERSION) @@ -649,33 +705,14 @@ else() string(REGEX REPLACE "([0-9]+)\\.([0-9]+).*" "\\2" CUDA_VERSION_MINOR "${CUDA_VERSION}") endif() + # Always set this convenience variable set(CUDA_VERSION_STRING "${CUDA_VERSION}") -# Support for arm cross compilation with CUDA 5.5 -if(CUDA_VERSION VERSION_GREATER "5.0" AND CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_PROCESSOR MATCHES "arm" AND EXISTS "${CUDA_TOOLKIT_ROOT_DIR}/targets/armv7-linux-gnueabihf") - set(CUDA_TOOLKIT_TARGET_DIR "${CUDA_TOOLKIT_ROOT_DIR}/targets/armv7-linux-gnueabihf" CACHE PATH "Toolkit target location.") -# Support for aarch64 cross compilation with CUDA 7.0 -elseif(CUDA_VERSION VERSION_GREATER "6.5" AND CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64" AND EXISTS "${CUDA_TOOLKIT_ROOT_DIR}/targets/aarch64-linux") - set(CUDA_TOOLKIT_TARGET_DIR "${CUDA_TOOLKIT_ROOT_DIR}/targets/aarch64-linux" CACHE PATH "Toolkit target location.") -else() - set(CUDA_TOOLKIT_TARGET_DIR "${CUDA_TOOLKIT_ROOT_DIR}" CACHE PATH "Toolkit target location.") -endif() -mark_as_advanced(CUDA_TOOLKIT_TARGET_DIR) - -# Target CPU architecture -if(CUDA_VERSION VERSION_GREATER "5.0" AND CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_PROCESSOR MATCHES "arm") - set(_cuda_target_cpu_arch_initial "ARM") -else() - set(_cuda_target_cpu_arch_initial "") -endif() -set(CUDA_TARGET_CPU_ARCH ${_cuda_target_cpu_arch_initial} CACHE STRING "Specify the name of the class of CPU architecture for which the input files must be compiled.") -mark_as_advanced(CUDA_TARGET_CPU_ARCH) - # CUDA_TOOLKIT_INCLUDE find_path(CUDA_TOOLKIT_INCLUDE device_functions.h # Header included in toolkit - PATHS "${CUDA_TOOLKIT_TARGET_DIR}" "${CUDA_TOOLKIT_ROOT_DIR}" + PATHS ${CUDA_TOOLKIT_TARGET_DIR} ENV CUDA_PATH ENV CUDA_INC_PATH PATH_SUFFIXES include @@ -705,19 +742,21 @@ macro(cuda_find_library_local_first_with_path_ext _var _names _doc _path_ext ) # (lib/Win32) and the old path (lib). find_library(${_var} NAMES ${_names} - PATHS "${CUDA_TOOLKIT_TARGET_DIR}" "${CUDA_TOOLKIT_ROOT_DIR}" + PATHS "${CUDA_TOOLKIT_TARGET_DIR}" ENV CUDA_PATH ENV CUDA_LIB_PATH PATH_SUFFIXES ${_cuda_64bit_lib_dir} "${_path_ext}lib/Win32" "${_path_ext}lib" "${_path_ext}libWin32" DOC ${_doc} NO_DEFAULT_PATH ) - # Search default search paths, after we search our own set of paths. - find_library(${_var} - NAMES ${_names} - PATHS "/usr/lib/nvidia-current" - DOC ${_doc} - ) + if (NOT CMAKE_CROSSCOMPILING) + # Search default search paths, after we search our own set of paths. + find_library(${_var} + NAMES ${_names} + PATHS "/usr/lib/nvidia-current" + DOC ${_doc} + ) + endif() endmacro() macro(cuda_find_library_local_first _var _names _doc) @@ -738,10 +777,13 @@ if(CUDA_VERSION VERSION_EQUAL "3.0") CUDA_CUDARTEMU_LIBRARY ) endif() -if(NOT CUDA_VERSION VERSION_LESS "5.5") + +if(CUDA_USE_STATIC_CUDA_RUNTIME AND NOT CUDA_VERSION VERSION_LESS "5.5") cuda_find_library_local_first(CUDA_cudart_static_LIBRARY cudart_static "static CUDA runtime library") mark_as_advanced(CUDA_cudart_static_LIBRARY) endif() + + if(CUDA_cudart_static_LIBRARY) # Set whether to use the static cuda runtime. option(CUDA_USE_STATIC_CUDA_RUNTIME "Use the static version of the CUDA runtime library if available" ON) @@ -772,12 +814,12 @@ if(CUDA_USE_STATIC_CUDA_RUNTIME) else() unset(CMAKE_THREAD_PREFER_PTHREAD) endif() - if (NOT APPLE) - # Here is librt that has things such as, clock_gettime, shm_open, and shm_unlink. - find_library(CUDA_rt_LIBRARY rt) - if (NOT CUDA_rt_LIBRARY) - message(WARNING "Expecting to find librt for libcudart_static, but didn't find it.") - endif() + endif() + if (NOT APPLE AND CUDA_VERSION VERSION_LESS "7.0") + # Before CUDA 7.0, there was librt that has things such as, clock_gettime, shm_open, and shm_unlink. + find_library(CUDA_rt_LIBRARY rt) + if (NOT CUDA_rt_LIBRARY) + message(WARNING "Expecting to find librt for libcudart_static, but didn't find it.") endif() endif() endif() @@ -955,6 +997,7 @@ set(CUDA_SDK_ROOT_DIR_INTERNAL "${CUDA_SDK_ROOT_DIR}" CACHE INTERNAL "This is the value of the last time CUDA_SDK_ROOT_DIR was set successfully." FORCE) include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) + find_package_handle_standard_args(CUDA REQUIRED_VARS CUDA_TOOLKIT_ROOT_DIR @@ -986,6 +1029,7 @@ endmacro() cuda_find_helper_file(parse_cubin cmake) cuda_find_helper_file(make2cmake cmake) cuda_find_helper_file(run_nvcc cmake) +include("${CMAKE_CURRENT_LIST_DIR}/FindCUDA/select_compute_arch.cmake") ############################################################################## # Separate the OPTIONS out from the sources diff --git a/Modules/FindCUDA/select_compute_arch.cmake b/Modules/FindCUDA/select_compute_arch.cmake new file mode 100644 index 0000000..d516831 --- /dev/null +++ b/Modules/FindCUDA/select_compute_arch.cmake @@ -0,0 +1,195 @@ +# Synopsis: +# CUDA_SELECT_NVCC_ARCH_FLAGS(out_variable [target_CUDA_architectures]) +# -- Selects GPU arch flags for nvcc based on target_CUDA_architectures +# target_CUDA_architectures : Auto | Common | All | LIST(ARCH_AND_PTX ...) +# - "Auto" detects local machine GPU compute arch at runtime. +# - "Common" and "All" cover common and entire subsets of architectures +# ARCH_AND_PTX : NAME | NUM.NUM | NUM.NUM(NUM.NUM) | NUM.NUM+PTX +# NAME: Fermi Kepler Maxwell Kepler+Tegra Kepler+Tesla Maxwell+Tegra Pascal +# NUM: Any number. Only those pairs are currently accepted by NVCC though: +# 2.0 2.1 3.0 3.2 3.5 3.7 5.0 5.2 5.3 6.0 6.2 +# Returns LIST of flags to be added to CUDA_NVCC_FLAGS in ${out_variable} +# Additionally, sets ${out_variable}_readable to the resulting numeric list +# Example: +# CUDA_SELECT_NVCC_ARCH_FLAGS(ARCH_FLAGS 3.0 3.5+PTX 5.2(5.0) Maxwell) +# LIST(APPEND CUDA_NVCC_FLAGS ${ARCH_FLAGS}) +# +# More info on CUDA architectures: https://en.wikipedia.org/wiki/CUDA +# + +# This list will be used for CUDA_ARCH_NAME = All option +set(CUDA_KNOWN_GPU_ARCHITECTURES "Fermi" "Kepler" "Maxwell") + +# This list will be used for CUDA_ARCH_NAME = Common option (enabled by default) +set(CUDA_COMMON_GPU_ARCHITECTURES "3.0" "3.5" "5.0") + +if (CUDA_VERSION VERSION_GREATER "6.5") + list(APPEND CUDA_KNOWN_GPU_ARCHITECTURES "Kepler+Tegra" "Kepler+Tesla" "Maxwell+Tegra") + list(APPEND CUDA_COMMON_GPU_ARCHITECTURES "5.2") +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") +else() + list(APPEND CUDA_COMMON_GPU_ARCHITECTURES "5.2+PTX") +endif () + + + +################################################################################################ +# A function for automatic detection of GPUs installed (if autodetection is enabled) +# Usage: +# CUDA_DETECT_INSTALLED_GPUS(OUT_VARIABLE) +# +function(CUDA_DETECT_INSTALLED_GPUS OUT_VARIABLE) + if(NOT CUDA_GPU_DETECT_OUTPUT) + set(cufile ${PROJECT_BINARY_DIR}/detect_cuda_archs.cu) + + file(WRITE ${cufile} "" + "#include <cstdio>\n" + "int main()\n" + "{\n" + " int count = 0;\n" + " if (cudaSuccess != cudaGetDeviceCount(&count)) return -1;\n" + " if (count == 0) return -1;\n" + " for (int device = 0; device < count; ++device)\n" + " {\n" + " cudaDeviceProp prop;\n" + " if (cudaSuccess == cudaGetDeviceProperties(&prop, device))\n" + " std::printf(\"%d.%d \", prop.major, prop.minor);\n" + " }\n" + " return 0;\n" + "}\n") + + execute_process(COMMAND "${CUDA_NVCC_EXECUTABLE}" "--run" "${cufile}" + WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/CMakeFiles/" + RESULT_VARIABLE nvcc_res OUTPUT_VARIABLE nvcc_out + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) + + if(nvcc_res EQUAL 0) + string(REPLACE "2.1" "2.1(2.0)" nvcc_out "${nvcc_out}") + set(CUDA_GPU_DETECT_OUTPUT ${nvcc_out} CACHE INTERNAL "Returned GPU architetures from detect_gpus tool" FORCE) + endif() + endif() + + if(NOT CUDA_GPU_DETECT_OUTPUT) + message(STATUS "Automatic GPU detection failed. Building for common architectures.") + set(${OUT_VARIABLE} ${CUDA_COMMON_GPU_ARCHITECTURES} PARENT_SCOPE) + else() + set(${OUT_VARIABLE} ${CUDA_GPU_DETECT_OUTPUT} PARENT_SCOPE) + endif() +endfunction() + + +################################################################################################ +# Function for selecting GPU arch flags for nvcc based on CUDA architectures from parameter list +# Usage: +# SELECT_NVCC_ARCH_FLAGS(out_variable [list of CUDA compute archs]) +function(CUDA_SELECT_NVCC_ARCH_FLAGS out_variable) + set(CUDA_ARCH_LIST "${ARGN}") + + if("X${CUDA_ARCH_LIST}" STREQUAL "X" ) + set(CUDA_ARCH_LIST "Auto") + endif() + + set(cuda_arch_bin) + set(cuda_arch_ptx) + + if("${CUDA_ARCH_LIST}" STREQUAL "All") + set(CUDA_ARCH_LIST ${CUDA_KNOWN_GPU_ARCHITECTURES}) + elseif("${CUDA_ARCH_LIST}" STREQUAL "Common") + set(CUDA_ARCH_LIST ${CUDA_COMMON_GPU_ARCHITECTURES}) + elseif("${CUDA_ARCH_LIST}" STREQUAL "Auto") + CUDA_DETECT_INSTALLED_GPUS(CUDA_ARCH_LIST) + message(STATUS "Autodetected CUDA architecture(s): ${cuda_arch_bin}") + endif() + + # Now process the list and look for names + string(REGEX REPLACE "[ \t]+" ";" CUDA_ARCH_LIST "${CUDA_ARCH_LIST}") + list(REMOVE_DUPLICATES CUDA_ARCH_LIST) + foreach(arch_name ${CUDA_ARCH_LIST}) + set(arch_bin) + set(add_ptx FALSE) + # Check to see if we are compiling PTX + if(arch_name MATCHES "(.*)\\+PTX$") + set(add_ptx TRUE) + set(arch_name ${CMAKE_MATCH_1}) + endif() + if(arch_name MATCHES "([0-9]\\.[0-9])$") + set(arch_bin ${CMAKE_MATCH_1}) + set(arch_ptx ${arch_bin}) + else() + # Look for it in our list of known architectures + if(${arch_name} STREQUAL "Fermi") + set(arch_bin 2.0 "2.1(2.0)") + elseif(${arch_name} STREQUAL "Kepler+Tegra") + set(arch_bin 3.2) + elseif(${arch_name} STREQUAL "Kepler+Tesla") + set(arch_bin 3.7) + elseif(${arch_name} STREQUAL "Kepler") + set(arch_bin 3.0 3.5) + set(arch_ptx 3.5) + elseif(${arch_name} STREQUAL "Maxwell+Tegra") + set(arch_bin 5.3) + elseif(${arch_name} STREQUAL "Maxwell") + set(arch_bin 5.0 5.2) + set(arch_ptx 5.2) + elseif(${arch_name} STREQUAL "Pascal") + set(arch_bin 6.0 6.1) + set(arch_ptx 6.1) + else() + message(SEND_ERROR "Unknown CUDA Architecture Name ${arch_name} in CUDA_SELECT_NVCC_ARCH_FLAGS") + endif() + endif() + if(NOT arch_bin) + message(SEND_ERROR "arch_bin wasn't set for some reason") + endif() + list(APPEND cuda_arch_bin ${arch_bin}) + if(add_ptx) + if (NOT arch_ptx) + set(arch_ptx ${arch_bin}) + endif() + list(APPEND cuda_arch_ptx ${arch_ptx}) + endif() + endforeach() + + # remove dots and convert to lists + string(REGEX REPLACE "\\." "" cuda_arch_bin "${cuda_arch_bin}") + string(REGEX REPLACE "\\." "" cuda_arch_ptx "${cuda_arch_ptx}") + string(REGEX MATCHALL "[0-9()]+" cuda_arch_bin "${cuda_arch_bin}") + string(REGEX MATCHALL "[0-9]+" cuda_arch_ptx "${cuda_arch_ptx}") + + if(cuda_arch_bin) + list(REMOVE_DUPLICATES cuda_arch_bin) + endif() + if(cuda_arch_ptx) + list(REMOVE_DUPLICATES cuda_arch_ptx) + endif() + + set(nvcc_flags "") + set(nvcc_archs_readable "") + + # Tell NVCC to add binaries for the specified GPUs + foreach(arch ${cuda_arch_bin}) + if(arch MATCHES "([0-9]+)\\(([0-9]+)\\)") + # User explicitly specified PTX for the concrete BIN + list(APPEND nvcc_flags -gencode arch=compute_${CMAKE_MATCH_2},code=sm_${CMAKE_MATCH_1}) + list(APPEND nvcc_archs_readable sm_${CMAKE_MATCH_1}) + else() + # User didn't explicitly specify PTX for the concrete BIN, we assume PTX=BIN + list(APPEND nvcc_flags -gencode arch=compute_${arch},code=sm_${arch}) + list(APPEND nvcc_archs_readable sm_${arch}) + endif() + endforeach() + + # Tell NVCC to add PTX intermediate code for the specified architectures + foreach(arch ${cuda_arch_ptx}) + list(APPEND nvcc_flags -gencode arch=compute_${arch},code=compute_${arch}) + list(APPEND nvcc_archs_readable compute_${arch}) + endforeach() + + string(REPLACE ";" " " nvcc_archs_readable "${nvcc_archs_readable}") + set(${out_variable} ${nvcc_flags} PARENT_SCOPE) + set(${out_variable}_readable ${nvcc_archs_readable} PARENT_SCOPE) +endfunction() diff --git a/Modules/FindFreetype.cmake b/Modules/FindFreetype.cmake index 7d46d15..dc6336d 100644 --- a/Modules/FindFreetype.cmake +++ b/Modules/FindFreetype.cmake @@ -51,9 +51,8 @@ # wants explicit full paths and this trickery doesn't work too well. # I'm going to attempt to cut out the middleman and hope # everything still works. -find_path( - FREETYPE_INCLUDE_DIR_ft2build - ft2build.h + +set(FREETYPE_FIND_ARGS HINTS ENV FREETYPE_DIR PATHS @@ -64,6 +63,12 @@ find_path( ENV GTKMM_BASEPATH [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path] [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path] +) + +find_path( + FREETYPE_INCLUDE_DIR_ft2build + ft2build.h + ${FREETYPE_FIND_ARGS} PATH_SUFFIXES include/freetype2 include @@ -75,16 +80,7 @@ find_path( NAMES freetype/config/ftheader.h config/ftheader.h - HINTS - ENV FREETYPE_DIR - PATHS - /usr/X11R6 - /usr/local/X11R6 - /usr/local/X11 - /usr/freeware - ENV GTKMM_BASEPATH - [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path] - [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path] + ${FREETYPE_FIND_ARGS} PATH_SUFFIXES include/freetype2 include @@ -96,20 +92,13 @@ find_library(FREETYPE_LIBRARY freetype libfreetype freetype219 - HINTS - ENV FREETYPE_DIR - PATHS - /usr/X11R6 - /usr/local/X11R6 - /usr/local/X11 - /usr/freeware - ENV GTKMM_BASEPATH - [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path] - [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path] + ${FREETYPE_FIND_ARGS} PATH_SUFFIXES lib ) +unset(FREETYPE_FIND_ARGS) + # set the user variables if(FREETYPE_INCLUDE_DIR_ft2build AND FREETYPE_INCLUDE_DIR_freetype2) set(FREETYPE_INCLUDE_DIRS "${FREETYPE_INCLUDE_DIR_ft2build};${FREETYPE_INCLUDE_DIR_freetype2}") diff --git a/Modules/FindOpenSSL.cmake b/Modules/FindOpenSSL.cmake index 8dbaf11..6393f2e 100644 --- a/Modules/FindOpenSSL.cmake +++ b/Modules/FindOpenSSL.cmake @@ -328,11 +328,11 @@ function(from_hex HEX DEC) set(${DEC} ${_res} PARENT_SCOPE) endfunction() -if (OPENSSL_INCLUDE_DIR) - if(OPENSSL_INCLUDE_DIR AND EXISTS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h") - file(STRINGS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h" openssl_version_str - REGEX "^#[\t ]*define[\t ]+OPENSSL_VERSION_NUMBER[\t ]+0x([0-9a-fA-F])+.*") +if(OPENSSL_INCLUDE_DIR AND EXISTS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h") + file(STRINGS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h" openssl_version_str + REGEX "^#[\t ]*define[\t ]+OPENSSL_VERSION_NUMBER[\t ]+0x([0-9a-fA-F])+.*") + if(openssl_version_str) # The version number is encoded as 0xMNNFFPPS: major minor fix patch status # The status gives if this is a developer or prerelease and is ignored here. # Major, minor, and fix directly translate into the version numbers shown in diff --git a/Modules/FindPkgConfig.cmake b/Modules/FindPkgConfig.cmake index 644687c..33290c4 100644 --- a/Modules/FindPkgConfig.cmake +++ b/Modules/FindPkgConfig.cmake @@ -316,9 +316,13 @@ macro(_pkg_check_modules_internal _is_required _is_silent _no_cmake_path _no_cma list(APPEND _lib_dirs "lib/${CMAKE_LIBRARY_ARCHITECTURE}/pkgconfig") endif() else() - # not debian, chech the FIND_LIBRARY_USE_LIB64_PATHS property + # not debian, check the FIND_LIBRARY_USE_LIB32_PATHS and FIND_LIBRARY_USE_LIB64_PATHS properties + get_property(uselib32 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS) + if(uselib32 AND CMAKE_SIZEOF_VOID_P EQUAL 4) + list(APPEND _lib_dirs "lib32/pkgconfig") + endif() get_property(uselib64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS) - if(uselib64) + if(uselib64 AND CMAKE_SIZEOF_VOID_P EQUAL 8) list(APPEND _lib_dirs "lib64/pkgconfig") endif() endif() diff --git a/Modules/FindProtobuf.cmake b/Modules/FindProtobuf.cmake index 8042073..c90a0a2 100644 --- a/Modules/FindProtobuf.cmake +++ b/Modules/FindProtobuf.cmake @@ -144,6 +144,10 @@ function(PROTOBUF_GENERATE_CPP SRCS HDRS) foreach(FIL ${ARGN}) get_filename_component(ABS_FIL ${FIL} ABSOLUTE) get_filename_component(FIL_WE ${FIL} NAME_WE) + get_filename_component(FIL_DIR ${FIL} DIRECTORY) + if(FIL_DIR) + set(FIL_WE "${FIL_DIR}/${FIL_WE}") + endif() list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc") list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h") @@ -197,6 +201,10 @@ function(PROTOBUF_GENERATE_PYTHON SRCS) foreach(FIL ${ARGN}) get_filename_component(ABS_FIL ${FIL} ABSOLUTE) get_filename_component(FIL_WE ${FIL} NAME_WE) + get_filename_component(FIL_DIR ${FIL} DIRECTORY) + if(FIL_DIR) + set(FIL_WE "${FIL_DIR}/${FIL_WE}") + endif() list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}_pb2.py") add_custom_command( diff --git a/Modules/FindVulkan.cmake b/Modules/FindVulkan.cmake new file mode 100644 index 0000000..b335f5f --- /dev/null +++ b/Modules/FindVulkan.cmake @@ -0,0 +1,85 @@ +#.rst: +# FindVulkan +# ---------- +# +# Try to find Vulkan +# +# IMPORTED Targets +# ^^^^^^^^^^^^^^^^ +# +# This module defines :prop_tgt:`IMPORTED` target ``Vulkan::Vulkan``, if +# Vulkan has been found. +# +# Result Variables +# ^^^^^^^^^^^^^^^^ +# +# This module defines the following variables:: +# +# Vulkan_FOUND - True if Vulkan was found +# Vulkan_INCLUDE_DIRS - include directories for Vulkan +# Vulkan_LIBRARIES - link against this library to use Vulkan +# +# The module will also define two cache variables:: +# +# Vulkan_INCLUDE_DIR - the Vulkan include directory +# Vulkan_LIBRARY - the path to the Vulkan library +# + +#============================================================================= +# Copyright 2016 Matthaeus G. Chajdas +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +if(WIN32) + find_path(Vulkan_INCLUDE_DIR + NAMES vulkan/vulkan.h + PATHS + "$ENV{VULKAN_SDK}/Include" + ) + + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + find_library(Vulkan_LIBRARY + NAMES vulkan-1 + PATHS + "$ENV{VULKAN_SDK}/Bin") + elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) + find_library(Vulkan_LIBRARY + NAMES vulkan-1 + PATHS + "$ENV{VULKAN_SDK}/Bin32") + endif() +else() + find_path(Vulkan_INCLUDE_DIR + NAMES vulkan/vulkan.h + PATHS + "$ENV{VULKAN_SDK}/include") + find_library(Vulkan_LIBRARY + NAMES vulkan + PATHS + "$ENV{VULKAN_SDK}/lib") +endif() + +set(Vulkan_LIBRARIES ${Vulkan_LIBRARY}) +set(Vulkan_INCLUDE_DIRS ${Vulkan_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Vulkan + DEFAULT_MSG + Vulkan_LIBRARY Vulkan_INCLUDE_DIR) + +mark_as_advanced(Vulkan_INCLUDE_DIR Vulkan_LIBRARY) + +if(Vulkan_FOUND AND NOT TARGET Vulkan::Vulkan) + add_library(Vulkan::Vulkan UNKNOWN IMPORTED) + set_target_properties(Vulkan::Vulkan PROPERTIES + IMPORTED_LOCATION "${Vulkan_LIBRARIES}" + INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}") +endif() diff --git a/Modules/Platform/Linux.cmake b/Modules/Platform/Linux.cmake index e40a74f..1f8c1b4 100644 --- a/Modules/Platform/Linux.cmake +++ b/Modules/Platform/Linux.cmake @@ -50,8 +50,9 @@ set(CMAKE_LIBRARY_ARCHITECTURE_REGEX "[a-z0-9_]+(-[a-z0-9_]+)?-linux-gnu[a-z0-9_ include(Platform/UnixPaths) -# Debian has lib64 paths only for compatibility so they should not be +# Debian has lib32 and lib64 paths only for compatibility so they should not be # searched. if(NOT CMAKE_CROSSCOMPILING AND EXISTS "/etc/debian_version") + set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS FALSE) set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS FALSE) endif() diff --git a/Modules/Platform/OpenBSD.cmake b/Modules/Platform/OpenBSD.cmake index 7ac6c7e..6466a0a 100644 --- a/Modules/Platform/OpenBSD.cmake +++ b/Modules/Platform/OpenBSD.cmake @@ -18,6 +18,7 @@ endif() set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_OPENBSD_VERSIONING 1) # OpenBSD has no multilib +set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS FALSE) set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS FALSE) # OpenBSD policy requires that shared libraries be installed without diff --git a/Modules/Platform/SunOS-PathScale-C.cmake b/Modules/Platform/SunOS-PathScale-C.cmake new file mode 100644 index 0000000..2f78da1 --- /dev/null +++ b/Modules/Platform/SunOS-PathScale-C.cmake @@ -0,0 +1,2 @@ +include(Platform/SunOS-PathScale) +__sunos_compiler_pathscale(C) diff --git a/Modules/Platform/SunOS-PathScale-CXX.cmake b/Modules/Platform/SunOS-PathScale-CXX.cmake new file mode 100644 index 0000000..bb79d86 --- /dev/null +++ b/Modules/Platform/SunOS-PathScale-CXX.cmake @@ -0,0 +1,2 @@ +include(Platform/SunOS-PathScale) +__sunos_compiler_pathscale(CXX) diff --git a/Modules/Platform/SunOS-PathScale-Fortran.cmake b/Modules/Platform/SunOS-PathScale-Fortran.cmake new file mode 100644 index 0000000..3c202f7 --- /dev/null +++ b/Modules/Platform/SunOS-PathScale-Fortran.cmake @@ -0,0 +1,2 @@ +include(Platform/SunOS-PathScale) +__sunos_compiler_pathscale(Fortran) diff --git a/Modules/Platform/SunOS-PathScale.cmake b/Modules/Platform/SunOS-PathScale.cmake new file mode 100644 index 0000000..1afe56a --- /dev/null +++ b/Modules/Platform/SunOS-PathScale.cmake @@ -0,0 +1,31 @@ + +#============================================================================= +# Copyright 2016 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +# This module is shared by multiple languages; use include blocker. +if(__SUNOS_COMPILER_PATHSCALE) + return() +endif() +set(__SUNOS_COMPILER_PATHSCALE 1) + +macro(__sunos_compiler_pathscale lang) + # Shared library compile and link flags. + set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC") + set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE") + set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-fPIC") + set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-shared") + + set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG "-Wl,-R") + set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG_SEP ":") + set(CMAKE_SHARED_LIBRARY_SONAME_${lang}_FLAG "-Wl,-h") +endmacro() diff --git a/Modules/Platform/UnixPaths.cmake b/Modules/Platform/UnixPaths.cmake index 20ee1d1..d6c3d41 100644 --- a/Modules/Platform/UnixPaths.cmake +++ b/Modules/Platform/UnixPaths.cmake @@ -93,5 +93,6 @@ list(APPEND CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES /usr/include ) -# Enable use of lib64 search path variants by default. +# Enable use of lib32 and lib64 search path variants by default. +set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS TRUE) set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS TRUE) diff --git a/Modules/UseJava.cmake b/Modules/UseJava.cmake index 7b3416e..cf9c2d7 100644 --- a/Modules/UseJava.cmake +++ b/Modules/UseJava.cmake @@ -217,6 +217,19 @@ # This command installs the TARGET_NAME files to the given DESTINATION. # It should be called in the same scope as add_jar() or it will fail. # +# Target Properties: +# +# :: +# +# The install_jar() function sets the INSTALL_DESTINATION target property +# on jars so installed. This property holds the DESTINATION as described +# above, and is used by install_jar_exports(). You can get this property +# with the +# get_property(TARGET <target_name> PROPERTY INSTALL_DESTINATION) +# command. +# +# +# # :: # # install_jni_symlink(target_name destination) @@ -228,6 +241,24 @@ # # :: # +# install_jar_exports(TARGETS jar1 [jar2 ...] +# FILE export_filename +# DESTINATION destination [COMPONENT component]) +# +# This command installs a target export file export_filename for the named jar +# targets to the given DESTINATION. Its function is similar to that of +# install(EXPORTS). +# +# :: +# +# export_jars(TARGETS jar1 [jar2 ...] +# FILE export_filename) +# +# This command writes a target export file export_filename for the named jar +# targets. Its function is similar to that of export(). +# +# :: +# # create_javadoc(<VAR> # PACKAGES pkg1 [pkg2 ...] # [SOURCEPATH <sourcepath>] @@ -396,7 +427,29 @@ function (__java_copy_file src dest comment) COMMENT ${comment}) endfunction () +function(__java_lcat VAR) + foreach(_line ${ARGN}) + set(${VAR} "${${VAR}}${_line}\n") + endforeach() + + set(${VAR} "${${VAR}}" PARENT_SCOPE) +endfunction() + +function(__java_export_jar VAR TARGET PATH) + get_target_property(_jarpath ${TARGET} JAR_FILE) + get_filename_component(_jarname ${_jarpath} NAME) + __java_lcat(${VAR} + "# Create imported target ${TARGET}" + "add_custom_target(${TARGET})" + "set_target_properties(${TARGET} PROPERTIES" + " JAR_FILE \"${PATH}/${_jarname}\")" + "" + ) + set(${VAR} "${${VAR}}" PARENT_SCOPE) +endfunction() + # define helper scripts +set(_JAVA_EXPORT_TARGETS_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/javaTargets.cmake.in) set(_JAVA_CLASS_FILELIST_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/UseJavaClassFilelist.cmake) set(_JAVA_SYMLINK_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/UseJavaSymlinks.cmake) @@ -435,6 +488,8 @@ function(add_jar _TARGET_NAME) if (NOT DEFINED _add_jar_OUTPUT_DIR) set(_add_jar_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}) + else() + get_filename_component(_add_jar_OUTPUT_DIR ${_add_jar_OUTPUT_DIR} ABSOLUTE) endif() if (_add_jar_ENTRY_POINT) @@ -554,11 +609,6 @@ function(add_jar _TARGET_NAME) endif () endforeach() - # create an empty java_class_filelist - if (NOT EXISTS ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist) - file(WRITE ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist "") - endif() - if (_JAVA_COMPILE_FILES OR _JAVA_COMPILE_FILELISTS) set (_JAVA_SOURCES_FILELISTS) @@ -598,6 +648,11 @@ function(add_jar _TARGET_NAME) DEPENDS ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_compiled_${_TARGET_NAME} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) + else () + # create an empty java_class_filelist + if (NOT EXISTS ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist) + file(WRITE ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist "") + endif() endif () # create the jar file @@ -716,6 +771,13 @@ function(INSTALL_JAR _TARGET_NAME) PROPERTY INSTALL_FILES ) + set_property( + TARGET + ${_TARGET_NAME} + PROPERTY + INSTALL_DESTINATION + ${_DESTINATION} + ) if (__FILES) install( @@ -1288,3 +1350,94 @@ function (create_javah) set (${_create_javah_GENERATED_FILES} ${_output_files} PARENT_SCOPE) endif() endfunction() + +function(export_jars) + # Parse and validate arguments + cmake_parse_arguments(_export_jars + "" + "FILE" + "TARGETS" + ${ARGN} + ) + if (NOT _export_jars_FILE) + message(SEND_ERROR "export_jars: FILE must be specified.") + endif() + if (NOT _export_jars_TARGETS) + message(SEND_ERROR "export_jars: TARGETS must be specified.") + endif() + + # Set content of generated exports file + string(REPLACE ";" " " __targets__ "${_export_jars_TARGETS}") + set(__targetdefs__ "") + foreach(_target ${_export_jars_TARGETS}) + get_target_property(_jarpath ${_target} JAR_FILE) + get_filename_component(_jarpath ${_jarpath} PATH) + __java_export_jar(__targetdefs__ ${_target} "${_jarpath}") + endforeach() + + # Generate exports file + configure_file( + ${_JAVA_EXPORT_TARGETS_SCRIPT} + ${_export_jars_FILE} + @ONLY + ) +endfunction() + +function(install_jar_exports) + # Parse and validate arguments + cmake_parse_arguments(_install_jar_exports + "" + "FILE;DESTINATION;COMPONENT" + "TARGETS" + ${ARGN} + ) + if (NOT _install_jar_exports_FILE) + message(SEND_ERROR "install_jar_exports: FILE must be specified.") + endif() + if (NOT _install_jar_exports_DESTINATION) + message(SEND_ERROR "install_jar_exports: DESTINATION must be specified.") + endif() + if (NOT _install_jar_exports_TARGETS) + message(SEND_ERROR "install_jar_exports: TARGETS must be specified.") + endif() + + if (_install_jar_exports_COMPONENT) + set (_COMPONENT COMPONENT ${_install_jar_exports_COMPONENT}) + endif() + + # Determine relative path from installed export file to install prefix + if(IS_ABSOLUTE ${_install_jar_exports_DESTINATION}) + file(RELATIVE_PATH _relpath + ${_install_jar_exports_DESTINATION} + ${CMAKE_INSTALL_PREFIX} + ) + else() + file(RELATIVE_PATH _relpath + ${CMAKE_INSTALL_PREFIX}/${_install_jar_exports_DESTINATION} + ${CMAKE_INSTALL_PREFIX} + ) + endif() + + # Set up unique location for generated exports file + string(SHA256 _hash "${_install_jar_exports_DESTINATION}") + set(_tmpdir ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/JavaExports/${_hash}) + + # Set content of generated exports file + string(REPLACE ";" " " __targets__ "${_install_jar_exports_TARGETS}") + set(__targetdefs__ "set(_prefix \${CMAKE_CURRENT_LIST_DIR}/${_relpath})\n\n") + foreach(_target ${_install_jar_exports_TARGETS}) + get_target_property(_dir ${_target} INSTALL_DESTINATION) + __java_export_jar(__targetdefs__ ${_target} "\${_prefix}/${_dir}") + endforeach() + __java_lcat(__targetdefs__ "\nunset(_prefix)") + + # Generate and install exports file + configure_file( + ${_JAVA_EXPORT_TARGETS_SCRIPT} + ${_tmpdir}/${_install_jar_exports_FILE} + @ONLY + ) + install(FILES ${_tmpdir}/${_install_jar_exports_FILE} + DESTINATION ${_install_jar_exports_DESTINATION} + ${_COMPONENT}) +endfunction() diff --git a/Modules/javaTargets.cmake.in b/Modules/javaTargets.cmake.in new file mode 100644 index 0000000..c5f9c78 --- /dev/null +++ b/Modules/javaTargets.cmake.in @@ -0,0 +1,39 @@ +cmake_minimum_required(VERSION 2.8) +cmake_policy(PUSH) +cmake_policy(VERSION 2.8) + +#---------------------------------------------------------------- +# Generated CMake Java target import file. +#---------------------------------------------------------------- + +# Protect against multiple inclusion, which would fail when already imported targets are added once more. +set(_targetsDefined) +set(_targetsNotDefined) +set(_expectedTargets) +foreach(_expectedTarget @__targets__@) + list(APPEND _expectedTargets ${_expectedTarget}) + if(TARGET ${_expectedTarget}) + list(APPEND _targetsDefined ${_expectedTarget}) + else() + list(APPEND _targetsNotDefined ${_expectedTarget}) + endif() +endforeach() +if("%${_targetsDefined}" STREQUAL "%${_expectedTargets}") + unset(_targetsDefined) + unset(_targetsNotDefined) + unset(_expectedTargets) + cmake_policy(POP) + return() +endif() +if(NOT "${_targetsDefined}" STREQUAL "") + message(FATAL_ERROR + "Some (but not all) targets in this export set were already defined.\n" + "Targets Defined: ${_targetsDefined}\n" + "Targets not yet defined: ${_targetsNotDefined}\n") +endif() +unset(_targetsDefined) +unset(_targetsNotDefined) +unset(_expectedTargets) + +@__targetdefs__@ +cmake_policy(POP) diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 93d02c3..26702f8 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 6) -set(CMake_VERSION_PATCH 20160606) +set(CMake_VERSION_PATCH 20160613) #set(CMake_VERSION_RC 1) diff --git a/Source/CPack/IFW/cmCPackIFWGenerator.cxx b/Source/CPack/IFW/cmCPackIFWGenerator.cxx index c1ff526..b47d46e 100644 --- a/Source/CPack/IFW/cmCPackIFWGenerator.cxx +++ b/Source/CPack/IFW/cmCPackIFWGenerator.cxx @@ -345,18 +345,21 @@ cmCPackComponent* cmCPackIFWGenerator::GetComponent( const std::string& projectName, const std::string& componentName) { ComponentsMap::iterator cit = Components.find(componentName); - if (cit != Components.end()) + if (cit != Components.end()) { return &(cit->second); + } cmCPackComponent* component = cmCPackGenerator::GetComponent(projectName, componentName); - if (!component) + if (!component) { return component; + } std::string name = GetComponentPackageName(component); PackagesMap::iterator pit = Packages.find(name); - if (pit != Packages.end()) + if (pit != Packages.end()) { return component; + } cmCPackIFWPackage* package = &Packages[name]; package->Name = name; @@ -387,13 +390,15 @@ cmCPackComponentGroup* cmCPackIFWGenerator::GetComponentGroup( { cmCPackComponentGroup* group = cmCPackGenerator::GetComponentGroup(projectName, groupName); - if (!group) + if (!group) { return group; + } std::string name = GetGroupPackageName(group); PackagesMap::iterator pit = Packages.find(name); - if (pit != Packages.end()) + if (pit != Packages.end()) { return group; + } cmCPackIFWPackage* package = &Packages[name]; package->Name = name; @@ -462,8 +467,9 @@ std::string cmCPackIFWGenerator::GetGroupPackageName( cmCPackComponentGroup* group) const { std::string name; - if (!group) + if (!group) { return name; + } if (cmCPackIFWPackage* package = GetGroupPackage(group)) { return package->Name; } @@ -488,8 +494,9 @@ std::string cmCPackIFWGenerator::GetComponentPackageName( cmCPackComponent* component) const { std::string name; - if (!component) + if (!component) { return name; + } if (cmCPackIFWPackage* package = GetComponentPackage(component)) { return package->Name; } @@ -534,8 +541,9 @@ cmCPackIFWRepository* cmCPackIFWGenerator::GetRepository( const std::string& repositoryName) { RepositoriesMap::iterator rit = Repositories.find(repositoryName); - if (rit != Repositories.end()) + if (rit != Repositories.end()) { return &(rit->second); + } cmCPackIFWRepository* repository = &Repositories[repositoryName]; repository->Name = repositoryName; diff --git a/Source/CPack/IFW/cmCPackIFWInstaller.cxx b/Source/CPack/IFW/cmCPackIFWInstaller.cxx index dfc509b..74f6da6 100644 --- a/Source/CPack/IFW/cmCPackIFWInstaller.cxx +++ b/Source/CPack/IFW/cmCPackIFWInstaller.cxx @@ -343,6 +343,7 @@ void cmCPackIFWInstaller::GeneratePackageFiles() void cmCPackIFWInstaller::WriteGeneratedByToStrim(cmXMLWriter& xout) { - if (Generator) + if (Generator) { Generator->WriteGeneratedByToStrim(xout); + } } diff --git a/Source/CPack/IFW/cmCPackIFWPackage.cxx b/Source/CPack/IFW/cmCPackIFWPackage.cxx index ad153d1..c44e389 100644 --- a/Source/CPack/IFW/cmCPackIFWPackage.cxx +++ b/Source/CPack/IFW/cmCPackIFWPackage.cxx @@ -71,8 +71,9 @@ cmCPackIFWPackage::DependenceStruct::DependenceStruct( std::string cmCPackIFWPackage::DependenceStruct::NameWithCompare() const { - if (Compare.Type == CompareNone) + if (Compare.Type == CompareNone) { return Name; + } std::string result = Name; @@ -128,8 +129,9 @@ bool cmCPackIFWPackage::IsVersionEqual(const char* version) std::string cmCPackIFWPackage::GetComponentName(cmCPackComponent* component) { - if (!component) + if (!component) { return ""; + } const char* option = GetOption("CPACK_IFW_COMPONENT_" + cmsys::SystemTools::UpperCase(component->Name) + "_NAME"); @@ -189,8 +191,9 @@ int cmCPackIFWPackage::ConfigureFromOptions() int cmCPackIFWPackage::ConfigureFromComponent(cmCPackComponent* component) { - if (!component) + if (!component) { return 0; + } // Restore defaul configuration DefaultConfiguration(); @@ -284,8 +287,9 @@ int cmCPackIFWPackage::ConfigureFromComponent(cmCPackComponent* component) int cmCPackIFWPackage::ConfigureFromGroup(cmCPackComponentGroup* group) { - if (!group) + if (!group) { return 0; + } // Restore defaul configuration DefaultConfiguration(); @@ -474,6 +478,7 @@ void cmCPackIFWPackage::GeneratePackageFile() void cmCPackIFWPackage::WriteGeneratedByToStrim(cmXMLWriter& xout) { - if (Generator) + if (Generator) { Generator->WriteGeneratedByToStrim(xout); + } } diff --git a/Source/CPack/IFW/cmCPackIFWRepository.cxx b/Source/CPack/IFW/cmCPackIFWRepository.cxx index 1838005..b8a10c6 100644 --- a/Source/CPack/IFW/cmCPackIFWRepository.cxx +++ b/Source/CPack/IFW/cmCPackIFWRepository.cxx @@ -89,8 +89,9 @@ bool cmCPackIFWRepository::IsVersionEqual(const char* version) bool cmCPackIFWRepository::ConfigureFromOptions() { // Name; - if (Name.empty()) + if (Name.empty()) { return false; + } std::string prefix = "CPACK_IFW_REPOSITORY_" + cmsys::SystemTools::UpperCase(Name) + "_"; @@ -198,8 +199,9 @@ protected: patched = true; } xout.EndElement(); - if (patched) + if (patched) { return; + } if (name == "Checksum") { repository->WriteRepositoryUpdates(xout); patched = true; @@ -209,8 +211,10 @@ protected: virtual void CharacterDataHandler(const char* data, int length) { std::string content(data, data + length); - if (content == "" || content == " " || content == " " || content == "\n") + if (content == "" || content == " " || content == " " || + content == "\n") { return; + } xout.Content(content); } }; @@ -332,6 +336,7 @@ void cmCPackIFWRepository::WriteRepositoryUpdates(cmXMLWriter& xout) void cmCPackIFWRepository::WriteGeneratedByToStrim(cmXMLWriter& xout) { - if (Generator) + if (Generator) { Generator->WriteGeneratedByToStrim(xout); + } } diff --git a/Source/CPack/OSXScriptLauncher.cxx b/Source/CPack/OSXScriptLauncher.cxx index 19204a2..a233e76 100644 --- a/Source/CPack/OSXScriptLauncher.cxx +++ b/Source/CPack/OSXScriptLauncher.cxx @@ -72,7 +72,7 @@ int main(int argc, char* argv[]) std::string scriptDirectory = cmsys::SystemTools::GetFilenamePath(fullScriptPath); - ofs << fullScriptPath.c_str() << std::endl; + ofs << fullScriptPath << std::endl; std::vector<const char*> args; args.push_back(fullScriptPath.c_str()); int cc; diff --git a/Source/CPack/cmCPackBundleGenerator.cxx b/Source/CPack/cmCPackBundleGenerator.cxx index 1164021..9276e3a 100644 --- a/Source/CPack/cmCPackBundleGenerator.cxx +++ b/Source/CPack/cmCPackBundleGenerator.cxx @@ -232,12 +232,12 @@ int cmCPackBundleGenerator::SignBundle(const std::string& src_dir) temp_sign_file_cmd << this->GetOption("CPACK_APPLE_BUNDLE_ID"); temp_sign_file_cmd << " \""; temp_sign_file_cmd << bundle_path; - temp_sign_file_cmd << it->c_str() << "\""; + temp_sign_file_cmd << *it << "\""; if (!this->RunCommand(temp_sign_file_cmd, &output)) { - cmCPackLogger(cmCPackLog::LOG_ERROR, "Error signing file:" - << bundle_path << it->c_str() << std::endl - << output << std::endl); + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Error signing file:" << bundle_path << *it << std::endl + << output << std::endl); return 0; } diff --git a/Source/CPack/cmCPackDebGenerator.cxx b/Source/CPack/cmCPackDebGenerator.cxx index ddaa483..b659359 100644 --- a/Source/CPack/cmCPackDebGenerator.cxx +++ b/Source/CPack/cmCPackDebGenerator.cxx @@ -57,9 +57,9 @@ int cmCPackDebGenerator::PackageOnePack(std::string const& initialTopLevel, // Begin the archive for this pack std::string localToplevel(initialTopLevel); std::string packageFileName(cmSystemTools::GetParentDirectory(toplevel)); - std::string outputFileName(std::string( - this->GetOption("CPACK_PACKAGE_FILE_NAME")) + - "-" + packageName + this->GetOutputExtension()); + std::string outputFileName( + std::string(this->GetOption("CPACK_PACKAGE_FILE_NAME")) + "-" + + packageName + this->GetOutputExtension()); localToplevel += "/" + packageName; /* replace the TEMP DIRECTORY with the component one */ @@ -174,9 +174,9 @@ int cmCPackDebGenerator::PackageComponentsAllInOne( // The ALL GROUPS in ONE package case std::string localToplevel(initialTopLevel); std::string packageFileName(cmSystemTools::GetParentDirectory(toplevel)); - std::string outputFileName(std::string( - this->GetOption("CPACK_PACKAGE_FILE_NAME")) + - this->GetOutputExtension()); + std::string outputFileName( + std::string(this->GetOption("CPACK_PACKAGE_FILE_NAME")) + + this->GetOutputExtension()); // all GROUP in one vs all COMPONENT in one localToplevel += "/" + compInstDirName; @@ -826,8 +826,9 @@ static int copy_ar(CF* cfp, off_t size) size_t nr, nw; char buf[8 * 1024]; - if (sz == 0) + if (sz == 0) { return 0; + } FILE* from = cfp->rFile; FILE* to = cfp->wFile; @@ -837,16 +838,20 @@ static int copy_ar(CF* cfp, off_t size) : sizeof(buf), from)) > 0) { sz -= nr; - for (size_t off = 0; off < nr; nr -= off, off += nw) - if ((nw = fwrite(buf + off, 1, nr, to)) < nr) + for (size_t off = 0; off < nr; nr -= off, off += nw) { + if ((nw = fwrite(buf + off, 1, nr, to)) < nr) { return -1; + } + } } - if (sz) + if (sz) { return -2; + } if (cfp->flags & WPAD && (size + ar_already_written) & 1 && - fwrite(&pad, 1, 1, to) != 1) + fwrite(&pad, 1, 1, to) != 1) { return -4; + } return 0; } @@ -874,11 +879,11 @@ 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(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); - else { + } else { lname = 0; (void)sprintf(ar_hb, HDR2, name, (long int)sb->st_mtime, (unsigned)uid, (unsigned)gid, (unsigned)sb->st_mode, (long long)sb->st_size, @@ -886,12 +891,14 @@ static int put_arobj(CF* cfp, struct stat* sb) } off_t size = sb->st_size; - if (fwrite(ar_hb, 1, sizeof(HDR), cfp->wFile) != sizeof(HDR)) + if (fwrite(ar_hb, 1, sizeof(HDR), cfp->wFile) != sizeof(HDR)) { return -1; + } if (lname) { - if (fwrite(name, 1, lname, cfp->wFile) != lname) + if (fwrite(name, 1, lname, cfp->wFile) != lname) { return -2; + } ar_already_written = lname; } result = copy_ar(cfp, size); diff --git a/Source/CPack/cmCPackGeneratorFactory.cxx b/Source/CPack/cmCPackGeneratorFactory.cxx index cf072bb..2210835 100644 --- a/Source/CPack/cmCPackGeneratorFactory.cxx +++ b/Source/CPack/cmCPackGeneratorFactory.cxx @@ -125,7 +125,7 @@ cmCPackGeneratorFactory::cmCPackGeneratorFactory() } if (cmCPackProductBuildGenerator::CanGenerate()) { this->RegisterGenerator("productbuild", "Mac OSX pkg", - cmCPackProductBuildGenerator::CreateGenerator); + cmCPackProductBuildGenerator::CreateGenerator); } #endif #if !defined(_WIN32) && !defined(__QNXNTO__) && !defined(__BEOS__) && \ diff --git a/Source/CPack/cmCPackNSISGenerator.cxx b/Source/CPack/cmCPackNSISGenerator.cxx index 9fa588d..5123edd 100644 --- a/Source/CPack/cmCPackNSISGenerator.cxx +++ b/Source/CPack/cmCPackNSISGenerator.cxx @@ -516,8 +516,8 @@ int cmCPackNSISGenerator::InitializeInternal() return this->Superclass::InitializeInternal(); } -void cmCPackNSISGenerator::CreateMenuLinks(std::ostringstream& str, - std::ostringstream& deleteStr) +void cmCPackNSISGenerator::CreateMenuLinks(std::ostream& str, + std::ostream& deleteStr) { const char* cpackMenuLinks = this->GetOption("CPACK_NSIS_MENU_LINKS"); if (!cpackMenuLinks) { @@ -621,7 +621,7 @@ bool cmCPackNSISGenerator::SupportsComponentInstallation() const } std::string cmCPackNSISGenerator::CreateComponentDescription( - cmCPackComponent* component, std::ostringstream& macrosOut) + cmCPackComponent* component, std::ostream& macrosOut) { // Basic description of the component std::string componentCode = "Section "; @@ -873,7 +873,7 @@ std::string cmCPackNSISGenerator::CreateDeselectionDependenciesDescription( } std::string cmCPackNSISGenerator::CreateComponentGroupDescription( - cmCPackComponentGroup* group, std::ostringstream& macrosOut) + cmCPackComponentGroup* group, std::ostream& macrosOut) { if (group->Components.empty() && group->Subgroups.empty()) { // Silently skip empty groups. NSIS doesn't support them. diff --git a/Source/CPack/cmCPackNSISGenerator.h b/Source/CPack/cmCPackNSISGenerator.h index fa52902..ae3ccca 100644 --- a/Source/CPack/cmCPackNSISGenerator.h +++ b/Source/CPack/cmCPackNSISGenerator.h @@ -40,7 +40,7 @@ public: protected: virtual int InitializeInternal(); - void CreateMenuLinks(std::ostringstream& str, std::ostringstream& deleteStr); + void CreateMenuLinks(std::ostream& str, std::ostream& deleteStr); int PackageFiles(); virtual const char* GetOutputExtension() { return ".exe"; } virtual const char* GetOutputPostfix() { return "win32"; } @@ -56,7 +56,7 @@ protected: /// particular component. Any added macros will be emitted via /// macrosOut. std::string CreateComponentDescription(cmCPackComponent* component, - std::ostringstream& macrosOut); + std::ostream& macrosOut); /// Produce NSIS code that selects all of the components that this component /// depends on, recursively. @@ -72,7 +72,7 @@ protected: /// particular component group, including its components. Any /// added macros will be emitted via macrosOut. std::string CreateComponentGroupDescription(cmCPackComponentGroup* group, - std::ostringstream& macrosOut); + std::ostream& macrosOut); /// Translations any newlines found in the string into \\r\\n, so that the /// resulting string can be used within NSIS. diff --git a/Source/CPack/cmCPackOSXX11Generator.cxx b/Source/CPack/cmCPackOSXX11Generator.cxx index d5691be..c0d2553 100644 --- a/Source/CPack/cmCPackOSXX11Generator.cxx +++ b/Source/CPack/cmCPackOSXX11Generator.cxx @@ -158,11 +158,10 @@ int cmCPackOSXX11Generator::PackageFiles() tmpFile += "/hdiutilOutput.log"; std::ostringstream dmgCmd; dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM_DISK_IMAGE") - << "\" create -ov -format UDZO -srcfolder \"" - << diskImageDirectory.c_str() << "\" \"" << packageFileNames[0] - << "\""; + << "\" create -ov -format UDZO -srcfolder \"" << diskImageDirectory + << "\" \"" << packageFileNames[0] << "\""; cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Compress disk image using command: " - << dmgCmd.str().c_str() << std::endl); + << dmgCmd.str() << std::endl); // since we get random dashboard failures with this one // try running it more than once int retVal = 1; @@ -181,12 +180,12 @@ int cmCPackOSXX11Generator::PackageFiles() } if (!res || retVal) { cmGeneratedFileStream ofs(tmpFile.c_str()); - ofs << "# Run command: " << dmgCmd.str().c_str() << std::endl + ofs << "# Run command: " << dmgCmd.str() << std::endl << "# Output:" << std::endl - << output.c_str() << std::endl; + << output << std::endl; cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running hdiutil command: " - << dmgCmd.str().c_str() << std::endl - << "Please check " << tmpFile.c_str() << " for errors" + << dmgCmd.str() << std::endl + << "Please check " << tmpFile << " for errors" << std::endl); return 0; } @@ -249,7 +248,7 @@ bool cmCPackOSXX11Generator::CopyCreateResourceFile(const std::string& name) cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: " << (inFileName ? inFileName : "(NULL)") - << " to " << destFileName.c_str() << std::endl); + << " to " << destFileName << std::endl); this->ConfigureFile(inFileName, destFileName.c_str()); return true; } @@ -277,9 +276,8 @@ bool cmCPackOSXX11Generator::CopyResourcePlistFile( destFileName += "/"; destFileName += outputFileName; - cmCPackLogger(cmCPackLog::LOG_VERBOSE, - "Configure file: " << inFileName.c_str() << " to " - << destFileName.c_str() << std::endl); + cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: " + << inFileName << " to " << destFileName << std::endl); this->ConfigureFile(inFileName.c_str(), destFileName.c_str(), copyOnly); return true; } diff --git a/Source/CPack/cmCPackPKGGenerator.cxx b/Source/CPack/cmCPackPKGGenerator.cxx index ff0fa8c..19b587a 100644 --- a/Source/CPack/cmCPackPKGGenerator.cxx +++ b/Source/CPack/cmCPackPKGGenerator.cxx @@ -11,17 +11,18 @@ ============================================================================*/ #include "cmCPackPKGGenerator.h" -#include "cmake.h" +#include "cmCPackComponentGroup.h" +#include "cmCPackLog.h" +#include "cmGeneratedFileStream.h" #include "cmGlobalGenerator.h" #include "cmLocalGenerator.h" -#include "cmSystemTools.h" #include "cmMakefile.h" -#include "cmGeneratedFileStream.h" -#include "cmCPackComponentGroup.h" -#include "cmCPackLog.h" +#include "cmSystemTools.h" +#include "cmXMLWriter.h" +#include "cmake.h" -#include <cmsys/SystemTools.hxx> #include <cmsys/Glob.hxx> +#include <cmsys/SystemTools.hxx> cmCPackPKGGenerator::cmCPackPKGGenerator() { @@ -39,13 +40,12 @@ bool cmCPackPKGGenerator::SupportsComponentInstallation() const int cmCPackPKGGenerator::InitializeInternal() { - cmCPackLogger(cmCPackLog::LOG_DEBUG, - "cmCPackPKGGenerator::Initialize()" << std::endl); + cmCPackLogger(cmCPackLog::LOG_DEBUG, "cmCPackPKGGenerator::Initialize()" + << std::endl); return this->Superclass::InitializeInternal(); } - std::string cmCPackPKGGenerator::GetPackageName( const cmCPackComponent& component) { @@ -53,16 +53,15 @@ std::string cmCPackPKGGenerator::GetPackageName( std::string packagesDir = this->GetOption("CPACK_TEMPORARY_DIRECTORY"); packagesDir += ".dummy"; std::ostringstream out; - out << cmSystemTools::GetFilenameWithoutLastExtension(packagesDir) - << "-" << component.Name << ".pkg"; + out << cmSystemTools::GetFilenameWithoutLastExtension(packagesDir) << "-" + << component.Name << ".pkg"; return out.str(); } else { return component.ArchiveFile + ".pkg"; } } -void cmCPackPKGGenerator::WriteDistributionFile( - const char* metapackageFile) +void cmCPackPKGGenerator::WriteDistributionFile(const char* metapackageFile) { std::string distributionTemplate = this->FindTemplate("CPack.distribution.dist.in"); @@ -78,14 +77,15 @@ void cmCPackPKGGenerator::WriteDistributionFile( // Create the choice outline, which provides a tree-based view of // the components in their groups. std::ostringstream choiceOut; - choiceOut << "<choices-outline>" << std::endl; + cmXMLWriter xout(choiceOut, 1); + xout.StartElement("choices-outline"); // Emit the outline for the groups std::map<std::string, cmCPackComponentGroup>::iterator groupIt; for (groupIt = this->ComponentGroups.begin(); groupIt != this->ComponentGroups.end(); ++groupIt) { if (groupIt->second.ParentGroup == 0) { - CreateChoiceOutline(groupIt->second, choiceOut); + CreateChoiceOutline(groupIt->second, xout); } } @@ -94,28 +94,32 @@ void cmCPackPKGGenerator::WriteDistributionFile( for (compIt = this->Components.begin(); compIt != this->Components.end(); ++compIt) { if (!compIt->second.Group) { - choiceOut << "<line choice=\"" << compIt->first << "Choice\"></line>" - << std::endl; + xout.StartElement("line"); + xout.Attribute("choice", compIt->first + "Choice"); + xout.Content(""); // Avoid self-closing tag. + xout.EndElement(); } } if (!this->PostFlightComponent.Name.empty()) { - choiceOut << "<line choice=\"" << PostFlightComponent.Name - << "Choice\"></line>" << std::endl; + xout.StartElement("line"); + xout.Attribute("choice", PostFlightComponent.Name + "Choice"); + xout.Content(""); // Avoid self-closing tag. + xout.EndElement(); } - choiceOut << "</choices-outline>" << std::endl; + xout.EndElement(); // choices-outline> // Create the actual choices for (groupIt = this->ComponentGroups.begin(); groupIt != this->ComponentGroups.end(); ++groupIt) { - CreateChoice(groupIt->second, choiceOut); + CreateChoice(groupIt->second, xout); } for (compIt = this->Components.begin(); compIt != this->Components.end(); ++compIt) { - CreateChoice(compIt->second, choiceOut); + CreateChoice(compIt->second, xout); } if (!this->PostFlightComponent.Name.empty()) { - CreateChoice(PostFlightComponent, choiceOut); + CreateChoice(PostFlightComponent, xout); } this->SetOption("CPACK_PACKAGEMAKER_CHOICES", choiceOut.str().c_str()); @@ -126,40 +130,44 @@ void cmCPackPKGGenerator::WriteDistributionFile( } void cmCPackPKGGenerator::CreateChoiceOutline( - const cmCPackComponentGroup& group, std::ostringstream& out) + const cmCPackComponentGroup& group, cmXMLWriter& xout) { - out << "<line choice=\"" << group.Name << "Choice\">" << std::endl; + xout.StartElement("line"); + xout.Attribute("choice", group.Name + "Choice"); std::vector<cmCPackComponentGroup*>::const_iterator groupIt; for (groupIt = group.Subgroups.begin(); groupIt != group.Subgroups.end(); ++groupIt) { - CreateChoiceOutline(**groupIt, out); + CreateChoiceOutline(**groupIt, xout); } std::vector<cmCPackComponent*>::const_iterator compIt; for (compIt = group.Components.begin(); compIt != group.Components.end(); ++compIt) { - out << " <line choice=\"" << (*compIt)->Name << "Choice\"></line>" - << std::endl; + xout.StartElement("line"); + xout.Attribute("choice", (*compIt)->Name + "Choice"); + xout.Content(""); // Avoid self-closing tag. + xout.EndElement(); } - out << "</line>" << std::endl; + xout.EndElement(); } -void cmCPackPKGGenerator::CreateChoice( - const cmCPackComponentGroup& group, std::ostringstream& out) +void cmCPackPKGGenerator::CreateChoice(const cmCPackComponentGroup& group, + cmXMLWriter& xout) { - out << "<choice id=\"" << group.Name << "Choice\" " - << "title=\"" << group.DisplayName << "\" " - << "start_selected=\"true\" " - << "start_enabled=\"true\" " - << "start_visible=\"true\" "; + xout.StartElement("choice"); + xout.Attribute("id", group.Name + "Choice"); + xout.Attribute("title", group.DisplayName); + xout.Attribute("start_selected", "true"); + xout.Attribute("start_enabled", "true"); + xout.Attribute("start_visible", "true"); if (!group.Description.empty()) { - out << "description=\"" << EscapeForXML(group.Description) << "\""; + xout.Attribute("description", group.Description); } - out << "></choice>" << std::endl; + xout.EndElement(); } -void cmCPackPKGGenerator::CreateChoice( - const cmCPackComponent& component, std::ostringstream& out) +void cmCPackPKGGenerator::CreateChoice(const cmCPackComponent& component, + cmXMLWriter& xout) { std::string packageId = "com."; packageId += this->GetOption("CPACK_PACKAGE_VENDOR"); @@ -168,18 +176,16 @@ void cmCPackPKGGenerator::CreateChoice( packageId += '.'; packageId += component.Name; - out << "<choice id=\"" << component.Name << "Choice\" " - << "title=\"" << component.DisplayName << "\" " - << "start_selected=\"" - << (component.IsDisabledByDefault && !component.IsRequired ? "false" - : "true") - << "\" " - << "start_enabled=\"" << (component.IsRequired ? "false" : "true") - << "\" " - << "start_visible=\"" << (component.IsHidden ? "false" : "true") - << "\" "; + xout.StartElement("choice"); + xout.Attribute("id", component.Name + "Choice"); + xout.Attribute("title", component.DisplayName); + xout.Attribute( + "start_selected", + component.IsDisabledByDefault && !component.IsRequired ? "false" : "true"); + xout.Attribute("start_enabled", component.IsRequired ? "false" : "true"); + xout.Attribute("start_visible", component.IsHidden ? "false" : "true"); if (!component.Description.empty()) { - out << "description=\"" << EscapeForXML(component.Description) << "\" "; + xout.Attribute("description", component.Description); } if (!component.Dependencies.empty() || !component.ReverseDependencies.empty()) { @@ -197,16 +203,17 @@ void cmCPackPKGGenerator::CreateChoice( // This way, selecting C will automatically select everything it depends // on (B and A), while selecting something that depends on C--either D // or E--will automatically cause C to get selected. - out << "selected=\"my.choice.selected"; + std::ostringstream selected("my.choice.selected"); std::set<const cmCPackComponent*> visited; - AddDependencyAttributes(component, visited, out); + AddDependencyAttributes(component, visited, selected); visited.clear(); - AddReverseDependencyAttributes(component, visited, out); - out << "\""; + AddReverseDependencyAttributes(component, visited, selected); + xout.Attribute("selected", selected.str()); } - out << ">" << std::endl; - out << " <pkg-ref id=\"" << packageId << "\"></pkg-ref>" << std::endl; - out << "</choice>" << std::endl; + xout.StartElement("pkg-ref"); + xout.Attribute("id", packageId); + xout.EndElement(); // pkg-ref + xout.EndElement(); // choice // Create a description of the package associated with this // component. @@ -221,17 +228,20 @@ void cmCPackPKGGenerator::CreateChoice( unsigned long installedSize = component.GetInstalledSizeInKbytes(dirName.c_str()); - out << "<pkg-ref id=\"" << packageId << "\" " - << "version=\"" << this->GetOption("CPACK_PACKAGE_VERSION") << "\" " - << "installKBytes=\"" << installedSize << "\" " - << ">"; + xout.StartElement("pkg-ref"); + xout.Attribute("id", packageId); + xout.Attribute("version", this->GetOption("CPACK_PACKAGE_VERSION")); + xout.Attribute("installKBytes", installedSize); + xout.Attribute("auth", "Admin"); + xout.Attribute("onConclusion", "None"); if (component.IsDownloaded) { - out << this->GetOption("CPACK_DOWNLOAD_SITE") - << this->GetPackageName(component); + xout.Content(this->GetOption("CPACK_DOWNLOAD_SITE")); + xout.Content(this->GetPackageName(component)); } else { - out << "file:./" << relativePackageLocation; + xout.Content("file:./"); + xout.Content(relativePackageLocation); } - out << "</pkg-ref>" << std::endl; + xout.EndElement(); // pkg-ref } void cmCPackPKGGenerator::AddDependencyAttributes( @@ -246,7 +256,7 @@ void cmCPackPKGGenerator::AddDependencyAttributes( std::vector<cmCPackComponent*>::const_iterator dependIt; for (dependIt = component.Dependencies.begin(); dependIt != component.Dependencies.end(); ++dependIt) { - out << " && choices['" << (*dependIt)->Name << "Choice'].selected"; + out << " && choices['" << (*dependIt)->Name << "Choice'].selected"; AddDependencyAttributes(**dependIt, visited, out); } } @@ -268,17 +278,8 @@ void cmCPackPKGGenerator::AddReverseDependencyAttributes( } } -std::string cmCPackPKGGenerator::EscapeForXML(std::string str) -{ - cmSystemTools::ReplaceString(str, "&", "&"); - cmSystemTools::ReplaceString(str, "<", "<"); - cmSystemTools::ReplaceString(str, ">", ">"); - cmSystemTools::ReplaceString(str, "\"", """); - return str; -} - -bool cmCPackPKGGenerator::CopyCreateResourceFile( - const std::string& name, const std::string& dirName) +bool cmCPackPKGGenerator::CopyCreateResourceFile(const std::string& name, + const std::string& dirName) { std::string uname = cmSystemTools::UpperCase(name); std::string cpackVar = "CPACK_RESOURCE_FILE_" + uname; @@ -316,15 +317,15 @@ bool cmCPackPKGGenerator::CopyCreateResourceFile( this->SetOption(("CPACK_RESOURCE_FILE_" + uname + "_NOPATH").c_str(), (name + ext).c_str()); - cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: " - << (inFileName ? inFileName : "(NULL)") << " to " - << destFileName.c_str() << std::endl); + cmCPackLogger(cmCPackLog::LOG_VERBOSE, + "Configure file: " << (inFileName ? inFileName : "(NULL)") + << " to " << destFileName << std::endl); this->ConfigureFile(inFileName, destFileName.c_str()); return true; } -bool cmCPackPKGGenerator::CopyResourcePlistFile( - const std::string& name, const char* outName) +bool cmCPackPKGGenerator::CopyResourcePlistFile(const std::string& name, + const char* outName) { if (!outName) { outName = name.c_str(); @@ -344,9 +345,8 @@ bool cmCPackPKGGenerator::CopyResourcePlistFile( destFileName += "/"; destFileName += outName; - cmCPackLogger(cmCPackLog::LOG_VERBOSE, - "Configure file: " << inFileName.c_str() << " to " - << destFileName.c_str() << std::endl); + cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: " + << inFileName << " to " << destFileName << std::endl); this->ConfigureFile(inFileName.c_str(), destFileName.c_str()); return true; } @@ -360,8 +360,8 @@ int cmCPackPKGGenerator::CopyInstallScript(const std::string& resdir, dst += name; cmSystemTools::CopyFileAlways(script.c_str(), dst.c_str()); cmSystemTools::SetPermissions(dst.c_str(), 0777); - cmCPackLogger(cmCPackLog::LOG_VERBOSE, "copy script : " - << script << "\ninto " << dst.c_str() << std::endl); + cmCPackLogger(cmCPackLog::LOG_VERBOSE, + "copy script : " << script << "\ninto " << dst << std::endl); return 1; } diff --git a/Source/CPack/cmCPackPKGGenerator.h b/Source/CPack/cmCPackPKGGenerator.h index 3011f78..8d10943 100644 --- a/Source/CPack/cmCPackPKGGenerator.h +++ b/Source/CPack/cmCPackPKGGenerator.h @@ -13,10 +13,10 @@ #ifndef cmCPackPKGGenerator_h #define cmCPackPKGGenerator_h - #include "cmCPackGenerator.h" class cmCPackComponent; +class cmXMLWriter; /** \class cmCPackPKGGenerator * \brief A generator for pkg files @@ -79,25 +79,18 @@ protected: // their components in a form that can be used by distribution // metapackages. void CreateChoiceOutline(const cmCPackComponentGroup& group, - std::ostringstream& out); + cmXMLWriter& xout); /// Create the "choice" XML element to describe a component group /// for the installer GUI. - void CreateChoice(const cmCPackComponentGroup& group, - std::ostringstream& out); + void CreateChoice(const cmCPackComponentGroup& group, cmXMLWriter& xout); /// Create the "choice" XML element to describe a component for the /// installer GUI. - void CreateChoice(const cmCPackComponent& component, - std::ostringstream& out); - - // Escape the given string to make it usable as an XML attribute - // value. - std::string EscapeForXML(std::string str); + void CreateChoice(const cmCPackComponent& component, cmXMLWriter& xout); // The PostFlight component when creating a metapackage cmCPackComponent PostFlightComponent; - }; #endif diff --git a/Source/CPack/cmCPackPackageMakerGenerator.cxx b/Source/CPack/cmCPackPackageMakerGenerator.cxx index 5bb24c0..ce329ca 100644 --- a/Source/CPack/cmCPackPackageMakerGenerator.cxx +++ b/Source/CPack/cmCPackPackageMakerGenerator.cxx @@ -17,6 +17,7 @@ #include "cmGlobalGenerator.h" #include "cmMakefile.h" #include "cmSystemTools.h" +#include "cmXMLWriter.h" #include "cmake.h" #include <cmsys/FStream.hxx> @@ -101,7 +102,7 @@ int cmCPackPackageMakerGenerator::PackageFiles() if (!cmsys::SystemTools::MakeDirectory(preflightDirName.c_str())) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem creating installer directory: " - << preflightDirName.c_str() << std::endl); + << preflightDirName << std::endl); return 0; } } @@ -109,7 +110,7 @@ int cmCPackPackageMakerGenerator::PackageFiles() if (!cmsys::SystemTools::MakeDirectory(postflightDirName.c_str())) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem creating installer directory: " - << postflightDirName.c_str() << std::endl); + << postflightDirName << std::endl); return 0; } } @@ -137,7 +138,7 @@ int cmCPackPackageMakerGenerator::PackageFiles() if (!cmsys::SystemTools::MakeDirectory(packageDir.c_str())) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem creating component packages directory: " - << packageDir.c_str() << std::endl); + << packageDir << std::endl); return 0; } @@ -147,7 +148,7 @@ int cmCPackPackageMakerGenerator::PackageFiles() cmCPackLogger( cmCPackLog::LOG_ERROR, "Problem creating component PostFlight Packages directory: " - << packageFileDir.c_str() << std::endl); + << packageFileDir << std::endl); return 0; } std::string packageFile = @@ -169,7 +170,7 @@ int cmCPackPackageMakerGenerator::PackageFiles() if (!cmsys::SystemTools::MakeDirectory(basePackageDir.c_str())) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem creating component packages directory: " - << basePackageDir.c_str() << std::endl); + << basePackageDir << std::endl); return 0; } @@ -314,12 +315,12 @@ int cmCPackPackageMakerGenerator::PackageFiles() } if (!res || retVal) { cmGeneratedFileStream ofs(tmpFile.c_str()); - ofs << "# Run command: " << dmgCmd.str().c_str() << std::endl + ofs << "# Run command: " << dmgCmd.str() << std::endl << "# Output:" << std::endl - << output.c_str() << std::endl; + << output << std::endl; cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running hdiutil command: " - << dmgCmd.str().c_str() << std::endl - << "Please check " << tmpFile.c_str() << " for errors" + << dmgCmd.str() << std::endl + << "Please check " << tmpFile << " for errors" << std::endl); return 0; } @@ -382,7 +383,7 @@ int cmCPackPackageMakerGenerator::InitializeInternal() if (!cmSystemTools::FileExists(versionFile.c_str())) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find PackageMaker compiler version file: " - << versionFile.c_str() << std::endl); + << versionFile << std::endl); return 0; } @@ -416,7 +417,7 @@ int cmCPackPackageMakerGenerator::InitializeInternal() if (!cmSystemTools::GetLineFromStream(ifs, line) || !rexVersion.find(line)) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem reading the PackageMaker compiler version file: " - << versionFile.c_str() << std::endl); + << versionFile << std::endl); return 0; } this->PackageMakerVersion = atof(rexVersion.match(1).c_str()); @@ -481,11 +482,11 @@ bool cmCPackPackageMakerGenerator::RunPackageMaker(const char* command, cmGeneratedFileStream ofs(tmpFile.c_str()); ofs << "# Run command: " << command << std::endl << "# Output:" << std::endl - << output.c_str() << std::endl; + << output << std::endl; cmCPackLogger( cmCPackLog::LOG_ERROR, "Problem running PackageMaker command: " << command << std::endl - << "Please check " << tmpFile.c_str() << " for errors" << std::endl); + << "Please check " << tmpFile << " for errors" << std::endl); return false; } // sometimes the command finishes but the directory is not yet @@ -523,21 +524,22 @@ bool cmCPackPackageMakerGenerator::GenerateComponentPackage( std::string descriptionFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); descriptionFile += '/' + component.Name + "-Description.plist"; cmsys::ofstream out(descriptionFile.c_str()); - out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl - << "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\"" - << "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">" << std::endl - << "<plist version=\"1.4\">" << std::endl - << "<dict>" << std::endl - << " <key>IFPkgDescriptionTitle</key>" << std::endl - << " <string>" << component.DisplayName << "</string>" << std::endl - << " <key>IFPkgDescriptionVersion</key>" << std::endl - << " <string>" << this->GetOption("CPACK_PACKAGE_VERSION") - << "</string>" << std::endl - << " <key>IFPkgDescriptionDescription</key>" << std::endl - << " <string>" + this->EscapeForXML(component.Description) - << "</string>" << std::endl - << "</dict>" << std::endl - << "</plist>" << std::endl; + cmXMLWriter xout(out); + xout.StartDocument(); + xout.Doctype("plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\"" + "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\""); + xout.StartElement("plist"); + xout.Attribute("version", "1.4"); + xout.StartElement("dict"); + xout.Element("key", "IFPkgDescriptionTitle"); + xout.Element("string", component.DisplayName); + xout.Element("key", "IFPkgDescriptionVersion"); + xout.Element("string", this->GetOption("CPACK_PACKAGE_VERSION")); + xout.Element("key", "IFPkgDescriptionDescription"); + xout.Element("string", component.Description); + xout.EndElement(); // dict + xout.EndElement(); // plist + xout.EndDocument(); out.close(); // Create the Info.plist file for this component diff --git a/Source/CPack/cmCPackProductBuildGenerator.cxx b/Source/CPack/cmCPackProductBuildGenerator.cxx index c1f63cc..c2a13d0 100644 --- a/Source/CPack/cmCPackProductBuildGenerator.cxx +++ b/Source/CPack/cmCPackProductBuildGenerator.cxx @@ -11,17 +11,17 @@ ============================================================================*/ #include "cmCPackProductBuildGenerator.h" -#include "cmake.h" +#include "cmCPackComponentGroup.h" +#include "cmCPackLog.h" +#include "cmGeneratedFileStream.h" #include "cmGlobalGenerator.h" #include "cmLocalGenerator.h" -#include "cmSystemTools.h" #include "cmMakefile.h" -#include "cmGeneratedFileStream.h" -#include "cmCPackComponentGroup.h" -#include "cmCPackLog.h" +#include "cmSystemTools.h" +#include "cmake.h" -#include <cmsys/SystemTools.hxx> #include <cmsys/Glob.hxx> +#include <cmsys/SystemTools.hxx> cmCPackProductBuildGenerator::cmCPackProductBuildGenerator() { @@ -37,56 +37,47 @@ int cmCPackProductBuildGenerator::PackageFiles() // TODO: Use toplevel // It is used! Is this an obsolete comment? - std::string packageDirFileName - = this->GetOption("CPACK_TEMPORARY_DIRECTORY"); + std::string packageDirFileName = + this->GetOption("CPACK_TEMPORARY_DIRECTORY"); // Create the directory where component packages will be built. std::string basePackageDir = packageDirFileName; basePackageDir += "/Contents/Packages"; - if (!cmsys::SystemTools::MakeDirectory(basePackageDir.c_str())) - { + if (!cmsys::SystemTools::MakeDirectory(basePackageDir.c_str())) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem creating component packages directory: " - << basePackageDir.c_str() << std::endl); + << basePackageDir << std::endl); return 0; } - if (!this->Components.empty()) - { + if (!this->Components.empty()) { std::map<std::string, cmCPackComponent>::iterator compIt; for (compIt = this->Components.begin(); compIt != this->Components.end(); - ++compIt) - { + ++compIt) { std::string packageDir = toplevel; packageDir += '/'; packageDir += compIt->first; if (!this->GenerateComponentPackage(basePackageDir, GetPackageName(compIt->second), - packageDir, - &compIt->second)) - { + packageDir, &compIt->second)) { return 0; - } } } - else - { - if(!this->GenerateComponentPackage(basePackageDir, - this->GetOption("CPACK_PACKAGE_NAME"), - toplevel, NULL)) - { + } else { + if (!this->GenerateComponentPackage(basePackageDir, + this->GetOption("CPACK_PACKAGE_NAME"), + toplevel, NULL)) { return 0; } } // Copy or create all of the resource files we need. std::string resDir = packageDirFileName + "/Contents"; - if ( !this->CopyCreateResourceFile("License", resDir.c_str()) - || !this->CopyCreateResourceFile("ReadMe", resDir.c_str()) - || !this->CopyCreateResourceFile("Welcome", resDir.c_str())) - { + if (!this->CopyCreateResourceFile("License", resDir.c_str()) || + !this->CopyCreateResourceFile("ReadMe", resDir.c_str()) || + !this->CopyCreateResourceFile("Welcome", resDir.c_str())) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying the resource files" - << std::endl); + << std::endl); return 0; } @@ -97,13 +88,13 @@ int cmCPackProductBuildGenerator::PackageFiles() std::string version = this->GetOption("CPACK_PACKAGE_VERSION"); std::string productbuild = this->GetOption("CPACK_COMMAND_PRODUCTBUILD"); - pkgCmd << productbuild - << " --distribution \"" << packageDirFileName - << "/Contents/distribution.dist\"" - << " --package-path \"" << packageDirFileName << "/Contents/Packages" << "\"" - << " --resources \"" << resDir << "\"" - << " --version \"" << version << "\"" - << " \"" << packageFileNames[0] << "\""; + pkgCmd << productbuild << " --distribution \"" << packageDirFileName + << "/Contents/distribution.dist\"" + << " --package-path \"" << packageDirFileName << "/Contents/Packages" + << "\"" + << " --resources \"" << resDir << "\"" + << " --version \"" << version << "\"" + << " \"" << packageFileNames[0] << "\""; // Run ProductBuild return RunProductBuild(pkgCmd.str()); @@ -123,7 +114,6 @@ int cmCPackProductBuildGenerator::InitializeInternal() } this->SetOptionIfNotSet("CPACK_COMMAND_PKGBUILD", program.c_str()); - program = cmSystemTools::FindProgram("productbuild", no_paths, false); if (program.empty()) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find productbuild executable" @@ -135,9 +125,7 @@ int cmCPackProductBuildGenerator::InitializeInternal() return this->Superclass::InitializeInternal(); } - -bool cmCPackProductBuildGenerator::RunProductBuild( - const std::string& command) +bool cmCPackProductBuildGenerator::RunProductBuild(const std::string& command) { std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); tmpFile += "/ProductBuildOutput.log"; @@ -145,38 +133,34 @@ bool cmCPackProductBuildGenerator::RunProductBuild( cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << command << std::endl); std::string output, error_output; int retVal = 1; - bool res = cmSystemTools::RunSingleCommand(command.c_str(), - &output, &error_output, &retVal, 0, this->GeneratorVerbose, 0); - cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Done running command" - << std::endl); - if ( !res || retVal ) - { + bool res = + cmSystemTools::RunSingleCommand(command.c_str(), &output, &error_output, + &retVal, 0, this->GeneratorVerbose, 0); + cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Done running command" << std::endl); + if (!res || retVal) { cmGeneratedFileStream ofs(tmpFile.c_str()); ofs << "# Run command: " << command << std::endl - << "# Output:" << std::endl - << output.c_str() << std::endl; + << "# Output:" << std::endl + << output << std::endl; cmCPackLogger(cmCPackLog::LOG_ERROR, - "Problem running command: " << command - << std::endl << "Please check " << tmpFile.c_str() << " for errors" - << std::endl); + "Problem running command: " << command << std::endl + << "Please check " << tmpFile + << " for errors" << std::endl); return false; - } + } return true; } bool cmCPackProductBuildGenerator::GenerateComponentPackage( - const std::string& packageFileDir, - const std::string& packageFileName, - const std::string& packageDir, - const cmCPackComponent* component) + const std::string& packageFileDir, const std::string& packageFileName, + const std::string& packageDir, const cmCPackComponent* component) { std::string packageFile = packageFileDir; packageFile += '/'; packageFile += packageFileName; - cmCPackLogger(cmCPackLog::LOG_OUTPUT, - "- Building component package: " << - packageFile << std::endl); + cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- Building component package: " + << packageFile << std::endl); const char* comp_name = component ? component->Name.c_str() : NULL; @@ -184,38 +168,29 @@ bool cmCPackProductBuildGenerator::GenerateComponentPackage( const char* postflight = this->GetComponentScript("POSTFLIGHT", comp_name); std::string resDir = packageFileDir; - if(component) - { + if (component) { resDir += "/"; resDir += component->Name; } std::string scriptDir = resDir + "/scripts"; - if ( !cmsys::SystemTools::MakeDirectory(scriptDir.c_str())) - { + if (!cmsys::SystemTools::MakeDirectory(scriptDir.c_str())) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "Problem creating installer directory: " - << scriptDir.c_str() << std::endl); + "Problem creating installer directory: " << scriptDir + << std::endl); return 0; } // if preflight, postflight, or postupgrade are set // then copy them into the script directory and make // them executable - if(preflight) - { - this->CopyInstallScript(scriptDir.c_str(), - preflight, - "preinstall"); + if (preflight) { + this->CopyInstallScript(scriptDir.c_str(), preflight, "preinstall"); } - if(postflight) - { - this->CopyInstallScript(scriptDir.c_str(), - postflight, - "postinstall"); + if (postflight) { + this->CopyInstallScript(scriptDir.c_str(), postflight, "postinstall"); } - // The command that will be used to run ProductBuild std::ostringstream pkgCmd; @@ -223,17 +198,15 @@ bool cmCPackProductBuildGenerator::GenerateComponentPackage( pkgId += this->GetOption("CPACK_PACKAGE_VENDOR"); pkgId += '.'; pkgId += this->GetOption("CPACK_PACKAGE_NAME"); - if(component) - { + if (component) { pkgId += '.'; pkgId += component->Name; - } + } std::string version = this->GetOption("CPACK_PACKAGE_VERSION"); std::string pkgbuild = this->GetOption("CPACK_COMMAND_PKGBUILD"); - pkgCmd << pkgbuild - << " --root \"" << packageDir << "\"" + pkgCmd << pkgbuild << " --root \"" << packageDir << "\"" << " --identifier \"" << pkgId << "\"" << " --scripts \"" << scriptDir << "\"" << " --version \"" << version << "\"" @@ -245,12 +218,10 @@ bool cmCPackProductBuildGenerator::GenerateComponentPackage( } const char* cmCPackProductBuildGenerator::GetComponentScript( - const char* script, - const char* component_name) + const char* script, const char* component_name) { std::string scriptname = std::string("CPACK_") + script + "_"; - if(component_name) - { + if (component_name) { scriptname += cmSystemTools::UpperCase(component_name); scriptname += "_"; } diff --git a/Source/CPack/cmCPackProductBuildGenerator.h b/Source/CPack/cmCPackProductBuildGenerator.h index 0740f89..b05b50a 100644 --- a/Source/CPack/cmCPackProductBuildGenerator.h +++ b/Source/CPack/cmCPackProductBuildGenerator.h @@ -13,7 +13,6 @@ #ifndef cmCPackProductBuildGenerator_h #define cmCPackProductBuildGenerator_h - #include "cmCPackPKGGenerator.h" class cmCPackComponent; @@ -54,7 +53,6 @@ protected: const char* GetComponentScript(const char* script, const char* script_component); - }; #endif diff --git a/Source/CTest/cmCTestBZR.cxx b/Source/CTest/cmCTestBZR.cxx index dd53be8..92eb570 100644 --- a/Source/CTest/cmCTestBZR.cxx +++ b/Source/CTest/cmCTestBZR.cxx @@ -61,8 +61,9 @@ extern "C" int cmBZRXMLParserUnknownEncodingHandler(void*, // workaround for these unknown encodings. if (name == std::string("ascii") || name == std::string("cp1252") || name == std::string("ANSI_X3.4-1968")) { - for (unsigned int i = 0; i < 256; ++i) + for (unsigned int i = 0; i < 256; ++i) { info->map[i] = latin1[i]; + } return 1; } @@ -336,8 +337,9 @@ private: void DoPath(char c0, char c1, char c2, std::string path) { - if (path.empty()) + if (path.empty()) { return; + } cmSystemTools::ConvertToUnixSlashes(path); const std::string dir = cmSystemTools::GetFilenamePath(path); @@ -441,8 +443,9 @@ private: void DoPath(char c0, char c1, char c2, std::string path) { - if (path.empty()) + if (path.empty()) { return; + } cmSystemTools::ConvertToUnixSlashes(path); if (c0 == 'C') { diff --git a/Source/CTest/cmCTestBatchTestHandler.cxx b/Source/CTest/cmCTestBatchTestHandler.cxx index 386c8d5..70f84cb 100644 --- a/Source/CTest/cmCTestBatchTestHandler.cxx +++ b/Source/CTest/cmCTestBatchTestHandler.cxx @@ -45,7 +45,7 @@ void cmCTestBatchTestHandler::WriteBatchScript() fout.close(); } -void cmCTestBatchTestHandler::WriteSrunArgs(int test, cmsys::ofstream& fout) +void cmCTestBatchTestHandler::WriteSrunArgs(int test, std::ostream& fout) { cmCTestTestHandler::cmCTestTestProperties* properties = this->Properties[test]; @@ -73,7 +73,7 @@ void cmCTestBatchTestHandler::WriteSrunArgs(int test, cmsys::ofstream& fout) } } -void cmCTestBatchTestHandler::WriteTestCommand(int test, cmsys::ofstream& fout) +void cmCTestBatchTestHandler::WriteTestCommand(int test, std::ostream& fout) { std::vector<std::string> args = this->Properties[test]->Args; std::vector<std::string> processArgs; diff --git a/Source/CTest/cmCTestBatchTestHandler.h b/Source/CTest/cmCTestBatchTestHandler.h index 7a2a4a2..ed60ea3 100644 --- a/Source/CTest/cmCTestBatchTestHandler.h +++ b/Source/CTest/cmCTestBatchTestHandler.h @@ -33,8 +33,8 @@ public: protected: void WriteBatchScript(); - void WriteSrunArgs(int test, cmsys::ofstream& fout); - void WriteTestCommand(int test, cmsys::ofstream& fout); + void WriteSrunArgs(int test, std::ostream& fout); + void WriteTestCommand(int test, std::ostream& fout); void SubmitBatchScript(); diff --git a/Source/CTest/cmCTestBuildAndTestHandler.cxx b/Source/CTest/cmCTestBuildAndTestHandler.cxx index 0cba8b2..632f452 100644 --- a/Source/CTest/cmCTestBuildAndTestHandler.cxx +++ b/Source/CTest/cmCTestBuildAndTestHandler.cxx @@ -302,7 +302,7 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring) out << "Could not find path to executable, perhaps it was not built: " << this->TestCommand << "\n"; out << "tried to find it in these places:\n"; - out << fullPath.c_str() << "\n"; + out << fullPath << "\n"; for (unsigned int i = 0; i < failed.size(); ++i) { out << failed[i] << "\n"; } diff --git a/Source/CTest/cmCTestCoverageHandler.cxx b/Source/CTest/cmCTestCoverageHandler.cxx index ba9e546..a631db9 100644 --- a/Source/CTest/cmCTestCoverageHandler.cxx +++ b/Source/CTest/cmCTestCoverageHandler.cxx @@ -1012,7 +1012,7 @@ int cmCTestCoverageHandler::HandleGCovCoverage( "-o \"" + fileDir + "\" " + "\"" + *it + "\""; cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - command.c_str() << std::endl, this->Quiet); + command << std::endl, this->Quiet); std::string output = ""; std::string errors = ""; @@ -1377,7 +1377,7 @@ int cmCTestCoverageHandler::HandleLCovCoverage( "Current coverage dir: " << fileDir << std::endl, this->Quiet); cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - command.c_str() << std::endl, this->Quiet); + command << std::endl, this->Quiet); std::string output = ""; std::string errors = ""; diff --git a/Source/CTest/cmCTestHG.cxx b/Source/CTest/cmCTestHG.cxx index c6cfa44..f1fe377 100644 --- a/Source/CTest/cmCTestHG.cxx +++ b/Source/CTest/cmCTestHG.cxx @@ -75,8 +75,9 @@ private: void DoPath(char status, std::string const& path) { - if (path.empty()) + if (path.empty()) { return; + } // See "hg help status". Note that there is no 'conflict' status. switch (status) { diff --git a/Source/CTest/cmCTestMemCheckHandler.cxx b/Source/CTest/cmCTestMemCheckHandler.cxx index 5b5caea..5f70f66 100644 --- a/Source/CTest/cmCTestMemCheckHandler.cxx +++ b/Source/CTest/cmCTestMemCheckHandler.cxx @@ -991,7 +991,7 @@ void cmCTestMemCheckHandler::PostProcessBoundsCheckerTest( cmsys::ifstream ifs(ofile.c_str()); if (!ifs) { std::string log = "Cannot read memory tester output file: " + ofile; - cmCTestLog(this->CTest, ERROR_MESSAGE, log.c_str() << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, log << std::endl); return; } res.Output += BOUNDS_CHECKER_MARKER; @@ -1024,7 +1024,7 @@ void cmCTestMemCheckHandler::AppendMemTesterOutput(cmCTestTestResult& res, cmsys::ifstream ifs(ofile.c_str()); if (!ifs) { std::string log = "Cannot read memory tester output file: " + ofile; - cmCTestLog(this->CTest, ERROR_MESSAGE, log.c_str() << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, log << std::endl); return; } std::string line; @@ -1056,7 +1056,7 @@ void cmCTestMemCheckHandler::TestOutputFileNames( g.FindFiles(ofile); if (g.GetFiles().empty()) { std::string log = "Cannot find memory tester output file: " + ofile; - cmCTestLog(this->CTest, ERROR_MESSAGE, log.c_str() << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, log << std::endl); ofile = ""; } else { files = g.GetFiles(); @@ -1064,7 +1064,7 @@ void cmCTestMemCheckHandler::TestOutputFileNames( } } else if (!cmSystemTools::FileExists(ofile.c_str())) { std::string log = "Cannot find memory tester output file: " + ofile; - cmCTestLog(this->CTest, ERROR_MESSAGE, log.c_str() << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, log << std::endl); ofile = ""; } files.push_back(ofile); diff --git a/Source/CTest/cmCTestMultiProcessHandler.cxx b/Source/CTest/cmCTestMultiProcessHandler.cxx index 6f19b32..ae97d32 100644 --- a/Source/CTest/cmCTestMultiProcessHandler.cxx +++ b/Source/CTest/cmCTestMultiProcessHandler.cxx @@ -413,12 +413,14 @@ void cmCTestMultiProcessHandler::UpdateCostData() std::string line; while (std::getline(fin, line)) { - if (line == "---") + if (line == "---") { break; + } std::vector<cmsys::String> parts = cmSystemTools::SplitString(line, ' '); // Format: <name> <previous_runs> <avg_cost> - if (parts.size() < 3) + if (parts.size() < 3) { break; + } std::string name = parts[0]; int prev = atoi(parts[1].c_str()); @@ -449,7 +451,7 @@ void cmCTestMultiProcessHandler::UpdateCostData() fout << "---\n"; for (std::vector<std::string>::iterator i = this->Failed->begin(); i != this->Failed->end(); ++i) { - fout << i->c_str() << "\n"; + fout << *i << "\n"; } fout.close(); cmSystemTools::RenameFile(tmpout.c_str(), fname.c_str()); @@ -464,8 +466,9 @@ void cmCTestMultiProcessHandler::ReadCostData() fin.open(fname.c_str()); std::string line; while (std::getline(fin, line)) { - if (line == "---") + if (line == "---") { break; + } std::vector<cmsys::String> parts = cmSystemTools::SplitString(line, ' '); @@ -480,8 +483,9 @@ void cmCTestMultiProcessHandler::ReadCostData() float cost = static_cast<float>(atof(parts[2].c_str())); int index = this->SearchByName(name); - if (index == -1) + if (index == -1) { continue; + } this->Properties[index]->PreviousRuns = prev; // When not running in parallel mode, don't use cost data @@ -710,8 +714,8 @@ void cmCTestMultiProcessHandler::PrintTestList() << indexStr.str(), this->Quiet); cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, " ", this->Quiet); - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - p.Name.c_str() << std::endl, this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, p.Name << std::endl, + this->Quiet); // pop working dir cmSystemTools::ChangeDirectory(current_dir); } diff --git a/Source/CTest/cmCTestP4.cxx b/Source/CTest/cmCTestP4.cxx index 07f9dad..ede11c9 100644 --- a/Source/CTest/cmCTestP4.cxx +++ b/Source/CTest/cmCTestP4.cxx @@ -426,8 +426,9 @@ void cmCTestP4::LoadRevisions() ChangeLists.clear(); this->RunChild(&p4_changes[0], &out, &err); - if (ChangeLists.empty()) + if (ChangeLists.empty()) { return; + } // p4 describe -s ...@1111111,2222222 std::vector<char const*> p4_describe; diff --git a/Source/CTest/cmCTestSVN.cxx b/Source/CTest/cmCTestSVN.cxx index a6885aa..fa01411 100644 --- a/Source/CTest/cmCTestSVN.cxx +++ b/Source/CTest/cmCTestSVN.cxx @@ -271,8 +271,9 @@ bool cmCTestSVN::UpdateImpl() bool cmCTestSVN::RunSVNCommand(std::vector<char const*> const& parameters, OutputParser* out, OutputParser* err) { - if (parameters.empty()) + if (parameters.empty()) { return false; + } std::vector<char const*> args; args.push_back(this->CommandLineTool.c_str()); diff --git a/Source/CTest/cmCTestSubmitHandler.cxx b/Source/CTest/cmCTestSubmitHandler.cxx index 015b908..69f2ac5 100644 --- a/Source/CTest/cmCTestSubmitHandler.cxx +++ b/Source/CTest/cmCTestSubmitHandler.cxx @@ -902,8 +902,7 @@ bool cmCTestSubmitHandler::SubmitUsingXMLRPC( /* Call the famous server at UserLand. */ cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, " Submitting to: " - << realURL.c_str() << " (" << remoteprefix.c_str() - << ")" << std::endl, + << realURL << " (" << remoteprefix << ")" << std::endl, this->Quiet); cmCTest::SetOfStrings::const_iterator file; for (file = files.begin(); file != files.end(); ++file) { @@ -914,12 +913,12 @@ bool cmCTestSubmitHandler::SubmitUsingXMLRPC( local_file = localprefix + "/" + *file; } cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - " Submit file: " << local_file.c_str() << std::endl, + " Submit file: " << local_file << std::endl, this->Quiet); struct stat st; if (::stat(local_file.c_str(), &st)) { cmCTestLog(this->CTest, ERROR_MESSAGE, - " Cannot find file: " << local_file.c_str() << std::endl); + " Cannot find file: " << local_file << std::endl); return false; } @@ -927,15 +926,15 @@ bool cmCTestSubmitHandler::SubmitUsingXMLRPC( // make sure the file is not too big. if (static_cast<off_t>(static_cast<size_t>(st.st_size)) != static_cast<off_t>(st.st_size)) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - " File too big: " << local_file.c_str() << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, " File too big: " << local_file + << std::endl); return false; } size_t fileSize = static_cast<size_t>(st.st_size); FILE* fp = cmsys::SystemTools::Fopen(local_file.c_str(), "rb"); if (!fp) { cmCTestLog(this->CTest, ERROR_MESSAGE, - " Cannot open file: " << local_file.c_str() << std::endl); + " Cannot open file: " << local_file << std::endl); return false; } @@ -944,7 +943,7 @@ bool cmCTestSubmitHandler::SubmitUsingXMLRPC( delete[] fileBuffer; fclose(fp); cmCTestLog(this->CTest, ERROR_MESSAGE, - " Cannot read file: " << local_file.c_str() << std::endl); + " Cannot read file: " << local_file << std::endl); return false; } fclose(fp); diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index f461ca8..96a22d9 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -1321,7 +1321,7 @@ std::string cmCTestTestHandler::FindExecutable( << "Looked in the following places:\n"); for (std::vector<std::string>::iterator i = failed.begin(); i != failed.end(); ++i) { - cmCTestLog(ctest, HANDLER_OUTPUT, i->c_str() << "\n"); + cmCTestLog(ctest, HANDLER_OUTPUT, *i << "\n"); } } diff --git a/Source/CursesDialog/cmCursesLongMessageForm.cxx b/Source/CursesDialog/cmCursesLongMessageForm.cxx index 84672ae..d03d330 100644 --- a/Source/CursesDialog/cmCursesLongMessageForm.cxx +++ b/Source/CursesDialog/cmCursesLongMessageForm.cxx @@ -54,9 +54,9 @@ void cmCursesLongMessageForm::UpdateStatusBar() size = cmCursesMainForm::MAX_WIDTH - 1; } strncpy(bar, this->Title.c_str(), size); - for (size_t i = size - 1; i < cmCursesMainForm::MAX_WIDTH; i++) + for (size_t i = size - 1; i < cmCursesMainForm::MAX_WIDTH; i++) { bar[i] = ' '; - + } int width; if (x < cmCursesMainForm::MAX_WIDTH) { width = x; diff --git a/Source/QtDialog/CMakeSetup.cxx b/Source/QtDialog/CMakeSetup.cxx index c3c1468..c849d52 100644 --- a/Source/QtDialog/CMakeSetup.cxx +++ b/Source/QtDialog/CMakeSetup.cxx @@ -19,6 +19,7 @@ #include <QApplication> #include <QDir> #include <QLocale> +#include <QString> #include <QTextCodec> #include <QTranslator> #include <cmsys/CommandLineArguments.hxx> @@ -40,6 +41,7 @@ static const char* cmDocumentationOptions[][2] = { { 0, 0 } }; #if defined(Q_OS_MAC) static int cmOSXInstall(std::string dir); +static void cmAddPluginPath(); #endif int main(int argc, char** argv) @@ -81,6 +83,15 @@ int main(int argc, char** argv) } #endif +// When we are on OSX and we are launching cmake-gui from a symlink, the +// application will fail to launch as it can't find the qt.conf file which +// tells it what the name of the plugin folder is. We need to add this path +// BEFORE the application is constructed as that is what triggers the +// searching for the platform plugins +#if defined(Q_OS_MAC) + cmAddPluginPath(); +#endif + QApplication app(argc, argv); setlocale(LC_NUMERIC, "C"); @@ -215,4 +226,27 @@ static int cmOSXInstall(std::string dir) ? 0 : 1; } + +// Locate the PlugIns directory and add it to the QApplication library paths. +// We need to resolve all symlinks so we have a known relative path between +// MacOS/CMake and the PlugIns directory. +// +// Note we are using cmSystemTools since Qt can't provide the path to the +// executable before the QApplication is created, and that is when plugin +// searching occurs. +static void cmAddPluginPath() +{ + std::string const& path = cmSystemTools::GetCMakeGUICommand(); + if (path.empty()) { + return; + } + std::string const& realPath = cmSystemTools::GetRealPath(path); + QFileInfo appPath(QString::fromLocal8Bit(realPath.c_str())); + QDir pluginDir = appPath.dir(); + bool const foundPluginDir = pluginDir.cd("../PlugIns"); + if (foundPluginDir) { + QApplication::addLibraryPath(pluginDir.path()); + } +} + #endif diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 6e08932..2e47298 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -1245,16 +1245,16 @@ int cmCTest::RunTest(std::vector<const char*> argv, std::string* output, if (output) { *output += outerr; } - cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, outerr.c_str() << std::endl - << std::flush); + cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, outerr << std::endl + << std::flush); } else if (result == cmsysProcess_State_Error) { std::string outerr = "\n*** ERROR executing: "; outerr += cmsysProcess_GetErrorString(cp); if (output) { *output += outerr; } - cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, outerr.c_str() << std::endl - << std::flush); + cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, outerr << std::endl + << std::flush); } cmsysProcess_Delete(cp); diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx index 676e84a..bcef3c8 100644 --- a/Source/cmCacheManager.cxx +++ b/Source/cmCacheManager.cxx @@ -71,8 +71,9 @@ bool cmCacheManager::LoadCache(const std::string& path, bool internal, while (*realbuffer != '0' && (*realbuffer == ' ' || *realbuffer == '\t' || *realbuffer == '\r' || *realbuffer == '\n')) { - if (*realbuffer == '\n') + if (*realbuffer == '\n') { lineno++; + } realbuffer++; } // skip blank lines and comment lines @@ -539,6 +540,11 @@ void cmCacheManager::CacheIterator::Next() } } +std::vector<std::string> cmCacheManager::CacheIterator::GetPropertyList() const +{ + return this->GetEntry().GetPropertyList(); +} + void cmCacheManager::CacheIterator::SetValue(const char* value) { if (this->IsAtEnd()) { @@ -558,6 +564,11 @@ bool cmCacheManager::CacheIterator::GetValueAsBool() const return cmSystemTools::IsOn(this->GetEntry().Value.c_str()); } +std::vector<std::string> cmCacheManager::CacheEntry::GetPropertyList() const +{ + return this->Properties.GetPropertyList(); +} + const char* cmCacheManager::CacheEntry::GetProperty( const std::string& prop) const { diff --git a/Source/cmCacheManager.h b/Source/cmCacheManager.h index e9b80cb..153e957 100644 --- a/Source/cmCacheManager.h +++ b/Source/cmCacheManager.h @@ -38,6 +38,7 @@ private: std::string Value; cmState::CacheEntryType Type; cmPropertyMap Properties; + std::vector<std::string> GetPropertyList() const; const char* GetProperty(const std::string&) const; void SetProperty(const std::string& property, const char* value); void AppendProperty(const std::string& property, const char* value, @@ -60,6 +61,7 @@ public: bool IsAtEnd() const; void Next(); std::string GetName() const { return this->Position->first; } + std::vector<std::string> GetPropertyList() const; const char* GetProperty(const std::string&) const; bool GetPropertyAsBool(const std::string&) const; bool PropertyExists(const std::string&) const; diff --git a/Source/cmCallVisualStudioMacro.cxx b/Source/cmCallVisualStudioMacro.cxx index e608d6b..515699d 100644 --- a/Source/cmCallVisualStudioMacro.cxx +++ b/Source/cmCallVisualStudioMacro.cxx @@ -105,8 +105,8 @@ HRESULT InstanceCallMacro(IDispatch* vsIDE, const std::string& macro, std::ostringstream oss; oss << std::endl; oss << "Invoke(ExecuteCommand)" << std::endl; - oss << " Macro: " << macro.c_str() << std::endl; - oss << " Args: " << args.c_str() << std::endl; + oss << " Macro: " << macro << std::endl; + oss << " Args: " << args << std::endl; if (DISP_E_EXCEPTION == hr) { oss << "DISP_E_EXCEPTION EXCEPINFO:" << excep.wCode << std::endl; diff --git a/Source/cmCommonTargetGenerator.cxx b/Source/cmCommonTargetGenerator.cxx index c630971..b893dd3 100644 --- a/Source/cmCommonTargetGenerator.cxx +++ b/Source/cmCommonTargetGenerator.cxx @@ -159,8 +159,7 @@ void cmCommonTargetGenerator::AddFortranFlags(std::string& flags) if (const char* modpath_flag = this->Makefile->GetDefinition("CMAKE_Fortran_MODPATH_FLAG")) { std::vector<std::string> includes; - const std::string& config = - this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); + const std::string& config = this->ConfigName; this->LocalGenerator->GetIncludeDirectories( includes, this->GeneratorTarget, "C", config); for (std::vector<std::string>::const_iterator idi = includes.begin(); @@ -178,10 +177,10 @@ void cmCommonTargetGenerator::AppendFortranFormatFlags( { const char* srcfmt = source.GetProperty("Fortran_FORMAT"); cmOutputConverter::FortranFormat format = - this->LocalGenerator->GetFortranFormat(srcfmt); + cmOutputConverter::GetFortranFormat(srcfmt); if (format == cmOutputConverter::FortranFormatNone) { const char* tgtfmt = this->GeneratorTarget->GetProperty("Fortran_FORMAT"); - format = this->LocalGenerator->GetFortranFormat(tgtfmt); + format = cmOutputConverter::GetFortranFormat(tgtfmt); } const char* var = 0; switch (format) { @@ -200,58 +199,6 @@ void cmCommonTargetGenerator::AppendFortranFormatFlags( } } -std::string cmCommonTargetGenerator::GetFrameworkFlags(std::string const& l) -{ - if (!this->Makefile->IsOn("APPLE")) { - return std::string(); - } - - std::string fwSearchFlagVar = "CMAKE_" + l + "_FRAMEWORK_SEARCH_FLAG"; - const char* fwSearchFlag = this->Makefile->GetDefinition(fwSearchFlagVar); - if (!(fwSearchFlag && *fwSearchFlag)) { - return std::string(); - } - - std::set<std::string> emitted; -#ifdef __APPLE__ /* don't insert this when crosscompiling e.g. to iphone */ - emitted.insert("/System/Library/Frameworks"); -#endif - std::vector<std::string> includes; - - const std::string& config = - this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); - this->LocalGenerator->GetIncludeDirectories(includes, this->GeneratorTarget, - "C", config); - // check all include directories for frameworks as this - // will already have added a -F for the framework - for (std::vector<std::string>::iterator i = includes.begin(); - i != includes.end(); ++i) { - if (this->GlobalGenerator->NameResolvesToFramework(*i)) { - std::string frameworkDir = *i; - frameworkDir += "/../"; - frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir); - emitted.insert(frameworkDir); - } - } - - std::string flags; - const char* cfg = this->LocalGenerator->GetConfigName().c_str(); - if (cmComputeLinkInformation* cli = - this->GeneratorTarget->GetLinkInformation(cfg)) { - std::vector<std::string> const& frameworks = cli->GetFrameworkPaths(); - for (std::vector<std::string>::const_iterator i = frameworks.begin(); - i != frameworks.end(); ++i) { - if (emitted.insert(*i).second) { - flags += fwSearchFlag; - flags += this->LocalGenerator->ConvertToOutputFormat( - *i, cmOutputConverter::SHELL); - flags += " "; - } - } - } - return flags; -} - std::string cmCommonTargetGenerator::GetFlags(const std::string& l) { ByLanguageMap::iterator i = this->FlagsByLanguage.find(l); @@ -280,7 +227,9 @@ std::string cmCommonTargetGenerator::GetFlags(const std::string& l) this->LocalGenerator->AppendFlags(flags, this->Makefile->GetDefineFlags()); // Add framework directory flags. - this->LocalGenerator->AppendFlags(flags, this->GetFrameworkFlags(l)); + this->LocalGenerator->AppendFlags( + flags, this->LocalGenerator->GetFrameworkFlags(l, this->ConfigName, + this->GeneratorTarget)); // Add target-specific flags. this->LocalGenerator->AddCompileOptions(flags, this->GeneratorTarget, lang, @@ -297,19 +246,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; - const char* lang = l.c_str(); - // Add the export symbol definition for shared library objects. - if (const char* exportMacro = this->GeneratorTarget->GetExportMacro()) { - this->LocalGenerator->AppendDefines(defines, exportMacro); - } - - // Add preprocessor definitions for this target and configuration. - this->LocalGenerator->AddCompileDefinitions( - defines, this->GeneratorTarget, this->LocalGenerator->GetConfigName(), - l); + this->LocalGenerator->GetTargetDefines(this->GeneratorTarget, + this->ConfigName, l, defines); std::string definesString; - this->LocalGenerator->JoinDefines(defines, definesString, lang); + this->LocalGenerator->JoinDefines(defines, definesString, l); ByLanguageMap::value_type entry(l, definesString); i = this->DefinesByLanguage.insert(entry).first; diff --git a/Source/cmCommonTargetGenerator.h b/Source/cmCommonTargetGenerator.h index c9645e7..ace5351 100644 --- a/Source/cmCommonTargetGenerator.h +++ b/Source/cmCommonTargetGenerator.h @@ -71,9 +71,6 @@ protected: void AppendFortranFormatFlags(std::string& flags, cmSourceFile const& source); - // Return the a string with -F flags on apple - std::string GetFrameworkFlags(std::string const& l); - virtual void AddIncludeFlags(std::string& flags, std::string const& lang) = 0; diff --git a/Source/cmDependsC.cxx b/Source/cmDependsC.cxx index 5be527c..57e719c 100644 --- a/Source/cmDependsC.cxx +++ b/Source/cmDependsC.cxx @@ -158,7 +158,7 @@ bool cmDependsC::WriteDependencies(const std::set<std::string>& sources, this->HeaderLocationCache.find(current.FileName); if (headerLocationIt != this->HeaderLocationCache.end()) { fullName = headerLocationIt->second; - } else + } else { for (std::vector<std::string>::const_iterator i = this->IncludePath.begin(); i != this->IncludePath.end(); ++i) { @@ -175,6 +175,7 @@ bool cmDependsC::WriteDependencies(const std::set<std::string>& sources, break; } } + } } // Complain if the file cannot be found and matches the complain @@ -343,16 +344,16 @@ void cmDependsC::WriteCacheFile() const this->FileCache.begin(); fileIt != this->FileCache.end(); ++fileIt) { if (fileIt->second->Used) { - cacheOut << fileIt->first.c_str() << std::endl; + cacheOut << fileIt->first << std::endl; for (std::vector<UnscannedEntry>::const_iterator incIt = fileIt->second->UnscannedEntries.begin(); incIt != fileIt->second->UnscannedEntries.end(); ++incIt) { - cacheOut << incIt->FileName.c_str() << std::endl; + cacheOut << incIt->FileName << std::endl; if (incIt->QuotedLocation.empty()) { cacheOut << "-" << std::endl; } else { - cacheOut << incIt->QuotedLocation.c_str() << std::endl; + cacheOut << incIt->QuotedLocation << std::endl; } } cacheOut << std::endl; diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx index a4d4dbb..3094fcf 100644 --- a/Source/cmFindLibraryCommand.cxx +++ b/Source/cmFindLibraryCommand.cxx @@ -40,11 +40,10 @@ bool cmFindLibraryCommand::InitialPass(std::vector<std::string> const& argsIn, return true; } - if (const char* abi_name = - this->Makefile->GetDefinition("CMAKE_INTERNAL_PLATFORM_ABI")) { - std::string abi = abi_name; - if (abi.find("ELF N32") != abi.npos) { - // Convert lib to lib32. + if (this->Makefile->GetState()->GetGlobalPropertyAsBool( + "FIND_LIBRARY_USE_LIB32_PATHS")) { + // add special 32 bit paths if this is a 32 bit compile. + if (this->Makefile->PlatformIs32Bit()) { this->AddArchitecturePaths("32"); } } diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 7908afe..1a44d73 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -43,6 +43,7 @@ cmFindPackageCommand::cmFindPackageCommand() this->UseConfigFiles = true; this->UseFindModules = true; this->DebugMode = false; + this->UseLib32Paths = false; this->UseLib64Paths = false; this->PolicyScope = true; this->VersionMajor = 0; @@ -110,6 +111,13 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args, this->LibraryArchitecture = arch; } + // Lookup whether lib32 paths should be used. + if (this->Makefile->PlatformIs32Bit() && + this->Makefile->GetState()->GetGlobalPropertyAsBool( + "FIND_LIBRARY_USE_LIB32_PATHS")) { + this->UseLib32Paths = true; + } + // Lookup whether lib64 paths should be used. if (this->Makefile->PlatformIs64Bit() && this->Makefile->GetState()->GetGlobalPropertyAsBool( @@ -1907,6 +1915,9 @@ bool cmFindPackageCommand::SearchPrefix(std::string const& prefix_in) if (!this->LibraryArchitecture.empty()) { common.push_back("lib/" + this->LibraryArchitecture); } + if (this->UseLib32Paths) { + common.push_back("lib32"); + } if (this->UseLib64Paths) { common.push_back("lib64"); } diff --git a/Source/cmFindPackageCommand.h b/Source/cmFindPackageCommand.h index eff6b80..9019f1b 100644 --- a/Source/cmFindPackageCommand.h +++ b/Source/cmFindPackageCommand.h @@ -148,6 +148,7 @@ private: bool NoUserRegistry; bool NoSystemRegistry; bool DebugMode; + bool UseLib32Paths; bool UseLib64Paths; bool PolicyScope; std::string LibraryArchitecture; diff --git a/Source/cmFindPathCommand.cxx b/Source/cmFindPathCommand.cxx index d24be6a..d71fc1a 100644 --- a/Source/cmFindPathCommand.cxx +++ b/Source/cmFindPathCommand.cxx @@ -117,7 +117,7 @@ std::string cmFindPathCommand::FindHeaderInFramework(std::string const& file, if (this->IncludeFileInPath) { return fheader; } - fheader = cmSystemTools::GetFilenamePath(fheader); + fheader.resize(fheader.size() - file.size()); return fheader; } return ""; diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 1607dd9..de02395 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -1348,8 +1348,9 @@ std::string cmGeneratorTarget::GetAppBundleDirectory(const std::string& config, fpath += ".app"; if (!this->Makefile->PlatformIsAppleIos()) { fpath += "/Contents"; - if (!contentOnly) + if (!contentOnly) { fpath += "/MacOS"; + } } return fpath; } @@ -1377,8 +1378,9 @@ std::string cmGeneratorTarget::GetCFBundleDirectory(const std::string& config, fpath += ext; if (!this->Makefile->PlatformIsAppleIos()) { fpath += "/Contents"; - if (!contentOnly) + if (!contentOnly) { fpath += "/MacOS"; + } } return fpath; } @@ -3336,11 +3338,13 @@ static std::string intersect(const std::set<std::string>& s1, { std::string result; result = intersect(s1, s2); - if (!result.empty()) + if (!result.empty()) { return result; + } result = intersect(s1, s3); - if (!result.empty()) + if (!result.empty()) { return result; + } return intersect(s2, s3); } @@ -3351,14 +3355,17 @@ static std::string intersect(const std::set<std::string>& s1, { std::string result; result = intersect(s1, s2); - if (!result.empty()) + if (!result.empty()) { return result; + } result = intersect(s1, s3); - if (!result.empty()) + if (!result.empty()) { return result; + } result = intersect(s1, s4); - if (!result.empty()) + if (!result.empty()) { return result; + } return intersect(s2, s3, s4); } diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx index 8565fdb..3d35114 100644 --- a/Source/cmGhsMultiTargetGenerator.cxx +++ b/Source/cmGhsMultiTargetGenerator.cxx @@ -371,7 +371,7 @@ void cmGhsMultiTargetGenerator::WriteTargetLinkLibraries( bool useWatcomQuote = this->Makefile->IsOn(createRule + "_USE_WATCOM_QUOTE"); this->LocalGenerator->GetTargetFlags( - linkLibraries, flags, linkFlags, frameworkPath, linkPath, + config, linkLibraries, flags, linkFlags, frameworkPath, linkPath, this->GeneratorTarget, useWatcomQuote); linkFlags = cmSystemTools::TrimWhitespace(linkFlags); diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index fc34b8b..aef3f44 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -2188,9 +2188,10 @@ void cmGlobalGenerator::CreateDefaultGlobalTargets(cmTargets* targets) // Install bool skipInstallRules = mf->IsOn("CMAKE_SKIP_INSTALL_RULES"); if (this->InstallTargetEnabled && skipInstallRules) { - mf->IssueMessage(cmake::WARNING, - "CMAKE_SKIP_INSTALL_RULES was enabled even though " - "installation rules have been specified"); + this->CMakeInstance->IssueMessage( + cmake::WARNING, "CMAKE_SKIP_INSTALL_RULES was enabled even though " + "installation rules have been specified", + mf->GetBacktrace()); } else if (this->InstallTargetEnabled && !skipInstallRules) { if (!cmakeCfgIntDir || !*cmakeCfgIntDir || cmakeCfgIntDir[0] == '.') { std::set<std::string>* componentsSet = &this->InstallComponents; diff --git a/Source/cmGlobalGeneratorFactory.h b/Source/cmGlobalGeneratorFactory.h index 640497a..7d4fe2c 100644 --- a/Source/cmGlobalGeneratorFactory.h +++ b/Source/cmGlobalGeneratorFactory.h @@ -51,8 +51,9 @@ public: virtual cmGlobalGenerator* CreateGlobalGenerator(const std::string& name, cmake* cm) const { - if (name != T::GetActualName()) + if (name != T::GetActualName()) { return 0; + } return new T(cm); } diff --git a/Source/cmGlobalKdevelopGenerator.cxx b/Source/cmGlobalKdevelopGenerator.cxx index 5c1e733..68a2538 100644 --- a/Source/cmGlobalKdevelopGenerator.cxx +++ b/Source/cmGlobalKdevelopGenerator.cxx @@ -213,7 +213,7 @@ bool cmGlobalKdevelopGenerator::CreateFilelistFile( cmSystemTools::ReplaceString(tmp, projectDir.c_str(), ""); // only put relative paths if (!tmp.empty() && tmp[0] != '/') { - fout << tmp.c_str() << "\n"; + fout << tmp << "\n"; } } return true; diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 3abcba3..f74e835 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -30,8 +30,9 @@ const char* cmGlobalNinjaGenerator::INDENT = " "; void cmGlobalNinjaGenerator::Indent(std::ostream& os, int count) { - for (int i = 0; i < count; ++i) + for (int i = 0; i < count; ++i) { os << cmGlobalNinjaGenerator::INDENT; + } } void cmGlobalNinjaGenerator::WriteDivider(std::ostream& os) @@ -43,8 +44,9 @@ void cmGlobalNinjaGenerator::WriteDivider(std::ostream& os) void cmGlobalNinjaGenerator::WriteComment(std::ostream& os, const std::string& comment) { - if (comment.empty()) + if (comment.empty()) { return; + } std::string::size_type lpos = 0; std::string::size_type rpos; @@ -165,16 +167,18 @@ void cmGlobalNinjaGenerator::WriteBuild( if (!implicitDeps.empty()) { arguments += " |"; for (cmNinjaDeps::const_iterator i = implicitDeps.begin(); - i != implicitDeps.end(); ++i) + i != implicitDeps.end(); ++i) { arguments += " " + EncodeIdent(EncodePath(*i), os); + } } // Write order-only dependencies. if (!orderOnlyDeps.empty()) { arguments += " ||"; for (cmNinjaDeps::const_iterator i = orderOnlyDeps.begin(); - i != orderOnlyDeps.end(); ++i) + i != orderOnlyDeps.end(); ++i) { arguments += " " + EncodeIdent(EncodePath(*i), os); + } } arguments += "\n"; @@ -198,9 +202,10 @@ void cmGlobalNinjaGenerator::WriteBuild( // Write the variables bound to this build statement. std::ostringstream variable_assignments; for (cmNinjaVars::const_iterator i = variables.begin(); i != variables.end(); - ++i) + ++i) { cmGlobalNinjaGenerator::WriteVariable(variable_assignments, i->first, i->second, "", 1); + } // check if a response file rule should be used std::string buildstr = build; @@ -430,8 +435,9 @@ void cmGlobalNinjaGenerator::WriteDefault(std::ostream& os, cmGlobalNinjaGenerator::WriteComment(os, comment); os << "default"; for (cmNinjaDeps::const_iterator i = targets.begin(); i != targets.end(); - ++i) + ++i) { os << " " << *i; + } os << "\n"; } @@ -907,15 +913,17 @@ void cmGlobalNinjaGenerator::AddTargetAlias(const std::string& alias, this->AppendTargetOutputs(target, outputs); // Mark the target's outputs as ambiguous to ensure that no other target uses // the output as an alias. - for (cmNinjaDeps::iterator i = outputs.begin(); i != outputs.end(); ++i) + for (cmNinjaDeps::iterator i = outputs.begin(); i != outputs.end(); ++i) { TargetAliases[*i] = 0; + } // Insert the alias into the map. If the alias was already present in the // map and referred to another target, mark it as ambiguous. std::pair<TargetAliasMap::iterator, bool> newAlias = TargetAliases.insert(std::make_pair(buildAlias, target)); - if (newAlias.second && newAlias.first->second != target) + if (newAlias.second && newAlias.first->second != target) { newAlias.first->second = 0; + } } void cmGlobalNinjaGenerator::WriteTargetAliases(std::ostream& os) @@ -926,8 +934,9 @@ void cmGlobalNinjaGenerator::WriteTargetAliases(std::ostream& os) for (TargetAliasMap::const_iterator i = TargetAliases.begin(); i != TargetAliases.end(); ++i) { // Don't write ambiguous aliases. - if (!i->second) + if (!i->second) { continue; + } cmNinjaDeps deps; this->AppendTargetOutputs(i->second, deps); diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index b666594..4d778ee 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -659,7 +659,7 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeSourceFile( // Add flags from target and source file properties. std::string flags; const char* srcfmt = sf->GetProperty("Fortran_FORMAT"); - switch (this->CurrentLocalGenerator->GetFortranFormat(srcfmt)) { + switch (cmOutputConverter::GetFortranFormat(srcfmt)) { case cmOutputConverter::FortranFormatFixed: flags = "-fixed " + flags; break; @@ -1544,7 +1544,7 @@ void cmGlobalXCodeGenerator::CreateCustomRulesMakefile( std::string echo_cmd = "echo "; echo_cmd += (this->CurrentLocalGenerator->EscapeForShell( comment, ccg.GetCC().GetEscapeAllowMakeVars())); - makefileStream << "\t" << echo_cmd.c_str() << "\n"; + makefileStream << "\t" << echo_cmd << "\n"; } // Add each command line to the set of commands. @@ -1562,7 +1562,7 @@ void cmGlobalXCodeGenerator::CreateCustomRulesMakefile( } cmd += cmd2; ccg.AppendArguments(c, cmd); - makefileStream << "\t" << cmd.c_str() << "\n"; + makefileStream << "\t" << cmd << "\n"; } } } @@ -1981,7 +1981,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, // Add Fortran source format attribute if property is set. const char* format = 0; const char* tgtfmt = gtgt->GetProperty("Fortran_FORMAT"); - switch (this->CurrentLocalGenerator->GetFortranFormat(tgtfmt)) { + switch (cmOutputConverter::GetFortranFormat(tgtfmt)) { case cmOutputConverter::FortranFormatFixed: format = "fixed"; break; diff --git a/Source/cmGraphVizWriter.cxx b/Source/cmGraphVizWriter.cxx index 6b3a870..3963cf8 100644 --- a/Source/cmGraphVizWriter.cxx +++ b/Source/cmGraphVizWriter.cxx @@ -427,7 +427,7 @@ int cmGraphVizWriter::CollectAllTargets() // Skip ignored targets continue; } - // std::cout << "Found target: " << tit->first.c_str() << std::endl; + // std::cout << "Found target: " << tit->first << std::endl; std::ostringstream ostr; ostr << this->GraphNodePrefix << cnt++; this->TargetNamesNodes[realTargetName] = ostr.str(); @@ -469,7 +469,7 @@ int cmGraphVizWriter::CollectAllExternalLibs(int cnt) ostr << this->GraphNodePrefix << cnt++; this->TargetNamesNodes[libName] = ostr.str(); this->TargetPtrs[libName] = NULL; - // str << " \"" << ostr.c_str() << "\" [ label=\"" << libName + // str << " \"" << ostr << "\" [ label=\"" << libName // << "\" shape=\"ellipse\"];" << std::endl; } } diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx index 33731e0..036a2b1 100644 --- a/Source/cmListFileCache.cxx +++ b/Source/cmListFileCache.cxx @@ -181,9 +181,6 @@ bool cmListFile::ParseFile(const char* filename, bool topLevel, cmMakefile* mf) mf->SetPolicyVersion("2.4"); } } - } - - if (topLevel) { bool hasProject = false; // search for a project command for (std::vector<cmListFileFunction>::iterator i = this->Functions.begin(); diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index b748b9c..2f50b7f 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -45,6 +45,7 @@ cmLocalGenerator::cmLocalGenerator(cmGlobalGenerator* gg, cmMakefile* makefile) : cmOutputConverter(makefile->GetStateSnapshot()) , StateSnapshot(makefile->GetStateSnapshot()) + , DirectoryBacktrace(makefile->GetBacktrace()) { this->GlobalGenerator = gg; @@ -68,7 +69,7 @@ cmLocalGenerator::~cmLocalGenerator() void cmLocalGenerator::IssueMessage(cmake::MessageType t, std::string const& text) const { - this->Makefile->IssueMessage(t, text); + this->GetCMakeInstance()->IssueMessage(t, text, this->DirectoryBacktrace); } void cmLocalGenerator::ComputeObjectMaxPath() @@ -943,7 +944,7 @@ std::string cmLocalGenerator::GetIncludeFlags( void cmLocalGenerator::AddCompileDefinitions(std::set<std::string>& defines, cmGeneratorTarget const* target, const std::string& config, - const std::string& lang) + const std::string& lang) const { std::vector<std::string> targetDefines; target->GetCompileDefinitions(targetDefines, config, lang); @@ -1152,13 +1153,11 @@ void cmLocalGenerator::GetStaticLibraryFlags(std::string& flags, } void cmLocalGenerator::GetTargetFlags( - std::string& linkLibs, std::string& flags, std::string& linkFlags, - std::string& frameworkPath, std::string& linkPath, cmGeneratorTarget* target, - bool useWatcomQuote) + const std::string& config, std::string& linkLibs, std::string& flags, + std::string& linkFlags, std::string& frameworkPath, std::string& linkPath, + cmGeneratorTarget* target, bool useWatcomQuote) { - std::string buildType = - this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); - buildType = cmSystemTools::UpperCase(buildType); + const std::string buildType = cmSystemTools::UpperCase(config); const char* libraryLinkVariable = "CMAKE_SHARED_LINKER_FLAGS"; // default to shared library @@ -1273,6 +1272,78 @@ void cmLocalGenerator::GetTargetFlags( } } +static std::string GetFrameworkFlags(const std::string& lang, + const std::string& config, + cmGeneratorTarget* target) +{ + cmLocalGenerator* lg = target->GetLocalGenerator(); + cmMakefile* mf = lg->GetMakefile(); + + if (!mf->IsOn("APPLE")) { + return std::string(); + } + + std::string fwSearchFlagVar = "CMAKE_" + lang + "_FRAMEWORK_SEARCH_FLAG"; + const char* fwSearchFlag = mf->GetDefinition(fwSearchFlagVar); + if (!(fwSearchFlag && *fwSearchFlag)) { + return std::string(); + } + + std::set<std::string> emitted; +#ifdef __APPLE__ /* don't insert this when crosscompiling e.g. to iphone */ + emitted.insert("/System/Library/Frameworks"); +#endif + std::vector<std::string> includes; + + lg->GetIncludeDirectories(includes, target, "C", config); + // check all include directories for frameworks as this + // will already have added a -F for the framework + for (std::vector<std::string>::iterator i = includes.begin(); + i != includes.end(); ++i) { + if (lg->GetGlobalGenerator()->NameResolvesToFramework(*i)) { + std::string frameworkDir = *i; + frameworkDir += "/../"; + frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir); + emitted.insert(frameworkDir); + } + } + + std::string flags; + if (cmComputeLinkInformation* cli = target->GetLinkInformation(config)) { + std::vector<std::string> const& frameworks = cli->GetFrameworkPaths(); + for (std::vector<std::string>::const_iterator i = frameworks.begin(); + i != frameworks.end(); ++i) { + if (emitted.insert(*i).second) { + flags += fwSearchFlag; + flags += lg->ConvertToOutputFormat(*i, cmOutputConverter::SHELL); + flags += " "; + } + } + } + return flags; +} + +std::string cmLocalGenerator::GetFrameworkFlags(std::string const& l, + std::string const& config, + cmGeneratorTarget* target) +{ + return ::GetFrameworkFlags(l, config, target); +} + +void cmLocalGenerator::GetTargetDefines(cmGeneratorTarget const* target, + std::string const& config, + std::string const& lang, + std::set<std::string>& defines) const +{ + // Add the export symbol definition for shared library objects. + if (const char* exportMacro = target->GetExportMacro()) { + this->AppendDefines(defines, exportMacro); + } + + // Add preprocessor definitions for this target and configuration. + this->AddCompileDefinitions(defines, target, config, lang.c_str()); +} + std::string cmLocalGenerator::ConvertToLinkReference(std::string const& lib, OutputFormat format) { @@ -1995,7 +2066,7 @@ void cmLocalGenerator::AppendFlagEscape(std::string& flags, } void cmLocalGenerator::AppendDefines(std::set<std::string>& defines, - const char* defines_list) + const char* defines_list) const { // Short-circuit if there are no definitions. if (!defines_list) { @@ -2009,7 +2080,8 @@ void cmLocalGenerator::AppendDefines(std::set<std::string>& defines, } void cmLocalGenerator::AppendDefines( - std::set<std::string>& defines, const std::vector<std::string>& defines_vec) + std::set<std::string>& defines, + const std::vector<std::string>& defines_vec) const { for (std::vector<std::string>::const_iterator di = defines_vec.begin(); di != defines_vec.end(); ++di) { diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 5c603a6..af561f6 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -138,13 +138,15 @@ public: * Encode a list of preprocessor definitions for the compiler * command line. */ - void AppendDefines(std::set<std::string>& defines, const char* defines_list); - void AppendDefines(std::set<std::string>& defines, std::string defines_list) + void AppendDefines(std::set<std::string>& defines, + const char* defines_list) const; + void AppendDefines(std::set<std::string>& defines, + std::string defines_list) const { this->AppendDefines(defines, defines_list.c_str()); } void AppendDefines(std::set<std::string>& defines, - const std::vector<std::string>& defines_vec); + const std::vector<std::string>& defines_vec) const; /** * Join a set of defines into a definesString with a space separator. @@ -200,7 +202,7 @@ public: void AddCompileDefinitions(std::set<std::string>& defines, cmGeneratorTarget const* target, const std::string& config, - const std::string& lang); + const std::string& lang) const; std::string GetProjectName() const; @@ -308,10 +310,17 @@ public: /** Fill out these strings for the given target. Libraries to link, * flags, and linkflags. */ - void GetTargetFlags(std::string& linkLibs, std::string& flags, - std::string& linkFlags, std::string& frameworkPath, - std::string& linkPath, cmGeneratorTarget* target, - bool useWatcomQuote); + void GetTargetFlags(const std::string& config, std::string& linkLibs, + std::string& flags, std::string& linkFlags, + std::string& frameworkPath, std::string& linkPath, + cmGeneratorTarget* target, bool useWatcomQuote); + void GetTargetDefines(cmGeneratorTarget const* target, + std::string const& config, std::string const& lang, + std::set<std::string>& defines) const; + + std::string GetFrameworkFlags(std::string const& l, + std::string const& config, + cmGeneratorTarget* target); virtual void ComputeObjectFilenames( std::map<cmSourceFile const*, std::string>& mapping, @@ -364,6 +373,7 @@ protected: cmMakefile* Makefile; cmState::Snapshot StateSnapshot; + cmListFileBacktrace DirectoryBacktrace; cmGlobalGenerator* GlobalGenerator; std::map<std::string, std::string> UniqueObjectNamesMap; std::string::size_type ObjectPathMax; diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index 6c231c3..6e676f1 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -81,8 +81,9 @@ void cmLocalNinjaGenerator::Generate() tg->Generate(); // Add the target to "all" if required. if (!this->GetGlobalNinjaGenerator()->IsExcluded( - this->GetGlobalNinjaGenerator()->GetLocalGenerators()[0], *t)) + this->GetGlobalNinjaGenerator()->GetLocalGenerators()[0], *t)) { this->GetGlobalNinjaGenerator()->AddDependencyToAll(*t); + } delete tg; } } @@ -257,8 +258,9 @@ void cmLocalNinjaGenerator::WriteProcessedMakefile(std::ostream& os) os << "# Write statements declared in CMakeLists.txt:" << std::endl << "# " << this->Makefile->GetDefinition("CMAKE_CURRENT_LIST_FILE") << std::endl; - if (this->IsRootMakefile()) + if (this->IsRootMakefile()) { os << "# Which is the root file." << std::endl; + } cmGlobalNinjaGenerator::WriteDivider(os); os << std::endl; } @@ -282,9 +284,10 @@ void cmLocalNinjaGenerator::AppendCustomCommandDeps( for (std::vector<std::string>::const_iterator i = deps.begin(); i != deps.end(); ++i) { std::string dep; - if (this->GetRealDependency(*i, this->GetConfigName(), dep)) + if (this->GetRealDependency(*i, this->GetConfigName(), dep)) { ninjaDeps.push_back( this->GetGlobalNinjaGenerator()->ConvertToNinjaPath(dep)); + } } } @@ -294,12 +297,13 @@ std::string cmLocalNinjaGenerator::BuildCommandLine( // If we have no commands but we need to build a command anyway, use ":". // This happens when building a POST_BUILD value for link targets that // don't use POST_BUILD. - if (cmdLines.empty()) + if (cmdLines.empty()) { #ifdef _WIN32 return "cd ."; #else return ":"; #endif + } std::ostringstream cmd; for (std::vector<std::string>::const_iterator li = cmdLines.begin(); @@ -332,8 +336,9 @@ void cmLocalNinjaGenerator::AppendCustomCommandLines( { if (ccg.GetNumberOfCommands() > 0) { std::string wd = ccg.GetWorkingDirectory(); - if (wd.empty()) + if (wd.empty()) { wd = this->GetCurrentBinaryDirectory(); + } std::ostringstream cdCmd; #ifdef _WIN32 @@ -361,8 +366,9 @@ void cmLocalNinjaGenerator::AppendCustomCommandLines( void cmLocalNinjaGenerator::WriteCustomCommandBuildStatement( cmCustomCommand const* cc, const cmNinjaDeps& orderOnlyDeps) { - if (this->GetGlobalNinjaGenerator()->SeenCustomCommand(cc)) + if (this->GetGlobalNinjaGenerator()->SeenCustomCommand(cc)) { return; + } cmCustomCommandGenerator ccg(*cc, this->GetConfigName(), this); @@ -391,8 +397,9 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatement( this->AppendCustomCommandDeps(ccg, ninjaDeps); for (cmNinjaDeps::iterator i = ninjaOutputs.begin(); i != ninjaOutputs.end(); - ++i) + ++i) { this->GetGlobalNinjaGenerator()->SeenCustomCommandOutput(*i); + } std::vector<std::string> cmdLines; this->AppendCustomCommandLines(ccg, cmdLines); diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 6e7d7d2..2f6bf07 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -683,7 +683,8 @@ void cmLocalVisualStudio7Generator::WriteConfiguration( } if (this->FortranProject) { - switch (this->GetFortranFormat(target->GetProperty("Fortran_FORMAT"))) { + switch (cmOutputConverter::GetFortranFormat( + target->GetProperty("Fortran_FORMAT"))) { case cmOutputConverter::FortranFormatFixed: flags += " -fixed"; break; @@ -1474,7 +1475,8 @@ cmLocalVisualStudio7GeneratorFCInfo::cmLocalVisualStudio7GeneratorFCInfo( needfc = true; } if (lg->FortranProject) { - switch (lg->GetFortranFormat(sf.GetProperty("Fortran_FORMAT"))) { + switch (cmOutputConverter::GetFortranFormat( + sf.GetProperty("Fortran_FORMAT"))) { case cmOutputConverter::FortranFormatFixed: fc.CompileFlags = "-fixed " + fc.CompileFlags; needfc = true; @@ -1686,12 +1688,12 @@ bool cmLocalVisualStudio7Generator::WriteGroup( ppLang); } if (!fc.AdditionalDeps.empty()) { - fout << "\t\t\t\t\tAdditionalDependencies=\"" - << fc.AdditionalDeps.c_str() << "\"\n"; + fout << "\t\t\t\t\tAdditionalDependencies=\"" << fc.AdditionalDeps + << "\"\n"; } if (!fc.ObjectName.empty()) { - fout << "\t\t\t\t\tObjectFile=\"$(IntDir)/" - << fc.ObjectName.c_str() << "\"\n"; + fout << "\t\t\t\t\tObjectFile=\"$(IntDir)/" << fc.ObjectName + << "\"\n"; } fout << "\t\t\t\t\t/>\n" << "\t\t\t\t</FileConfiguration>\n"; diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 45fb7cf..c9192fd 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -105,8 +105,8 @@ cmMakefile::~cmMakefile() cmDeleteAll(this->EvaluationFiles); } -void cmMakefile::IssueMessage(cmake::MessageType t, std::string const& text, - bool force) const +void cmMakefile::IssueMessage(cmake::MessageType t, + std::string const& text) const { // Collect context information. if (!this->ExecutionStatusStack.empty()) { @@ -114,7 +114,7 @@ void cmMakefile::IssueMessage(cmake::MessageType t, std::string const& text, this->ExecutionStatusStack.back()->SetNestedError(true); } } - this->GetCMakeInstance()->IssueMessage(t, text, this->GetBacktrace(), force); + this->GetCMakeInstance()->IssueMessage(t, text, this->GetBacktrace()); } cmStringRange cmMakefile::GetIncludeDirectoriesEntries() const @@ -546,7 +546,8 @@ void cmMakefile::EnforceDirectoryLevelRules() const case cmPolicies::WARN: // Warn because the user did not provide a mimimum required // version. - this->IssueMessage(cmake::AUTHOR_WARNING, msg.str()); + this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, + msg.str(), this->Backtrace); case cmPolicies::OLD: // OLD behavior is to use policy version 2.4 set in // cmListFileCache. @@ -555,7 +556,8 @@ void cmMakefile::EnforceDirectoryLevelRules() const case cmPolicies::REQUIRED_ALWAYS: case cmPolicies::NEW: // NEW behavior is to issue an error. - this->IssueMessage(cmake::FATAL_ERROR, msg.str()); + this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, msg.str(), + this->Backtrace); cmSystemTools::SetFatalErrorOccured(); return; } @@ -651,12 +653,13 @@ void cmMakefile::ConfigureFinalPass() const char* oldValue = this->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY"); if (oldValue && cmSystemTools::VersionCompare(cmSystemTools::OP_LESS, oldValue, "2.4")) { - this->IssueMessage( + this->GetCMakeInstance()->IssueMessage( cmake::FATAL_ERROR, "You have set CMAKE_BACKWARDS_COMPATIBILITY to a CMake version less " "than 2.4. This version of CMake only supports backwards compatibility " "with CMake 2.4 or later. For compatibility with older versions please " - "use any CMake 2.8.x release or lower."); + "use any CMake 2.8.x release or lower.", + this->Backtrace); } } @@ -2048,7 +2051,8 @@ void cmMakefile::ExpandVariablesCMP0019() << "The following variable evaluations were encountered:\n" << w.str(); /* clang-format on */ - this->IssueMessage(cmake::AUTHOR_WARNING, m.str()); + this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, m.str(), + this->Backtrace); } } @@ -2076,6 +2080,14 @@ bool cmMakefile::IsSet(const std::string& name) const return true; } +bool cmMakefile::PlatformIs32Bit() const +{ + if (const char* sizeof_dptr = this->GetDefinition("CMAKE_SIZEOF_VOID_P")) { + return atoi(sizeof_dptr) == 4; + } + return false; +} + bool cmMakefile::PlatformIs64Bit() const { if (const char* sizeof_dptr = this->GetDefinition("CMAKE_SIZEOF_VOID_P")) { @@ -3416,7 +3428,7 @@ int cmMakefile::ConfigureFile(const char* infile, const char* outfile, while (cmSystemTools::GetLineFromStream(fin, inLine)) { outLine = ""; this->ConfigureString(inLine, outLine, atOnly, escapeQuotes); - fout << outLine.c_str() << newLineCharacters; + fout << outLine << newLineCharacters; } // close the files before attempting to copy fin.close(); @@ -3620,8 +3632,9 @@ cmTarget* cmMakefile::FindTargetToUse(const std::string& name, bool cmMakefile::IsAlias(const std::string& name) const { - if (this->AliasTargets.find(name) != this->AliasTargets.end()) + if (this->AliasTargets.find(name) != this->AliasTargets.end()) { return true; + } return this->GetGlobalGenerator()->IsAlias(name); } @@ -3993,14 +4006,20 @@ bool cmMakefile::AddRequiredTargetFeature(cmTarget* target, << this->GetDefinition("CMAKE_" + lang + "_COMPILER_ID") << "\"\nversion " << this->GetDefinition("CMAKE_" + lang + "_COMPILER_VERSION") << "."; - this->IssueMessage(cmake::FATAL_ERROR, e.str()); + if (error) { + *error = e.str(); + } else { + this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(), + this->Backtrace); + } return false; } target->AppendProperty("COMPILE_FEATURES", feature.c_str()); - return lang == "C" ? this->AddRequiredTargetCFeature(target, feature) - : this->AddRequiredTargetCxxFeature(target, feature); + return lang == "C" + ? this->AddRequiredTargetCFeature(target, feature, error) + : this->AddRequiredTargetCxxFeature(target, feature, error); } bool cmMakefile::CompileFeatureKnown(cmTarget const* target, @@ -4036,7 +4055,8 @@ bool cmMakefile::CompileFeatureKnown(cmTarget const* target, if (error) { *error = e.str(); } else { - this->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(), + this->Backtrace); } return false; } @@ -4061,7 +4081,8 @@ const char* cmMakefile::CompileFeaturesAvailable(const std::string& lang, if (error) { *error = e.str(); } else { - this->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(), + this->Backtrace); } return 0; } @@ -4248,7 +4269,8 @@ void cmMakefile::CheckNeededCxxLanguage(const std::string& feature, } bool cmMakefile::AddRequiredTargetCxxFeature(cmTarget* target, - const std::string& feature) const + const std::string& feature, + std::string* error) const { bool needCxx98 = false; bool needCxx11 = false; @@ -4264,7 +4286,12 @@ bool cmMakefile::AddRequiredTargetCxxFeature(cmTarget* target, std::ostringstream e; e << "The CXX_STANDARD property on target \"" << target->GetName() << "\" contained an invalid value: \"" << existingCxxStandard << "\"."; - this->IssueMessage(cmake::FATAL_ERROR, e.str()); + if (error) { + *error = e.str(); + } else { + this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(), + this->Backtrace); + } return false; } } @@ -4329,7 +4356,8 @@ void cmMakefile::CheckNeededCLanguage(const std::string& feature, } bool cmMakefile::AddRequiredTargetCFeature(cmTarget* target, - const std::string& feature) const + const std::string& feature, + std::string* error) const { bool needC90 = false; bool needC99 = false; @@ -4344,7 +4372,12 @@ bool cmMakefile::AddRequiredTargetCFeature(cmTarget* target, std::ostringstream e; e << "The C_STANDARD property on target \"" << target->GetName() << "\" contained an invalid value: \"" << existingCStandard << "\"."; - this->IssueMessage(cmake::FATAL_ERROR, e.str()); + if (error) { + *error = e.str(); + } else { + this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(), + this->Backtrace); + } return false; } } diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index c665b1f..1680c6a 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -437,6 +437,9 @@ public: bool IsOn(const std::string& name) const; bool IsSet(const std::string& name) const; + /** Return whether the target platform is 32-bit. */ + bool PlatformIs32Bit() const; + /** Return whether the target platform is 64-bit. */ bool PlatformIs64Bit() const; @@ -643,8 +646,9 @@ public: void AddInstallGenerator(cmInstallGenerator* g) { - if (g) + if (g) { this->InstallGenerators.push_back(g); + } } std::vector<cmInstallGenerator*>& GetInstallGenerators() { @@ -653,8 +657,9 @@ public: void AddTestGenerator(cmTestGenerator* g) { - if (g) + if (g) { this->TestGenerators.push_back(g); + } } const std::vector<cmTestGenerator*>& GetTestGenerators() const { @@ -715,8 +720,7 @@ public: cmMakefile* Makefile; }; - void IssueMessage(cmake::MessageType t, std::string const& text, - bool force = false) const; + void IssueMessage(cmake::MessageType t, std::string const& text) const; /** Set whether or not to report a CMP0000 violation. */ void SetCheckCMP0000(bool b) { this->CheckCMP0000 = b; } @@ -928,11 +932,12 @@ private: std::vector<cmSourceFile*> QtUiFilesWithOptions; - bool AddRequiredTargetCFeature(cmTarget* target, - const std::string& feature) const; + bool AddRequiredTargetCFeature(cmTarget* target, const std::string& feature, + std::string* error = 0) const; bool AddRequiredTargetCxxFeature(cmTarget* target, - const std::string& feature) const; + const std::string& feature, + std::string* error = 0) const; void CheckNeededCLanguage(const std::string& feature, bool& needC90, bool& needC99, bool& needC11) const; diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx index 128291d..438f90f 100644 --- a/Source/cmMakefileLibraryTargetGenerator.cxx +++ b/Source/cmMakefileLibraryTargetGenerator.cxx @@ -329,8 +329,9 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules( buildEcho += " shared library "; break; case cmState::MODULE_LIBRARY: - if (this->GeneratorTarget->IsCFBundleOnApple()) + if (this->GeneratorTarget->IsCFBundleOnApple()) { buildEcho += " CFBundle"; + } buildEcho += " shared module "; break; default: @@ -676,7 +677,10 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules( i != archiveFinishCommands.end(); ++i) { std::string cmd = *i; this->LocalGenerator->ExpandRuleVariables(cmd, vars); - real_link_commands.push_back(cmd); + // If there is no ranlib the command will be ":". Skip it. + if (!cmd.empty() && cmd[0] != ':') { + real_link_commands.push_back(cmd); + } } } else { // Get the set of commands. diff --git a/Source/cmMessageCommand.cxx b/Source/cmMessageCommand.cxx index f4458a7..080880b 100644 --- a/Source/cmMessageCommand.cxx +++ b/Source/cmMessageCommand.cxx @@ -24,7 +24,6 @@ bool cmMessageCommand::InitialPass(std::vector<std::string> const& args, cmake::MessageType type = cmake::MESSAGE; bool status = false; bool fatal = false; - cmake* cm = this->Makefile->GetCMakeInstance(); if (*i == "SEND_ERROR") { type = cmake::FATAL_ERROR; ++i; @@ -36,10 +35,11 @@ bool cmMessageCommand::InitialPass(std::vector<std::string> const& args, type = cmake::WARNING; ++i; } else if (*i == "AUTHOR_WARNING") { - if (cm->GetDevWarningsAsErrors(this->Makefile)) { + if (this->Makefile->IsSet("CMAKE_SUPPRESS_DEVELOPER_ERRORS") && + !this->Makefile->IsOn("CMAKE_SUPPRESS_DEVELOPER_ERRORS")) { fatal = true; type = cmake::AUTHOR_ERROR; - } else if (!cm->GetSuppressDevWarnings(this->Makefile)) { + } else if (!this->Makefile->IsOn("CMAKE_SUPPRESS_DEVELOPER_WARNINGS")) { type = cmake::AUTHOR_WARNING; } else { return true; @@ -49,10 +49,11 @@ bool cmMessageCommand::InitialPass(std::vector<std::string> const& args, status = true; ++i; } else if (*i == "DEPRECATION") { - if (cm->GetDeprecatedWarningsAsErrors(this->Makefile)) { + if (this->Makefile->IsOn("CMAKE_ERROR_DEPRECATED")) { fatal = true; type = cmake::DEPRECATION_ERROR; - } else if (!cm->GetSuppressDeprecatedWarnings(this->Makefile)) { + } else if ((!this->Makefile->IsSet("CMAKE_WARN_DEPRECATED") || + this->Makefile->IsOn("CMAKE_WARN_DEPRECATED"))) { type = cmake::DEPRECATION_WARNING; } else { return true; @@ -63,8 +64,9 @@ bool cmMessageCommand::InitialPass(std::vector<std::string> const& args, std::string message = cmJoin(cmMakeRange(i, args.end()), std::string()); if (type != cmake::MESSAGE) { - // we've overriden the message type, above, so force IssueMessage to use it - this->Makefile->IssueMessage(type, message, true); + // we've overriden the message type, above, so display it directly + cmake* cm = this->Makefile->GetCMakeInstance(); + cm->DisplayMessage(type, message, this->Makefile->GetBacktrace()); } else { if (status) { this->Makefile->DisplayStatus(message.c_str(), -1); diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 3e91545..5225e3f 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -41,15 +41,16 @@ cmNinjaNormalTargetGenerator::cmNinjaNormalTargetGenerator( , TargetLinkLanguage("") { this->TargetLinkLanguage = target->GetLinkerLanguage(this->GetConfigName()); - if (target->GetType() == cmState::EXECUTABLE) + if (target->GetType() == cmState::EXECUTABLE) { this->GetGeneratorTarget()->GetExecutableNames( this->TargetNameOut, this->TargetNameReal, this->TargetNameImport, this->TargetNamePDB, GetLocalGenerator()->GetConfigName()); - else + } else { this->GetGeneratorTarget()->GetLibraryNames( this->TargetNameOut, this->TargetNameSO, this->TargetNameReal, this->TargetNameImport, this->TargetNamePDB, GetLocalGenerator()->GetConfigName()); + } if (target->GetType() != cmState::OBJECT_LIBRARY) { // on Windows the output dir is already needed at compile time @@ -125,10 +126,11 @@ const char* cmNinjaNormalTargetGenerator::GetVisibleTypeName() const case cmState::SHARED_LIBRARY: return "shared library"; case cmState::MODULE_LIBRARY: - if (this->GetGeneratorTarget()->IsCFBundleOnApple()) + if (this->GetGeneratorTarget()->IsCFBundleOnApple()) { return "CFBundle shared module"; - else + } else { return "shared module"; + } case cmState::EXECUTABLE: return "executable"; default: @@ -144,6 +146,14 @@ std::string cmNinjaNormalTargetGenerator::LanguageLinkerRule() const this->GetGeneratorTarget()->GetName()); } +struct cmNinjaRemoveNoOpCommands +{ + bool operator()(std::string const& cmd) + { + return cmd.empty() || cmd[0] == ':'; + } +}; + void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile) { cmState::TargetType targetType = this->GetGeneratorTarget()->GetType(); @@ -231,6 +241,13 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile) i != linkCmds.end(); ++i) { this->GetLocalGenerator()->ExpandRuleVariables(*i, vars); } + { + // If there is no ranlib the command will be ":". Skip it. + std::vector<std::string>::iterator newEnd = std::remove_if( + linkCmds.begin(), linkCmds.end(), cmNinjaRemoveNoOpCommands()); + linkCmds.erase(newEnd, linkCmds.end()); + } + linkCmds.insert(linkCmds.begin(), "$PRE_LINK"); linkCmds.push_back("$POST_BUILD"); std::string linkCmd = @@ -256,7 +273,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile) std::string cmakeCommand = this->GetLocalGenerator()->ConvertToOutputFormat( cmSystemTools::GetCMakeCommand(), cmOutputConverter::SHELL); - if (targetType == cmState::EXECUTABLE) + if (targetType == cmState::EXECUTABLE) { this->GetGlobalGenerator()->AddRule( "CMAKE_SYMLINK_EXECUTABLE", cmakeCommand + " -E cmake_symlink_executable" @@ -269,7 +286,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile) /*rspcontent*/ "", /*restat*/ "", /*generator*/ false); - else + } else { this->GetGlobalGenerator()->AddRule( "CMAKE_SYMLINK_LIBRARY", cmakeCommand + " -E cmake_symlink_library" @@ -282,6 +299,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile) /*rspcontent*/ "", /*restat*/ "", /*generator*/ false); + } } } @@ -434,9 +452,9 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() vars["TARGET_FILE"] = localGen.ConvertToOutputFormat(targetOutputReal, cmOutputConverter::SHELL); - localGen.GetTargetFlags(vars["LINK_LIBRARIES"], vars["FLAGS"], - vars["LINK_FLAGS"], frameworkPath, linkPath, - &genTarget, useWatcomQuote); + localGen.GetTargetFlags(this->GetConfigName(), vars["LINK_LIBRARIES"], + vars["FLAGS"], vars["LINK_FLAGS"], frameworkPath, + linkPath, &genTarget, useWatcomQuote); if (this->GetMakefile()->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS") && gt.GetType() == cmState::SHARED_LIBRARY) { if (gt.GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS")) { diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index b0f0d9b..05a0a63 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -46,8 +46,9 @@ cmNinjaTargetGenerator* cmNinjaTargetGenerator::New(cmGeneratorTarget* target) // (i.e. top-level) directory. CMake creates copies of these targets // in every directory, which we don't need. if (strcmp(target->GetLocalGenerator()->GetCurrentSourceDirectory(), - target->GetLocalGenerator()->GetSourceDirectory()) == 0) + target->GetLocalGenerator()->GetSourceDirectory()) == 0) { return new cmNinjaUtilityTargetGenerator(target); + } // else fallthrough } @@ -132,8 +133,9 @@ void cmNinjaTargetGenerator::AddIncludeFlags(std::string& languageFlags, includes, this->GeneratorTarget, language, language == "RC", // full include paths for RC needed by cmcldeps false, this->GetConfigName()); - if (this->GetGlobalGenerator()->IsGCCOnWindows()) + if (this->GetGlobalGenerator()->IsGCCOnWindows()) { std::replace(includeFlags.begin(), includeFlags.end(), '\\', '/'); + } this->LocalGenerator->AppendFlags(languageFlags, includeFlags); } @@ -170,13 +172,15 @@ cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps() const { // Static libraries never depend on other targets for linking. if (this->GeneratorTarget->GetType() == cmState::STATIC_LIBRARY || - this->GeneratorTarget->GetType() == cmState::OBJECT_LIBRARY) + this->GeneratorTarget->GetType() == cmState::OBJECT_LIBRARY) { return cmNinjaDeps(); + } cmComputeLinkInformation* cli = this->GeneratorTarget->GetLinkInformation(this->GetConfigName()); - if (!cli) + if (!cli) { return cmNinjaDeps(); + } const std::vector<std::string>& deps = cli->GetDepends(); cmNinjaDeps result(deps.size()); @@ -218,8 +222,9 @@ std::string cmNinjaTargetGenerator::GetObjectFilePath( cmSourceFile const* source) const { std::string path = this->LocalGenerator->GetHomeRelativeOutputPath(); - if (!path.empty()) + if (!path.empty()) { path += "/"; + } std::string const& objectName = this->GeneratorTarget->GetObjectName(source); path += this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget); path += "/"; @@ -237,8 +242,9 @@ std::string cmNinjaTargetGenerator::GetTargetFilePath( const std::string& name) const { std::string path = this->GetTargetOutputDir(); - if (path.empty() || path == ".") + if (path.empty() || path == ".") { return name; + } path += "/"; path += name; return path; @@ -420,8 +426,9 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang) } for (std::vector<std::string>::iterator i = compileCmds.begin(); - i != compileCmds.end(); ++i) + i != compileCmds.end(); ++i) { this->GetLocalGenerator()->ExpandRuleVariables(*i, vars); + } std::string cmdLine = this->GetLocalGenerator()->BuildCommandLine(compileCmds); @@ -653,8 +660,9 @@ void cmNinjaTargetGenerator::ExportObjectCompileCommand( cmSystemTools::ExpandListArgument(compileCmd, compileCmds); for (std::vector<std::string>::iterator i = compileCmds.begin(); - i != compileCmds.end(); ++i) + i != compileCmds.end(); ++i) { this->GetLocalGenerator()->ExpandRuleVariables(*i, compileObjectVars); + } std::string cmdLine = this->GetLocalGenerator()->BuildCommandLine(compileCmds); diff --git a/Source/cmNinjaUtilityTargetGenerator.cxx b/Source/cmNinjaUtilityTargetGenerator.cxx index f7a7f38..c549646 100644 --- a/Source/cmNinjaUtilityTargetGenerator.cxx +++ b/Source/cmNinjaUtilityTargetGenerator.cxx @@ -57,8 +57,9 @@ void cmNinjaUtilityTargetGenerator::Generate() std::vector<std::string> const& ccByproducts = ccg.GetByproducts(); std::transform(ccByproducts.begin(), ccByproducts.end(), std::back_inserter(util_outputs), MapToNinjaPath()); - if (ci->GetUsesTerminal()) + if (ci->GetUsesTerminal()) { uses_terminal = true; + } } } @@ -99,10 +100,11 @@ void cmNinjaUtilityTargetGenerator::Generate() const char* echoStr = this->GetGeneratorTarget()->GetProperty("EchoString"); std::string desc; - if (echoStr) + if (echoStr) { desc = echoStr; - else + } else { desc = "Running utility command for " + this->GetTargetName(); + } // TODO: fix problematic global targets. For now, search and replace the // makefile vars. @@ -122,8 +124,9 @@ void cmNinjaUtilityTargetGenerator::Generate() .c_str()); cmSystemTools::ReplaceString(command, "$(ARGS)", ""); - if (command.find('$') != std::string::npos) + if (command.find('$') != std::string::npos) { return; + } for (cmNinjaDeps::const_iterator oi = util_outputs.begin(), oe = util_outputs.end(); diff --git a/Source/cmOSXBundleGenerator.cxx b/Source/cmOSXBundleGenerator.cxx index f62ba40..c19cae0 100644 --- a/Source/cmOSXBundleGenerator.cxx +++ b/Source/cmOSXBundleGenerator.cxx @@ -25,8 +25,9 @@ cmOSXBundleGenerator::cmOSXBundleGenerator(cmGeneratorTarget* target, , ConfigName(configName) , MacContentFolders(0) { - if (this->MustSkip()) + if (this->MustSkip()) { return; + } } bool cmOSXBundleGenerator::MustSkip() @@ -37,8 +38,9 @@ bool cmOSXBundleGenerator::MustSkip() void cmOSXBundleGenerator::CreateAppBundle(const std::string& targetName, std::string& outpath) { - if (this->MustSkip()) + if (this->MustSkip()) { return; + } // Compute bundle directory names. std::string out = outpath; @@ -64,8 +66,9 @@ void cmOSXBundleGenerator::CreateAppBundle(const std::string& targetName, void cmOSXBundleGenerator::CreateFramework(const std::string& targetName, const std::string& outpath) { - if (this->MustSkip()) + if (this->MustSkip()) { return; + } assert(this->MacContentFolders); @@ -92,8 +95,9 @@ void cmOSXBundleGenerator::CreateFramework(const std::string& targetName, plist.c_str()); // Generate Versions directory only for MacOSX frameworks - if (this->Makefile->PlatformIsAppleIos()) + if (this->Makefile->PlatformIsAppleIos()) { return; + } // TODO: Use the cmMakefileTargetGenerator::ExtraFiles vector to // drive rules to create these files at build time. @@ -162,8 +166,9 @@ void cmOSXBundleGenerator::CreateFramework(const std::string& targetName, void cmOSXBundleGenerator::CreateCFBundle(const std::string& targetName, const std::string& root) { - if (this->MustSkip()) + if (this->MustSkip()) { return; + } // Compute bundle directory names. std::string out = root; @@ -186,8 +191,9 @@ void cmOSXBundleGenerator::GenerateMacOSXContentStatements( std::vector<cmSourceFile const*> const& sources, MacOSXContentGeneratorType* generator) { - if (this->MustSkip()) + if (this->MustSkip()) { return; + } for (std::vector<cmSourceFile const*>::const_iterator si = sources.begin(); si != sources.end(); ++si) { diff --git a/Source/cmPropertyMap.cxx b/Source/cmPropertyMap.cxx index 74e04da..de1281e 100644 --- a/Source/cmPropertyMap.cxx +++ b/Source/cmPropertyMap.cxx @@ -15,6 +15,7 @@ #include "cmSystemTools.h" #include "cmake.h" +#include <algorithm> #include <assert.h> cmProperty* cmPropertyMap::GetOrCreateProperty(const std::string& name) @@ -29,6 +30,17 @@ cmProperty* cmPropertyMap::GetOrCreateProperty(const std::string& name) return prop; } +std::vector<std::string> cmPropertyMap::GetPropertyList() const +{ + std::vector<std::string> keyList; + for (cmPropertyMap::const_iterator i = this->begin(), e = this->end(); + i != e; ++i) { + keyList.push_back(i->first); + } + std::sort(keyList.begin(), keyList.end()); + return keyList; +} + void cmPropertyMap::SetProperty(const std::string& name, const char* value) { if (!value) { diff --git a/Source/cmPropertyMap.h b/Source/cmPropertyMap.h index 4e98750..6dc7bfb 100644 --- a/Source/cmPropertyMap.h +++ b/Source/cmPropertyMap.h @@ -19,6 +19,8 @@ class cmPropertyMap : public std::map<std::string, cmProperty> public: cmProperty* GetOrCreateProperty(const std::string& name); + std::vector<std::string> GetPropertyList() const; + void SetProperty(const std::string& name, const char* value); void AppendProperty(const std::string& name, const char* value, diff --git a/Source/cmStandardIncludes.h b/Source/cmStandardIncludes.h index 6669e5c..d3bf301 100644 --- a/Source/cmStandardIncludes.h +++ b/Source/cmStandardIncludes.h @@ -75,17 +75,21 @@ struct cmDocumentationEntry cmDocumentationEntry() {} cmDocumentationEntry(const char* doc[2]) { - if (doc[0]) + if (doc[0]) { this->Name = doc[0]; - if (doc[1]) + } + if (doc[1]) { this->Brief = doc[1]; + } } cmDocumentationEntry(const char* n, const char* b) { - if (n) + if (n) { this->Name = n; - if (b) + } + if (b) { this->Brief = b; + } } }; diff --git a/Source/cmState.cxx b/Source/cmState.cxx index 04f07ce..d2cfaba 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -246,6 +246,14 @@ void cmState::SetCacheEntryBoolProperty(std::string const& key, it.SetProperty(propertyName, value); } +std::vector<std::string> cmState::GetCacheEntryPropertyList( + const std::string& key) +{ + cmCacheManager::CacheIterator it = + this->CacheManager->GetCacheIterator(key.c_str()); + return it.GetPropertyList(); +} + const char* cmState::GetCacheEntryProperty(std::string const& key, std::string const& propertyName) { diff --git a/Source/cmState.h b/Source/cmState.h index 18c45b8..935faec 100644 --- a/Source/cmState.h +++ b/Source/cmState.h @@ -247,6 +247,7 @@ public: std::string const& value); void SetCacheEntryBoolProperty(std::string const& key, std::string const& propertyName, bool value); + std::vector<std::string> GetCacheEntryPropertyList(std::string const& key); const char* GetCacheEntryProperty(std::string const& key, std::string const& propertyName); bool GetCacheEntryPropertyAsBool(std::string const& key, diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 10c68d1..26cbfb6 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -228,14 +228,16 @@ std::string cmSystemTools::HelpFileName(std::string name) std::string cmSystemTools::TrimWhitespace(const std::string& s) { std::string::const_iterator start = s.begin(); - while (start != s.end() && cm_isspace(*start)) + while (start != s.end() && cm_isspace(*start)) { ++start; - if (start == s.end()) + } + if (start == s.end()) { return ""; - + } std::string::const_iterator stop = s.end() - 1; - while (cm_isspace(*stop)) + while (cm_isspace(*stop)) { --stop; + } return std::string(start, stop + 1); } diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index f435a1d..55da611 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -287,8 +287,9 @@ cmListFileBacktrace const* cmTarget::GetUtilityBacktrace( { std::map<std::string, cmListFileBacktrace>::const_iterator i = this->UtilityBacktraces.find(u); - if (i == this->UtilityBacktraces.end()) + if (i == this->UtilityBacktraces.end()) { return 0; + } return &i->second; } @@ -580,8 +581,7 @@ bool cmTarget::PushTLLCommandTrace(TLLSignature signature, return ret; } -void cmTarget::GetTllSignatureTraces(std::ostringstream& s, - TLLSignature sig) const +void cmTarget::GetTllSignatureTraces(std::ostream& s, TLLSignature sig) const { const char* sigString = (sig == cmTarget::KeywordTLLSignature ? "keyword" : "plain"); diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 71ba0cd..f91e5c6 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -156,7 +156,7 @@ public: }; bool PushTLLCommandTrace(TLLSignature signature, cmListFileContext const& lfc); - void GetTllSignatureTraces(std::ostringstream& s, TLLSignature sig) const; + void GetTllSignatureTraces(std::ostream& s, TLLSignature sig) const; void MergeLinkLibraries(cmMakefile& mf, const std::string& selfname, const LinkLibraryVectorType& libs); diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 89ea955..e404fa3 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -145,7 +145,6 @@ cmake::cmake() } #endif - this->Verbose = false; this->GlobalGenerator = 0; this->ProgressCallback = 0; this->ProgressCallbackClientData = 0; @@ -482,6 +481,9 @@ bool cmake::FindPackage(const std::vector<std::string>& args) mf->AddLinkLibraryForTarget(targetName, *libIt, GENERAL_LibraryType); } + std::string buildType = mf->GetSafeDefinition("CMAKE_BUILD_TYPE"); + buildType = cmSystemTools::UpperCase(buildType); + std::string linkLibs; std::string frameworkPath; std::string linkPath; @@ -490,8 +492,8 @@ bool cmake::FindPackage(const std::vector<std::string>& args) gg->CreateGenerationObjects(); cmGeneratorTarget* gtgt = gg->FindGeneratorTarget(tgt->GetName()); cmLocalGenerator* lg = gtgt->GetLocalGenerator(); - lg->GetTargetFlags(linkLibs, frameworkPath, linkPath, flags, linkFlags, - gtgt, false); + lg->GetTargetFlags(buildType, linkLibs, frameworkPath, linkPath, flags, + linkFlags, gtgt, false); linkLibs = frameworkPath + linkPath + linkLibs; printf("%s\n", linkLibs.c_str()); @@ -555,9 +557,7 @@ void cmake::SetArgs(const std::vector<std::string>& args, this->VSSolutionFile = args[++i]; } #endif - else if (arg.find("-V", 0) == 0) { - this->Verbose = true; - } else if (arg.find("-D", 0) == 0) { + else if (arg.find("-D", 0) == 0) { // skip for now } else if (arg.find("-U", 0) == 0) { // skip for now @@ -1989,9 +1989,7 @@ int cmake::GetSystemInformation(std::vector<std::string>& args) bool writeToStdout = true; for (unsigned int i = 1; i < args.size(); ++i) { std::string arg = args[i]; - if (arg.find("-V", 0) == 0) { - this->Verbose = true; - } else if (arg.find("-G", 0) == 0) { + if (arg.find("-G", 0) == 0) { std::string value = arg.substr(2); if (value.empty()) { ++i; @@ -2176,7 +2174,7 @@ static bool cmakeCheckStampList(const char* stampList) return true; } -cmake::MessageType cmake::ConvertMessageType(cmake::MessageType t) +cmake::MessageType cmake::ConvertMessageType(cmake::MessageType t) const { bool warningsAsErrors; @@ -2200,7 +2198,7 @@ cmake::MessageType cmake::ConvertMessageType(cmake::MessageType t) return t; } -bool cmake::IsMessageTypeVisible(cmake::MessageType t) +bool cmake::IsMessageTypeVisible(cmake::MessageType t) const { bool isVisible = true; @@ -2225,7 +2223,7 @@ bool cmake::IsMessageTypeVisible(cmake::MessageType t) return isVisible; } -bool cmake::PrintMessagePreamble(cmake::MessageType t, std::ostream& msg) +static bool printMessagePreamble(cmake::MessageType t, std::ostream& msg) { // Construct the message header. if (t == cmake::FATAL_ERROR) { @@ -2296,23 +2294,28 @@ void displayMessage(cmake::MessageType t, std::ostringstream& msg) } void cmake::IssueMessage(cmake::MessageType t, std::string const& text, - cmListFileBacktrace const& backtrace, bool force) + cmListFileBacktrace const& backtrace) const { - if (!force) { - // override the message type, if needed, for warnings and errors - cmake::MessageType override = this->ConvertMessageType(t); - if (override != t) { - t = override; - force = true; - } + bool force = false; + // override the message type, if needed, for warnings and errors + cmake::MessageType override = this->ConvertMessageType(t); + if (override != t) { + t = override; + force = true; } if (!force && !this->IsMessageTypeVisible(t)) { return; } + this->DisplayMessage(t, text, backtrace); +} + +void cmake::DisplayMessage(cmake::MessageType t, std::string const& text, + cmListFileBacktrace const& backtrace) const +{ std::ostringstream msg; - if (!this->PrintMessagePreamble(t, msg)) { + if (!printMessagePreamble(t, msg)) { return; } @@ -2448,19 +2451,11 @@ void cmake::RunCheckForUnusedVariables() #endif } -bool cmake::GetSuppressDevWarnings(cmMakefile const* mf) +bool cmake::GetSuppressDevWarnings() const { - /* - * The suppression CMake variable may be set in the CMake configuration file - * itself, so we have to check what its set to in the makefile if we can. - */ - if (mf) { - return mf->IsOn("CMAKE_SUPPRESS_DEVELOPER_WARNINGS"); - } else { - const char* cacheEntryValue = - this->State->GetCacheEntryValue("CMAKE_SUPPRESS_DEVELOPER_WARNINGS"); - return cmSystemTools::IsOn(cacheEntryValue); - } + const char* cacheEntryValue = + this->State->GetCacheEntryValue("CMAKE_SUPPRESS_DEVELOPER_WARNINGS"); + return cmSystemTools::IsOn(cacheEntryValue); } void cmake::SetSuppressDevWarnings(bool b) @@ -2482,20 +2477,11 @@ void cmake::SetSuppressDevWarnings(bool b) cmState::INTERNAL); } -bool cmake::GetSuppressDeprecatedWarnings(cmMakefile const* mf) +bool cmake::GetSuppressDeprecatedWarnings() const { - /* - * The suppression CMake variable may be set in the CMake configuration file - * itself, so we have to check what its set to in the makefile if we can. - */ - if (mf) { - return (mf->IsSet("CMAKE_WARN_DEPRECATED") && - !mf->IsOn("CMAKE_WARN_DEPRECATED")); - } else { - const char* cacheEntryValue = - this->State->GetCacheEntryValue("CMAKE_WARN_DEPRECATED"); - return cacheEntryValue && cmSystemTools::IsOff(cacheEntryValue); - } + const char* cacheEntryValue = + this->State->GetCacheEntryValue("CMAKE_WARN_DEPRECATED"); + return cacheEntryValue && cmSystemTools::IsOff(cacheEntryValue); } void cmake::SetSuppressDeprecatedWarnings(bool b) @@ -2517,16 +2503,11 @@ void cmake::SetSuppressDeprecatedWarnings(bool b) cmState::INTERNAL); } -bool cmake::GetDevWarningsAsErrors(cmMakefile const* mf) +bool cmake::GetDevWarningsAsErrors() const { - if (mf) { - return (mf->IsSet("CMAKE_SUPPRESS_DEVELOPER_ERRORS") && - !mf->IsOn("CMAKE_SUPPRESS_DEVELOPER_ERRORS")); - } else { - const char* cacheEntryValue = - this->State->GetCacheEntryValue("CMAKE_SUPPRESS_DEVELOPER_ERRORS"); - return cacheEntryValue && cmSystemTools::IsOff(cacheEntryValue); - } + const char* cacheEntryValue = + this->State->GetCacheEntryValue("CMAKE_SUPPRESS_DEVELOPER_ERRORS"); + return cacheEntryValue && cmSystemTools::IsOff(cacheEntryValue); } void cmake::SetDevWarningsAsErrors(bool b) @@ -2548,15 +2529,11 @@ void cmake::SetDevWarningsAsErrors(bool b) cmState::INTERNAL); } -bool cmake::GetDeprecatedWarningsAsErrors(cmMakefile const* mf) +bool cmake::GetDeprecatedWarningsAsErrors() const { - if (mf) { - return mf->IsOn("CMAKE_ERROR_DEPRECATED"); - } else { - const char* cacheEntryValue = - this->State->GetCacheEntryValue("CMAKE_ERROR_DEPRECATED"); - return cmSystemTools::IsOn(cacheEntryValue); - } + const char* cacheEntryValue = + this->State->GetCacheEntryValue("CMAKE_ERROR_DEPRECATED"); + return cmSystemTools::IsOn(cacheEntryValue); } void cmake::SetDeprecatedWarningsAsErrors(bool b) diff --git a/Source/cmake.h b/Source/cmake.h index 266c33d..c5d7cbb 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -209,9 +209,6 @@ public: return this->GeneratorToolset; } - ///! get the cmCachemManager used by this invocation of cmake - cmCacheManager* GetCacheManager() { return this->CacheManager; } - const std::vector<std::string>& GetSourceExtensions() const { return this->SourceFileExtensions; @@ -339,7 +336,7 @@ public: * Returns false, by default, if developer warnings should be shown, true * otherwise. */ - bool GetSuppressDevWarnings(cmMakefile const* mf = NULL); + bool GetSuppressDevWarnings() const; /* * Set the state of the suppression of developer (author) warnings. */ @@ -350,7 +347,7 @@ public: * Returns false, by default, if deprecated warnings should be shown, true * otherwise. */ - bool GetSuppressDeprecatedWarnings(cmMakefile const* mf = NULL); + bool GetSuppressDeprecatedWarnings() const; /* * Set the state of the suppression of deprecated warnings. */ @@ -361,7 +358,7 @@ public: * Returns false, by default, if warnings should not be treated as errors, * true otherwise. */ - bool GetDevWarningsAsErrors(cmMakefile const* mf = NULL); + bool GetDevWarningsAsErrors() const; /** * Set the state of treating developer (author) warnings as errors. */ @@ -372,7 +369,7 @@ public: * Returns false, by default, if warnings should not be treated as errors, * true otherwise. */ - bool GetDeprecatedWarningsAsErrors(cmMakefile const* mf = NULL); + bool GetDeprecatedWarningsAsErrors() const; /** * Set the state of treating developer (author) warnings as errors. */ @@ -381,8 +378,10 @@ public: /** Display a message to the user. */ void IssueMessage( cmake::MessageType t, std::string const& text, - cmListFileBacktrace const& backtrace = cmListFileBacktrace(), - bool force = false); + cmListFileBacktrace const& backtrace = cmListFileBacktrace()) const; + + void DisplayMessage(cmake::MessageType t, std::string const& text, + cmListFileBacktrace const& backtrace) const; ///! run the --build option int Build(const std::string& dir, const std::string& target, @@ -421,7 +420,6 @@ protected: CreateExtraGeneratorFunctionType newFunction); cmGlobalGenerator* GlobalGenerator; - cmCacheManager* CacheManager; std::map<std::string, DiagLevel> DiagLevels; std::string GeneratorPlatform; std::string GeneratorToolset; @@ -455,7 +453,6 @@ private: void operator=(const cmake&); // Not implemented. ProgressCallbackType ProgressCallback; void* ProgressCallbackClientData; - bool Verbose; bool InTryCompile; WorkingMode CurrentWorkingMode; bool DebugOutput; @@ -493,15 +490,13 @@ private: * Convert a message type between a warning and an error, based on the state * of the error output CMake variables, in the cache. */ - cmake::MessageType ConvertMessageType(cmake::MessageType t); + cmake::MessageType ConvertMessageType(cmake::MessageType t) const; /* * Check if messages of this type should be output, based on the state of the * warning and error output CMake variables, in the cache. */ - bool IsMessageTypeVisible(cmake::MessageType t); - - bool PrintMessagePreamble(cmake::MessageType t, std::ostream& msg); + bool IsMessageTypeVisible(cmake::MessageType t) const; }; #define CMAKE_STANDARD_OPTIONS_TABLE \ diff --git a/Tests/CMakeLib/PseudoMemcheck/memtester.cxx.in b/Tests/CMakeLib/PseudoMemcheck/memtester.cxx.in index b141942..e2cdec8 100644 --- a/Tests/CMakeLib/PseudoMemcheck/memtester.cxx.in +++ b/Tests/CMakeLib/PseudoMemcheck/memtester.cxx.in @@ -4,8 +4,7 @@ #define RETVAL @_retval@ -int -main(int ac, char **av) +int main(int ac, char** av) { cmsys::Encoding::CommandLineArguments args = cmsys::Encoding::CommandLineArguments::Main(ac, av); @@ -16,42 +15,39 @@ main(int ac, char **av) std::string logarg; bool nextarg = false; - if (exename.find("valgrind") != exename.npos) + if (exename.find("valgrind") != exename.npos) { logarg = "--log-file="; - else if (exename.find("purify") != exename.npos) + } else if (exename.find("purify") != exename.npos) { #ifdef _WIN32 logarg = "/SAVETEXTDATA="; #else logarg = "-log-file="; #endif - else if (exename.find("BC") != exename.npos) - { + } else if (exename.find("BC") != exename.npos) { nextarg = true; logarg = "/X"; - } + } if (!logarg.empty()) { std::string logfile; for (int i = 1; i < argc; i++) { std::string arg = argv[i]; - if (arg.find(logarg) == 0) - { - if (nextarg) - { - if (i == argc - 1) + if (arg.find(logarg) == 0) { + if (nextarg) { + if (i == argc - 1) { return 1; // invalid command line - logfile = argv[i + 1]; } - else - { + logfile = argv[i + 1]; + } else { logfile = arg.substr(logarg.length()); - } - // keep searching, it may be overridden later to provoke an error } + // keep searching, it may be overridden later to provoke an error } + } - if (!logfile.empty()) + if (!logfile.empty()) { cmSystemTools::Touch(logfile, true); + } } return RETVAL; diff --git a/Tests/CMakeLib/run_compile_commands.cxx b/Tests/CMakeLib/run_compile_commands.cxx index 1cfd381..b811c7f 100644 --- a/Tests/CMakeLib/run_compile_commands.cxx +++ b/Tests/CMakeLib/run_compile_commands.cxx @@ -46,10 +46,12 @@ private: void ParseTranslationUnit() { this->Command = CommandType(); - if (!Expect('{')) + if (!Expect('{')) { return; - if (Expect('}')) + } + if (Expect('}')) { return; + } do { ParseString(); std::string name = this->String; @@ -64,8 +66,9 @@ private: void ParseString() { this->String = ""; - if (!Expect('"')) + if (!Expect('"')) { return; + } while (!Expect('"')) { Expect('\\'); this->String.append(1, C); @@ -84,8 +87,9 @@ private: void ExpectOrDie(char c, const std::string& message) { - if (!Expect(c)) + if (!Expect(c)) { ErrorExit(std::string("'") + c + "' expected " + message + "."); + } } void NextNonWhitespace() @@ -98,8 +102,9 @@ private: void Next() { this->C = char(Input->get()); - if (this->Input->bad()) + if (this->Input->bad()) { ErrorExit("Unexpected end of file."); + } } void ErrorExit(const std::string& message) diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 9442ea7..5911682 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1405,6 +1405,10 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release add_subdirectory(FindTIFF) endif() + if(CMake_TEST_FindVulkan) + add_subdirectory(FindVulkan) + endif() + if(CMake_TEST_FindXalanC) add_subdirectory(FindXalanC) endif() @@ -3104,6 +3108,10 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release find_package(Java COMPONENTS Development QUIET) if(Java_JAVA_EXECUTABLE AND Java_JAVAC_EXECUTABLE AND Java_JAR_EXECUTABLE AND NOT MINGW AND NOT "${CMAKE_GENERATOR}" MATCHES "Xcode") + + set(JavaExportImport_BUILD_OPTIONS -DCMake_TEST_NESTED_MAKE_PROGRAM:FILEPATH=${CMake_TEST_EXPLICIT_MAKE_PROGRAM}) + ADD_TEST_MACRO(JavaExportImport JavaExportImport) + get_filename_component(JNIPATH ${JAVA_COMPILE} PATH) find_file(JNI_H jni.h "${JNIPATH}/../include" diff --git a/Tests/CMakeOnly/find_library/CMakeLists.txt b/Tests/CMakeOnly/find_library/CMakeLists.txt index 2d4ecaf..9958650 100644 --- a/Tests/CMakeOnly/find_library/CMakeLists.txt +++ b/Tests/CMakeOnly/find_library/CMakeLists.txt @@ -33,16 +33,23 @@ endmacro() set(CMAKE_FIND_LIBRARY_PREFIXES "lib") set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") +set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS TRUE) set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS TRUE) set(CMAKE_SIZEOF_VOID_P 4) foreach(lib + lib/32/libtest5.a lib/A/lib/libtest1.a + lib/A/lib32/libtest3.a lib/A/libtest1.a lib/libtest1.a lib/libtest2.a lib/libtest3.a lib/libtest3.a + lib32/A/lib/libtest2.a + lib32/A/lib32/libtest4.a + lib32/A/libtest4.a + lib32/libtest4.a ) test_find_library_subst(${lib}) endforeach() diff --git a/Tests/CMakeOnly/find_library/lib/32/libtest5.a b/Tests/CMakeOnly/find_library/lib/32/libtest5.a new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/CMakeOnly/find_library/lib/32/libtest5.a diff --git a/Tests/CMakeOnly/find_library/lib/A/lib32/libtest3.a b/Tests/CMakeOnly/find_library/lib/A/lib32/libtest3.a new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/CMakeOnly/find_library/lib/A/lib32/libtest3.a diff --git a/Tests/CMakeOnly/find_library/lib32/A/lib/libtest2.a b/Tests/CMakeOnly/find_library/lib32/A/lib/libtest2.a new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/CMakeOnly/find_library/lib32/A/lib/libtest2.a diff --git a/Tests/CMakeOnly/find_library/lib32/A/lib32/libtest4.a b/Tests/CMakeOnly/find_library/lib32/A/lib32/libtest4.a new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/CMakeOnly/find_library/lib32/A/lib32/libtest4.a diff --git a/Tests/CMakeOnly/find_library/lib32/A/libtest4.a b/Tests/CMakeOnly/find_library/lib32/A/libtest4.a new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/CMakeOnly/find_library/lib32/A/libtest4.a diff --git a/Tests/CMakeOnly/find_library/lib32/libtest4.a b/Tests/CMakeOnly/find_library/lib32/libtest4.a new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/CMakeOnly/find_library/lib32/libtest4.a diff --git a/Tests/FindOpenCL/Test/main.c b/Tests/FindOpenCL/Test/main.c index b075caf..dc77636 100644 --- a/Tests/FindOpenCL/Test/main.c +++ b/Tests/FindOpenCL/Test/main.c @@ -1,16 +1,17 @@ #ifdef __APPLE__ - #include <OpenCL/opencl.h> +#include <OpenCL/opencl.h> #else - #include <CL/cl.h> +#include <CL/cl.h> #endif int main() { cl_uint platformIdCount; - // We can't assert on the result because this may return an error if no ICD is + // We can't assert on the result because this may return an error if no ICD + // is // found - clGetPlatformIDs (0, NULL, &platformIdCount); + clGetPlatformIDs(0, NULL, &platformIdCount); return 0; } diff --git a/Tests/FindVulkan/CMakeLists.txt b/Tests/FindVulkan/CMakeLists.txt new file mode 100644 index 0000000..46ce1c6 --- /dev/null +++ b/Tests/FindVulkan/CMakeLists.txt @@ -0,0 +1,10 @@ +add_test(NAME FindVulkan.Test COMMAND + ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindVulkan/Test" + "${CMake_BINARY_DIR}/Tests/FindVulkan/Test" + ${build_generator_args} + --build-project TestFindVulkan + --build-options ${build_options} + --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> + ) diff --git a/Tests/FindVulkan/Test/CMakeLists.txt b/Tests/FindVulkan/Test/CMakeLists.txt new file mode 100644 index 0000000..0b13d53 --- /dev/null +++ b/Tests/FindVulkan/Test/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.4) +project(TestFindVulkan C) +include(CTest) + +SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../) +find_package(Vulkan REQUIRED) + +add_executable(test_tgt main.c) +target_link_libraries(test_tgt Vulkan::Vulkan) +add_test(NAME test_tgt COMMAND test_tgt) + +add_executable(test_var main.c) +target_include_directories(test_var PRIVATE ${Vulkan_INCLUDE_DIRS}) +target_link_libraries(test_var PRIVATE ${Vulkan_LIBRARIES}) +add_test(NAME test_var COMMAND test_var) diff --git a/Tests/FindVulkan/Test/main.c b/Tests/FindVulkan/Test/main.c new file mode 100644 index 0000000..b29c9ec --- /dev/null +++ b/Tests/FindVulkan/Test/main.c @@ -0,0 +1,29 @@ +#include <vulkan/vulkan.h> + +int main() +{ + VkInstanceCreateInfo instanceCreateInfo = {}; + instanceCreateInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; + + VkApplicationInfo applicationInfo = {}; + applicationInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; + applicationInfo.apiVersion = VK_API_VERSION_1_0; + applicationInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0); + applicationInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0); + applicationInfo.pApplicationName = "CMake Test application"; + applicationInfo.pEngineName = "CMake Test Engine"; + + instanceCreateInfo.pApplicationInfo = &applicationInfo; + + VkInstance instance = VK_NULL_HANDLE; + vkCreateInstance(&instanceCreateInfo, NULL, &instance); + + // We can't assert here because in general vkCreateInstance will return an + // error if no driver is found - but if we get here, FindVulkan is working + + if (instance != VK_NULL_HANDLE) { + vkDestroyInstance(instance, NULL); + } + + return 0; +} diff --git a/Tests/Java/A.java b/Tests/Java/A.java index 403a7f8..b7fdb49 100644 --- a/Tests/Java/A.java +++ b/Tests/Java/A.java @@ -1,11 +1,11 @@ class A { public A() - { - } + { + } public void printName() - { - System.out.println("A"); - } + { + System.out.println("A"); + } } diff --git a/Tests/Java/HelloWorld.java b/Tests/Java/HelloWorld.java index 378e371..995ee48 100644 --- a/Tests/Java/HelloWorld.java +++ b/Tests/Java/HelloWorld.java @@ -1,11 +1,11 @@ class HelloWorld { - public static void main(String args[]) - { - A a; - a = new A(); - a.printName(); - System.out.println("Hello World!"); - } + public static void main(String args[]) + { + A a; + a = new A(); + a.printName(); + System.out.println("Hello World!"); + } } diff --git a/Tests/JavaExportImport/BuildExport/CMakeLists.txt b/Tests/JavaExportImport/BuildExport/CMakeLists.txt new file mode 100644 index 0000000..953f9d0 --- /dev/null +++ b/Tests/JavaExportImport/BuildExport/CMakeLists.txt @@ -0,0 +1,10 @@ +project(foo Java) + +cmake_minimum_required (VERSION 3.5) +set(CMAKE_VERBOSE_MAKEFILE 1) + +find_package(Java COMPONENTS Development) +include(UseJava) + +add_jar(${PROJECT_NAME} Foo.java) +export_jars(TARGETS ${PROJECT_NAME} FILE JavaBuildExportTestConfig.cmake) diff --git a/Tests/JavaExportImport/BuildExport/Foo.java b/Tests/JavaExportImport/BuildExport/Foo.java new file mode 100644 index 0000000..20815ba --- /dev/null +++ b/Tests/JavaExportImport/BuildExport/Foo.java @@ -0,0 +1,11 @@ +class Foo +{ + public Foo() + { + } + + public void printName() + { + System.out.println("Foo"); + } +} diff --git a/Tests/JavaExportImport/CMakeLists.txt b/Tests/JavaExportImport/CMakeLists.txt new file mode 100644 index 0000000..a075301 --- /dev/null +++ b/Tests/JavaExportImport/CMakeLists.txt @@ -0,0 +1,104 @@ +cmake_minimum_required (VERSION 3.5) +project(JavaExportImport) +if(NOT DEFINED CMake_TEST_NESTED_MAKE_PROGRAM AND NOT CMAKE_GENERATOR MATCHES "Visual Studio") + set(CMake_TEST_NESTED_MAKE_PROGRAM "${CMAKE_MAKE_PROGRAM}") +endif() + +find_package(Java COMPONENTS Development) + +# Wipe out the install tree to make sure the exporter works. +add_custom_command( + OUTPUT ${JavaExportImport_BINARY_DIR}/CleanupProject + COMMAND ${CMAKE_COMMAND} -E remove_directory ${JavaExportImport_BINARY_DIR}/Root + ) +add_custom_target(CleanupTarget ALL DEPENDS ${JavaExportImport_BINARY_DIR}/CleanupProject) +set_property( + SOURCE ${JavaExportImport_BINARY_DIR}/CleanupProject + PROPERTY SYMBOLIC 1 + ) + +if(CMAKE_CONFIGURATION_TYPES) + set(NESTED_CONFIG_TYPE -C "${CMAKE_CFG_INTDIR}") +else() + if(CMAKE_BUILD_TYPE) + set(NESTED_CONFIG_TYPE -C "${CMAKE_BUILD_TYPE}") + else() + set(NESTED_CONFIG_TYPE) + endif() +endif() + +configure_file(${JavaExportImport_SOURCE_DIR}/InitialCache.cmake.in + ${JavaExportImport_BINARY_DIR}/InitialCache.cmake @ONLY) + +# Build the build exporter. +add_custom_command( + OUTPUT ${JavaExportImport_BINARY_DIR}/BuildExportProject + COMMAND ${CMAKE_CTEST_COMMAND} ${NESTED_CONFIG_TYPE} + --build-and-test + ${JavaExportImport_SOURCE_DIR}/BuildExport + ${JavaExportImport_BINARY_DIR}/BuildExport + --build-noclean + --build-project BuildExport + --build-generator ${CMAKE_GENERATOR} + --build-generator-platform "${CMAKE_GENERATOR_PLATFORM}" + --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}" + --build-options -C${JavaExportImport_BINARY_DIR}/InitialCache.cmake + VERBATIM + ) +add_custom_target(BuildExportTarget ALL DEPENDS ${JavaExportImport_BINARY_DIR}/BuildExportProject) +add_dependencies(BuildExportTarget CleanupTarget) +set_property( + SOURCE ${JavaExportImport_BINARY_DIR}/BuildExportProject + PROPERTY SYMBOLIC 1 + ) + +# Build and install the install exporter. +add_custom_command( + OUTPUT ${JavaExportImport_BINARY_DIR}/InstallExportProject + COMMAND ${CMAKE_CTEST_COMMAND} ${NESTED_CONFIG_TYPE} + --build-and-test + ${JavaExportImport_SOURCE_DIR}/InstallExport + ${JavaExportImport_BINARY_DIR}/InstallExport + --build-noclean + --build-project InstallExport + --build-target install + --build-generator ${CMAKE_GENERATOR} + --build-generator-platform "${CMAKE_GENERATOR_PLATFORM}" + --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}" + --build-options -C${JavaExportImport_BINARY_DIR}/InitialCache.cmake + VERBATIM + ) +add_custom_target(InstallExportTarget ALL DEPENDS ${JavaExportImport_BINARY_DIR}/InstallExportProject) +add_dependencies(InstallExportTarget CleanupTarget) +set_property( + SOURCE ${JavaExportImport_BINARY_DIR}/InstallExportProject + PROPERTY SYMBOLIC 1 + ) + +# Build and install the importer. +add_custom_command( + OUTPUT ${JavaExportImport_BINARY_DIR}/ImportProject + COMMAND ${CMAKE_CTEST_COMMAND} ${NESTED_CONFIG_TYPE} + --build-and-test + ${JavaExportImport_SOURCE_DIR}/Import + ${JavaExportImport_BINARY_DIR}/Import + --build-noclean + --build-project Import + --build-generator ${CMAKE_GENERATOR} + --build-generator-platform "${CMAKE_GENERATOR_PLATFORM}" + --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}" + --build-options + -C${JavaExportImport_BINARY_DIR}/InitialCache.cmake + -DJavaBuildExportTest_DIR:PATH=${JavaExportImport_BINARY_DIR}/BuildExport + -DJavaInstallExportTest_DIR:PATH=${JavaExportImport_BINARY_DIR}/Root/share/cmake + VERBATIM + ) +add_custom_target(ImportTarget ALL DEPENDS ${JavaExportImport_BINARY_DIR}/ImportProject) +add_dependencies(ImportTarget BuildExportTarget InstallExportTarget) +set_property( + SOURCE ${JavaExportImport_BINARY_DIR}/ImportProject + PROPERTY SYMBOLIC 1 + ) + +add_executable(JavaExportImport main.c) +add_dependencies(JavaExportImport ImportTarget) diff --git a/Tests/JavaExportImport/Import/CMakeLists.txt b/Tests/JavaExportImport/Import/CMakeLists.txt new file mode 100644 index 0000000..79a1447 --- /dev/null +++ b/Tests/JavaExportImport/Import/CMakeLists.txt @@ -0,0 +1,14 @@ +project(import Java) + +cmake_minimum_required (VERSION 3.5) +set(CMAKE_VERBOSE_MAKEFILE 1) + +find_package(Java COMPONENTS Development) +include(UseJava) + +find_package(JavaBuildExportTest REQUIRED) +find_package(JavaInstallExportTest REQUIRED) + +add_jar(${PROJECT_NAME} + SOURCES Import.java + INCLUDE_JARS foo bar) diff --git a/Tests/JavaExportImport/Import/Import.java b/Tests/JavaExportImport/Import/Import.java new file mode 100644 index 0000000..08eb03f --- /dev/null +++ b/Tests/JavaExportImport/Import/Import.java @@ -0,0 +1,10 @@ +class Import +{ + public static void main(String args[]) + { + Foo foo = new Foo(); + Bar bar = new Bar(); + foo.printName(); + bar.printName(); + } +} diff --git a/Tests/JavaExportImport/InitialCache.cmake.in b/Tests/JavaExportImport/InitialCache.cmake.in new file mode 100644 index 0000000..d15e6d1 --- /dev/null +++ b/Tests/JavaExportImport/InitialCache.cmake.in @@ -0,0 +1,5 @@ +set(CMAKE_MAKE_PROGRAM "@CMake_TEST_NESTED_MAKE_PROGRAM@" CACHE FILEPATH "Make Program") +set(Java_JAVA_EXECUTABLE "@Java_JAVA_EXECUTABLE@" CACHE STRING "Java Interpreter") +set(Java_JAVAC_EXECUTABLE "@Java_JAVAC_EXECUTABLE@" CACHE STRING "Java Compiler") +set(Java_JAR_EXECUTABLE "@Java_JAR_EXECUTABLE@" CACHE STRING "Java Archive Tool") +set(CMAKE_INSTALL_PREFIX "@JavaExportImport_BINARY_DIR@/Root" CACHE STRING "Installation Prefix") diff --git a/Tests/JavaExportImport/InstallExport/Bar.java b/Tests/JavaExportImport/InstallExport/Bar.java new file mode 100644 index 0000000..a1068a8 --- /dev/null +++ b/Tests/JavaExportImport/InstallExport/Bar.java @@ -0,0 +1,11 @@ +class Bar +{ + public Bar() + { + } + + public void printName() + { + System.out.println("Bar"); + } +} diff --git a/Tests/JavaExportImport/InstallExport/CMakeLists.txt b/Tests/JavaExportImport/InstallExport/CMakeLists.txt new file mode 100644 index 0000000..0a9afd9 --- /dev/null +++ b/Tests/JavaExportImport/InstallExport/CMakeLists.txt @@ -0,0 +1,14 @@ +project(bar Java) + +cmake_minimum_required (VERSION 3.5) +set(CMAKE_VERBOSE_MAKEFILE 1) + +find_package(Java COMPONENTS Development) +include(UseJava) + +add_jar(${PROJECT_NAME} Bar.java) +install_jar(${PROJECT_NAME} DESTINATION share/java) +install_jar_exports( + TARGETS ${PROJECT_NAME} + FILE JavaInstallExportTestConfig.cmake + DESTINATION share/cmake) diff --git a/Tests/JavaExportImport/main.c b/Tests/JavaExportImport/main.c new file mode 100644 index 0000000..f8b643a --- /dev/null +++ b/Tests/JavaExportImport/main.c @@ -0,0 +1,4 @@ +int main() +{ + return 0; +} diff --git a/Tests/Plugin/src/example_exe.cxx b/Tests/Plugin/src/example_exe.cxx index 857ad54..017fbf6 100644 --- a/Tests/Plugin/src/example_exe.cxx +++ b/Tests/Plugin/src/example_exe.cxx @@ -31,6 +31,7 @@ int main() kwsys::DynamicLoader::LibraryHandle handle = kwsys::DynamicLoader::OpenLibrary(libName.c_str()); if (!handle) { + // Leave the .c_str() on this one. It is needed on OpenWatcom. std::cerr << "Could not open plugin \"" << libName.c_str() << "\"!" << std::endl; return 1; diff --git a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_CMAKE_APPBUNDLE_PATH.cmake b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_CMAKE_APPBUNDLE_PATH.cmake index 9d4826f..4a41533 100644 --- a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_CMAKE_APPBUNDLE_PATH.cmake +++ b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_CMAKE_APPBUNDLE_PATH.cmake @@ -1,4 +1,4 @@ -# Needed for CMAKE_SYSTEM_NAME, CMAKE_LIBRARY_ARCHITECTURE and FIND_LIBRARY_USE_LIB64_PATHS +# Needed for CMAKE_SYSTEM_NAME, CMAKE_LIBRARY_ARCHITECTURE, FIND_LIBRARY_USE_LIB32_PATHS and FIND_LIBRARY_USE_LIB64_PATHS enable_language(C) # Prepare environment and variables @@ -29,10 +29,15 @@ if(NOT DEFINED CMAKE_SYSTEM_NAME set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig") endif() else() - # not debian, chech the FIND_LIBRARY_USE_LIB64_PATHS property + # not debian, check the FIND_LIBRARY_USE_LIB32_PATHS and FIND_LIBRARY_USE_LIB64_PATHS properties + get_property(uselib32 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS) get_property(uselib64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS) - if(uselib64) + if(uselib32 AND CMAKE_SIZEOF_VOID_P EQUAL 4) + set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib32/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib32/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig") + elseif(uselib64 AND CMAKE_SIZEOF_VOID_P EQUAL 8) set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib64/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib64/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig") + else() + set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig") endif() endif() else() diff --git a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_CMAKE_FRAMEWORK_PATH.cmake b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_CMAKE_FRAMEWORK_PATH.cmake index d9943d4..b66d02f 100644 --- a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_CMAKE_FRAMEWORK_PATH.cmake +++ b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_CMAKE_FRAMEWORK_PATH.cmake @@ -1,4 +1,4 @@ -# Needed for CMAKE_SYSTEM_NAME, CMAKE_LIBRARY_ARCHITECTURE and FIND_LIBRARY_USE_LIB64_PATHS +# Needed for CMAKE_SYSTEM_NAME, CMAKE_LIBRARY_ARCHITECTURE, FIND_LIBRARY_USE_LIB32_PATHS and FIND_LIBRARY_USE_LIB64_PATHS enable_language(C) # Prepare environment and variables @@ -29,10 +29,15 @@ if(NOT DEFINED CMAKE_SYSTEM_NAME set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig") endif() else() - # not debian, chech the FIND_LIBRARY_USE_LIB64_PATHS property + # not debian, check the FIND_LIBRARY_USE_LIB64_PATHS and FIND_LIBRARY_USE_LIB64_PATHS properties + get_property(uselib32 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS) get_property(uselib64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS) - if(uselib64) + if(uselib32 AND CMAKE_SIZEOF_VOID_P EQUAL 4) + set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib32/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib32/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig") + elseif(uselib64 AND CMAKE_SIZEOF_VOID_P EQUAL 8) set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib64/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib64/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig") + else() + set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig") endif() endif() else() diff --git a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_NO_PKGCONFIG_PATH.cmake b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_NO_PKGCONFIG_PATH.cmake index 89ce4c6..25a775d 100644 --- a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_NO_PKGCONFIG_PATH.cmake +++ b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_NO_PKGCONFIG_PATH.cmake @@ -1,6 +1,3 @@ -# Needed for CMAKE_SYSTEM_NAME, CMAKE_LIBRARY_ARCHITECTURE and FIND_LIBRARY_USE_LIB64_PATHS -enable_language(C) - # Prepare environment and variables set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH FALSE) set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}/pc-foo") diff --git a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH.cmake b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH.cmake index c903279..bdecb8a 100644 --- a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH.cmake +++ b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH.cmake @@ -1,4 +1,4 @@ -# Needed for CMAKE_SYSTEM_NAME, CMAKE_LIBRARY_ARCHITECTURE and FIND_LIBRARY_USE_LIB64_PATHS +# Needed for CMAKE_SYSTEM_NAME, CMAKE_LIBRARY_ARCHITECTURE, FIND_LIBRARY_USE_LIB32_PATHS and FIND_LIBRARY_USE_LIB64_PATHS enable_language(C) # Prepare environment and variables @@ -29,10 +29,15 @@ if(NOT DEFINED CMAKE_SYSTEM_NAME set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig") endif() else() - # not debian, chech the FIND_LIBRARY_USE_LIB64_PATHS property + # not debian, check the FIND_LIBRARY_USE_LIB32_PATHS and FIND_LIBRARY_USE_LIB64_PATHS propertie + get_property(uselib32 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS) get_property(uselib64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS) - if(uselib64) + if(uselib32 AND CMAKE_SIZEOF_VOID_P EQUAL 4) + set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib32/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib32/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig") + elseif(uselib64 AND CMAKE_SIZEOF_VOID_P EQUAL 8) set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib64/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib64/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig") + else() + set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig") endif() endif() else() diff --git a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH_NO_CMAKE_ENVIRONMENT_PATH.cmake b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH_NO_CMAKE_ENVIRONMENT_PATH.cmake index a52bcbf..df67235 100644 --- a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH_NO_CMAKE_ENVIRONMENT_PATH.cmake +++ b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH_NO_CMAKE_ENVIRONMENT_PATH.cmake @@ -1,4 +1,4 @@ -# Needed for CMAKE_SYSTEM_NAME, CMAKE_LIBRARY_ARCHITECTURE and FIND_LIBRARY_USE_LIB64_PATHS +# Needed for CMAKE_SYSTEM_NAME, CMAKE_LIBRARY_ARCHITECTURE, FIND_LIBRARY_USE_LIB32_PATHS and FIND_LIBRARY_USE_LIB64_PATHS enable_language(C) # Prepare environment and variables @@ -29,10 +29,15 @@ if(NOT DEFINED CMAKE_SYSTEM_NAME set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig") endif() else() - # not debian, chech the FIND_LIBRARY_USE_LIB64_PATHS property + # not debian, check the FIND_LIBRARY_USE_LIB32_PATHS and FIND_LIBRARY_USE_LIB64_PATHS properties + get_property(uselib32 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS) get_property(uselib64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS) - if(uselib64) + if(uselib32 AND CMAKE_SIZEOF_VOID_P EQUAL 4) + set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib32/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig") + elseif(uselib64 AND CMAKE_SIZEOF_VOID_P EQUAL 8) set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib64/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig") + else() + set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig") endif() endif() else() diff --git a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH_NO_CMAKE_PATH.cmake b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH_NO_CMAKE_PATH.cmake index 2fabe5b..1351b6f 100644 --- a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH_NO_CMAKE_PATH.cmake +++ b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH_NO_CMAKE_PATH.cmake @@ -1,4 +1,4 @@ -# Needed for CMAKE_SYSTEM_NAME, CMAKE_LIBRARY_ARCHITECTURE and FIND_LIBRARY_USE_LIB64_PATHS +# Needed for CMAKE_SYSTEM_NAME, CMAKE_LIBRARY_ARCHITECTURE, FIND_LIBRARY_USE_LIB32_PATHS and FIND_LIBRARY_USE_LIB64_PATHS enable_language(C) # Prepare environment and variables @@ -29,10 +29,15 @@ if(NOT DEFINED CMAKE_SYSTEM_NAME set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig") endif() else() - # not debian, chech the FIND_LIBRARY_USE_LIB64_PATHS property + # not debian, check the FIND_LIBRARY_USE_LIB64_PATHS and FIND_LIBRARY_USE_LIB32_PATHS properties + get_property(uselib32 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS) get_property(uselib64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS) - if(uselib64) + if(uselib32 AND CMAKE_SIZEOF_VOID_P EQUAL 4) + set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib32/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig") + elseif(uselib64 AND CMAKE_SIZEOF_VOID_P EQUAL 8) set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib64/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig") + else() + set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig") endif() endif() else() diff --git a/Tests/RunCMake/FindPkgConfig/pc-bar/lib32/pkgconfig/.placeholder b/Tests/RunCMake/FindPkgConfig/pc-bar/lib32/pkgconfig/.placeholder new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/FindPkgConfig/pc-bar/lib32/pkgconfig/.placeholder diff --git a/Tests/RunCMake/FindPkgConfig/pc-foo/lib32/pkgconfig/.placeholder b/Tests/RunCMake/FindPkgConfig/pc-foo/lib32/pkgconfig/.placeholder new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/FindPkgConfig/pc-foo/lib32/pkgconfig/.placeholder diff --git a/Tests/RunCMake/find_path/Frameworks/Foo.framework/Headers/Some/Dir/Header.h b/Tests/RunCMake/find_path/Frameworks/Foo.framework/Headers/Some/Dir/Header.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/find_path/Frameworks/Foo.framework/Headers/Some/Dir/Header.h diff --git a/Tests/RunCMake/find_path/FrameworksWithSubdirs-stdout.txt b/Tests/RunCMake/find_path/FrameworksWithSubdirs-stdout.txt new file mode 100644 index 0000000..001a3e9 --- /dev/null +++ b/Tests/RunCMake/find_path/FrameworksWithSubdirs-stdout.txt @@ -0,0 +1 @@ +-- SOME_INCLUDE_DIR='[^']*Tests/RunCMake/find_path/Frameworks/Foo.framework/Headers' diff --git a/Tests/RunCMake/find_path/FrameworksWithSubdirs.cmake b/Tests/RunCMake/find_path/FrameworksWithSubdirs.cmake new file mode 100644 index 0000000..b286021 --- /dev/null +++ b/Tests/RunCMake/find_path/FrameworksWithSubdirs.cmake @@ -0,0 +1,3 @@ +set(CMAKE_FRAMEWORK_PATH "${CMAKE_CURRENT_SOURCE_DIR}/Frameworks") +find_path(SOME_INCLUDE_DIR "Some/Dir/Header.h") +message(STATUS "SOME_INCLUDE_DIR='${SOME_INCLUDE_DIR}'") diff --git a/Tests/RunCMake/find_path/RunCMakeTest.cmake b/Tests/RunCMake/find_path/RunCMakeTest.cmake index 5ce96e0..bf0fa89 100644 --- a/Tests/RunCMake/find_path/RunCMakeTest.cmake +++ b/Tests/RunCMake/find_path/RunCMakeTest.cmake @@ -3,3 +3,7 @@ include(RunCMake) if(WIN32 OR CYGWIN) run_cmake(PrefixInPATH) endif() + +if(APPLE) + run_cmake(FrameworksWithSubdirs) +endif() diff --git a/Tests/RunCMake/message/RunCMakeTest.cmake b/Tests/RunCMake/message/RunCMakeTest.cmake index 9489693..2346c86 100644 --- a/Tests/RunCMake/message/RunCMakeTest.cmake +++ b/Tests/RunCMake/message/RunCMakeTest.cmake @@ -2,6 +2,8 @@ include(RunCMake) run_cmake(defaultmessage) run_cmake(nomessage) +run_cmake(message-internal-warning) +run_cmake(nomessage-internal-warning) run_cmake(warnmessage) # message command sets fatal occurred flag, so check each type of error diff --git a/Tests/RunCMake/message/message-internal-warning-stderr.txt b/Tests/RunCMake/message/message-internal-warning-stderr.txt new file mode 100644 index 0000000..25946e9 --- /dev/null +++ b/Tests/RunCMake/message/message-internal-warning-stderr.txt @@ -0,0 +1,13 @@ +^CMake Warning \(dev\) in message-internal-warning.cmake: + A logical block opening on the line + + .*Tests/RunCMake/message/message-internal-warning.cmake:4 \(macro\) + + closes on the line + + .*Tests/RunCMake/message/message-internal-warning.cmake:5 \(endmacro\) + + with mis-matching arguments. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) +This warning is for project developers. Use -Wno-dev to suppress it.$ diff --git a/Tests/RunCMake/message/message-internal-warning.cmake b/Tests/RunCMake/message/message-internal-warning.cmake new file mode 100644 index 0000000..33993c7 --- /dev/null +++ b/Tests/RunCMake/message/message-internal-warning.cmake @@ -0,0 +1,5 @@ + +set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS ON) + +macro(mymacro) +endmacro(notmymacro) diff --git a/Tests/RunCMake/message/nomessage-internal-warning-stderr.txt b/Tests/RunCMake/message/nomessage-internal-warning-stderr.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/message/nomessage-internal-warning-stderr.txt diff --git a/Tests/RunCMake/message/nomessage-internal-warning.cmake b/Tests/RunCMake/message/nomessage-internal-warning.cmake new file mode 100644 index 0000000..3ec2e28 --- /dev/null +++ b/Tests/RunCMake/message/nomessage-internal-warning.cmake @@ -0,0 +1,5 @@ + +set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS ON CACHE BOOL "") + +macro(mymacro) +endmacro(notmymacro) diff --git a/Utilities/cmexpat/lib/expat.h b/Utilities/cmexpat/lib/expat.h index ec62f14..5abcefd 100644 --- a/Utilities/cmexpat/lib/expat.h +++ b/Utilities/cmexpat/lib/expat.h @@ -973,9 +973,12 @@ XML_FreeContentModel(XML_Parser parser, XML_Content *model); /* Exposing the memory handling functions used in Expat */ XMLPARSEAPI(void *) +XML_ATTR_MALLOC +XML_ATTR_ALLOC_SIZE(2) XML_MemMalloc(XML_Parser parser, size_t size); XMLPARSEAPI(void *) +XML_ATTR_ALLOC_SIZE(3) XML_MemRealloc(XML_Parser parser, void *ptr, size_t size); XMLPARSEAPI(void) diff --git a/Utilities/cmexpat/lib/expat_external.h b/Utilities/cmexpat/lib/expat_external.h index b2be17b..07a3c5c 100644 --- a/Utilities/cmexpat/lib/expat_external.h +++ b/Utilities/cmexpat/lib/expat_external.h @@ -67,12 +67,26 @@ #endif #endif /* not defined XML_STATIC */ +#if !defined(XMLIMPORT) && defined(__GNUC__) && (__GNUC__ >= 4) +#define XMLIMPORT __attribute__ ((visibility ("default"))) +#endif /* If we didn't define it above, define it away: */ #ifndef XMLIMPORT #define XMLIMPORT #endif +#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)) +#define XML_ATTR_MALLOC __attribute__((__malloc__)) +#else +#define XML_ATTR_MALLOC +#endif + +#if defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) +#define XML_ATTR_ALLOC_SIZE(x) __attribute__((__alloc_size__(x))) +#else +#define XML_ATTR_ALLOC_SIZE(x) +#endif #define XMLPARSEAPI(type) XMLIMPORT type XMLCALL diff --git a/Utilities/cmexpat/lib/internal.h b/Utilities/cmexpat/lib/internal.h index dd54548..94cb98e 100644 --- a/Utilities/cmexpat/lib/internal.h +++ b/Utilities/cmexpat/lib/internal.h @@ -71,3 +71,25 @@ #define inline #endif #endif + +#ifndef UNUSED_P +# ifdef __GNUC__ +# define UNUSED_P(p) UNUSED_ ## p __attribute__((__unused__)) +# else +# define UNUSED_P(p) UNUSED_ ## p +# endif +#endif + + +#ifdef __cplusplus +extern "C" { +#endif + + +void +align_limit_to_full_utf8_characters(const char * from, const char ** fromLimRef); + + +#ifdef __cplusplus +} +#endif diff --git a/Utilities/cmexpat/lib/xmlparse.c b/Utilities/cmexpat/lib/xmlparse.c index c0e8f6e..b56b66a 100644 --- a/Utilities/cmexpat/lib/xmlparse.c +++ b/Utilities/cmexpat/lib/xmlparse.c @@ -1730,7 +1730,8 @@ XML_GetBuffer(XML_Parser parser, int len) #ifdef XML_CONTEXT_BYTES int keep; #endif /* defined XML_CONTEXT_BYTES */ - int neededSize = len + (int)(bufferEnd - bufferPtr); + /* Do not invoke signed arithmetic overflow: */ + int neededSize = (int) ((unsigned)len + (unsigned)(bufferEnd - bufferPtr)); if (neededSize < 0) { errorCode = XML_ERROR_NO_MEMORY; return NULL; @@ -1761,7 +1762,8 @@ XML_GetBuffer(XML_Parser parser, int len) if (bufferSize == 0) bufferSize = INIT_BUFFER_SIZE; do { - bufferSize *= 2; + /* Do not invoke signed arithmetic overflow: */ + bufferSize = (int) (2U * (unsigned) bufferSize); } while (bufferSize < neededSize && bufferSize > 0); if (bufferSize <= 0) { errorCode = XML_ERROR_NO_MEMORY; @@ -2462,11 +2464,11 @@ doContent(XML_Parser parser, for (;;) { int bufSize; int convLen; - XmlConvert(enc, + const enum XML_Convert_Result convert_res = XmlConvert(enc, &fromPtr, rawNameEnd, (ICHAR **)&toPtr, (ICHAR *)tag->bufEnd - 1); convLen = (int)(toPtr - (XML_Char *)tag->buf); - if (fromPtr == rawNameEnd) { + if ((convert_res == XML_CONVERT_COMPLETED) || (convert_res == XML_CONVERT_INPUT_INCOMPLETE)) { tag->name.strLen = convLen; break; } @@ -2687,11 +2689,11 @@ doContent(XML_Parser parser, if (MUST_CONVERT(enc, s)) { for (;;) { ICHAR *dataPtr = (ICHAR *)dataBuf; - XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd); + const enum XML_Convert_Result convert_res = XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd); *eventEndPP = s; charDataHandler(handlerArg, dataBuf, (int)(dataPtr - (ICHAR *)dataBuf)); - if (s == next) + if ((convert_res == XML_CONVERT_COMPLETED) || (convert_res == XML_CONVERT_INPUT_INCOMPLETE)) break; *eventPP = s; } @@ -3297,11 +3299,11 @@ doCdataSection(XML_Parser parser, if (MUST_CONVERT(enc, s)) { for (;;) { ICHAR *dataPtr = (ICHAR *)dataBuf; - XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd); + const enum XML_Convert_Result convert_res = XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd); *eventEndPP = next; charDataHandler(handlerArg, dataBuf, (int)(dataPtr - (ICHAR *)dataBuf)); - if (s == next) + if ((convert_res == XML_CONVERT_COMPLETED) || (convert_res == XML_CONVERT_INPUT_INCOMPLETE)) break; *eventPP = s; } @@ -4960,9 +4962,9 @@ internalEntityProcessor(XML_Parser parser, static enum XML_Error PTRCALL errorProcessor(XML_Parser parser, - const char *s, - const char *end, - const char **nextPtr) + const char *UNUSED_P(s), + const char *UNUSED_P(end), + const char **UNUSED_P(nextPtr)) { return errorCode; } @@ -5378,6 +5380,7 @@ reportDefault(XML_Parser parser, const ENCODING *enc, const char *s, const char *end) { if (MUST_CONVERT(enc, s)) { + enum XML_Convert_Result convert_res; const char **eventPP; const char **eventEndPP; if (enc == encoding) { @@ -5390,11 +5393,11 @@ reportDefault(XML_Parser parser, const ENCODING *enc, } do { ICHAR *dataPtr = (ICHAR *)dataBuf; - XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd); + convert_res = XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd); *eventEndPP = s; defaultHandler(handlerArg, dataBuf, (int)(dataPtr - (ICHAR *)dataBuf)); *eventPP = s; - } while (s != end); + } while ((convert_res != XML_CONVERT_COMPLETED) && (convert_res != XML_CONVERT_INPUT_INCOMPLETE)); } else defaultHandler(handlerArg, (XML_Char *)s, (int)((XML_Char *)end - (XML_Char *)s)); @@ -6199,8 +6202,8 @@ poolAppend(STRING_POOL *pool, const ENCODING *enc, if (!pool->ptr && !poolGrow(pool)) return NULL; for (;;) { - XmlConvert(enc, &ptr, end, (ICHAR **)&(pool->ptr), (ICHAR *)pool->end); - if (ptr == end) + const enum XML_Convert_Result convert_res = XmlConvert(enc, &ptr, end, (ICHAR **)&(pool->ptr), (ICHAR *)pool->end); + if ((convert_res == XML_CONVERT_COMPLETED) || (convert_res == XML_CONVERT_INPUT_INCOMPLETE)) break; if (!poolGrow(pool)) return NULL; @@ -6284,8 +6287,13 @@ poolGrow(STRING_POOL *pool) } } if (pool->blocks && pool->start == pool->blocks->s) { - int blockSize = (int)(pool->end - pool->start)*2; - BLOCK *temp = (BLOCK *) + BLOCK *temp; + int blockSize = (int)((unsigned)(pool->end - pool->start)*2U); + + if (blockSize < 0) + return XML_FALSE; + + temp = (BLOCK *) pool->mem->realloc_fcn(pool->blocks, (offsetof(BLOCK, s) + blockSize * sizeof(XML_Char))); @@ -6300,6 +6308,10 @@ poolGrow(STRING_POOL *pool) else { BLOCK *tem; int blockSize = (int)(pool->end - pool->start); + + if (blockSize < 0) + return XML_FALSE; + if (blockSize < INIT_BLOCK_SIZE) blockSize = INIT_BLOCK_SIZE; else diff --git a/Utilities/cmexpat/lib/xmlrole.c b/Utilities/cmexpat/lib/xmlrole.c index f6e66ab..4e79ffd 100644 --- a/Utilities/cmexpat/lib/xmlrole.c +++ b/Utilities/cmexpat/lib/xmlrole.c @@ -195,9 +195,9 @@ prolog1(PROLOG_STATE *state, static int PTRCALL prolog2(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -216,9 +216,9 @@ prolog2(PROLOG_STATE *state, static int PTRCALL doctype0(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -264,9 +264,9 @@ doctype1(PROLOG_STATE *state, static int PTRCALL doctype2(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -281,9 +281,9 @@ doctype2(PROLOG_STATE *state, static int PTRCALL doctype3(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -298,9 +298,9 @@ doctype3(PROLOG_STATE *state, static int PTRCALL doctype4(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -318,9 +318,9 @@ doctype4(PROLOG_STATE *state, static int PTRCALL doctype5(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -437,9 +437,9 @@ externalSubset1(PROLOG_STATE *state, static int PTRCALL entity0(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -457,9 +457,9 @@ entity0(PROLOG_STATE *state, static int PTRCALL entity1(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -502,9 +502,9 @@ entity2(PROLOG_STATE *state, static int PTRCALL entity3(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -519,9 +519,9 @@ entity3(PROLOG_STATE *state, static int PTRCALL entity4(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -559,9 +559,9 @@ entity5(PROLOG_STATE *state, static int PTRCALL entity6(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -605,9 +605,9 @@ entity7(PROLOG_STATE *state, static int PTRCALL entity8(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -622,9 +622,9 @@ entity8(PROLOG_STATE *state, static int PTRCALL entity9(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -639,9 +639,9 @@ entity9(PROLOG_STATE *state, static int PTRCALL entity10(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -656,9 +656,9 @@ entity10(PROLOG_STATE *state, static int PTRCALL notation0(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -697,9 +697,9 @@ notation1(PROLOG_STATE *state, static int PTRCALL notation2(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -714,9 +714,9 @@ notation2(PROLOG_STATE *state, static int PTRCALL notation3(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -732,9 +732,9 @@ notation3(PROLOG_STATE *state, static int PTRCALL notation4(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -753,9 +753,9 @@ notation4(PROLOG_STATE *state, static int PTRCALL attlist0(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -771,9 +771,9 @@ attlist0(PROLOG_STATE *state, static int PTRCALL attlist1(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -833,9 +833,9 @@ attlist2(PROLOG_STATE *state, static int PTRCALL attlist3(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -852,9 +852,9 @@ attlist3(PROLOG_STATE *state, static int PTRCALL attlist4(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -872,9 +872,9 @@ attlist4(PROLOG_STATE *state, static int PTRCALL attlist5(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -889,9 +889,9 @@ attlist5(PROLOG_STATE *state, static int PTRCALL attlist6(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -906,9 +906,9 @@ attlist6(PROLOG_STATE *state, static int PTRCALL attlist7(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -967,9 +967,9 @@ attlist8(PROLOG_STATE *state, static int PTRCALL attlist9(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -984,9 +984,9 @@ attlist9(PROLOG_STATE *state, static int PTRCALL element0(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -1072,9 +1072,9 @@ element2(PROLOG_STATE *state, static int PTRCALL element3(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -1097,9 +1097,9 @@ element3(PROLOG_STATE *state, static int PTRCALL element4(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -1115,9 +1115,9 @@ element4(PROLOG_STATE *state, static int PTRCALL element5(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -1136,9 +1136,9 @@ element5(PROLOG_STATE *state, static int PTRCALL element6(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -1166,9 +1166,9 @@ element6(PROLOG_STATE *state, static int PTRCALL element7(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -1240,9 +1240,9 @@ condSect0(PROLOG_STATE *state, static int PTRCALL condSect1(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -1258,9 +1258,9 @@ condSect1(PROLOG_STATE *state, static int PTRCALL condSect2(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -1277,9 +1277,9 @@ condSect2(PROLOG_STATE *state, static int PTRCALL declClose(PROLOG_STATE *state, int tok, - const char *ptr, - const char *end, - const ENCODING *enc) + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { switch (tok) { case XML_TOK_PROLOG_S: @@ -1292,11 +1292,11 @@ declClose(PROLOG_STATE *state, } static int PTRCALL -error(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) +error(PROLOG_STATE *UNUSED_P(state), + int UNUSED_P(tok), + const char *UNUSED_P(ptr), + const char *UNUSED_P(end), + const ENCODING *UNUSED_P(enc)) { return XML_ROLE_NONE; } diff --git a/Utilities/cmexpat/lib/xmltok.c b/Utilities/cmexpat/lib/xmltok.c index 814fe92..4195279 100644 --- a/Utilities/cmexpat/lib/xmltok.c +++ b/Utilities/cmexpat/lib/xmltok.c @@ -46,7 +46,7 @@ #define VTABLE VTABLE1, PREFIX(toUtf8), PREFIX(toUtf16) #define UCS2_GET_NAMING(pages, hi, lo) \ - (namingBitmap[(pages[hi] << 3) + ((lo) >> 5)] & (1 << ((lo) & 0x1F))) + (namingBitmap[(pages[hi] << 3) + ((lo) >> 5)] & (1u << ((lo) & 0x1F))) /* A 2 byte UTF-8 representation splits the characters 11 bits between the bottom 5 and 6 bits of the bytes. We need 8 bits to index into @@ -56,7 +56,7 @@ (namingBitmap[((pages)[(((byte)[0]) >> 2) & 7] << 3) \ + ((((byte)[0]) & 3) << 1) \ + ((((byte)[1]) >> 5) & 1)] \ - & (1 << (((byte)[1]) & 0x1F))) + & (1u << (((byte)[1]) & 0x1F))) /* A 3 byte UTF-8 representation splits the characters 16 bits between the bottom 4, 6 and 6 bits of the bytes. We need 8 bits to index @@ -69,7 +69,7 @@ << 3) \ + ((((byte)[1]) & 3) << 1) \ + ((((byte)[2]) >> 5) & 1)] \ - & (1 << (((byte)[2]) & 0x1F))) + & (1u << (((byte)[2]) & 0x1F))) #define UTF8_GET_NAMING(pages, p, n) \ ((n) == 2 \ @@ -122,19 +122,19 @@ ((*p) == 0xF4 ? (p)[1] > 0x8F : ((p)[1] & 0xC0) == 0xC0))) static int PTRFASTCALL -isNever(const ENCODING *enc, const char *p) +isNever(const ENCODING *UNUSED_P(enc), const char *UNUSED_P(p)) { return 0; } static int PTRFASTCALL -utf8_isName2(const ENCODING *enc, const char *p) +utf8_isName2(const ENCODING *UNUSED_P(enc), const char *p) { return UTF8_GET_NAMING2(namePages, (const unsigned char *)p); } static int PTRFASTCALL -utf8_isName3(const ENCODING *enc, const char *p) +utf8_isName3(const ENCODING *UNUSED_P(enc), const char *p) { return UTF8_GET_NAMING3(namePages, (const unsigned char *)p); } @@ -142,13 +142,13 @@ utf8_isName3(const ENCODING *enc, const char *p) #define utf8_isName4 isNever static int PTRFASTCALL -utf8_isNmstrt2(const ENCODING *enc, const char *p) +utf8_isNmstrt2(const ENCODING *UNUSED_P(enc), const char *p) { return UTF8_GET_NAMING2(nmstrtPages, (const unsigned char *)p); } static int PTRFASTCALL -utf8_isNmstrt3(const ENCODING *enc, const char *p) +utf8_isNmstrt3(const ENCODING *UNUSED_P(enc), const char *p) { return UTF8_GET_NAMING3(nmstrtPages, (const unsigned char *)p); } @@ -156,19 +156,19 @@ utf8_isNmstrt3(const ENCODING *enc, const char *p) #define utf8_isNmstrt4 isNever static int PTRFASTCALL -utf8_isInvalid2(const ENCODING *enc, const char *p) +utf8_isInvalid2(const ENCODING *UNUSED_P(enc), const char *p) { return UTF8_INVALID2((const unsigned char *)p); } static int PTRFASTCALL -utf8_isInvalid3(const ENCODING *enc, const char *p) +utf8_isInvalid3(const ENCODING *UNUSED_P(enc), const char *p) { return UTF8_INVALID3((const unsigned char *)p); } static int PTRFASTCALL -utf8_isInvalid4(const ENCODING *enc, const char *p) +utf8_isInvalid4(const ENCODING *UNUSED_P(enc), const char *p) { return UTF8_INVALID4((const unsigned char *)p); } @@ -329,39 +329,89 @@ enum { /* UTF8_cvalN is value of masked first byte of N byte sequence */ UTF8_cval4 = 0xf0 }; -static void PTRCALL -utf8_toUtf8(const ENCODING *enc, +void +align_limit_to_full_utf8_characters(const char * from, const char ** fromLimRef) +{ + const char * fromLim = *fromLimRef; + size_t walked = 0; + for (; fromLim > from; fromLim--, walked++) { + const unsigned char prev = (unsigned char)fromLim[-1]; + if ((prev & 0xf8u) == 0xf0u) { /* 4-byte character, lead by 0b11110xxx byte */ + if (walked + 1 >= 4) { + fromLim += 4 - 1; + break; + } else { + walked = 0; + } + } else if ((prev & 0xf0u) == 0xe0u) { /* 3-byte character, lead by 0b1110xxxx byte */ + if (walked + 1 >= 3) { + fromLim += 3 - 1; + break; + } else { + walked = 0; + } + } else if ((prev & 0xe0u) == 0xc0u) { /* 2-byte character, lead by 0b110xxxxx byte */ + if (walked + 1 >= 2) { + fromLim += 2 - 1; + break; + } else { + walked = 0; + } + } else if ((prev & 0x80u) == 0x00u) { /* 1-byte character, matching 0b0xxxxxxx */ + break; + } + } + *fromLimRef = fromLim; +} + +static enum XML_Convert_Result PTRCALL +utf8_toUtf8(const ENCODING *UNUSED_P(enc), const char **fromP, const char *fromLim, char **toP, const char *toLim) { + enum XML_Convert_Result res = XML_CONVERT_COMPLETED; char *to; const char *from; if (fromLim - *fromP > toLim - *toP) { /* Avoid copying partial characters. */ - for (fromLim = *fromP + (toLim - *toP); fromLim > *fromP; fromLim--) - if (((unsigned char)fromLim[-1] & 0xc0) != 0x80) - break; + res = XML_CONVERT_OUTPUT_EXHAUSTED; + fromLim = *fromP + (toLim - *toP); + align_limit_to_full_utf8_characters(*fromP, &fromLim); } - for (to = *toP, from = *fromP; from != fromLim; from++, to++) + for (to = *toP, from = *fromP; (from < fromLim) && (to < toLim); from++, to++) *to = *from; *fromP = from; *toP = to; + + if ((to == toLim) && (from < fromLim)) + return XML_CONVERT_OUTPUT_EXHAUSTED; + else + return res; } -static void PTRCALL +static enum XML_Convert_Result PTRCALL utf8_toUtf16(const ENCODING *enc, const char **fromP, const char *fromLim, unsigned short **toP, const unsigned short *toLim) { + enum XML_Convert_Result res = XML_CONVERT_COMPLETED; unsigned short *to = *toP; const char *from = *fromP; - while (from != fromLim && to != toLim) { + while (from < fromLim && to < toLim) { switch (((struct normal_encoding *)enc)->type[(unsigned char)*from]) { case BT_LEAD2: + if (fromLim - from < 2) { + res = XML_CONVERT_INPUT_INCOMPLETE; + break; + } *to++ = (unsigned short)(((from[0] & 0x1f) << 6) | (from[1] & 0x3f)); from += 2; break; case BT_LEAD3: + if (fromLim - from < 3) { + res = XML_CONVERT_INPUT_INCOMPLETE; + break; + } *to++ = (unsigned short)(((from[0] & 0xf) << 12) | ((from[1] & 0x3f) << 6) | (from[2] & 0x3f)); from += 3; @@ -369,8 +419,14 @@ utf8_toUtf16(const ENCODING *enc, case BT_LEAD4: { unsigned long n; - if (to + 1 == toLim) + if (toLim - to < 2) { + res = XML_CONVERT_OUTPUT_EXHAUSTED; goto after; + } + if (fromLim - from < 4) { + res = XML_CONVERT_INPUT_INCOMPLETE; + goto after; + } n = ((from[0] & 0x7) << 18) | ((from[1] & 0x3f) << 12) | ((from[2] & 0x3f) << 6) | (from[3] & 0x3f); n -= 0x10000; @@ -388,6 +444,7 @@ utf8_toUtf16(const ENCODING *enc, after: *fromP = from; *toP = to; + return res; } #ifdef XML_NS @@ -436,38 +493,43 @@ static const struct normal_encoding internal_utf8_encoding = { STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_) }; -static void PTRCALL -latin1_toUtf8(const ENCODING *enc, +static enum XML_Convert_Result PTRCALL +latin1_toUtf8(const ENCODING *UNUSED_P(enc), const char **fromP, const char *fromLim, char **toP, const char *toLim) { for (;;) { unsigned char c; if (*fromP == fromLim) - break; + return XML_CONVERT_COMPLETED; c = (unsigned char)**fromP; if (c & 0x80) { if (toLim - *toP < 2) - break; + return XML_CONVERT_OUTPUT_EXHAUSTED; *(*toP)++ = (char)((c >> 6) | UTF8_cval2); *(*toP)++ = (char)((c & 0x3f) | 0x80); (*fromP)++; } else { if (*toP == toLim) - break; + return XML_CONVERT_OUTPUT_EXHAUSTED; *(*toP)++ = *(*fromP)++; } } } -static void PTRCALL -latin1_toUtf16(const ENCODING *enc, +static enum XML_Convert_Result PTRCALL +latin1_toUtf16(const ENCODING *UNUSED_P(enc), const char **fromP, const char *fromLim, unsigned short **toP, const unsigned short *toLim) { - while (*fromP != fromLim && *toP != toLim) + while (*fromP < fromLim && *toP < toLim) *(*toP)++ = (unsigned char)*(*fromP)++; + + if ((*toP == toLim) && (*fromP < fromLim)) + return XML_CONVERT_OUTPUT_EXHAUSTED; + else + return XML_CONVERT_COMPLETED; } #ifdef XML_NS @@ -494,13 +556,18 @@ static const struct normal_encoding latin1_encoding = { STANDARD_VTABLE(sb_) NULL_VTABLE }; -static void PTRCALL -ascii_toUtf8(const ENCODING *enc, +static enum XML_Convert_Result PTRCALL +ascii_toUtf8(const ENCODING *UNUSED_P(enc), const char **fromP, const char *fromLim, char **toP, const char *toLim) { - while (*fromP != fromLim && *toP != toLim) + while (*fromP < fromLim && *toP < toLim) *(*toP)++ = *(*fromP)++; + + if ((*toP == toLim) && (*fromP < fromLim)) + return XML_CONVERT_OUTPUT_EXHAUSTED; + else + return XML_CONVERT_COMPLETED; } #ifdef XML_NS @@ -547,13 +614,14 @@ unicode_byte_type(char hi, char lo) } #define DEFINE_UTF16_TO_UTF8(E) \ -static void PTRCALL \ -E ## toUtf8(const ENCODING *enc, \ +static enum XML_Convert_Result PTRCALL \ +E ## toUtf8(const ENCODING *UNUSED_P(enc), \ const char **fromP, const char *fromLim, \ char **toP, const char *toLim) \ { \ - const char *from; \ - for (from = *fromP; from != fromLim; from += 2) { \ + const char *from = *fromP; \ + fromLim = from + (((fromLim - from) >> 1) << 1); /* shrink to even */ \ + for (; from < fromLim; from += 2) { \ int plane; \ unsigned char lo2; \ unsigned char lo = GET_LO(from); \ @@ -563,7 +631,7 @@ E ## toUtf8(const ENCODING *enc, \ if (lo < 0x80) { \ if (*toP == toLim) { \ *fromP = from; \ - return; \ + return XML_CONVERT_OUTPUT_EXHAUSTED; \ } \ *(*toP)++ = lo; \ break; \ @@ -573,7 +641,7 @@ E ## toUtf8(const ENCODING *enc, \ case 0x4: case 0x5: case 0x6: case 0x7: \ if (toLim - *toP < 2) { \ *fromP = from; \ - return; \ + return XML_CONVERT_OUTPUT_EXHAUSTED; \ } \ *(*toP)++ = ((lo >> 6) | (hi << 2) | UTF8_cval2); \ *(*toP)++ = ((lo & 0x3f) | 0x80); \ @@ -581,7 +649,7 @@ E ## toUtf8(const ENCODING *enc, \ default: \ if (toLim - *toP < 3) { \ *fromP = from; \ - return; \ + return XML_CONVERT_OUTPUT_EXHAUSTED; \ } \ /* 16 bits divided 4, 6, 6 amongst 3 bytes */ \ *(*toP)++ = ((hi >> 4) | UTF8_cval3); \ @@ -591,7 +659,11 @@ E ## toUtf8(const ENCODING *enc, \ case 0xD8: case 0xD9: case 0xDA: case 0xDB: \ if (toLim - *toP < 4) { \ *fromP = from; \ - return; \ + return XML_CONVERT_OUTPUT_EXHAUSTED; \ + } \ + if (fromLim - from < 4) { \ + *fromP = from; \ + return XML_CONVERT_INPUT_INCOMPLETE; \ } \ plane = (((hi & 0x3) << 2) | ((lo >> 6) & 0x3)) + 1; \ *(*toP)++ = ((plane >> 2) | UTF8_cval4); \ @@ -607,20 +679,32 @@ E ## toUtf8(const ENCODING *enc, \ } \ } \ *fromP = from; \ + if (from < fromLim) \ + return XML_CONVERT_INPUT_INCOMPLETE; \ + else \ + return XML_CONVERT_COMPLETED; \ } #define DEFINE_UTF16_TO_UTF16(E) \ -static void PTRCALL \ -E ## toUtf16(const ENCODING *enc, \ +static enum XML_Convert_Result PTRCALL \ +E ## toUtf16(const ENCODING *UNUSED_P(enc), \ const char **fromP, const char *fromLim, \ unsigned short **toP, const unsigned short *toLim) \ { \ + enum XML_Convert_Result res = XML_CONVERT_COMPLETED; \ + fromLim = *fromP + (((fromLim - *fromP) >> 1) << 1); /* shrink to even */ \ /* Avoid copying first half only of surrogate */ \ if (fromLim - *fromP > ((toLim - *toP) << 1) \ - && (GET_HI(fromLim - 2) & 0xF8) == 0xD8) \ + && (GET_HI(fromLim - 2) & 0xF8) == 0xD8) { \ fromLim -= 2; \ - for (; *fromP != fromLim && *toP != toLim; *fromP += 2) \ + res = XML_CONVERT_INPUT_INCOMPLETE; \ + } \ + for (; *fromP < fromLim && *toP < toLim; *fromP += 2) \ *(*toP)++ = (GET_HI(*fromP) << 8) | GET_LO(*fromP); \ + if ((*toP == toLim) && (*fromP < fromLim)) \ + return XML_CONVERT_OUTPUT_EXHAUSTED; \ + else \ + return res; \ } #define SET2(ptr, ch) \ @@ -949,7 +1033,7 @@ streqci(const char *s1, const char *s2) } static void PTRCALL -initUpdatePosition(const ENCODING *enc, const char *ptr, +initUpdatePosition(const ENCODING *UNUSED_P(enc), const char *ptr, const char *end, POSITION *pos) { normal_updatePosition(&utf8_encoding.enc, ptr, end, pos); @@ -1299,7 +1383,7 @@ unknown_isInvalid(const ENCODING *enc, const char *p) return (c & ~0xFFFF) || checkCharRefNumber(c) < 0; } -static void PTRCALL +static enum XML_Convert_Result PTRCALL unknown_toUtf8(const ENCODING *enc, const char **fromP, const char *fromLim, char **toP, const char *toLim) @@ -1310,21 +1394,21 @@ unknown_toUtf8(const ENCODING *enc, const char *utf8; int n; if (*fromP == fromLim) - break; + return XML_CONVERT_COMPLETED; utf8 = uenc->utf8[(unsigned char)**fromP]; n = *utf8++; if (n == 0) { int c = uenc->convert(uenc->userData, *fromP); n = XmlUtf8Encode(c, buf); if (n > toLim - *toP) - break; + return XML_CONVERT_OUTPUT_EXHAUSTED; utf8 = buf; *fromP += (AS_NORMAL_ENCODING(enc)->type[(unsigned char)**fromP] - (BT_LEAD2 - 2)); } else { if (n > toLim - *toP) - break; + return XML_CONVERT_OUTPUT_EXHAUSTED; (*fromP)++; } do { @@ -1333,13 +1417,13 @@ unknown_toUtf8(const ENCODING *enc, } } -static void PTRCALL +static enum XML_Convert_Result PTRCALL unknown_toUtf16(const ENCODING *enc, const char **fromP, const char *fromLim, unsigned short **toP, const unsigned short *toLim) { const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc); - while (*fromP != fromLim && *toP != toLim) { + while (*fromP < fromLim && *toP < toLim) { unsigned short c = uenc->utf16[(unsigned char)**fromP]; if (c == 0) { c = (unsigned short) @@ -1351,6 +1435,11 @@ unknown_toUtf16(const ENCODING *enc, (*fromP)++; *(*toP)++ = c; } + + if ((*toP == toLim) && (*fromP < fromLim)) + return XML_CONVERT_OUTPUT_EXHAUSTED; + else + return XML_CONVERT_COMPLETED; } ENCODING * @@ -1514,7 +1603,7 @@ initScan(const ENCODING * const *encodingTable, { const ENCODING **encPtr; - if (ptr == end) + if (ptr >= end) return XML_TOK_NONE; encPtr = enc->encPtr; if (ptr + 1 == end) { diff --git a/Utilities/cmexpat/lib/xmltok.h b/Utilities/cmexpat/lib/xmltok.h index ca867aa..752007e 100644 --- a/Utilities/cmexpat/lib/xmltok.h +++ b/Utilities/cmexpat/lib/xmltok.h @@ -130,6 +130,12 @@ typedef int (PTRCALL *SCANNER)(const ENCODING *, const char *, const char **); +enum XML_Convert_Result { + XML_CONVERT_COMPLETED = 0, + XML_CONVERT_INPUT_INCOMPLETE = 1, + XML_CONVERT_OUTPUT_EXHAUSTED = 2 /* and therefore potentially input remaining as well */ +}; + struct encoding { SCANNER scanners[XML_N_STATES]; SCANNER literalScanners[XML_N_LITERAL_TYPES]; @@ -158,12 +164,12 @@ struct encoding { const char *ptr, const char *end, const char **badPtr); - void (PTRCALL *utf8Convert)(const ENCODING *enc, + enum XML_Convert_Result (PTRCALL *utf8Convert)(const ENCODING *enc, const char **fromP, const char *fromLim, char **toP, const char *toLim); - void (PTRCALL *utf16Convert)(const ENCODING *enc, + enum XML_Convert_Result (PTRCALL *utf16Convert)(const ENCODING *enc, const char **fromP, const char *fromLim, unsigned short **toP, diff --git a/Utilities/cmexpat/lib/xmltok_impl.c b/Utilities/cmexpat/lib/xmltok_impl.c index 9c2895b..fd0ee22 100644 --- a/Utilities/cmexpat/lib/xmltok_impl.c +++ b/Utilities/cmexpat/lib/xmltok_impl.c @@ -87,27 +87,45 @@ #define PREFIX(ident) ident #endif + +#define HAS_CHARS(enc, ptr, end, count) \ + (end - ptr >= count * MINBPC(enc)) + +#define HAS_CHAR(enc, ptr, end) \ + HAS_CHARS(enc, ptr, end, 1) + +#define REQUIRE_CHARS(enc, ptr, end, count) \ + { \ + if (! HAS_CHARS(enc, ptr, end, count)) { \ + return XML_TOK_PARTIAL; \ + } \ + } + +#define REQUIRE_CHAR(enc, ptr, end) \ + REQUIRE_CHARS(enc, ptr, end, 1) + + /* ptr points to character following "<!-" */ static int PTRCALL PREFIX(scanComment)(const ENCODING *enc, const char *ptr, const char *end, const char **nextTokPtr) { - if (ptr != end) { + if (HAS_CHAR(enc, ptr, end)) { if (!CHAR_MATCHES(enc, ptr, ASCII_MINUS)) { *nextTokPtr = ptr; return XML_TOK_INVALID; } ptr += MINBPC(enc); - while (ptr != end) { + while (HAS_CHAR(enc, ptr, end)) { switch (BYTE_TYPE(enc, ptr)) { INVALID_CASES(ptr, nextTokPtr) case BT_MINUS: - if ((ptr += MINBPC(enc)) == end) - return XML_TOK_PARTIAL; + ptr += MINBPC(enc); + REQUIRE_CHAR(enc, ptr, end); if (CHAR_MATCHES(enc, ptr, ASCII_MINUS)) { - if ((ptr += MINBPC(enc)) == end) - return XML_TOK_PARTIAL; + ptr += MINBPC(enc); + REQUIRE_CHAR(enc, ptr, end); if (!CHAR_MATCHES(enc, ptr, ASCII_GT)) { *nextTokPtr = ptr; return XML_TOK_INVALID; @@ -131,8 +149,7 @@ static int PTRCALL PREFIX(scanDecl)(const ENCODING *enc, const char *ptr, const char *end, const char **nextTokPtr) { - if (ptr == end) - return XML_TOK_PARTIAL; + REQUIRE_CHAR(enc, ptr, end); switch (BYTE_TYPE(enc, ptr)) { case BT_MINUS: return PREFIX(scanComment)(enc, ptr + MINBPC(enc), end, nextTokPtr); @@ -147,11 +164,10 @@ PREFIX(scanDecl)(const ENCODING *enc, const char *ptr, *nextTokPtr = ptr; return XML_TOK_INVALID; } - while (ptr != end) { + while (HAS_CHAR(enc, ptr, end)) { switch (BYTE_TYPE(enc, ptr)) { case BT_PERCNT: - if (ptr + MINBPC(enc) == end) - return XML_TOK_PARTIAL; + REQUIRE_CHARS(enc, ptr, end, 2); /* don't allow <!ENTITY% foo "whatever"> */ switch (BYTE_TYPE(enc, ptr + MINBPC(enc))) { case BT_S: case BT_CR: case BT_LF: case BT_PERCNT: @@ -175,7 +191,7 @@ PREFIX(scanDecl)(const ENCODING *enc, const char *ptr, } static int PTRCALL -PREFIX(checkPiTarget)(const ENCODING *enc, const char *ptr, +PREFIX(checkPiTarget)(const ENCODING *UNUSED_P(enc), const char *ptr, const char *end, int *tokPtr) { int upper = 0; @@ -225,15 +241,14 @@ PREFIX(scanPi)(const ENCODING *enc, const char *ptr, { int tok; const char *target = ptr; - if (ptr == end) - return XML_TOK_PARTIAL; + REQUIRE_CHAR(enc, ptr, end); switch (BYTE_TYPE(enc, ptr)) { CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) default: *nextTokPtr = ptr; return XML_TOK_INVALID; } - while (ptr != end) { + while (HAS_CHAR(enc, ptr, end)) { switch (BYTE_TYPE(enc, ptr)) { CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) case BT_S: case BT_CR: case BT_LF: @@ -242,13 +257,12 @@ PREFIX(scanPi)(const ENCODING *enc, const char *ptr, return XML_TOK_INVALID; } ptr += MINBPC(enc); - while (ptr != end) { + while (HAS_CHAR(enc, ptr, end)) { switch (BYTE_TYPE(enc, ptr)) { INVALID_CASES(ptr, nextTokPtr) case BT_QUEST: ptr += MINBPC(enc); - if (ptr == end) - return XML_TOK_PARTIAL; + REQUIRE_CHAR(enc, ptr, end); if (CHAR_MATCHES(enc, ptr, ASCII_GT)) { *nextTokPtr = ptr + MINBPC(enc); return tok; @@ -266,8 +280,7 @@ PREFIX(scanPi)(const ENCODING *enc, const char *ptr, return XML_TOK_INVALID; } ptr += MINBPC(enc); - if (ptr == end) - return XML_TOK_PARTIAL; + REQUIRE_CHAR(enc, ptr, end); if (CHAR_MATCHES(enc, ptr, ASCII_GT)) { *nextTokPtr = ptr + MINBPC(enc); return tok; @@ -282,15 +295,14 @@ PREFIX(scanPi)(const ENCODING *enc, const char *ptr, } static int PTRCALL -PREFIX(scanCdataSection)(const ENCODING *enc, const char *ptr, +PREFIX(scanCdataSection)(const ENCODING *UNUSED_P(enc), const char *ptr, const char *end, const char **nextTokPtr) { static const char CDATA_LSQB[] = { ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, ASCII_LSQB }; int i; /* CDATA[ */ - if (end - ptr < 6 * MINBPC(enc)) - return XML_TOK_PARTIAL; + REQUIRE_CHARS(enc, ptr, end, 6); for (i = 0; i < 6; i++, ptr += MINBPC(enc)) { if (!CHAR_MATCHES(enc, ptr, CDATA_LSQB[i])) { *nextTokPtr = ptr; @@ -305,7 +317,7 @@ static int PTRCALL PREFIX(cdataSectionTok)(const ENCODING *enc, const char *ptr, const char *end, const char **nextTokPtr) { - if (ptr == end) + if (ptr >= end) return XML_TOK_NONE; if (MINBPC(enc) > 1) { size_t n = end - ptr; @@ -319,13 +331,11 @@ PREFIX(cdataSectionTok)(const ENCODING *enc, const char *ptr, switch (BYTE_TYPE(enc, ptr)) { case BT_RSQB: ptr += MINBPC(enc); - if (ptr == end) - return XML_TOK_PARTIAL; + REQUIRE_CHAR(enc, ptr, end); if (!CHAR_MATCHES(enc, ptr, ASCII_RSQB)) break; ptr += MINBPC(enc); - if (ptr == end) - return XML_TOK_PARTIAL; + REQUIRE_CHAR(enc, ptr, end); if (!CHAR_MATCHES(enc, ptr, ASCII_GT)) { ptr -= MINBPC(enc); break; @@ -334,8 +344,7 @@ PREFIX(cdataSectionTok)(const ENCODING *enc, const char *ptr, return XML_TOK_CDATA_SECT_CLOSE; case BT_CR: ptr += MINBPC(enc); - if (ptr == end) - return XML_TOK_PARTIAL; + REQUIRE_CHAR(enc, ptr, end); if (BYTE_TYPE(enc, ptr) == BT_LF) ptr += MINBPC(enc); *nextTokPtr = ptr; @@ -348,7 +357,7 @@ PREFIX(cdataSectionTok)(const ENCODING *enc, const char *ptr, ptr += MINBPC(enc); break; } - while (ptr != end) { + while (HAS_CHAR(enc, ptr, end)) { switch (BYTE_TYPE(enc, ptr)) { #define LEAD_CASE(n) \ case BT_LEAD ## n: \ @@ -383,19 +392,18 @@ static int PTRCALL PREFIX(scanEndTag)(const ENCODING *enc, const char *ptr, const char *end, const char **nextTokPtr) { - if (ptr == end) - return XML_TOK_PARTIAL; + REQUIRE_CHAR(enc, ptr, end); switch (BYTE_TYPE(enc, ptr)) { CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) default: *nextTokPtr = ptr; return XML_TOK_INVALID; } - while (ptr != end) { + while (HAS_CHAR(enc, ptr, end)) { switch (BYTE_TYPE(enc, ptr)) { CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) case BT_S: case BT_CR: case BT_LF: - for (ptr += MINBPC(enc); ptr != end; ptr += MINBPC(enc)) { + for (ptr += MINBPC(enc); HAS_CHAR(enc, ptr, end); ptr += MINBPC(enc)) { switch (BYTE_TYPE(enc, ptr)) { case BT_S: case BT_CR: case BT_LF: break; @@ -432,7 +440,7 @@ static int PTRCALL PREFIX(scanHexCharRef)(const ENCODING *enc, const char *ptr, const char *end, const char **nextTokPtr) { - if (ptr != end) { + if (HAS_CHAR(enc, ptr, end)) { switch (BYTE_TYPE(enc, ptr)) { case BT_DIGIT: case BT_HEX: @@ -441,7 +449,7 @@ PREFIX(scanHexCharRef)(const ENCODING *enc, const char *ptr, *nextTokPtr = ptr; return XML_TOK_INVALID; } - for (ptr += MINBPC(enc); ptr != end; ptr += MINBPC(enc)) { + for (ptr += MINBPC(enc); HAS_CHAR(enc, ptr, end); ptr += MINBPC(enc)) { switch (BYTE_TYPE(enc, ptr)) { case BT_DIGIT: case BT_HEX: @@ -464,7 +472,7 @@ static int PTRCALL PREFIX(scanCharRef)(const ENCODING *enc, const char *ptr, const char *end, const char **nextTokPtr) { - if (ptr != end) { + if (HAS_CHAR(enc, ptr, end)) { if (CHAR_MATCHES(enc, ptr, ASCII_x)) return PREFIX(scanHexCharRef)(enc, ptr + MINBPC(enc), end, nextTokPtr); switch (BYTE_TYPE(enc, ptr)) { @@ -474,7 +482,7 @@ PREFIX(scanCharRef)(const ENCODING *enc, const char *ptr, *nextTokPtr = ptr; return XML_TOK_INVALID; } - for (ptr += MINBPC(enc); ptr != end; ptr += MINBPC(enc)) { + for (ptr += MINBPC(enc); HAS_CHAR(enc, ptr, end); ptr += MINBPC(enc)) { switch (BYTE_TYPE(enc, ptr)) { case BT_DIGIT: break; @@ -496,8 +504,7 @@ static int PTRCALL PREFIX(scanRef)(const ENCODING *enc, const char *ptr, const char *end, const char **nextTokPtr) { - if (ptr == end) - return XML_TOK_PARTIAL; + REQUIRE_CHAR(enc, ptr, end); switch (BYTE_TYPE(enc, ptr)) { CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) case BT_NUM: @@ -506,7 +513,7 @@ PREFIX(scanRef)(const ENCODING *enc, const char *ptr, const char *end, *nextTokPtr = ptr; return XML_TOK_INVALID; } - while (ptr != end) { + while (HAS_CHAR(enc, ptr, end)) { switch (BYTE_TYPE(enc, ptr)) { CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) case BT_SEMI: @@ -529,7 +536,7 @@ PREFIX(scanAtts)(const ENCODING *enc, const char *ptr, const char *end, #ifdef XML_NS int hadColon = 0; #endif - while (ptr != end) { + while (HAS_CHAR(enc, ptr, end)) { switch (BYTE_TYPE(enc, ptr)) { CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) #ifdef XML_NS @@ -540,8 +547,7 @@ PREFIX(scanAtts)(const ENCODING *enc, const char *ptr, const char *end, } hadColon = 1; ptr += MINBPC(enc); - if (ptr == end) - return XML_TOK_PARTIAL; + REQUIRE_CHAR(enc, ptr, end); switch (BYTE_TYPE(enc, ptr)) { CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) default: @@ -555,8 +561,7 @@ PREFIX(scanAtts)(const ENCODING *enc, const char *ptr, const char *end, int t; ptr += MINBPC(enc); - if (ptr == end) - return XML_TOK_PARTIAL; + REQUIRE_CHAR(enc, ptr, end); t = BYTE_TYPE(enc, ptr); if (t == BT_EQUALS) break; @@ -579,8 +584,7 @@ PREFIX(scanAtts)(const ENCODING *enc, const char *ptr, const char *end, #endif for (;;) { ptr += MINBPC(enc); - if (ptr == end) - return XML_TOK_PARTIAL; + REQUIRE_CHAR(enc, ptr, end); open = BYTE_TYPE(enc, ptr); if (open == BT_QUOT || open == BT_APOS) break; @@ -598,8 +602,7 @@ PREFIX(scanAtts)(const ENCODING *enc, const char *ptr, const char *end, /* in attribute value */ for (;;) { int t; - if (ptr == end) - return XML_TOK_PARTIAL; + REQUIRE_CHAR(enc, ptr, end); t = BYTE_TYPE(enc, ptr); if (t == open) break; @@ -624,8 +627,7 @@ PREFIX(scanAtts)(const ENCODING *enc, const char *ptr, const char *end, } } ptr += MINBPC(enc); - if (ptr == end) - return XML_TOK_PARTIAL; + REQUIRE_CHAR(enc, ptr, end); switch (BYTE_TYPE(enc, ptr)) { case BT_S: case BT_CR: @@ -642,8 +644,7 @@ PREFIX(scanAtts)(const ENCODING *enc, const char *ptr, const char *end, /* ptr points to closing quote */ for (;;) { ptr += MINBPC(enc); - if (ptr == end) - return XML_TOK_PARTIAL; + REQUIRE_CHAR(enc, ptr, end); switch (BYTE_TYPE(enc, ptr)) { CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) case BT_S: case BT_CR: case BT_LF: @@ -655,8 +656,7 @@ PREFIX(scanAtts)(const ENCODING *enc, const char *ptr, const char *end, case BT_SOL: sol: ptr += MINBPC(enc); - if (ptr == end) - return XML_TOK_PARTIAL; + REQUIRE_CHAR(enc, ptr, end); if (!CHAR_MATCHES(enc, ptr, ASCII_GT)) { *nextTokPtr = ptr; return XML_TOK_INVALID; @@ -688,13 +688,12 @@ PREFIX(scanLt)(const ENCODING *enc, const char *ptr, const char *end, #ifdef XML_NS int hadColon; #endif - if (ptr == end) - return XML_TOK_PARTIAL; + REQUIRE_CHAR(enc, ptr, end); switch (BYTE_TYPE(enc, ptr)) { CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) case BT_EXCL: - if ((ptr += MINBPC(enc)) == end) - return XML_TOK_PARTIAL; + ptr += MINBPC(enc); + REQUIRE_CHAR(enc, ptr, end); switch (BYTE_TYPE(enc, ptr)) { case BT_MINUS: return PREFIX(scanComment)(enc, ptr + MINBPC(enc), end, nextTokPtr); @@ -716,7 +715,7 @@ PREFIX(scanLt)(const ENCODING *enc, const char *ptr, const char *end, hadColon = 0; #endif /* we have a start-tag */ - while (ptr != end) { + while (HAS_CHAR(enc, ptr, end)) { switch (BYTE_TYPE(enc, ptr)) { CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) #ifdef XML_NS @@ -727,8 +726,7 @@ PREFIX(scanLt)(const ENCODING *enc, const char *ptr, const char *end, } hadColon = 1; ptr += MINBPC(enc); - if (ptr == end) - return XML_TOK_PARTIAL; + REQUIRE_CHAR(enc, ptr, end); switch (BYTE_TYPE(enc, ptr)) { CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) default: @@ -740,7 +738,7 @@ PREFIX(scanLt)(const ENCODING *enc, const char *ptr, const char *end, case BT_S: case BT_CR: case BT_LF: { ptr += MINBPC(enc); - while (ptr != end) { + while (HAS_CHAR(enc, ptr, end)) { switch (BYTE_TYPE(enc, ptr)) { CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) case BT_GT: @@ -765,8 +763,7 @@ PREFIX(scanLt)(const ENCODING *enc, const char *ptr, const char *end, case BT_SOL: sol: ptr += MINBPC(enc); - if (ptr == end) - return XML_TOK_PARTIAL; + REQUIRE_CHAR(enc, ptr, end); if (!CHAR_MATCHES(enc, ptr, ASCII_GT)) { *nextTokPtr = ptr; return XML_TOK_INVALID; @@ -785,7 +782,7 @@ static int PTRCALL PREFIX(contentTok)(const ENCODING *enc, const char *ptr, const char *end, const char **nextTokPtr) { - if (ptr == end) + if (ptr >= end) return XML_TOK_NONE; if (MINBPC(enc) > 1) { size_t n = end - ptr; @@ -803,7 +800,7 @@ PREFIX(contentTok)(const ENCODING *enc, const char *ptr, const char *end, return PREFIX(scanRef)(enc, ptr + MINBPC(enc), end, nextTokPtr); case BT_CR: ptr += MINBPC(enc); - if (ptr == end) + if (! HAS_CHAR(enc, ptr, end)) return XML_TOK_TRAILING_CR; if (BYTE_TYPE(enc, ptr) == BT_LF) ptr += MINBPC(enc); @@ -814,12 +811,12 @@ PREFIX(contentTok)(const ENCODING *enc, const char *ptr, const char *end, return XML_TOK_DATA_NEWLINE; case BT_RSQB: ptr += MINBPC(enc); - if (ptr == end) + if (! HAS_CHAR(enc, ptr, end)) return XML_TOK_TRAILING_RSQB; if (!CHAR_MATCHES(enc, ptr, ASCII_RSQB)) break; ptr += MINBPC(enc); - if (ptr == end) + if (! HAS_CHAR(enc, ptr, end)) return XML_TOK_TRAILING_RSQB; if (!CHAR_MATCHES(enc, ptr, ASCII_GT)) { ptr -= MINBPC(enc); @@ -832,7 +829,7 @@ PREFIX(contentTok)(const ENCODING *enc, const char *ptr, const char *end, ptr += MINBPC(enc); break; } - while (ptr != end) { + while (HAS_CHAR(enc, ptr, end)) { switch (BYTE_TYPE(enc, ptr)) { #define LEAD_CASE(n) \ case BT_LEAD ## n: \ @@ -845,12 +842,12 @@ PREFIX(contentTok)(const ENCODING *enc, const char *ptr, const char *end, LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) #undef LEAD_CASE case BT_RSQB: - if (ptr + MINBPC(enc) != end) { + if (HAS_CHARS(enc, ptr, end, 2)) { if (!CHAR_MATCHES(enc, ptr + MINBPC(enc), ASCII_RSQB)) { ptr += MINBPC(enc); break; } - if (ptr + 2*MINBPC(enc) != end) { + if (HAS_CHARS(enc, ptr, end, 3)) { if (!CHAR_MATCHES(enc, ptr + 2*MINBPC(enc), ASCII_GT)) { ptr += MINBPC(enc); break; @@ -884,8 +881,7 @@ static int PTRCALL PREFIX(scanPercent)(const ENCODING *enc, const char *ptr, const char *end, const char **nextTokPtr) { - if (ptr == end) - return XML_TOK_PARTIAL; + REQUIRE_CHAR(enc, ptr, end); switch (BYTE_TYPE(enc, ptr)) { CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) case BT_S: case BT_LF: case BT_CR: case BT_PERCNT: @@ -895,7 +891,7 @@ PREFIX(scanPercent)(const ENCODING *enc, const char *ptr, const char *end, *nextTokPtr = ptr; return XML_TOK_INVALID; } - while (ptr != end) { + while (HAS_CHAR(enc, ptr, end)) { switch (BYTE_TYPE(enc, ptr)) { CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) case BT_SEMI: @@ -913,15 +909,14 @@ static int PTRCALL PREFIX(scanPoundName)(const ENCODING *enc, const char *ptr, const char *end, const char **nextTokPtr) { - if (ptr == end) - return XML_TOK_PARTIAL; + REQUIRE_CHAR(enc, ptr, end); switch (BYTE_TYPE(enc, ptr)) { CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) default: *nextTokPtr = ptr; return XML_TOK_INVALID; } - while (ptr != end) { + while (HAS_CHAR(enc, ptr, end)) { switch (BYTE_TYPE(enc, ptr)) { CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) case BT_CR: case BT_LF: case BT_S: @@ -941,7 +936,7 @@ PREFIX(scanLit)(int open, const ENCODING *enc, const char *ptr, const char *end, const char **nextTokPtr) { - while (ptr != end) { + while (HAS_CHAR(enc, ptr, end)) { int t = BYTE_TYPE(enc, ptr); switch (t) { INVALID_CASES(ptr, nextTokPtr) @@ -950,7 +945,7 @@ PREFIX(scanLit)(int open, const ENCODING *enc, ptr += MINBPC(enc); if (t != open) break; - if (ptr == end) + if (! HAS_CHAR(enc, ptr, end)) return -XML_TOK_LITERAL; *nextTokPtr = ptr; switch (BYTE_TYPE(enc, ptr)) { @@ -973,7 +968,7 @@ PREFIX(prologTok)(const ENCODING *enc, const char *ptr, const char *end, const char **nextTokPtr) { int tok; - if (ptr == end) + if (ptr >= end) return XML_TOK_NONE; if (MINBPC(enc) > 1) { size_t n = end - ptr; @@ -992,8 +987,7 @@ PREFIX(prologTok)(const ENCODING *enc, const char *ptr, const char *end, case BT_LT: { ptr += MINBPC(enc); - if (ptr == end) - return XML_TOK_PARTIAL; + REQUIRE_CHAR(enc, ptr, end); switch (BYTE_TYPE(enc, ptr)) { case BT_EXCL: return PREFIX(scanDecl)(enc, ptr + MINBPC(enc), end, nextTokPtr); @@ -1021,7 +1015,7 @@ PREFIX(prologTok)(const ENCODING *enc, const char *ptr, const char *end, case BT_S: case BT_LF: for (;;) { ptr += MINBPC(enc); - if (ptr == end) + if (! HAS_CHAR(enc, ptr, end)) break; switch (BYTE_TYPE(enc, ptr)) { case BT_S: case BT_LF: @@ -1048,11 +1042,10 @@ PREFIX(prologTok)(const ENCODING *enc, const char *ptr, const char *end, return XML_TOK_OPEN_BRACKET; case BT_RSQB: ptr += MINBPC(enc); - if (ptr == end) + if (! HAS_CHAR(enc, ptr, end)) return -XML_TOK_CLOSE_BRACKET; if (CHAR_MATCHES(enc, ptr, ASCII_RSQB)) { - if (ptr + MINBPC(enc) == end) - return XML_TOK_PARTIAL; + REQUIRE_CHARS(enc, ptr, end, 2); if (CHAR_MATCHES(enc, ptr + MINBPC(enc), ASCII_GT)) { *nextTokPtr = ptr + 2*MINBPC(enc); return XML_TOK_COND_SECT_CLOSE; @@ -1065,7 +1058,7 @@ PREFIX(prologTok)(const ENCODING *enc, const char *ptr, const char *end, return XML_TOK_OPEN_PAREN; case BT_RPAR: ptr += MINBPC(enc); - if (ptr == end) + if (! HAS_CHAR(enc, ptr, end)) return -XML_TOK_CLOSE_PAREN; switch (BYTE_TYPE(enc, ptr)) { case BT_AST: @@ -1141,7 +1134,7 @@ PREFIX(prologTok)(const ENCODING *enc, const char *ptr, const char *end, *nextTokPtr = ptr; return XML_TOK_INVALID; } - while (ptr != end) { + while (HAS_CHAR(enc, ptr, end)) { switch (BYTE_TYPE(enc, ptr)) { CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) case BT_GT: case BT_RPAR: case BT_COMMA: @@ -1154,8 +1147,7 @@ PREFIX(prologTok)(const ENCODING *enc, const char *ptr, const char *end, ptr += MINBPC(enc); switch (tok) { case XML_TOK_NAME: - if (ptr == end) - return XML_TOK_PARTIAL; + REQUIRE_CHAR(enc, ptr, end); tok = XML_TOK_PREFIXED_NAME; switch (BYTE_TYPE(enc, ptr)) { CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) @@ -1204,10 +1196,10 @@ PREFIX(attributeValueTok)(const ENCODING *enc, const char *ptr, const char *end, const char **nextTokPtr) { const char *start; - if (ptr == end) + if (ptr >= end) return XML_TOK_NONE; start = ptr; - while (ptr != end) { + while (HAS_CHAR(enc, ptr, end)) { switch (BYTE_TYPE(enc, ptr)) { #define LEAD_CASE(n) \ case BT_LEAD ## n: ptr += n; break; @@ -1232,7 +1224,7 @@ PREFIX(attributeValueTok)(const ENCODING *enc, const char *ptr, case BT_CR: if (ptr == start) { ptr += MINBPC(enc); - if (ptr == end) + if (! HAS_CHAR(enc, ptr, end)) return XML_TOK_TRAILING_CR; if (BYTE_TYPE(enc, ptr) == BT_LF) ptr += MINBPC(enc); @@ -1262,10 +1254,10 @@ PREFIX(entityValueTok)(const ENCODING *enc, const char *ptr, const char *end, const char **nextTokPtr) { const char *start; - if (ptr == end) + if (ptr >= end) return XML_TOK_NONE; start = ptr; - while (ptr != end) { + while (HAS_CHAR(enc, ptr, end)) { switch (BYTE_TYPE(enc, ptr)) { #define LEAD_CASE(n) \ case BT_LEAD ## n: ptr += n; break; @@ -1294,7 +1286,7 @@ PREFIX(entityValueTok)(const ENCODING *enc, const char *ptr, case BT_CR: if (ptr == start) { ptr += MINBPC(enc); - if (ptr == end) + if (! HAS_CHAR(enc, ptr, end)) return XML_TOK_TRAILING_CR; if (BYTE_TYPE(enc, ptr) == BT_LF) ptr += MINBPC(enc); @@ -1326,15 +1318,15 @@ PREFIX(ignoreSectionTok)(const ENCODING *enc, const char *ptr, end = ptr + n; } } - while (ptr != end) { + while (HAS_CHAR(enc, ptr, end)) { switch (BYTE_TYPE(enc, ptr)) { INVALID_CASES(ptr, nextTokPtr) case BT_LT: - if ((ptr += MINBPC(enc)) == end) - return XML_TOK_PARTIAL; + ptr += MINBPC(enc); + REQUIRE_CHAR(enc, ptr, end); if (CHAR_MATCHES(enc, ptr, ASCII_EXCL)) { - if ((ptr += MINBPC(enc)) == end) - return XML_TOK_PARTIAL; + ptr += MINBPC(enc); + REQUIRE_CHAR(enc, ptr, end); if (CHAR_MATCHES(enc, ptr, ASCII_LSQB)) { ++level; ptr += MINBPC(enc); @@ -1342,11 +1334,11 @@ PREFIX(ignoreSectionTok)(const ENCODING *enc, const char *ptr, } break; case BT_RSQB: - if ((ptr += MINBPC(enc)) == end) - return XML_TOK_PARTIAL; + ptr += MINBPC(enc); + REQUIRE_CHAR(enc, ptr, end); if (CHAR_MATCHES(enc, ptr, ASCII_RSQB)) { - if ((ptr += MINBPC(enc)) == end) - return XML_TOK_PARTIAL; + ptr += MINBPC(enc); + REQUIRE_CHAR(enc, ptr, end); if (CHAR_MATCHES(enc, ptr, ASCII_GT)) { ptr += MINBPC(enc); if (level == 0) { @@ -1373,7 +1365,7 @@ PREFIX(isPublicId)(const ENCODING *enc, const char *ptr, const char *end, { ptr += MINBPC(enc); end -= MINBPC(enc); - for (; ptr != end; ptr += MINBPC(enc)) { + for (; HAS_CHAR(enc, ptr, end); ptr += MINBPC(enc)) { switch (BYTE_TYPE(enc, ptr)) { case BT_DIGIT: case BT_HEX: @@ -1521,7 +1513,7 @@ PREFIX(getAtts)(const ENCODING *enc, const char *ptr, } static int PTRFASTCALL -PREFIX(charRefNumber)(const ENCODING *enc, const char *ptr) +PREFIX(charRefNumber)(const ENCODING *UNUSED_P(enc), const char *ptr) { int result = 0; /* skip &# */ @@ -1565,7 +1557,7 @@ PREFIX(charRefNumber)(const ENCODING *enc, const char *ptr) } static int PTRCALL -PREFIX(predefinedEntityName)(const ENCODING *enc, const char *ptr, +PREFIX(predefinedEntityName)(const ENCODING *UNUSED_P(enc), const char *ptr, const char *end) { switch ((end - ptr)/MINBPC(enc)) { @@ -1683,11 +1675,11 @@ PREFIX(sameName)(const ENCODING *enc, const char *ptr1, const char *ptr2) } static int PTRCALL -PREFIX(nameMatchesAscii)(const ENCODING *enc, const char *ptr1, +PREFIX(nameMatchesAscii)(const ENCODING *UNUSED_P(enc), const char *ptr1, const char *end1, const char *ptr2) { for (; *ptr2; ptr1 += MINBPC(enc), ptr2++) { - if (ptr1 == end1) + if (end1 - ptr1 < MINBPC(enc)) return 0; if (!CHAR_MATCHES(enc, ptr1, *ptr2)) return 0; @@ -1744,7 +1736,7 @@ PREFIX(updatePosition)(const ENCODING *enc, const char *end, POSITION *pos) { - while (ptr < end) { + while (HAS_CHAR(enc, ptr, end)) { switch (BYTE_TYPE(enc, ptr)) { #define LEAD_CASE(n) \ case BT_LEAD ## n: \ @@ -1760,7 +1752,7 @@ PREFIX(updatePosition)(const ENCODING *enc, case BT_CR: pos->lineNumber++; ptr += MINBPC(enc); - if (ptr != end && BYTE_TYPE(enc, ptr) == BT_LF) + if (HAS_CHAR(enc, ptr, end) && BYTE_TYPE(enc, ptr) == BT_LF) ptr += MINBPC(enc); pos->columnNumber = (XML_Size)-1; break; diff --git a/Utilities/cmlibarchive/CMakeLists.txt b/Utilities/cmlibarchive/CMakeLists.txt index 453a737..09bef51 100644 --- a/Utilities/cmlibarchive/CMakeLists.txt +++ b/Utilities/cmlibarchive/CMakeLists.txt @@ -509,6 +509,7 @@ IF(ENABLE_OPENSSL AND NOT CMAKE_SYSTEM_NAME MATCHES "Darwin") FIND_PACKAGE(OpenSSL) IF(OPENSSL_FOUND) SET(HAVE_LIBCRYPTO 1) + INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR}) ENDIF(OPENSSL_FOUND) ELSE() SET(OPENSSL_FOUND FALSE) # Override cached value |