1#------------------------------------------------------------------------- 2# drawElements CMake utilities 3# ---------------------------- 4# 5# Copyright 2014 The Android Open Source Project 6# 7# Licensed under the Apache License, Version 2.0 (the "License"); 8# you may not use this file except in compliance with the License. 9# You may obtain a copy of the License at 10# 11# http://www.apache.org/licenses/LICENSE-2.0 12# 13# Unless required by applicable law or agreed to in writing, software 14# distributed under the License is distributed on an "AS IS" BASIS, 15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16# See the License for the specific language governing permissions and 17# limitations under the License. 18# 19#------------------------------------------------------------------------- 20 21set(DE_COVERAGE_BUILD "OFF" CACHE STRING "Build with coverage instrumentation with GCC (ON/OFF)") 22 23if (NOT DE_DEFS) 24 message(FATAL_ERROR "Defs.cmake is not included") 25endif () 26 27if (DE_COMPILER_IS_GCC OR DE_COMPILER_IS_CLANG) 28 # Compiler flags for GCC/Clang 29 30 set(TARGET_FLAGS "") 31 32 if (DE_COVERAGE_BUILD) 33 if (not DE_COMPILER_IS_GCC) 34 message(FATAL_ERROR "Coverage build requires GCC") 35 endif () 36 37 add_definitions("-DDE_COVERAGE_BUILD") 38 set(TARGET_FLAGS "-fprofile-arcs -ftest-coverage") 39 set(LINK_FLAGS "${LINK_FLAGS} -lgcov") 40 endif () 41 42 # \note Remove -Wno-sign-conversion for more warnings 43 set(WARNING_FLAGS "-Wall -Wextra -Wno-long-long -Wshadow -Wundef -Wconversion -Wno-sign-conversion") 44 45 set(CMAKE_C_FLAGS "${TARGET_FLAGS} ${WARNING_FLAGS} ${CMAKE_C_FLAGS} -std=c99 -pedantic ") 46 set(CMAKE_CXX_FLAGS "${TARGET_FLAGS} ${WARNING_FLAGS} ${CMAKE_CXX_FLAGS} -std=c++11 -Wno-delete-non-virtual-dtor") 47 48 # Force compiler to generate code where integers have well defined overflow 49 # Turn on -Wstrict-overflow=5 and check all warnings before removing 50 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fwrapv") 51 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fwrapv") 52 53 # Force compiler to not export any symbols. 54 # Any static libraries build are linked into the standalone executable binaries. 55 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden") 56 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden") 57 58 # For 3rd party sw disable all warnings 59 set(DE_3RD_PARTY_C_FLAGS "${CMAKE_C_FLAGS} ${TARGET_FLAGS} -w") 60 set(DE_3RD_PARTY_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TARGET_FLAGS} -w") 61elseif (DE_COMPILER_IS_MSC) 62 # Compiler flags for msc 63 64 # \note Following unnecessary nagging warnings are disabled: 65 # 4820: automatic padding added after data 66 # 4255: no function prototype given (from system headers) 67 # 4668: undefined identifier in preprocessor expression (from system headers) 68 # 4738: storing 32-bit float result in memory 69 # 4711: automatic inline expansion 70 set(MSC_BASE_FLAGS "/DWIN32 /D_WINDOWS /D_CRT_SECURE_NO_WARNINGS") 71 set(MSC_WARNING_FLAGS "/W3 /wd4820 /wd4255 /wd4668 /wd4738 /wd4711") 72 73 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MSC_BASE_FLAGS} ${MSC_WARNING_FLAGS}") 74 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MSC_BASE_FLAGS} /EHsc ${MSC_WARNING_FLAGS}") 75 76 # For 3rd party sw disable all warnings 77 set(DE_3RD_PARTY_C_FLAGS "${CMAKE_C_FLAGS} ${MSC_BASE_FLAGS} /W0") 78 set(DE_3RD_PARTY_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MSC_BASE_FLAGS} /EHsc /W0") 79else () 80 message(FATAL_ERROR "DE_COMPILER is not valid") 81endif () 82 83if (DE_MINGW AND DE_PTR_SIZE EQUAL 8) 84 # Pass -mbig-obj to mingw gas on Win64. COFF has a 2**16 section limit, and 85 # on Win64, every COMDAT function creates at least 3 sections: .text, .pdata, 86 # and .xdata. 87 # Enable static libgcc and libstdc++ also to avoid needing to have 88 # Windows builds of the standard libraries distributed. 89 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wa,-mbig-obj -static -static-libgcc") 90 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wa,-mbig-obj -static -static-libgcc -static-libstdc++") 91endif() 92