diff options
author | Brad King <brad.king@kitware.com> | 2021-01-07 13:22:20 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2021-01-07 13:22:27 (GMT) |
commit | 1cbbfbc78f7d22b89ccbce4cb5a4961afe943886 (patch) | |
tree | 5d80b2e8842bd72b834b55af7884bbbf0a899c50 /Tests | |
parent | 455d016863534e748325ea01b3b33772de89798a (diff) | |
parent | a742b5d137d0855430a044dc4237de5aabfb08b4 (diff) | |
download | CMake-1cbbfbc78f7d22b89ccbce4cb5a4961afe943886.zip CMake-1cbbfbc78f7d22b89ccbce4cb5a4961afe943886.tar.gz CMake-1cbbfbc78f7d22b89ccbce4cb5a4961afe943886.tar.bz2 |
Merge topic 'export-compile-commands-per-target'
a742b5d137 CMAKE_EXPORT_COMPILE_COMMANDS: allow configuration per target
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5651
Diffstat (limited to 'Tests')
5 files changed, 69 insertions, 0 deletions
diff --git a/Tests/RunCMake/ExportCompileCommands/Properties.cmake b/Tests/RunCMake/ExportCompileCommands/Properties.cmake new file mode 100644 index 0000000..c7a38b7 --- /dev/null +++ b/Tests/RunCMake/ExportCompileCommands/Properties.cmake @@ -0,0 +1,22 @@ +enable_language(C) + +add_library(Unset STATIC empty.c) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +add_library(SetOn STATIC empty.c) +set(CMAKE_EXPORT_COMPILE_COMMANDS OFF) +add_library(SetOff STATIC empty.c) + +get_property(_set TARGET Unset PROPERTY EXPORT_COMPILE_COMMANDS) +if(_set) + message(SEND_ERROR "EXPORT_COMPILE_COMMANDS property should be unset for Unset target (got \"${_set}\")") +endif() + +get_property(_on TARGET SetOn PROPERTY EXPORT_COMPILE_COMMANDS) +if(NOT _on STREQUAL "ON") + message(SEND_ERROR "EXPORT_COMPILE_COMMANDS property should be \"ON\" for SetOn target (got \"${_on}\")") +endif() + +get_property(_off TARGET SetOff PROPERTY EXPORT_COMPILE_COMMANDS) +if(NOT _off STREQUAL "OFF") + message(SEND_ERROR "EXPORT_COMPILE_COMMANDS property should be \"OFF\" for SetOff target (got \"${_off}\")") +endif() diff --git a/Tests/RunCMake/ExportCompileCommands/PropertiesGenerateCommand-check.cmake b/Tests/RunCMake/ExportCompileCommands/PropertiesGenerateCommand-check.cmake new file mode 100644 index 0000000..d698742 --- /dev/null +++ b/Tests/RunCMake/ExportCompileCommands/PropertiesGenerateCommand-check.cmake @@ -0,0 +1,32 @@ +if(NOT EXISTS "${RunCMake_TEST_BINARY_DIR}/compile_commands.json") + set(RunCMake_TEST_FAILED "compile_commands.json not generated") + return() +endif() + +file(READ "${RunCMake_TEST_BINARY_DIR}/compile_commands.json" compile_commands) + +macro(check_error) + if(error) + message(SEND_ERROR "Unexpected error \"${error}\"\nFor: ${compile_commands}") + endif() +endmacro() + +string(JSON num_commands ERROR_VARIABLE error LENGTH "${compile_commands}") +check_error() + +# Only one of the targets has the EXPORT_COMPILE_COMMANDS property enabled. +if(NOT num_commands STREQUAL 1) + message(SEND_ERROR "Expected 1 compile command, got ${num_commands} for ${compile_commands}") +endif() + +# Get the compile command generated. +string(JSON result ERROR_VARIABLE error GET "${compile_commands}" 0) +check_error() +string(JSON result ERROR_VARIABLE error GET "${result}" file) +check_error() + +# And ensure the correct target is in that compile command. +cmake_path(COMPARE "${result}" EQUAL "${RunCMake_TEST_SOURCE_DIR}/expected_file.c" good) +if(NOT good) + message(SEND_ERROR "Expected \"${result}\" in \"${RunCMake_TEST_SOURCE_DIR}/expected_file.c\"") +endif() diff --git a/Tests/RunCMake/ExportCompileCommands/PropertiesGenerateCommand.cmake b/Tests/RunCMake/ExportCompileCommands/PropertiesGenerateCommand.cmake new file mode 100644 index 0000000..46c8845 --- /dev/null +++ b/Tests/RunCMake/ExportCompileCommands/PropertiesGenerateCommand.cmake @@ -0,0 +1,7 @@ +enable_language(C) + +add_library(Unset STATIC empty.c) +add_library(ToBeSet STATIC expected_file.c) + +# Only one target with EXPORT_COMPILE_COMMANDS property. +set_property(TARGET ToBeSet PROPERTY EXPORT_COMPILE_COMMANDS TRUE) diff --git a/Tests/RunCMake/ExportCompileCommands/RunCMakeTest.cmake b/Tests/RunCMake/ExportCompileCommands/RunCMakeTest.cmake index 9e7e732..b691637 100644 --- a/Tests/RunCMake/ExportCompileCommands/RunCMakeTest.cmake +++ b/Tests/RunCMake/ExportCompileCommands/RunCMakeTest.cmake @@ -1,4 +1,12 @@ include(RunCMake) +if(RunCMake_GENERATOR_IS_MULTI_CONFIG) + set(RunCMake_TEST_OPTIONS -DCMAKE_CONFIGURATION_TYPES=Debug) +else() + set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug) +endif() + run_cmake_with_options(BeforeProject -DCMAKE_PROJECT_INCLUDE_BEFORE=BeforeProjectBEFORE.cmake) run_cmake(CustomCompileRule) +run_cmake(Properties) +run_cmake(PropertiesGenerateCommand) diff --git a/Tests/RunCMake/ExportCompileCommands/expected_file.c b/Tests/RunCMake/ExportCompileCommands/expected_file.c new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/ExportCompileCommands/expected_file.c |