From b7a5d6b38428a988435ee420a55bf42304072752 Mon Sep 17 00:00:00 2001 From: "Michael Hirsch, Ph.D" Date: Tue, 16 Jul 2019 14:09:57 -0400 Subject: [PATCH] add cross-platform test for cmake_module_path This test tolerates CMake >= 3.7, and checks that dependency(..., cmake_module_path=...) works on any OS with CMake. --- .../cmake/FindSomethingLikePython.cmake | 24 +++++++++++++++++++ .../cmake/10 cmake_module_path/meson.build | 17 +++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 test cases/cmake/10 cmake_module_path/cmake/FindSomethingLikePython.cmake create mode 100644 test cases/cmake/10 cmake_module_path/meson.build diff --git a/test cases/cmake/10 cmake_module_path/cmake/FindSomethingLikePython.cmake b/test cases/cmake/10 cmake_module_path/cmake/FindSomethingLikePython.cmake new file mode 100644 index 000000000..4a189bffc --- /dev/null +++ b/test cases/cmake/10 cmake_module_path/cmake/FindSomethingLikePython.cmake @@ -0,0 +1,24 @@ +cmake_policy(VERSION 3.7) + +if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12) + find_package(Python COMPONENTS Interpreter) +else() + find_package(PythonInterp) +endif() + +if(Python_FOUND OR PYTHONINTERP_FOUND) + set(SomethingLikePython_FOUND ON) + set(SomethingLikePython_EXECUTABLE ${Python_EXECUTABLE}) + + if(NOT DEFINED Python_VERSION) + set(Python_VERSION ${Python_VERSION_STRING}) + endif() + if(NOT TARGET Python::Interpreter) + add_executable(Python::Interpreter IMPORTED) + set_target_properties(Python::Interpreter PROPERTIES + IMPORTED_LOCATION ${Python_EXECUTABLE} + VERSION ${Python_VERSION}) + endif() +else() + set(SomethingLikePython_FOUND OFF) +endif() diff --git a/test cases/cmake/10 cmake_module_path/meson.build b/test cases/cmake/10 cmake_module_path/meson.build new file mode 100644 index 000000000..225926824 --- /dev/null +++ b/test cases/cmake/10 cmake_module_path/meson.build @@ -0,0 +1,17 @@ +# We use Python3 as it's the only thing guaranteed to be available on any platform Meson can run on (unlike Zlib in linuxlike/13 cmake dependency). + +project('user CMake find_package module using cmake_module_path', + meson_version: '>= 0.50.0') + +if not find_program('cmake', required: false).found() + error('MESON_SKIP_TEST cmake binary not available.') +endif + +# NOTE: can't request Python3 via dependency('Python3', method: 'cmake') +# Meson intercepts and wants "method: auto" + +# Try to find a dependency with a custom CMake module + +dependency('SomethingLikePython', required : true, method : 'cmake', cmake_module_path : 'cmake', modules: 'Python::Interpreter') + +dependency('SomethingLikePython', method : 'cmake', cmake_module_path : ['doesNotExist', 'cmake'], modules: 'Python::Interpreter')