From c3c75004f9422f67c1686647ff6920ec47ca8262 Mon Sep 17 00:00:00 2001 From: Eric Womer Date: Sat, 28 Dec 2019 14:28:30 -0500 Subject: [PATCH] CMakeLists.txt: * FORCE_COLOR_OUTPUT, force diagnostic color output for clang and gnc compiler when using ninja build * COMPILE_COMMANDS, force cmake to generate the compile_commands.json file * Use set() for setting c++ standard since with clang it bleeds through down to C source files causing errors with cmake and can cause other issues with C source files and set(CMAKE_CXX_STANDARD 11) forced the use of gnu++11 as the standard. --- neo/CMakeLists.txt | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/neo/CMakeLists.txt b/neo/CMakeLists.txt index 0ad09288..c073c92a 100644 --- a/neo/CMakeLists.txt +++ b/neo/CMakeLists.txt @@ -3,6 +3,12 @@ set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) project(RBDoom3BFG) +option(FORCE_COLOR_OUTPUT + "Always produce ANSI-colored output (GNU/Clang only)." OFF) + +option(COMPILE_COMMANDS + "Generate compile_commands.json" OFF) + option(USE_MFC_TOOLS "Compile the built-in MFC based tools" OFF) @@ -67,7 +73,19 @@ endif() if(UNIX) set(OPENAL TRUE) endif() - + +if(COMPILE_COMMANDS) + set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +endif() + +if (FORCE_COLOR_OUTPUT) + if (CMAKE_COMPILER_IS_GNUCC) + add_compile_options(-fdiagnostics-color=always) + elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang") + add_compile_options(-fcolor-diagnostics) + endif () +endif () + if(MSVC) #message(STATUS CMAKE_ROOT: ${CMAKE_ROOT}) @@ -93,11 +111,9 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang") CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X) if(COMPILER_SUPPORTS_CXX11) - set(CMAKE_CXX_STANDARD 11) - set(CMAKE_CXX_STANDARD_REQUIRED ON) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") elseif(COMPILER_SUPPORTS_CXX0X) - set(CMAKE_CXX_STANDARD 0x) - set(CMAKE_CXX_STANDARD_REQUIRED ON) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") else() message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") endif()