| 1 |
# @HEADER |
| 2 |
# ***************************************************************************** |
| 3 |
# TriBITS: Tribal Build, Integrate, and Test System |
| 4 |
# |
| 5 |
# Copyright 2013-2016 NTESS and the TriBITS contributors. |
| 6 |
# SPDX-License-Identifier: BSD-3-Clause |
| 7 |
# ***************************************************************************** |
| 8 |
# @HEADER |
| 9 |
|
| 10 |
include(TribitsDefineStandardCompileVars) |
| 11 |
include(DualScopePrependCmndlineArgs) |
| 12 |
include(PrintVar) |
| 13 |
|
| 14 |
# |
| 15 |
# Helper macros |
| 16 |
# |
| 17 |
|
| 18 |
macro(tribits_set_language_buildtype_flags LANG BUILDTYPE) |
| 19 |
|
| 20 |
#print_var(CMAKE_${LANG}_FLAGS_${BUILDTYPE}) |
| 21 |
#print_var(GENERAL_${BUILDTYPE}_FLAGS) |
| 22 |
|
| 23 |
# Set the default CMAKE_${LANG}_FLAGS_${BUILDTYPE} to empty to override the |
| 24 |
# default that CMake gives! We want to define these for ourselves. |
| 25 |
set(CMAKE_${LANG}_FLAGS_${BUILDTYPE} "") |
| 26 |
|
| 27 |
if (${LANG}_${BUILDTYPE}_FLAGS) |
| 28 |
dual_scope_prepend_cmndline_args(CMAKE_${LANG}_FLAGS_${BUILDTYPE} |
| 29 |
"${${LANG}_${BUILDTYPE}_FLAGS}") |
| 30 |
endif() |
| 31 |
if(${PROJECT_NAME}_VERBOSE_CONFIGURE) |
| 32 |
message(STATUS "Adding ${LANG} ${BUILDTYPE} flags" |
| 33 |
" \"${${LANG}_${BUILDTYPE}_FLAGS}\"") |
| 34 |
print_var(CMAKE_${LANG}_FLAGS_${BUILDTYPE}) |
| 35 |
endif() |
| 36 |
|
| 37 |
endmacro() |
| 38 |
|
| 39 |
|
| 40 |
macro(tribits_set_language_buildtype_flags_override LANG BUILDTYPE) |
| 41 |
|
| 42 |
set(CMAKE_${LANG}_FLAGS_${BUILDTYPE}_OVERRIDE "" |
| 43 |
CACHE STRING |
| 44 |
"If set to non-empty, will override CMAKE_${LANG}_FLAGS_${BUILDTYPE}") |
| 45 |
|
| 46 |
if (CMAKE_${LANG}_FLAGS_${BUILDTYPE}_OVERRIDE) |
| 47 |
if(${PROJECT_NAME}_VERBOSE_CONFIGURE) |
| 48 |
message( |
| 49 |
"-- Overriding CMAKE_${LANG}_FLAGS_${BUILDTYPE}:\n" |
| 50 |
"-- from\n" |
| 51 |
"-- ${CMAKE_${LANG}_FLAGS_${BUILDTYPE}}") |
| 52 |
endif() |
| 53 |
dual_scope_set(CMAKE_${LANG}_FLAGS_${BUILDTYPE} |
| 54 |
${CMAKE_${LANG}_FLAGS_${BUILDTYPE}_OVERRIDE}) |
| 55 |
if(${PROJECT_NAME}_VERBOSE_CONFIGURE) |
| 56 |
message( |
| 57 |
"-- to\n" |
| 58 |
"-- ${CMAKE_${LANG}_FLAGS_${BUILDTYPE}}") |
| 59 |
endif() |
| 60 |
endif() |
| 61 |
|
| 62 |
# NOTE: Above, we can't just let users set CMAKE_${LANG}_FLAGS_${BUILDTYPE} |
| 63 |
# in the cache because CMake overrides it. We have to add this override |
| 64 |
# option to allow them to override it. |
| 65 |
|
| 66 |
endmacro() |
| 67 |
|
| 68 |
|
| 69 |
macro(tribits_set_language_all_buildtypes_flags_override LANG) |
| 70 |
|
| 71 |
foreach(BUILDTYPE ${CMAKE_BUILD_TYPES_LIST}) |
| 72 |
tribits_set_language_buildtype_flags_override(${LANG} ${BUILDTYPE}) |
| 73 |
endforeach() |
| 74 |
|
| 75 |
endmacro() |
| 76 |
|
| 77 |
|
| 78 |
macro(tribits_set_language_general_flags LANG) |
| 79 |
|
| 80 |
dual_scope_prepend_cmndline_args(CMAKE_${LANG}_FLAGS "${GENERAL_BUILD_FLAGS}") |
| 81 |
if(${PROJECT_NAME}_VERBOSE_CONFIGURE) |
| 82 |
message(STATUS "Adding general ${LANG} flags \"${${GENERAL_BUILD_FLAGS}}\"") |
| 83 |
print_var(CMAKE_${LANG}_FLAGS) |
| 84 |
endif() |
| 85 |
|
| 86 |
endmacro() |
| 87 |
|
| 88 |
|
| 89 |
macro(tribits_set_language_coverage_flags LANG) |
| 90 |
|
| 91 |
dual_scope_prepend_cmndline_args(CMAKE_${LANG}_FLAGS |
| 92 |
"${COVERAGE_OPTIONS}") |
| 93 |
if(COVERAGE_OPTIONS AND ${PROJECT_NAME}_VERBOSE_CONFIGURE) |
| 94 |
message(STATUS "Adding coverage ${LANG} flags \"${COVERAGE_OPTIONS}\"") |
| 95 |
print_var(CMAKE_${LANG}_FLAGS) |
| 96 |
endif() |
| 97 |
|
| 98 |
endmacro() |
| 99 |
|
| 100 |
|
| 101 |
# |
| 102 |
# Function that sets up strong compile options for the primary |
| 103 |
# development platform (i.e. gcc) |
| 104 |
# |
| 105 |
# NOTE: The compiler flags in the cache, which may have been set by |
| 106 |
# the user, are not disturbed in this function. Instead variables in |
| 107 |
# the parent base scope are set. |
| 108 |
# |
| 109 |
# NOTE: This function should be called only once before adding any libraries, |
| 110 |
# executables, etc. |
| 111 |
# |
| 112 |
|
| 113 |
function(tribits_setup_basic_compile_link_flags) |
| 114 |
|
| 115 |
# |
| 116 |
# Setup and general flags |
| 117 |
# |
| 118 |
|
| 119 |
tribits_define_standard_compile_flags_vars(FALSE) |
| 120 |
|
| 121 |
# |
| 122 |
# Set up coverage testing options |
| 123 |
# |
| 124 |
|
| 125 |
if (${PROJECT_NAME}_ENABLE_COVERAGE_TESTING) |
| 126 |
set(COVERAGE_OPTIONS "-fprofile-arcs -ftest-coverage") |
| 127 |
else() |
| 128 |
set(COVERAGE_OPTIONS "") |
| 129 |
endif() |
| 130 |
|
| 131 |
# |
| 132 |
# C compiler options |
| 133 |
# |
| 134 |
|
| 135 |
assert_defined(${PROJECT_NAME}_ENABLE_C CMAKE_C_COMPILER_ID) |
| 136 |
if (${PROJECT_NAME}_ENABLE_C AND CMAKE_C_COMPILER_ID STREQUAL "GNU") |
| 137 |
tribits_set_language_buildtype_flags(C DEBUG) |
| 138 |
tribits_set_language_buildtype_flags(C RELEASE) |
| 139 |
tribits_set_language_general_flags(C) |
| 140 |
tribits_set_language_coverage_flags(C) |
| 141 |
endif() |
| 142 |
tribits_set_language_all_buildtypes_flags_override(C) |
| 143 |
|
| 144 |
# |
| 145 |
# C++ compiler options |
| 146 |
# |
| 147 |
|
| 148 |
assert_defined(${PROJECT_NAME}_ENABLE_CXX CMAKE_CXX_COMPILER_ID) |
| 149 |
if (${PROJECT_NAME}_ENABLE_CXX AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
| 150 |
tribits_set_language_buildtype_flags(CXX DEBUG) |
| 151 |
tribits_set_language_buildtype_flags(CXX RELEASE) |
| 152 |
tribits_set_language_general_flags(CXX) |
| 153 |
tribits_set_language_coverage_flags(CXX) |
| 154 |
endif() |
| 155 |
tribits_set_language_all_buildtypes_flags_override(CXX) |
| 156 |
|
| 157 |
# |
| 158 |
# Fortran compiler options |
| 159 |
# |
| 160 |
|
| 161 |
assert_defined(${PROJECT_NAME}_ENABLE_Fortran) |
| 162 |
if (${PROJECT_NAME}_ENABLE_Fortran AND CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") |
| 163 |
tribits_set_language_buildtype_flags(Fortran DEBUG) |
| 164 |
tribits_set_language_buildtype_flags(Fortran RELEASE) |
| 165 |
tribits_set_language_general_flags(Fortran) |
| 166 |
tribits_set_language_coverage_flags(Fortran) |
| 167 |
endif() |
| 168 |
tribits_set_language_all_buildtypes_flags_override(Fortran) |
| 169 |
|
| 170 |
# |
| 171 |
# Linker options |
| 172 |
# |
| 173 |
|
| 174 |
assert_defined(${PROJECT_NAME}_ENABLE_COVERAGE_TESTING COVERAGE_OPTIONS) |
| 175 |
if (${PROJECT_NAME}_ENABLE_COVERAGE_TESTING AND COVERAGE_OPTIONS) |
| 176 |
dual_scope_prepend_cmndline_args(CMAKE_EXE_LINKER_FLAGS |
| 177 |
"${COVERAGE_OPTIONS} ${CMAKE_EXE_LINKER_FLAGS}") |
| 178 |
if(${PROJECT_NAME}_VERBOSE_CONFIGURE) |
| 179 |
message(STATUS "Adding coverage linker flags flags \"${COVERAGE_OPTIONS}\"") |
| 180 |
print_var(CMAKE_EXE_LINKER_FLAGS) |
| 181 |
endif() |
| 182 |
endif() |
| 183 |
|
| 184 |
endfunction() |