Variables.cmake 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. # -*- cmake -*-
  2. if (VARIABLES_CMAKE_INCLUDED)
  3. return()
  4. endif (VARIABLES_CMAKE_INCLUDED)
  5. set (VARIABLES_CMAKE_INCLUDED TRUE)
  6. # Definitions of variables used throughout the Second Life build process.
  7. #
  8. # Platform variables:
  9. #
  10. # DARWIN - macOS
  11. # LINUX - Linux
  12. # WINDOWS - Windows
  13. # Relative and absolute paths to subtrees.
  14. set(SCRIPTS_DIR ${CMAKE_SOURCE_DIR}/../scripts)
  15. set(LIBS_PREBUILT_DIR ${CMAKE_SOURCE_DIR}/.. CACHE PATH "Location of prebuilt libraries.")
  16. if (${CMAKE_VERSION} VERSION_GREATER 3.1.0)
  17. # Prevents a warning about arguments as variables or keywords when unquoted
  18. # happening when comparing "${CMAKE_CXX_COMPILER_ID}" and "MSVC" below...
  19. cmake_policy(SET CMP0054 NEW)
  20. endif (${CMAKE_VERSION} VERSION_GREATER 3.1.0)
  21. # Only 64 bits builds are now supported, for all platforms.
  22. # *TODO: support for cross-compilation on a different build architecture ?
  23. if (${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "x86_64" OR ${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "AMD64")
  24. set(ARCH x86_64)
  25. elseif (${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "aarch64*" OR ${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "arm64*")
  26. set(ARCH arm64)
  27. else ()
  28. message(FATAL_ERROR "Unsupported architecture ${CMAKE_HOST_SYSTEM_PROCESSOR}, sorry !")
  29. endif ()
  30. message(STATUS "Architecture to build for: ${ARCH}")
  31. if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  32. set(DARWIN 1)
  33. if (${CMAKE_VERSION} VERSION_LESS 3.12.0)
  34. message(FATAL_ERROR "Minimum cmake version required to build the viewer with Xcode is 3.12.0")
  35. endif (${CMAKE_VERSION} VERSION_LESS 3.12.0)
  36. execute_process(
  37. COMMAND sh -c "xcodebuild -version | grep Xcode | cut -d ' ' -f2 | cut -d'.' -f1-2"
  38. OUTPUT_VARIABLE XCODE_VERSION
  39. )
  40. string(REGEX REPLACE "(\r?\n)+$" "" XCODE_VERSION "${XCODE_VERSION}")
  41. if (XCODE_VERSION LESS 11.0)
  42. message(FATAL_ERROR "Minimum Xcode version required to build the viewer is 11.0")
  43. endif (XCODE_VERSION LESS 11.0)
  44. # Use the new Xcode 12 build system if possible
  45. if (NOT ${CMAKE_VERSION} VERSION_LESS 3.19.0 AND NOT XCODE_VERSION LESS 12.0)
  46. set(CMAKE_XCODE_BUILD_SYSTEM 12)
  47. endif ()
  48. set (GCC_VERSION 0)
  49. if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
  50. execute_process(
  51. COMMAND sh -c "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} --version"
  52. COMMAND head -1
  53. COMMAND sed "s/^[^0-9]*//"
  54. OUTPUT_VARIABLE CLANG_VERSION
  55. OUTPUT_STRIP_TRAILING_WHITESPACE
  56. )
  57. # Let's actually get a numerical version of Clang's version
  58. STRING(REGEX REPLACE "([0-9]+)\\.([0-9])\\.([0-9]).*" "\\1\\2\\3" CLANG_VERSION ${CLANG_VERSION})
  59. message(STATUS "Clang version (dots removed): ${CLANG_VERSION}")
  60. elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
  61. message(FATAL_ERROR "Unsupported compiler on this platform, sorry !")
  62. else ()
  63. message(FATAL_ERROR "Unknown compiler !")
  64. endif ()
  65. set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvm.clang.1_0")
  66. set(CMAKE_XCODE_ATTRIBUTE_GCC_STRICT_ALIASING NO)
  67. set(CMAKE_XCODE_ATTRIBUTE_GCC_FAST_MATH NO)
  68. set(CMAKE_XCODE_ATTRIBUTE_CLANG_X86_VECTOR_INSTRUCTIONS sse2)
  69. set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_64_TO_32_BIT_CONVERSION NO)
  70. set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "")
  71. set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED NO)
  72. set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS "")
  73. # We target macOS 10.13 which is the minimum for Xcode 14.4 and newer. HB
  74. set(CMAKE_OSX_DEPLOYMENT_TARGET 10.13)
  75. # Support for Unix Makefiles generator
  76. if (CMAKE_GENERATOR STREQUAL "Unix Makefiles")
  77. execute_process(COMMAND xcodebuild -version -sdk "${CMAKE_OSX_SYSROOT}" Path | head -n 1 OUTPUT_VARIABLE CMAKE_OSX_SYSROOT)
  78. string(REGEX REPLACE "(\r?\n)+$" "" CMAKE_OSX_SYSROOT "${CMAKE_OSX_SYSROOT}")
  79. endif (CMAKE_GENERATOR STREQUAL "Unix Makefiles")
  80. message(STATUS "Xcode version: ${XCODE_VERSION}")
  81. message(STATUS "OSX sysroot: ${CMAKE_OSX_SYSROOT}")
  82. message(STATUS "OSX deployment target: ${CMAKE_OSX_DEPLOYMENT_TARGET}")
  83. # NOTE: CMAKE_OSX_ARCHITECTURES is apparently always empty...
  84. #message(STATUS "OSX target architecture: ${CMAKE_OSX_ARCHITECTURES}")
  85. endif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  86. if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
  87. set(LINUX ON BOOl FORCE)
  88. set (GCC_VERSION 0)
  89. set (CLANG_VERSION 0)
  90. if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  91. execute_process(
  92. COMMAND sh -c "${CMAKE_CXX_COMPILER} -dumpversion"
  93. OUTPUT_VARIABLE CLANG_VERSION
  94. )
  95. # Let's actually get a numerical version of Clang's version
  96. STRING(REGEX REPLACE "([0-9]+)\\.([0-9])\\.([0-9]).*" "\\1\\2\\3" CLANG_VERSION ${CLANG_VERSION})
  97. message(STATUS "Clang version (dots removed): ${CLANG_VERSION}")
  98. elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  99. execute_process(
  100. COMMAND sh -c "${CMAKE_CXX_COMPILER} -dumpversion"
  101. OUTPUT_VARIABLE GCC_VERSION
  102. )
  103. # Let's actually get a numerical version of GCC's version
  104. STRING(REGEX REPLACE "([0-9]+)\\.([0-9])\\.([0-9]).*" "\\1\\2\\3" GCC_VERSION ${GCC_VERSION})
  105. # When compiled with --with-gcc-major-version-only newer gcc versions
  106. # only report the major number with -dumpversion, and -dumpfullversion
  107. # (which is not understood by older gcc versions) must be used instead
  108. # to get the true version !!! The guy who coded this (instead of
  109. # simply adding a -dumpmajorversion) should face death penalty for
  110. # utter (and lethal, natural-selection wise) stupidity !
  111. if (${GCC_VERSION} LESS 100)
  112. execute_process(
  113. COMMAND sh -c "${CMAKE_CXX_COMPILER} -dumpfullversion"
  114. OUTPUT_VARIABLE GCC_VERSION
  115. )
  116. STRING(REGEX REPLACE "([0-9]+)\\.([0-9])\\.([0-9]).*" "\\1\\2\\3" GCC_VERSION ${GCC_VERSION})
  117. endif (${GCC_VERSION} LESS 100)
  118. message(STATUS "GCC version (dots removed): ${GCC_VERSION}")
  119. elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
  120. # ICC might actually work for compiling the viewer, but would require
  121. # to make approriate changes/additions to 00-Common.cmake. If you feel
  122. # like it, be my guest and provide me with the necessary patch... HB
  123. message(FATAL_ERROR "Unsupported compiler on this platform, sorry !")
  124. else ()
  125. message(FATAL_ERROR "Unknown compiler !")
  126. endif ()
  127. endif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
  128. if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
  129. set(USING_CLANG OFF)
  130. if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
  131. set(USING_CLANG ON)
  132. elseif (MSVC_VERSION EQUAL 1937)
  133. message(FATAL_ERROR "The MSVC1937 compiler is utterly broken (e.g. the builds crash when ran under Wine), please roll back to MSVC1936 or update to a fixed version !")
  134. elseif (MSVC_VERSION LESS 1930 OR MSVC_VERSION GREATER 1949)
  135. message(FATAL_ERROR "You need VS2022 to build this viewer !")
  136. else ()
  137. message(STATUS "MSVC version: ${MSVC_VERSION}")
  138. endif ()
  139. set(WINDOWS ON BOOL FORCE)
  140. endif (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
  141. if (DARWIN)
  142. set(PREBUILT_TYPE darwin64)
  143. elseif (LINUX)
  144. if (ARCH STREQUAL "arm64")
  145. set(PREBUILT_TYPE linux64-arm)
  146. else ()
  147. set(PREBUILT_TYPE linux64)
  148. endif ()
  149. elseif (WINDOWS)
  150. set(PREBUILT_TYPE windows64)
  151. endif ()
  152. set(VIEWER_BRANDING_ID "cool_vl_viewer" CACHE STRING "Viewer branding id (currently cool_vl_viewer)")
  153. set(VIEWER_BRANDING_NAME "Cool VL Viewer")
  154. set(VIEWER_BRANDING_NAME_CAMELCASE "CoolVLViewer")
  155. set(USESYSTEMLIBS OFF CACHE BOOL "Use system libraries instead of prebuilt libraries whenever possible.")
  156. # NOTE: USEAVX and USEAVX2 are mainly geared towards the MSVC compiler. For gcc
  157. # or clang, you would rather pass -mavx[2] or -march=<cpu-type or native> in
  158. # CMAKE_C_FLAGS and CMAKE_CXX_FLAGS[_RELEASE]. In particular, -march=native
  159. # would automatically enable the adequate SSE2/AVX/AVX2 optimizations for
  160. # compiler-generated maths on the build system.
  161. set(USEAVX OFF CACHE BOOL "Use AVX instead of SSE2 for compiler-generated maths.")
  162. set(USEAVX2 OFF CACHE BOOL "Use AVX2 instead of SSE2 for compiler-generated maths.")
  163. # NOTE: LTO may actually prove detrimental (or simply neutral) to frame rates,
  164. # because the compiler will try too hard to common up code that would otherwise
  165. # get inlined... It appears, however that newer compilers (gcc 11/clang 12) do
  166. # provide better results (frame rates) with LTO, especially llvm/clang v12.
  167. set(USELTO OFF CACHE BOOL "Use link time optimization (Linux only and not supported by all compiler versions).")
  168. # Use unity builds where possible (only available with cmake v3.16.0 or newer;
  169. # this option is simply ignored with older versions). EXPERIMENTAL and largely
  170. # untested: may result in weird bugs in the final binaries... See the comment
  171. # at the end of indra/llplugin/CMakeLists.txt.
  172. set(USEUNITYBUILD OFF CACHE BOOL "Use cmake v3.16.0+ UNITY_BUILD feature for faster builds.")
  173. # Use -fstack-protector option to protect the stack with canaries (causes a
  174. # small loss in speed due to added code and caches usage for each function
  175. # call). Not really needed for an application such as the SL viewer; the risk
  176. # of seeing some injected rogue data triggering an overflow bug and allowing
  177. # arbitrary code execution (and without crashing the viewer, i.e. without the
  178. # user noticing something is wrong) is totally negligible and hardly feasible
  179. # at all for someone not controlling the grid servers.
  180. set(PROTECTSTACK OFF CACHE BOOL "Protect the stack against overflows (for the paranoids).")
  181. # Prevent the use of an executable stack by gcc, if requested. Note: this is
  182. # EXPERIMENTAL and may result in slightly slower code or, at worst, a crashing
  183. # viewer (see the corresponding comment in 00-Common.cmake).
  184. set(NOEXECSTACK OFF CACHE BOOL "Prevent the use of an executable stack by gcc (for the paranoids).")
  185. # OpenMP support, if requested
  186. set(OPENMP OFF CACHE BOOL "Enable OpenMP optimizations.")
  187. # Enable the Tracy profiler support, if requested.
  188. set(TRACY OFF CACHE BOOL "Enable Tracy profiler support.")
  189. # Profiling with gprof, if requested (Linux only).
  190. set(GPROF OFF CACHE BOOL "Enable gprof profiling.")
  191. # Sanitizing with ASAN, if requested (Linux only).
  192. set(ASAN OFF CACHE BOOL "Enable ASAN sanitizer.")
  193. source_group("CMake Rules" FILES CMakeLists.txt)