From bddc54a37d6d04cc574f9edfc49f941e69dd5379 Mon Sep 17 00:00:00 2001 From: Samir Benmendil Date: Fri, 16 Oct 2020 12:21:46 +0100 Subject: CheckLanguage: Pass CMAKE_TOOLCHAIN_FILE to test project Fixes: #20545 --- Modules/CheckLanguage.cmake | 6 ++++++ Tests/RunCMake/ToolchainFile/CheckLanguage-stdout.txt | 1 + Tests/RunCMake/ToolchainFile/CheckLanguage-toolchain.cmake | 4 ++++ Tests/RunCMake/ToolchainFile/CheckLanguage.cmake | 2 ++ Tests/RunCMake/ToolchainFile/RunCMakeTest.cmake | 1 + 5 files changed, 14 insertions(+) create mode 100644 Tests/RunCMake/ToolchainFile/CheckLanguage-stdout.txt create mode 100644 Tests/RunCMake/ToolchainFile/CheckLanguage-toolchain.cmake create mode 100644 Tests/RunCMake/ToolchainFile/CheckLanguage.cmake diff --git a/Modules/CheckLanguage.cmake b/Modules/CheckLanguage.cmake index 44387d4..928881c 100644 --- a/Modules/CheckLanguage.cmake +++ b/Modules/CheckLanguage.cmake @@ -68,6 +68,11 @@ file(WRITE \"\${CMAKE_CURRENT_BINARY_DIR}/result.cmake\" else() set(_D_CMAKE_MAKE_PROGRAM "-DCMAKE_MAKE_PROGRAM:FILEPATH=${CMAKE_MAKE_PROGRAM}") endif() + if(CMAKE_TOOLCHAIN_FILE) + set(_D_CMAKE_TOOLCHAIN_FILE "-DCMAKE_TOOLCHAIN_FILE:FILEPATH=${CMAKE_TOOLCHAIN_FILE}") + else() + set(_D_CMAKE_TOOLCHAIN_FILE "") + endif() execute_process( WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Check${lang} COMMAND ${CMAKE_COMMAND} . -G ${CMAKE_GENERATOR} @@ -75,6 +80,7 @@ file(WRITE \"\${CMAKE_CURRENT_BINARY_DIR}/result.cmake\" -T "${CMAKE_GENERATOR_TOOLSET}" ${_D_CMAKE_GENERATOR_INSTANCE} ${_D_CMAKE_MAKE_PROGRAM} + ${_D_CMAKE_TOOLCHAIN_FILE} OUTPUT_VARIABLE _cl_output ERROR_VARIABLE _cl_output RESULT_VARIABLE _cl_result diff --git a/Tests/RunCMake/ToolchainFile/CheckLanguage-stdout.txt b/Tests/RunCMake/ToolchainFile/CheckLanguage-stdout.txt new file mode 100644 index 0000000..b96eee6 --- /dev/null +++ b/Tests/RunCMake/ToolchainFile/CheckLanguage-stdout.txt @@ -0,0 +1 @@ +-- Looking for a C compiler - NOTFOUND diff --git a/Tests/RunCMake/ToolchainFile/CheckLanguage-toolchain.cmake b/Tests/RunCMake/ToolchainFile/CheckLanguage-toolchain.cmake new file mode 100644 index 0000000..081f905 --- /dev/null +++ b/Tests/RunCMake/ToolchainFile/CheckLanguage-toolchain.cmake @@ -0,0 +1,4 @@ +get_property(in_try_compile GLOBAL PROPERTY IN_TRY_COMPILE) +if(in_try_compile) + message(FATAL_ERROR "Toolchain file included") +endif() diff --git a/Tests/RunCMake/ToolchainFile/CheckLanguage.cmake b/Tests/RunCMake/ToolchainFile/CheckLanguage.cmake new file mode 100644 index 0000000..854b3d4 --- /dev/null +++ b/Tests/RunCMake/ToolchainFile/CheckLanguage.cmake @@ -0,0 +1,2 @@ +include(CheckLanguage) +check_language(C) diff --git a/Tests/RunCMake/ToolchainFile/RunCMakeTest.cmake b/Tests/RunCMake/ToolchainFile/RunCMakeTest.cmake index 7eb4485..659523c 100644 --- a/Tests/RunCMake/ToolchainFile/RunCMakeTest.cmake +++ b/Tests/RunCMake/ToolchainFile/RunCMakeTest.cmake @@ -7,6 +7,7 @@ endfunction() run_cmake_toolchain(CallEnableLanguage) run_cmake_toolchain(CallProject) +run_cmake_toolchain(CheckLanguage) run_cmake_toolchain(FlagsInit) run_cmake_toolchain(LinkFlagsInit) -- cgit v0.12