diff options
Diffstat (limited to 'meson/test cases/cmake/11 cmake_module_path')
5 files changed, 63 insertions, 0 deletions
diff --git a/meson/test cases/cmake/11 cmake_module_path/cmake/FindSomethingLikePython.cmake b/meson/test cases/cmake/11 cmake_module_path/cmake/FindSomethingLikePython.cmake new file mode 100644 index 000000000..0c663f4fc --- /dev/null +++ b/meson/test cases/cmake/11 cmake_module_path/cmake/FindSomethingLikePython.cmake @@ -0,0 +1,9 @@ +cmake_policy(VERSION 3.7) + +find_package(Python COMPONENTS Interpreter) +if(Python_FOUND OR PYTHONINTERP_FOUND) + set(SomethingLikePython_FOUND ON) + set(SomethingLikePython_EXECUTABLE ${Python_EXECUTABLE}) +else() + set(SomethingLikePython_FOUND OFF) +endif() diff --git a/meson/test cases/cmake/11 cmake_module_path/meson.build b/meson/test cases/cmake/11 cmake_module_path/meson.build new file mode 100644 index 000000000..e20193696 --- /dev/null +++ b/meson/test cases/cmake/11 cmake_module_path/meson.build @@ -0,0 +1,25 @@ +# 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', ['c', 'cpp'], + meson_version: '>= 0.55.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') + +# Test a custom target with Python::Interpreter in COMMAND +cm = import('cmake') +op = cm.subproject_options() +op.add_cmake_defines({'CMAKE_MODULE_PATH': meson.source_root() / 'cmake'}) +sp = cm.subproject('cmMod', options: op) +main = sp.target('main') +test('main', main) diff --git a/meson/test cases/cmake/11 cmake_module_path/subprojects/cmMod/CMakeLists.txt b/meson/test cases/cmake/11 cmake_module_path/subprojects/cmMod/CMakeLists.txt new file mode 100644 index 000000000..88ba9bc57 --- /dev/null +++ b/meson/test cases/cmake/11 cmake_module_path/subprojects/cmMod/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.5) + +project(cmMod) + +message(STATUS "CMAKE_MODULE_PATH: '${CMAKE_MODULE_PATH}'") + +find_package(SomethingLikePython REQUIRED) + +add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/main.c" + COMMAND Python::Interpreter "${CMAKE_CURRENT_SOURCE_DIR}/gen.py" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" +) + +add_executable(main "${CMAKE_CURRENT_BINARY_DIR}/main.c") diff --git a/meson/test cases/cmake/11 cmake_module_path/subprojects/cmMod/gen.py b/meson/test cases/cmake/11 cmake_module_path/subprojects/cmMod/gen.py new file mode 100644 index 000000000..5c7164604 --- /dev/null +++ b/meson/test cases/cmake/11 cmake_module_path/subprojects/cmMod/gen.py @@ -0,0 +1,9 @@ +with open('main.c', 'w') as fp: + print(''' +#include <stdio.h> + +int main(void) { + printf(\"Hello World\"); + return 0; +} +''', file=fp) diff --git a/meson/test cases/cmake/11 cmake_module_path/test.json b/meson/test cases/cmake/11 cmake_module_path/test.json new file mode 100644 index 000000000..79a2b60d3 --- /dev/null +++ b/meson/test cases/cmake/11 cmake_module_path/test.json @@ -0,0 +1,5 @@ +{ + "tools": { + "cmake": ">=3.12" + } +} |