diff options
author | Brad King <brad.king@kitware.com> | 2020-05-12 11:48:17 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2020-05-12 12:08:20 (GMT) |
commit | fe19df49d48680cbfd8e1023d4a93b39f12d4b64 (patch) | |
tree | f976accb2ab186b588431acf93c93c0c0626d642 /Tests/RunCMake | |
parent | 4dc95526868d903c7f9e9505001cb5dbeec259c0 (diff) | |
download | CMake-fe19df49d48680cbfd8e1023d4a93b39f12d4b64.zip CMake-fe19df49d48680cbfd8e1023d4a93b39f12d4b64.tar.gz CMake-fe19df49d48680cbfd8e1023d4a93b39f12d4b64.tar.bz2 |
Initialize CMAKE_EXPORT_COMPILE_COMMANDS only if not set already
Also de-duplicate its initialization code.
Fixes: #16588
Diffstat (limited to 'Tests/RunCMake')
7 files changed, 17 insertions, 0 deletions
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index cc88868..8aeb412 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -197,6 +197,9 @@ endif() add_RunCMake_test(CompilerNotFound) add_RunCMake_test(Configure -DMSVC_IDE=${MSVC_IDE}) add_RunCMake_test(DisallowedCommands) +if("${CMAKE_GENERATOR}" MATCHES "Unix Makefiles|Ninja") + add_RunCMake_test(ExportCompileCommands) +endif() add_RunCMake_test(ExternalData) add_RunCMake_test(FeatureSummary) add_RunCMake_test(FPHSA) diff --git a/Tests/RunCMake/ExportCompileCommands/BeforeProject-check.cmake b/Tests/RunCMake/ExportCompileCommands/BeforeProject-check.cmake new file mode 100644 index 0000000..87058e2 --- /dev/null +++ b/Tests/RunCMake/ExportCompileCommands/BeforeProject-check.cmake @@ -0,0 +1,4 @@ +if(NOT EXISTS "${RunCMake_TEST_BINARY_DIR}/compile_commands.json") + set(RunCMake_TEST_FAILED "compile_commands.json not generated") + return() +endif() diff --git a/Tests/RunCMake/ExportCompileCommands/BeforeProject.cmake b/Tests/RunCMake/ExportCompileCommands/BeforeProject.cmake new file mode 100644 index 0000000..b8cbdef --- /dev/null +++ b/Tests/RunCMake/ExportCompileCommands/BeforeProject.cmake @@ -0,0 +1,3 @@ +enable_language(C) +add_library(empty STATIC empty.c) +message(STATUS "CMAKE_EXPORT_COMPILE_COMMANDS='${CMAKE_EXPORT_COMPILE_COMMANDS}'") diff --git a/Tests/RunCMake/ExportCompileCommands/BeforeProjectBEFORE.cmake b/Tests/RunCMake/ExportCompileCommands/BeforeProjectBEFORE.cmake new file mode 100644 index 0000000..87f9c87 --- /dev/null +++ b/Tests/RunCMake/ExportCompileCommands/BeforeProjectBEFORE.cmake @@ -0,0 +1 @@ +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) diff --git a/Tests/RunCMake/ExportCompileCommands/CMakeLists.txt b/Tests/RunCMake/ExportCompileCommands/CMakeLists.txt new file mode 100644 index 0000000..b7117bd --- /dev/null +++ b/Tests/RunCMake/ExportCompileCommands/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.17) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/ExportCompileCommands/RunCMakeTest.cmake b/Tests/RunCMake/ExportCompileCommands/RunCMakeTest.cmake new file mode 100644 index 0000000..b540a04 --- /dev/null +++ b/Tests/RunCMake/ExportCompileCommands/RunCMakeTest.cmake @@ -0,0 +1,3 @@ +include(RunCMake) + +run_cmake_with_options(BeforeProject -DCMAKE_PROJECT_INCLUDE_BEFORE=BeforeProjectBEFORE.cmake) diff --git a/Tests/RunCMake/ExportCompileCommands/empty.c b/Tests/RunCMake/ExportCompileCommands/empty.c new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/ExportCompileCommands/empty.c |