1 # Copyright 2013 Intel Corporation
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are met:
8 # - Redistributions of source code must retain the above copyright notice, this
9 # list of conditions and the following disclaimer.
11 # - Redistributions in binary form must reproduce the above copyright notice,
12 # this list of conditions and the following disclaimer in the documentation
13 # and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 include(CheckCCompilerFlag)
27 include(WaffleCheckThreadLocalStorage)
29 function(waffle_add_c_flag flag var)
30 check_c_compiler_flag("${flag}" ${var})
32 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}" PARENT_SCOPE)
40 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --std=c99")
41 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
42 set(CMAKE_C_FLAGS_DEBUG "-g3 -O0 -DDEBUG")
44 # Use '-g1' to produce enough debug info for generating backtraces, but not
45 # enough for single-stepping.
46 set(CMAKE_C_FLAGS_RELEASE "-g1 -O2 -DNDEBUG")
48 # These are disabled for NaCl because compilation against ppapi_simple would fail.
49 if(NOT waffle_has_nacl)
50 waffle_add_c_flag("-Werror=implicit-function-declaration" WERROR_IMPLICIT_FUNCTION_DECLARATION)
51 waffle_add_c_flag("-fvisibility=hidden" WITH_VISIBILITY_HIDDEN)
54 waffle_add_c_flag("-Werror=incompatible-pointer-types" WERROR_INCOMPATIBLE_POINTER_TYPES)
55 waffle_add_c_flag("-Werror=int-conversion" WERROR_INT_CONVERSION)
57 if(waffle_on_linux AND NOT waffle_has_nacl)
58 # On MacOS, the SSE2 headers trigger this error.
59 waffle_add_c_flag("-Werror=missing-prototypes" WERROR_MISSING_PROTOTYPES)
63 foreach(FLAG ${egl_CFLAGS_OTHER})
64 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAG}")
69 # Avoid depending on MinGW runtime DLLs
70 check_c_compiler_flag(-static-libgcc HAVE_STATIC_LIBGCC_FLAG)
71 if (HAVE_STATIC_LIBGCC_FLAG)
72 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc")
73 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc")
74 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libgcc")
77 # Avoid using TLS with MinGW builds.
78 waffle_check_thread_local_storage()
81 # XXX: and update the threads code
82 # http://msdn.microsoft.com/en-us/library/aa383745.aspx
83 if(CMAKE_GENERATOR_TOOLSET MATCHES "_xp$")
85 add_definitions(-D_WIN32_WINNT=0x0501 -DWINVER=0x0501)
88 add_definitions(-D_WIN32_WINNT=0x0601 -DWINVER=0x0601)
92 add_definitions(-D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS)
95 # http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
97 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
99 if(${flag_var} MATCHES "/MD")
100 string (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
107 add_definitions(-DWAFFLE_HAS_CGL)
112 add_definitions(-DWAFFLE_HAS_GLX)
115 if(waffle_has_wayland)
116 add_definitions(-DWAFFLE_HAS_WAYLAND)
119 if(waffle_has_x11_egl)
120 add_definitions(-DWAFFLE_HAS_X11_EGL)
124 add_definitions(-DWAFFLE_HAS_GBM)
127 if(waffle_has_surfaceless_egl)
128 add_definitions(-DWAFFLE_HAS_SURFACELESS_EGL)
132 add_definitions(-DWAFFLE_HAS_TLS)
135 if(waffle_has_tls_model_initial_exec)
136 add_definitions(-DWAFFLE_HAS_TLS_MODEL_INITIAL_EXEC)
139 add_definitions(-D_XOPEN_SOURCE=700)
143 add_definitions(-DWAFFLE_HAS_NACL)
146 if(waffle_on_windows)
147 add_definitions(-DWAFFLE_HAS_WGL)