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.
This commit is contained in:
Eric Womer 2019-12-28 14:28:30 -05:00
parent 62170b3d06
commit c3c75004f9

View file

@ -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()