diff options
-rw-r--r-- | Help/manual/cmake.1.rst | 2 | ||||
-rw-r--r-- | Modules/CheckLanguage.cmake | 16 | ||||
-rw-r--r-- | Modules/FindPkgConfig.cmake | 21 | ||||
-rw-r--r-- | Modules/FindPython/Support.cmake | 8 | ||||
-rw-r--r-- | Modules/FindRuby.cmake | 143 | ||||
-rw-r--r-- | Source/CMakeVersion.cmake | 2 | ||||
-rw-r--r-- | Source/cmake.cxx | 3 | ||||
-rw-r--r-- | Tests/CMakeLists.txt | 4 | ||||
-rw-r--r-- | Tests/FindPython/CMakeLists.txt | 56 | ||||
-rw-r--r-- | Tests/FindPython/Python/CMakeLists.txt | 26 | ||||
-rw-r--r-- | Tests/FindRuby/CMakeLists.txt | 44 | ||||
-rw-r--r-- | Tests/FindRuby/Fail/CMakeLists.txt | 5 | ||||
-rw-r--r-- | Tests/FindRuby/FailExact/CMakeLists.txt | 8 | ||||
-rw-r--r-- | Tests/FindRuby/Test/CMakeLists.txt | 14 | ||||
-rw-r--r-- | Tests/FindRuby/Test/ruby_version.c | 7 | ||||
-rw-r--r-- | Tests/RunCMake/FindPkgConfig/PkgConfigDoesNotExist-stdout.txt | 6 | ||||
-rw-r--r-- | Tests/RunCMake/FindPkgConfig/PkgConfigDoesNotExist.cmake | 4 | ||||
-rw-r--r-- | Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake | 2 | ||||
-rwxr-xr-x | bootstrap | 2 |
19 files changed, 290 insertions, 83 deletions
diff --git a/Help/manual/cmake.1.rst b/Help/manual/cmake.1.rst index 429cba4..e497890 100644 --- a/Help/manual/cmake.1.rst +++ b/Help/manual/cmake.1.rst @@ -266,7 +266,7 @@ Options Prints each trace line in a human-readable format. This is the default format. - ``json`` + ``json-v1`` Prints each line as a separate JSON document. Each document is separated by a newline ( ``\n`` ). It is guaranteed that no newline characters will be present inside a JSON document. diff --git a/Modules/CheckLanguage.cmake b/Modules/CheckLanguage.cmake index 997cc8d..f48107a 100644 --- a/Modules/CheckLanguage.cmake +++ b/Modules/CheckLanguage.cmake @@ -47,7 +47,7 @@ macro(check_language lang) set(extra_compiler_variables "set(CMAKE_CUDA_HOST_COMPILER \\\"\${CMAKE_CUDA_HOST_COMPILER}\\\")") endif() - set(content + set(_cl_content "cmake_minimum_required(VERSION ${CMAKE_VERSION}) project(Check${lang} ${lang}) file(WRITE \"\${CMAKE_CURRENT_BINARY_DIR}/result.cmake\" @@ -57,7 +57,7 @@ file(WRITE \"\${CMAKE_CURRENT_BINARY_DIR}/result.cmake\" ) file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Check${lang}/CMakeLists.txt" - "${content}") + "${_cl_content}") if(CMAKE_GENERATOR_INSTANCE) set(_D_CMAKE_GENERATOR_INSTANCE "-DCMAKE_GENERATOR_INSTANCE:INTERNAL=${CMAKE_GENERATOR_INSTANCE}") else() @@ -75,22 +75,22 @@ file(WRITE \"\${CMAKE_CURRENT_BINARY_DIR}/result.cmake\" -T "${CMAKE_GENERATOR_TOOLSET}" ${_D_CMAKE_GENERATOR_INSTANCE} ${_D_CMAKE_MAKE_PROGRAM} - OUTPUT_VARIABLE output - ERROR_VARIABLE output - RESULT_VARIABLE result + OUTPUT_VARIABLE _cl_output + ERROR_VARIABLE _cl_output + RESULT_VARIABLE _cl_result ) include(${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Check${lang}/result.cmake OPTIONAL) - if(CMAKE_${lang}_COMPILER AND "${result}" STREQUAL "0") + if(CMAKE_${lang}_COMPILER AND "${_cl_result}" STREQUAL "0") file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log "${_desc} passed with the following output:\n" - "${output}\n") + "${_cl_output}\n") set(_CHECK_COMPILER_STATUS CHECK_PASS) else() set(CMAKE_${lang}_COMPILER NOTFOUND) set(_CHECK_COMPILER_STATUS CHECK_FAIL) file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log "${_desc} failed with the following output:\n" - "${output}\n") + "${_cl_output}\n") endif() message(${_CHECK_COMPILER_STATUS} "${CMAKE_${lang}_COMPILER}") set(CMAKE_${lang}_COMPILER "${CMAKE_${lang}_COMPILER}" CACHE FILEPATH "${lang} compiler") diff --git a/Modules/FindPkgConfig.cmake b/Modules/FindPkgConfig.cmake index c79f20f..b7e6442 100644 --- a/Modules/FindPkgConfig.cmake +++ b/Modules/FindPkgConfig.cmake @@ -34,16 +34,31 @@ endif() find_program(PKG_CONFIG_EXECUTABLE NAMES pkg-config DOC "pkg-config executable") mark_as_advanced(PKG_CONFIG_EXECUTABLE) +set(_PKG_CONFIG_FAILURE_MESSAGE "") if (PKG_CONFIG_EXECUTABLE) execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --version - OUTPUT_VARIABLE PKG_CONFIG_VERSION_STRING - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) + OUTPUT_VARIABLE PKG_CONFIG_VERSION_STRING OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_VARIABLE _PKG_CONFIG_VERSION_ERROR ERROR_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE _PKG_CONFIG_VERSION_RESULT + ) + + if (NOT _PKG_CONFIG_VERSION_RESULT EQUAL 0) + string(REPLACE "\n" "\n " _PKG_CONFIG_VERSION_ERROR " ${_PKG_CONFIG_VERSION_ERROR}") + string(APPEND _PKG_CONFIG_FAILURE_MESSAGE + "The command\n" + " \"${PKG_CONFIG_EXECUTABLE}\" --version\n" + " failed with output\n${_PKG_CONFIG_VERSION_ERROR}" + ) + set(PKG_CONFIG_EXECUTABLE "") + unset(PKG_CONFIG_VERSION_STRING) + endif () + unset(_PKG_CONFIG_VERSION_RESULT) endif () include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) find_package_handle_standard_args(PkgConfig REQUIRED_VARS PKG_CONFIG_EXECUTABLE + REASON_FAILURE_MESSAGE "${_PKG_CONFIG_FAILURE_MESSAGE}" VERSION_VAR PKG_CONFIG_VERSION_STRING) # This is needed because the module name is "PkgConfig" but the name of diff --git a/Modules/FindPython/Support.cmake b/Modules/FindPython/Support.cmake index 77b6562..a40d7f7 100644 --- a/Modules/FindPython/Support.cmake +++ b/Modules/FindPython/Support.cmake @@ -314,7 +314,7 @@ function (_PYTHON_GET_CONFIG_VAR _PYTHON_PGCV_VALUE NAME) list (REMOVE_DUPLICATES _values) elseif (NAME STREQUAL "SOABI") # clean-up: remove prefix character and suffix - string (REGEX REPLACE "^[.-](.+)(${CMAKE_SHARED_LIBRARY_SUFFIX}|\.(so|pyd))$" "\\1" _values "${_values}") + string (REGEX REPLACE "^[.-](.+)(${CMAKE_SHARED_LIBRARY_SUFFIX}|\\.(so|pyd))$" "\\1" _values "${_values}") endif() endif() endif() @@ -355,7 +355,7 @@ function (_PYTHON_GET_CONFIG_VAR _PYTHON_PGCV_VALUE NAME) list (GET _soabi 1 _values) if (_values) # clean-up: remove prefix character and suffix - string (REGEX REPLACE "^[.-](.+)(${CMAKE_SHARED_LIBRARY_SUFFIX}|\.(so|pyd))$" "\\1" _values "${_values}") + string (REGEX REPLACE "^[.-](.+)(${CMAKE_SHARED_LIBRARY_SUFFIX}|\\.(so|pyd))$" "\\1" _values "${_values}") endif() endif() endif() @@ -525,8 +525,8 @@ function (_PYTHON_VALIDATE_INTERPRETER) set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE PROPERTY VALUE "${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND") else() # check that version is OK - string(REGEX REPLACE "^([0-9]+)\." "\\1" major_version "${version}") - string(REGEX REPLACE "^([0-9]+)\." "\\1" expected_major_version "${expected_version}") + string(REGEX REPLACE "^([0-9]+)\\..*$" "\\1" major_version "${version}") + string(REGEX REPLACE "^([0-9]+)\\.?.*$" "\\1" expected_major_version "${expected_version}") if (NOT major_version VERSION_EQUAL expected_major_version OR NOT version VERSION_GREATER_EQUAL expected_version) set (_${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE "Wrong version for the interpreter \"${_${_PYTHON_PREFIX}_EXECUTABLE}\"") diff --git a/Modules/FindRuby.cmake b/Modules/FindRuby.cmake index 5df242b..1e010bf 100644 --- a/Modules/FindRuby.cmake +++ b/Modules/FindRuby.cmake @@ -8,25 +8,42 @@ FindRuby Find Ruby This module finds if Ruby is installed and determines where the -include files and libraries are. Ruby 1.8, 1.9, 2.0 and 2.1 are +include files and libraries are. Ruby 1.8 through 2.7 are supported. The minimum required version of Ruby can be specified using the -standard syntax, e.g. find_package(Ruby 1.8) +standard syntax, e.g. -It also determines what the name of the library is. This code sets -the following variables: +.. code-block:: cmake + find_package(Ruby 2.5.1 EXACT REQUIRED) + # OR + find_package(Ruby 2.4) + +It also determines what the name of the library is. + +Result Variables +^^^^^^^^^^^^^^^^ + +This module will set the following variables in your project: + +``Ruby_FOUND`` + set to true if ruby was found successfully ``Ruby_EXECUTABLE`` full path to the ruby binary ``Ruby_INCLUDE_DIRS`` include dirs to be used when using the ruby library -``Ruby_LIBRARY`` - full path to the ruby library +``Ruby_LIBRARIES`` + libraries needed to use ruby from C. ``Ruby_VERSION`` the version of ruby which was found, e.g. "1.8.7" -``Ruby_FOUND`` - set to true if ruby ws found successfully +``Ruby_VERSION_MAJOR`` + Ruby major version. +``Ruby_VERSION_MINOR`` + Ruby minor version. +``Ruby_VERSION_PATCH`` + Ruby patch version. + Also: @@ -63,37 +80,57 @@ endforeach() # on which version of ruby is required set(_Ruby_POSSIBLE_EXECUTABLE_NAMES ruby) -# if 1.9 is required, don't look for ruby18 and ruby1.8, default to version 1.8 -if(DEFINED Ruby_FIND_VERSION_MAJOR AND DEFINED Ruby_FIND_VERSION_MINOR) - set(Ruby_FIND_VERSION_SHORT_NODOT "${Ruby_FIND_VERSION_MAJOR}${Ruby_FIND_VERSION_MINOR}") - # we can't construct that if only major version is given - set(_Ruby_POSSIBLE_EXECUTABLE_NAMES - ruby${Ruby_FIND_VERSION_MAJOR}.${Ruby_FIND_VERSION_MINOR} - ruby${Ruby_FIND_VERSION_MAJOR}${Ruby_FIND_VERSION_MINOR} - ${_Ruby_POSSIBLE_EXECUTABLE_NAMES}) -else() - set(Ruby_FIND_VERSION_SHORT_NODOT "18") +# If not specified, allow everything as far back as 1.8.0 +if(NOT DEFINED Ruby_FIND_VERSION_MAJOR) + set(Ruby_FIND_VERSION "1.8.0") + set(Ruby_FIND_VERSION_MAJOR 1) + set(Ruby_FIND_VERSION_MINOR 8) + set(Ruby_FIND_VERSION_PATCH 0) +endif() + +if(_Ruby_DEBUG_OUTPUT) + message("Ruby_FIND_VERSION=${Ruby_FIND_VERSION}") + message("Ruby_FIND_VERSION_MAJOR=${Ruby_FIND_VERSION_MAJOR}") + message("Ruby_FIND_VERSION_MINOR=${Ruby_FIND_VERSION_MINOR}") + message("Ruby_FIND_VERSION_PATCH=${Ruby_FIND_VERSION_PATCH}") endif() +set(Ruby_FIND_VERSION_SHORT_NODOT "${Ruby_FIND_VERSION_MAJOR}${Ruby_FIND_VERSION_MINOR}") + +# Set name of possible executables, ignoring the minor +# Eg: +# 2.1.1 => from ruby27 to ruby21 included +# 2.1 => from ruby27 to ruby21 included +# 2 => from ruby26 to ruby20 included +# empty => from ruby27 to ruby18 included if(NOT Ruby_FIND_VERSION_EXACT) - list(APPEND _Ruby_POSSIBLE_EXECUTABLE_NAMES ruby2.4 ruby24) - list(APPEND _Ruby_POSSIBLE_EXECUTABLE_NAMES ruby2.3 ruby23) - list(APPEND _Ruby_POSSIBLE_EXECUTABLE_NAMES ruby2.2 ruby22) - list(APPEND _Ruby_POSSIBLE_EXECUTABLE_NAMES ruby2.1 ruby21) - list(APPEND _Ruby_POSSIBLE_EXECUTABLE_NAMES ruby2.0 ruby20) - list(APPEND _Ruby_POSSIBLE_EXECUTABLE_NAMES ruby1.9 ruby19) - - # if we want a version below 1.9, also look for ruby 1.8 - if("${Ruby_FIND_VERSION_SHORT_NODOT}" VERSION_LESS "19") - list(APPEND _Ruby_POSSIBLE_EXECUTABLE_NAMES ruby1.8 ruby18) - endif() + + foreach(_ruby_version RANGE 27 18 -1) + string(SUBSTRING "${_ruby_version}" 0 1 _ruby_major_version) + string(SUBSTRING "${_ruby_version}" 1 1 _ruby_minor_version) + + if(NOT "${_ruby_major_version}${_ruby_minor_version}" VERSION_LESS ${Ruby_FIND_VERSION_SHORT_NODOT}) + # Append both rubyX.Y and rubyXY (eg: ruby2.7 ruby27) + list(APPEND _Ruby_POSSIBLE_EXECUTABLE_NAMES ruby${_ruby_major_version}.${_ruby_minor_version} ruby${_ruby_major_version}${_ruby_minor_version}) + else() + break() + endif() + + endforeach() list(REMOVE_DUPLICATES _Ruby_POSSIBLE_EXECUTABLE_NAMES) endif() -find_program(Ruby_EXECUTABLE NAMES ${_Ruby_POSSIBLE_EXECUTABLE_NAMES}) +if(_Ruby_DEBUG_OUTPUT) + message("_Ruby_POSSIBLE_EXECUTABLE_NAMES=${_Ruby_POSSIBLE_EXECUTABLE_NAMES}") +endif() -if(Ruby_EXECUTABLE AND NOT Ruby_VERSION_MAJOR) +find_program (Ruby_EXECUTABLE + NAMES ${_Ruby_POSSIBLE_EXECUTABLE_NAMES} + NAMES_PER_DIR + ) + +if(Ruby_EXECUTABLE AND NOT Ruby_VERSION_MAJOR) function(_RUBY_CONFIG_VAR RBVAR OUTVAR) execute_process(COMMAND ${Ruby_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['${RBVAR}']" RESULT_VARIABLE _Ruby_SUCCESS @@ -205,6 +242,21 @@ if(Ruby_EXECUTABLE AND NOT Ruby_VERSION_MAJOR) set(Ruby_VERSION_MAJOR 2) set(Ruby_VERSION_MINOR 4) endif() + # check whether we found 2.5.x + if(${Ruby_EXECUTABLE} MATCHES "ruby2\\.?5") + set(Ruby_VERSION_MAJOR 2) + set(Ruby_VERSION_MINOR 5) + endif() + # check whether we found 2.6.x + if(${Ruby_EXECUTABLE} MATCHES "ruby2\\.?6") + set(Ruby_VERSION_MAJOR 2) + set(Ruby_VERSION_MINOR 6) + endif() + # check whether we found 2.7.x + if(${Ruby_EXECUTABLE} MATCHES "ruby2\\.?7") + set(Ruby_VERSION_MAJOR 2) + set(Ruby_VERSION_MINOR 7) + endif() endif() if(Ruby_VERSION_MAJOR) @@ -222,10 +274,10 @@ find_path(Ruby_INCLUDE_DIR /usr/lib/ruby/${_Ruby_VERSION_SHORT}/i586-linux-gnu/ ) -set(Ruby_INCLUDE_DIRS ${Ruby_INCLUDE_DIR} ) +set(Ruby_INCLUDE_DIRS ${Ruby_INCLUDE_DIR}) # if ruby > 1.8 is required or if ruby > 1.8 was found, search for the config.h dir -if( "${Ruby_FIND_VERSION_SHORT_NODOT}" GREATER 18 OR "${_Ruby_VERSION_SHORT_NODOT}" GREATER 18 OR Ruby_HDR_DIR) +if( Ruby_FIND_VERSION VERSION_GREATER_EQUAL "1.9" OR Ruby_VERSION VERSION_GREATER_EQUAL "1.9" OR Ruby_HDR_DIR) find_path(Ruby_CONFIG_INCLUDE_DIR NAMES ruby/config.h config.h HINTS @@ -242,21 +294,10 @@ endif() set(_Ruby_POSSIBLE_LIB_NAMES ruby ruby-static ruby${_Ruby_VERSION_SHORT} ruby${_Ruby_VERSION_SHORT_NODOT} ruby-${_Ruby_VERSION_SHORT} ruby-${Ruby_VERSION}) if(WIN32) - set( _Ruby_MSVC_RUNTIME "" ) - if( MSVC_VERSION EQUAL 1200 ) - set( _Ruby_MSVC_RUNTIME "60" ) - endif() - if( MSVC_VERSION EQUAL 1300 ) - set( _Ruby_MSVC_RUNTIME "70" ) - endif() - if( MSVC_VERSION EQUAL 1310 ) - set( _Ruby_MSVC_RUNTIME "71" ) - endif() - if( MSVC_VERSION EQUAL 1400 ) - set( _Ruby_MSVC_RUNTIME "80" ) - endif() - if( MSVC_VERSION EQUAL 1500 ) - set( _Ruby_MSVC_RUNTIME "90" ) + if(MSVC_TOOLSET_VERSION) + set(_Ruby_MSVC_RUNTIME "${MSVC_TOOLSET_VERSION}") + else() + set(_Ruby_MSVC_RUNTIME "") endif() set(_Ruby_ARCH_PREFIX "") @@ -273,7 +314,6 @@ endif() find_library(Ruby_LIBRARY NAMES ${_Ruby_POSSIBLE_LIB_NAMES} HINTS ${Ruby_POSSIBLE_LIB_DIR} ) -include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) set(_Ruby_REQUIRED_VARS Ruby_EXECUTABLE Ruby_INCLUDE_DIR Ruby_LIBRARY) if(_Ruby_VERSION_SHORT_NODOT GREATER 18) list(APPEND _Ruby_REQUIRED_VARS Ruby_CONFIG_INCLUDE_DIR) @@ -295,9 +335,14 @@ if(_Ruby_DEBUG_OUTPUT) message(STATUS "--------------------") endif() +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) FIND_PACKAGE_HANDLE_STANDARD_ARGS(Ruby REQUIRED_VARS ${_Ruby_REQUIRED_VARS} VERSION_VAR Ruby_VERSION ) +if(Ruby_FOUND) + set(Ruby_LIBRARIES ${Ruby_LIBRARY}) +endif() + mark_as_advanced( Ruby_EXECUTABLE Ruby_LIBRARY diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index d68a4c9..f21ea80 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,7 +1,7 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 17) -set(CMake_VERSION_PATCH 20200317) +set(CMake_VERSION_PATCH 20200319) #set(CMake_VERSION_RC 0) set(CMake_VERSION_IS_DIRTY 0) diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 29ed61d..5f04ea3 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -759,7 +759,8 @@ void cmake::SetArgs(const std::vector<std::string>& args) const auto traceFormat = StringToTraceFormat(arg.substr(strlen("--trace-format="))); if (traceFormat == TraceFormat::TRACE_UNDEFINED) { - cmSystemTools::Error("Invalid format specified for --trace-format"); + cmSystemTools::Error("Invalid format specified for --trace-format. " + "Valid formats are human, json-v1."); return; } this->SetTraceFormat(traceFormat); diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 6f86a5f..6428235 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1478,6 +1478,10 @@ ${CMake_SOURCE_DIR}/Utilities/Release/push.bash --dir dev -- '${CMake_BUILD_NIGH add_subdirectory(UseSWIG) endif() + if(CMake_TEST_FindRuby) + add_subdirectory(FindRuby) + endif() + add_subdirectory(FindThreads) # Matlab module diff --git a/Tests/FindPython/CMakeLists.txt b/Tests/FindPython/CMakeLists.txt index bd6e8ab..d2326e4 100644 --- a/Tests/FindPython/CMakeLists.txt +++ b/Tests/FindPython/CMakeLists.txt @@ -67,14 +67,64 @@ if(CMake_TEST_FindPython) set_tests_properties(FindPython.Python3Fail PROPERTIES PASS_REGULAR_EXPRESSION "Could NOT find Python3 \\(missing: foobar\\)") - add_test(NAME FindPython.Python COMMAND + add_test(NAME FindPython.Python.LOCATION COMMAND ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> --build-and-test "${CMake_SOURCE_DIR}/Tests/FindPython/Python" - "${CMake_BINARY_DIR}/Tests/FindPython/Python" + "${CMake_BINARY_DIR}/Tests/FindPython/Python.LOCATION" ${build_generator_args} --build-project TestPython - --build-options ${build_options} + --build-options ${build_options} -DPython_FIND_STRATEGY=LOCATION + --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> + ) + add_test(NAME FindPython.Python.VERSION COMMAND + ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindPython/Python" + "${CMake_BINARY_DIR}/Tests/FindPython/Python.VERSION" + ${build_generator_args} + --build-project TestPython + --build-options ${build_options} -DPython_FIND_STRATEGY=VERSION + --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> + ) + add_test(NAME FindPython.Python.V2.LOCATION COMMAND + ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindPython/Python" + "${CMake_BINARY_DIR}/Tests/FindPython/Python.V2.LOCATION" + ${build_generator_args} + --build-project TestPython + --build-options ${build_options} -DPython_REQUESTED_VERSION=2 -DPython_FIND_STRATEGY=LOCATION + --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> + ) + add_test(NAME FindPython.Python.V2.VERSION COMMAND + ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindPython/Python" + "${CMake_BINARY_DIR}/Tests/FindPython/Python.V2.VERSION" + ${build_generator_args} + --build-project TestPython + --build-options ${build_options} -DPython_REQUESTED_VERSION=2 -DPython_FIND_STRATEGY=VERSION + --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> + ) + add_test(NAME FindPython.Python.V3.LOCATION COMMAND + ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindPython/Python" + "${CMake_BINARY_DIR}/Tests/FindPython/Python.V3.LOCATION" + ${build_generator_args} + --build-project TestPython + --build-options ${build_options} -DPython_REQUESTED_VERSION=3 -DPython_FIND_STRATEGY=LOCATION + --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> + ) + add_test(NAME FindPython.Python.V3.VERSION COMMAND + ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindPython/Python" + "${CMake_BINARY_DIR}/Tests/FindPython/Python.V3.VERSION" + ${build_generator_args} + --build-project TestPython + --build-options ${build_options} -DPython_REQUESTED_VERSION=3 -DPython_FIND_STRATEGY=VERSION --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> ) diff --git a/Tests/FindPython/Python/CMakeLists.txt b/Tests/FindPython/Python/CMakeLists.txt index 62c805e..3ee38e3 100644 --- a/Tests/FindPython/Python/CMakeLists.txt +++ b/Tests/FindPython/Python/CMakeLists.txt @@ -4,9 +4,9 @@ project(TestPython C) include(CTest) -find_package(Python 3 REQUIRED COMPONENTS Interpreter Development) +find_package(Python ${Python_REQUESTED_VERSION} REQUIRED COMPONENTS Interpreter Development) if (NOT Python_FOUND) - message (FATAL_ERROR "Fail to found Python 3") + message (FATAL_ERROR "Fail to found Python ${Python_REQUESTED_VERSION}") endif() if(NOT TARGET Python::Interpreter) @@ -20,13 +20,15 @@ if(NOT TARGET Python::Module) message(SEND_ERROR "Python::Module not found") endif() -Python_add_library (spam3 MODULE ../spam.c) -target_compile_definitions (spam3 PRIVATE PYTHON3) - -add_test (NAME python_spam3 - COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$<TARGET_FILE_DIR:spam3>" - "${Python_EXECUTABLE}" -c "import spam3; spam3.system(\"cd\")") - -add_test(NAME findpython_script - COMMAND "${CMAKE_COMMAND}" -DPYTHON_PACKAGE_NAME=Python - -P "${CMAKE_CURRENT_LIST_DIR}/../FindPythonScript.cmake") +if (Python_REQUESTED_VERSION) + Python_add_library (spam${Python_REQUESTED_VERSION} MODULE ../spam.c) + target_compile_definitions (spam${Python_REQUESTED_VERSION} PRIVATE PYTHON${Python_REQUESTED_VERSION}) + + add_test (NAME python_spam${Python_REQUESTED_VERSION} + COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$<TARGET_FILE_DIR:spam${Python_REQUESTED_VERSION}>" + "${Python_EXECUTABLE}" -c "import spam${Python_REQUESTED_VERSION}; spam${Python_REQUESTED_VERSION}.system(\"cd\")") +else() + add_test(NAME findpython_script + COMMAND "${CMAKE_COMMAND}" -DPYTHON_PACKAGE_NAME=Python + -P "${CMAKE_CURRENT_LIST_DIR}/../FindPythonScript.cmake") +endif() diff --git a/Tests/FindRuby/CMakeLists.txt b/Tests/FindRuby/CMakeLists.txt new file mode 100644 index 0000000..193cb4f --- /dev/null +++ b/Tests/FindRuby/CMakeLists.txt @@ -0,0 +1,44 @@ +if(CMake_TEST_FindRuby) + + # Looks for ruby >=1.9.9, which is true on any Ubuntu (that installs it) or macOS (> 10.9) + add_test(NAME FindRuby.Test COMMAND + ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindRuby/Test" + "${CMake_BINARY_DIR}/Tests/FindRuby/Test" + ${build_generator_args} + --build-project TestRuby + --build-options ${build_options} + --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> + ) + + # Looks for ruby >= 50.1.0, which should logically fail + add_test(NAME FindRuby.Fail COMMAND + ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindRuby/Fail" + "${CMake_BINARY_DIR}/Tests/FindRuby/Fail" + ${build_generator_args} + --build-project TestRubyFail + --build-options ${build_options} + --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> + ) + set_tests_properties(FindRuby.Fail PROPERTIES + PASS_REGULAR_EXPRESSION "Could NOT find Ruby: Found unsuitable version \".*\", but required is.*least \"[0-9]+\\.[0-9]+\\.[0-9]+\" \\(found .*\\)") + + # Looks for 1.9.9 EXACTLY, which unlike the "FindRuby" test above will fail on every machine + # since this version doesn't exist (ruby goes from 1.9.3 to 2.0.0) + add_test(NAME FindRuby.FailExact COMMAND + ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindRuby/FailExact" + "${CMake_BINARY_DIR}/Tests/FindRuby/FailExact" + ${build_generator_args} + --build-project TestRubyFailExact + --build-options ${build_options} + --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> + ) + set_tests_properties(FindRuby.FailExact PROPERTIES + PASS_REGULAR_EXPRESSION "Could NOT find Ruby: Found unsuitable version \".*\", but required is.*exact version \"[0-9]+\\.[0-9]+\\.[0-9]+\" \\(found .*\\)") + +endif() diff --git a/Tests/FindRuby/Fail/CMakeLists.txt b/Tests/FindRuby/Fail/CMakeLists.txt new file mode 100644 index 0000000..9185ba5 --- /dev/null +++ b/Tests/FindRuby/Fail/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.17) +project(TestRubyFail LANGUAGES NONE) + +# Should always fail since there is NO ruby 50.1.0 yet. +find_package(Ruby 50.1.0 REQUIRED) diff --git a/Tests/FindRuby/FailExact/CMakeLists.txt b/Tests/FindRuby/FailExact/CMakeLists.txt new file mode 100644 index 0000000..1ebc0ae --- /dev/null +++ b/Tests/FindRuby/FailExact/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.17) +project(TestRubyFailExact LANGUAGES NONE) + +# Should always fail since there is NO ruby 1.9.9 (goes from 1.9.3 to 2.0.0) +find_package(Ruby 1.9.9 EXACT REQUIRED) +if (NOT Ruby_FOUND) + message (FATAL_ERROR "Failed to find Ruby 1.9.9") +endif() diff --git a/Tests/FindRuby/Test/CMakeLists.txt b/Tests/FindRuby/Test/CMakeLists.txt new file mode 100644 index 0000000..dcf3ec3 --- /dev/null +++ b/Tests/FindRuby/Test/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.17) +project(TestRuby LANGUAGES C) +include(CTest) + +find_package(Ruby 1.9.9 REQUIRED) +if (NOT Ruby_FOUND) + message (FATAL_ERROR "Failed to find Ruby >=1.9.9") +endif() + +add_executable(ruby_version ruby_version.c) +target_include_directories(ruby_version PRIVATE ${Ruby_INCLUDE_DIRS}) +target_link_libraries(ruby_version PRIVATE ${Ruby_LIBRARIES}) + +add_test(NAME ruby_version COMMAND ruby_version) diff --git a/Tests/FindRuby/Test/ruby_version.c b/Tests/FindRuby/Test/ruby_version.c new file mode 100644 index 0000000..8800436 --- /dev/null +++ b/Tests/FindRuby/Test/ruby_version.c @@ -0,0 +1,7 @@ +#include "ruby.h" + +int main(void) +{ + ruby_show_version(); + return 0; +} diff --git a/Tests/RunCMake/FindPkgConfig/PkgConfigDoesNotExist-stdout.txt b/Tests/RunCMake/FindPkgConfig/PkgConfigDoesNotExist-stdout.txt new file mode 100644 index 0000000..ef5f7f6 --- /dev/null +++ b/Tests/RunCMake/FindPkgConfig/PkgConfigDoesNotExist-stdout.txt @@ -0,0 +1,6 @@ +-- Could NOT find PkgConfig \(missing: PKG_CONFIG_EXECUTABLE\) * + Reason given by package: The command + "pkg-config-does-not-exist" --version + failed with output.* +-- PKG_CONFIG_FOUND='FALSE' +-- PKG_CONFIG_EXECUTABLE='' diff --git a/Tests/RunCMake/FindPkgConfig/PkgConfigDoesNotExist.cmake b/Tests/RunCMake/FindPkgConfig/PkgConfigDoesNotExist.cmake new file mode 100644 index 0000000..a4fabde --- /dev/null +++ b/Tests/RunCMake/FindPkgConfig/PkgConfigDoesNotExist.cmake @@ -0,0 +1,4 @@ +set(PKG_CONFIG_EXECUTABLE "pkg-config-does-not-exist" CACHE FILEPATH "") +find_package(PkgConfig) +message(STATUS "PKG_CONFIG_FOUND='${PKG_CONFIG_FOUND}'") +message(STATUS "PKG_CONFIG_EXECUTABLE='${PKG_CONFIG_EXECUTABLE}'") diff --git a/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake b/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake index b77bb54..9df1d5b 100644 --- a/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake +++ b/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake @@ -1,5 +1,7 @@ include(RunCMake) +run_cmake(PkgConfigDoesNotExist) + run_cmake(FindPkgConfig_NO_PKGCONFIG_PATH) run_cmake(FindPkgConfig_PKGCONFIG_PATH) run_cmake(FindPkgConfig_PKGCONFIG_PATH_NO_CMAKE_PATH) @@ -17,7 +17,7 @@ cmake_extract_standard_flags() cmake_version_component() { sed -n " -/^set(CMake_VERSION_${1}/ {s/set(CMake_VERSION_${1} *\([0-9]*\))/\1/;p;} +/^set(CMake_VERSION_${1}/ {s/set(CMake_VERSION_${1} *\([0-9]*\)).*/\1/;p;} " "${cmake_source_dir}/Source/CMakeVersion.cmake" } |