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 # Set _FILE_OFFSET_BITS=64 on 32-bit build on Linux to enable output log files to exceed 2GB 49 if ((DE_CPU_X86) AND (DE_OS_UNIX)) 50 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FILE_OFFSET_BITS=64") 51 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_FILE_OFFSET_BITS=64") 52 endif () 53 54 # Force compiler to generate code where integers have well defined overflow 55 # Turn on -Wstrict-overflow=5 and check all warnings before removing 56 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fwrapv") 57 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fwrapv") 58 59 # Force compiler to not export any symbols. 60 # Any static libraries build are linked into the standalone executable binaries. 61 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden") 62 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden") 63 64 # For 3rd party sw disable all warnings 65 set(DE_3RD_PARTY_C_FLAGS "${CMAKE_C_FLAGS} ${TARGET_FLAGS} -w") 66 set(DE_3RD_PARTY_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TARGET_FLAGS} -w") 67elseif (DE_COMPILER_IS_MSC) 68 # Compiler flags for msc 69 70 # \note Following unnecessary nagging warnings are disabled: 71 # 4820: automatic padding added after data 72 # 4255: no function prototype given (from system headers) 73 # 4668: undefined identifier in preprocessor expression (from system headers) 74 # 4738: storing 32-bit float result in memory 75 # 4711: automatic inline expansion 76 set(MSC_BASE_FLAGS "/DWIN32 /D_WINDOWS /D_CRT_SECURE_NO_WARNINGS") 77 set(MSC_WARNING_FLAGS "/W3 /wd4820 /wd4255 /wd4668 /wd4738 /wd4711") 78 79 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MSC_BASE_FLAGS} ${MSC_WARNING_FLAGS}") 80 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MSC_BASE_FLAGS} /EHsc ${MSC_WARNING_FLAGS}") 81 82 # For 3rd party sw disable all warnings 83 set(DE_3RD_PARTY_C_FLAGS "${CMAKE_C_FLAGS} ${MSC_BASE_FLAGS} /W0") 84 set(DE_3RD_PARTY_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MSC_BASE_FLAGS} /EHsc /W0") 85else () 86 message(FATAL_ERROR "DE_COMPILER is not valid") 87endif () 88 89if (DE_MINGW AND DE_PTR_SIZE EQUAL 8) 90 # Pass -mbig-obj to mingw gas on Win64. COFF has a 2**16 section limit, and 91 # on Win64, every COMDAT function creates at least 3 sections: .text, .pdata, 92 # and .xdata. 93 # Enable static libgcc and libstdc++ also to avoid needing to have 94 # Windows builds of the standard libraries distributed. 95 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wa,-mbig-obj -static -static-libgcc") 96 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wa,-mbig-obj -static -static-libgcc -static-libstdc++") 97endif() 98