draco_build_definitions.cmake 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. # Copyright 2021 The Draco Authors
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may not
  4. # use this file except in compliance with the License. You may obtain a copy of
  5. # the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  11. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  12. # License for the specific language governing permissions and limitations under
  13. # the License.
  14. if(DRACO_CMAKE_DRACO_BUILD_DEFINITIONS_CMAKE_)
  15. return()
  16. endif() # DRACO_CMAKE_DRACO_BUILD_DEFINITIONS_CMAKE_
  17. set(DRACO_CMAKE_DRACO_BUILD_DEFINITIONS_CMAKE_ 1)
  18. # Utility for controlling the main draco library dependency. This changes in
  19. # shared builds, and when an optional target requires a shared library build.
  20. macro(set_draco_target)
  21. if(MSVC)
  22. set(draco_dependency draco)
  23. set(draco_plugin_dependency ${draco_dependency})
  24. else()
  25. if(BUILD_SHARED_LIBS)
  26. set(draco_dependency draco_shared)
  27. else()
  28. set(draco_dependency draco_static)
  29. endif()
  30. set(draco_plugin_dependency draco_static)
  31. endif()
  32. endmacro()
  33. # Configures flags and sets build system globals.
  34. macro(draco_set_build_definitions)
  35. string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type_lowercase)
  36. if(build_type_lowercase MATCHES "rel" AND DRACO_FAST)
  37. if(MSVC)
  38. list(APPEND draco_msvc_cxx_flags "/Ox")
  39. else()
  40. list(APPEND draco_base_cxx_flags "-O3")
  41. endif()
  42. endif()
  43. draco_load_version_info()
  44. # Library version info. See the libtool docs for updating the values:
  45. # https://www.gnu.org/software/libtool/manual/libtool.html#Updating-version-info
  46. #
  47. # c=<current>, r=<revision>, a=<age>
  48. #
  49. # libtool generates a .so file as .so.[c-a].a.r, while -version-info c:r:a is
  50. # passed to libtool.
  51. #
  52. # We set DRACO_SOVERSION = [c-a].a.r
  53. set(LT_CURRENT 8)
  54. set(LT_REVISION 0)
  55. set(LT_AGE 0)
  56. math(EXPR DRACO_SOVERSION_MAJOR "${LT_CURRENT} - ${LT_AGE}")
  57. set(DRACO_SOVERSION "${DRACO_SOVERSION_MAJOR}.${LT_AGE}.${LT_REVISION}")
  58. unset(LT_CURRENT)
  59. unset(LT_REVISION)
  60. unset(LT_AGE)
  61. list(APPEND draco_include_paths "${draco_root}" "${draco_root}/src"
  62. "${draco_build}")
  63. if(DRACO_TRANSCODER_SUPPORTED)
  64. draco_setup_eigen()
  65. draco_setup_filesystem()
  66. draco_setup_tinygltf()
  67. endif()
  68. list(APPEND draco_defines "DRACO_CMAKE=1"
  69. "DRACO_FLAGS_SRCDIR=\"${draco_root}\""
  70. "DRACO_FLAGS_TMPDIR=\"/tmp\"")
  71. if(MSVC OR WIN32)
  72. list(APPEND draco_defines "_CRT_SECURE_NO_DEPRECATE=1" "NOMINMAX=1")
  73. if(BUILD_SHARED_LIBS)
  74. set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
  75. endif()
  76. endif()
  77. if(NOT MSVC)
  78. if(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
  79. # Ensure 64-bit platforms can support large files.
  80. list(APPEND draco_defines "_LARGEFILE_SOURCE" "_FILE_OFFSET_BITS=64")
  81. endif()
  82. if(NOT DRACO_DEBUG_COMPILER_WARNINGS)
  83. if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
  84. list(APPEND draco_clang_cxx_flags
  85. "-Wno-implicit-const-int-float-conversion")
  86. else()
  87. list(APPEND draco_base_cxx_flags "-Wno-deprecated-declarations")
  88. endif()
  89. endif()
  90. endif()
  91. if(ANDROID)
  92. if(CMAKE_ANDROID_ARCH_ABI STREQUAL "armeabi-v7a")
  93. set(CMAKE_ANDROID_ARM_MODE ON)
  94. endif()
  95. endif()
  96. set_draco_target()
  97. if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
  98. if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6")
  99. # Quiet warnings in copy-list-initialization where {} elision has always
  100. # been allowed.
  101. list(APPEND draco_clang_cxx_flags "-Wno-missing-braces")
  102. endif()
  103. endif()
  104. if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  105. if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "7")
  106. if(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7")
  107. # Quiet gcc 6 vs 7 abi warnings:
  108. # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77728
  109. list(APPEND draco_base_cxx_flags "-Wno-psabi")
  110. list(APPEND ABSL_GCC_FLAGS "-Wno-psabi")
  111. endif()
  112. endif()
  113. endif()
  114. # Source file names ending in these suffixes will have the appropriate
  115. # compiler flags added to their compile commands to enable intrinsics.
  116. set(draco_neon_source_file_suffix "neon.cc")
  117. set(draco_sse4_source_file_suffix "sse4.cc")
  118. if((${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" AND ${CMAKE_CXX_COMPILER_VERSION}
  119. VERSION_LESS 5)
  120. OR (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang"
  121. AND ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 4))
  122. message(
  123. WARNING "GNU/GCC < v5 or Clang/LLVM < v4, ENABLING COMPATIBILITY MODE.")
  124. draco_enable_feature(FEATURE "DRACO_OLD_GCC")
  125. endif()
  126. if(EMSCRIPTEN)
  127. draco_check_emscripten_environment()
  128. draco_get_required_emscripten_flags(
  129. FLAG_LIST_VAR_COMPILER draco_base_cxx_flags
  130. FLAG_LIST_VAR_LINKER draco_base_exe_linker_flags)
  131. endif()
  132. draco_configure_sanitizer()
  133. endmacro()