1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-18 00:02:21 +08:00

color: Add tests for CMAKE_COLOR_DIAGNOSTICS

This commit is contained in:
Brad King
2022-03-08 16:59:51 -05:00
parent 78adb1b952
commit 6ab9fbd43b
12 changed files with 96 additions and 0 deletions

View File

@@ -278,6 +278,9 @@ endif()
add_RunCMake_test(CMakeDependentOption)
add_RunCMake_test(CMakeRoleGlobalProperty)
add_RunCMake_test(CMakeRelease -DCMake_TEST_JQ=${CMake_TEST_JQ})
if(CMAKE_GENERATOR MATCHES "Make|Ninja")
add_RunCMake_test(Color)
endif()
if(UNIX AND "${CMAKE_GENERATOR}" MATCHES "Unix Makefiles|Ninja")
add_RunCMake_test(CompilerChange)
endif()

View File

@@ -0,0 +1,3 @@
cmake_minimum_required(VERSION 3.23)
project(${RunCMake_TEST} NONE)
include(${RunCMake_TEST}.cmake)

View File

@@ -0,0 +1,9 @@
enable_language(C)
set(CMAKE_C_COMPILE_OPTIONS_COLOR_DIAGNOSTICS -DCOLOR_ON)
set(CMAKE_C_COMPILE_OPTIONS_COLOR_DIAGNOSTICS_OFF -DCOLOR_OFF)
add_library(diag STATIC diag.c)
if(DEFINED EXPECT_COLOR)
target_compile_definitions(diag PRIVATE EXPECT_COLOR=${EXPECT_COLOR})
endif()

View File

@@ -0,0 +1,8 @@
include(DiagCommon.cmake)
if(DEFINED CMAKE_COLOR_DIAGNOSTICS)
message(FATAL_ERROR "CMAKE_COLOR_DIAGNOSTICS incorrectly defined.")
endif()
if(CMAKE_GENERATOR MATCHES "Make" AND NOT DEFINED CMAKE_COLOR_MAKEFILE)
message(FATAL_ERROR "CMAKE_COLOR_MAKEFILE incorrectly not defined.")
endif()

View File

@@ -0,0 +1,6 @@
set(EXPECT_COLOR 0)
include(DiagCommon.cmake)
if(DEFINED CMAKE_COLOR_MAKEFILE)
message(FATAL_ERROR "CMAKE_COLOR_MAKEFILE incorrectly defined.")
endif()

View File

@@ -0,0 +1,6 @@
set(EXPECT_COLOR 1)
include(DiagCommon.cmake)
if(DEFINED CMAKE_COLOR_MAKEFILE)
message(FATAL_ERROR "CMAKE_COLOR_MAKEFILE incorrectly defined.")
endif()

View File

@@ -0,0 +1,14 @@
include(RunCMake)
unset(ENV{CMAKE_COLOR_DIAGNOSTICS})
function(run_Diag case)
set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/Diag${case}-build")
run_cmake_with_options(Diag${case} ${ARGN})
set(RunCMake_TEST_NO_CLEAN 1)
run_cmake_command(Diag${case}-build ${CMAKE_COMMAND} --build . --config Debug)
endfunction()
run_Diag(On -DCMAKE_COLOR_DIAGNOSTICS=ON)
run_Diag(Off -DCMAKE_COLOR_DIAGNOSTICS=OFF)
run_Diag(Default)

View File

@@ -0,0 +1,28 @@
#ifdef EXPECT_COLOR
# if EXPECT_COLOR
# ifndef COLOR_ON
# error "COLOR_ON incorrectly not defined"
# endif
# ifdef COLOR_OFF
# error "COLOR_OFF incorrectly defined"
# endif
# else
# ifdef COLOR_ON
# error "COLOR_ON incorrectly defined"
# endif
# ifndef COLOR_OFF
# error "COLOR_OFF incorrectly not defined"
# endif
# endif
#else
# ifdef COLOR_ON
# error "COLOR_ON incorrectly defined"
# endif
# ifdef COLOR_OFF
# error "COLOR_OFF incorrectly defined"
# endif
#endif
void diag(void)
{
}

View File

@@ -0,0 +1,6 @@
if(DEFINED CMAKE_COLOR_DIAGNOSTICS)
message(FATAL_ERROR "CMAKE_COLOR_DIAGNOSTICS incorrectly defined.")
endif()
if(CMAKE_GENERATOR MATCHES "Make" AND NOT DEFINED CMAKE_COLOR_MAKEFILE)
message(FATAL_ERROR "CMAKE_COLOR_MAKEFILE incorrectly not defined.")
endif()

View File

@@ -0,0 +1 @@
-- CMAKE_COLOR_DIAGNOSTICS='ON'

View File

@@ -0,0 +1,4 @@
message(STATUS "CMAKE_COLOR_DIAGNOSTICS='${CMAKE_COLOR_DIAGNOSTICS}'")
if(DEFINED CMAKE_COLOR_MAKEFILE)
message(FATAL_ERROR "CMAKE_COLOR_MAKEFILE incorrectly defined.")
endif()

View File

@@ -416,6 +416,14 @@ function(run_EnvironmentToolchain)
endfunction()
run_EnvironmentToolchain()
function(run_EnvironmentColor)
set(ENV{CMAKE_COLOR_DIAGNOSTICS} "ON")
run_cmake(EnvColorOn)
unset(ENV{CMAKE_COLOR_DIAGNOSTICS})
run_cmake(EnvColorDefault)
endfunction()
run_EnvironmentColor()
if(RunCMake_GENERATOR STREQUAL "Ninja")
# Use a single build tree for a few tests without cleaning.
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Build-build)