PageRenderTime 8ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/cmake/00-Common.cmake

https://bitbucket.org/lindenlab/viewer-beta/
CMake | 253 lines | 170 code | 47 blank | 36 comment | 27 complexity | 5bbd5dfaec14033766272e2286a7ead1 MD5 | raw file
  1# -*- cmake -*-
  2#
  3# Compilation options shared by all Second Life components.
  4
  5include(Variables)
  6
  7# Portable compilation flags.
  8set(CMAKE_CXX_FLAGS_DEBUG "-D_DEBUG -DLL_DEBUG=1")
  9set(CMAKE_CXX_FLAGS_RELEASE
 10    "-DLL_RELEASE=1 -DLL_RELEASE_FOR_DOWNLOAD=1 -DNDEBUG") 
 11
 12set(CMAKE_CXX_FLAGS_RELWITHDEBINFO 
 13    "-DLL_RELEASE=1 -DNDEBUG -DLL_RELEASE_WITH_DEBUG_INFO=1")
 14
 15# Configure crash reporting
 16set(RELEASE_CRASH_REPORTING OFF CACHE BOOL "Enable use of crash reporting in release builds")
 17set(NON_RELEASE_CRASH_REPORTING OFF CACHE BOOL "Enable use of crash reporting in developer builds")
 18
 19if(RELEASE_CRASH_REPORTING)
 20  set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DLL_SEND_CRASH_REPORTS=1")
 21endif()
 22
 23if(NON_RELEASE_CRASH_REPORTING)
 24  set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -DLL_SEND_CRASH_REPORTS=1")
 25  set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DLL_SEND_CRASH_REPORTS=1")
 26endif()  
 27
 28# Don't bother with a MinSizeRel build.
 29set(CMAKE_CONFIGURATION_TYPES "RelWithDebInfo;Release;Debug" CACHE STRING
 30    "Supported build types." FORCE)
 31
 32
 33# Platform-specific compilation flags.
 34
 35if (WINDOWS)
 36  # Don't build DLLs.
 37  set(BUILD_SHARED_LIBS OFF)
 38
 39  # for "backwards compatibility", cmake sneaks in the Zm1000 option which royally
 40  # screws incredibuild. this hack disables it.
 41  # for details see: http://connect.microsoft.com/VisualStudio/feedback/details/368107/clxx-fatal-error-c1027-inconsistent-values-for-ym-between-creation-and-use-of-precompiled-headers
 42  # http://www.ogre3d.org/forums/viewtopic.php?f=2&t=60015
 43  # http://www.cmake.org/pipermail/cmake/2009-September/032143.html
 44  string(REPLACE "/Zm1000" " " CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
 45
 46  set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Od /Zi /MDd /MP -D_SCL_SECURE_NO_WARNINGS=1"
 47      CACHE STRING "C++ compiler debug options" FORCE)
 48  set(CMAKE_CXX_FLAGS_RELWITHDEBINFO 
 49      "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /Od /Zi /MD /MP /Ob0 -D_SECURE_STL=0"
 50      CACHE STRING "C++ compiler release-with-debug options" FORCE)
 51  set(CMAKE_CXX_FLAGS_RELEASE
 52      "${CMAKE_CXX_FLAGS_RELEASE} ${LL_CXX_FLAGS} /O2 /Zi /MD /MP /Ob2 -D_SECURE_STL=0 -D_HAS_ITERATOR_DEBUGGING=0"
 53      CACHE STRING "C++ compiler release options" FORCE)
 54
 55  set(CMAKE_CXX_STANDARD_LIBRARIES "")
 56  set(CMAKE_C_STANDARD_LIBRARIES "")
 57
 58  add_definitions(
 59      /DLL_WINDOWS=1
 60      /DDOM_DYNAMIC
 61      /DUNICODE
 62      /D_UNICODE 
 63      /GS
 64      /TP
 65      /W3
 66      /c
 67      /Zc:forScope
 68      /nologo
 69      /Oy-
 70      /Zc:wchar_t-
 71      /arch:SSE2
 72      )
 73     
 74  # Are we using the crummy Visual Studio KDU build workaround?
 75  if (NOT VS_DISABLE_FATAL_WARNINGS)
 76    add_definitions(/WX)
 77  endif (NOT VS_DISABLE_FATAL_WARNINGS)
 78
 79  # configure win32 API for windows XP+ compatibility
 80  set(WINVER "0x0501" CACHE STRING "Win32 API Target version (see http://msdn.microsoft.com/en-us/library/aa383745%28v=VS.85%29.aspx)")
 81  add_definitions("/DWINVER=${WINVER}" "/D_WIN32_WINNT=${WINVER}")
 82endif (WINDOWS)
 83
 84
 85if (LINUX)
 86  set(CMAKE_SKIP_RPATH TRUE)
 87
 88  # Here's a giant hack for Fedora 8, where we can't use
 89  # _FORTIFY_SOURCE if we're using a compiler older than gcc 4.1.
 90
 91  find_program(GXX g++)
 92  mark_as_advanced(GXX)
 93
 94  if (GXX)
 95    execute_process(
 96        COMMAND ${GXX} --version
 97        COMMAND sed "s/^[gc+ ]*//"
 98        COMMAND head -1
 99        OUTPUT_VARIABLE GXX_VERSION
100        OUTPUT_STRIP_TRAILING_WHITESPACE
101        )
102  else (GXX)
103    set(GXX_VERSION x)
104  endif (GXX)
105
106  # The quoting hack here is necessary in case we're using distcc or
107  # ccache as our compiler.  CMake doesn't pass the command line
108  # through the shell by default, so we end up trying to run "distcc"
109  # " g++" - notice the leading space.  Ugh.
110
111  execute_process(
112      COMMAND sh -c "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} --version"
113      COMMAND sed "s/^[gc+ ]*//"
114      COMMAND head -1
115      OUTPUT_VARIABLE CXX_VERSION
116      OUTPUT_STRIP_TRAILING_WHITESPACE)
117
118  if (${GXX_VERSION} STREQUAL ${CXX_VERSION})
119    add_definitions(-D_FORTIFY_SOURCE=2)
120  else (${GXX_VERSION} STREQUAL ${CXX_VERSION})
121    if (NOT ${GXX_VERSION} MATCHES " 4.1.*Red Hat")
122      add_definitions(-D_FORTIFY_SOURCE=2)
123    endif (NOT ${GXX_VERSION} MATCHES " 4.1.*Red Hat")
124  endif (${GXX_VERSION} STREQUAL ${CXX_VERSION})
125
126  # Let's actually get a numerical version of gxx's version
127  STRING(REGEX REPLACE ".* ([0-9])\\.([0-9])\\.([0-9]).*" "\\1\\2\\3" CXX_VERSION_NUMBER ${CXX_VERSION})
128
129  # gcc 4.3 and above don't like the LL boost and also
130  # cause warnings due to our use of deprecated headers
131  if(${CXX_VERSION_NUMBER} GREATER 429)
132    add_definitions(-Wno-parentheses)
133    set(CMAKE_CXX_FLAGS "-Wno-deprecated ${CMAKE_CXX_FLAGS}")
134  endif (${CXX_VERSION_NUMBER} GREATER 429)
135
136  # End of hacks.
137
138  add_definitions(
139      -DLL_LINUX=1
140      -D_REENTRANT
141      -fexceptions
142      -fno-math-errno
143      -fno-strict-aliasing
144      -fsigned-char
145      -g
146      -msse2
147      -mfpmath=sse
148      -pthread
149      )
150
151  if (SERVER)
152    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-depth-60")
153    if (EXISTS /etc/debian_version)
154      FILE(READ /etc/debian_version DEBIAN_VERSION)
155    else (EXISTS /etc/debian_version)
156      set(DEBIAN_VERSION "")
157    endif (EXISTS /etc/debian_version)
158
159    if (NOT DEBIAN_VERSION STREQUAL "3.1")
160      add_definitions(-DCTYPE_WORKAROUND)
161    endif (NOT DEBIAN_VERSION STREQUAL "3.1")
162
163    if (EXISTS /usr/lib/mysql4/mysql)
164      link_directories(/usr/lib/mysql4/mysql)
165    endif (EXISTS /usr/lib/mysql4/mysql)
166
167  endif (SERVER)
168
169  if (VIEWER)
170    add_definitions(-DAPPID=secondlife)
171    add_definitions(-fvisibility=hidden)
172    # don't catch SIGCHLD in our base application class for the viewer - some of our 3rd party libs may need their *own* SIGCHLD handler to work.  Sigh!  The viewer doesn't need to catch SIGCHLD anyway.
173    add_definitions(-DLL_IGNORE_SIGCHLD)
174    if (WORD_SIZE EQUAL 32)
175      add_definitions(-march=pentium4)
176    endif (WORD_SIZE EQUAL 32)
177    add_definitions(-mfpmath=sse)
178    #add_definitions(-ftree-vectorize) # THIS CRASHES GCC 3.1-3.2
179    if (NOT STANDALONE)
180      # this stops us requiring a really recent glibc at runtime
181      add_definitions(-fno-stack-protector)
182      # linking can be very memory-hungry, especially the final viewer link
183      set(CMAKE_CXX_LINK_FLAGS "-Wl,--no-keep-memory")
184    endif (NOT STANDALONE)
185  endif (VIEWER)
186
187  set(CMAKE_CXX_FLAGS_DEBUG "-fno-inline ${CMAKE_CXX_FLAGS_DEBUG}")
188  set(CMAKE_CXX_FLAGS_RELEASE "-O2 ${CMAKE_CXX_FLAGS_RELEASE}")
189endif (LINUX)
190
191
192if (DARWIN)
193  # NOTE (per http://lists.apple.com/archives/darwin-dev/2008/Jan/msg00232.html):
194  # > Why the bus error? What am I doing wrong? 
195  # This is a known issue where getcontext(3) is writing past the end of the
196  # ucontext_t struct when _XOPEN_SOURCE is not defined (rdar://problem/5578699 ).
197  # As a workaround, define _XOPEN_SOURCE before including ucontext.h.
198  add_definitions(-DLL_DARWIN=1 -D_XOPEN_SOURCE)
199  set(CMAKE_CXX_LINK_FLAGS "-Wl,-headerpad_max_install_names,-search_paths_first")
200  set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_CXX_LINK_FLAGS}")
201  set(DARWIN_extra_cstar_flags "-mlong-branch")
202  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DARWIN_extra_cstar_flags}")
203  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}  ${DARWIN_extra_cstar_flags}")
204  # NOTE: it's critical that the optimization flag is put in front.
205  # NOTE: it's critical to have both CXX_FLAGS and C_FLAGS covered.
206  set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O0 ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
207  set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O0 ${CMAKE_C_FLAGS_RELWITHDEBINFO}")
208endif (DARWIN)
209
210
211if (LINUX OR DARWIN)
212  set(GCC_WARNINGS "-Wall -Wno-sign-compare -Wno-trigraphs")
213
214  if (NOT GCC_DISABLE_FATAL_WARNINGS)
215    set(GCC_WARNINGS "${GCC_WARNINGS} -Werror")
216  endif (NOT GCC_DISABLE_FATAL_WARNINGS)
217
218  set(GCC_CXX_WARNINGS "${GCC_WARNINGS} -Wno-reorder -Wno-non-virtual-dtor")
219
220  set(CMAKE_C_FLAGS "${GCC_WARNINGS} ${CMAKE_C_FLAGS}")
221  set(CMAKE_CXX_FLAGS "${GCC_CXX_WARNINGS} ${CMAKE_CXX_FLAGS}")
222
223  if (WORD_SIZE EQUAL 32)
224    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
225    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
226  elseif (WORD_SIZE EQUAL 64)
227    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m64")
228    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64")
229  endif (WORD_SIZE EQUAL 32)
230endif (LINUX OR DARWIN)
231
232
233if (STANDALONE)
234  add_definitions(-DLL_STANDALONE=1)
235
236  if (LINUX AND ${ARCH} STREQUAL "i686")
237    add_definitions(-march=pentiumpro)
238  endif (LINUX AND ${ARCH} STREQUAL "i686")
239
240else (STANDALONE)
241  set(${ARCH}_linux_INCLUDES
242      ELFIO
243      atk-1.0
244      glib-2.0
245      gstreamer-0.10
246      gtk-2.0
247      pango-1.0
248      )
249endif (STANDALONE)
250
251if(SERVER)
252  include_directories(${LIBS_PREBUILT_DIR}/include/havok)
253endif(SERVER)