SampleOptions.cmake 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. # Copyright 2021 DeepMind Technologies Limited
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # https://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,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # Global compilation settings
  15. set(CMAKE_C_STANDARD 11)
  16. set(CMAKE_C_STANDARD_REQUIRED ON)
  17. set(CMAKE_CXX_STANDARD 17)
  18. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  19. set(CMAKE_CXX_EXTENSIONS OFF)
  20. set(CMAKE_C_EXTENSIONS OFF)
  21. set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # For LLVM tooling
  22. if(NOT CMAKE_CONFIGURATION_TYPES)
  23. if(NOT CMAKE_BUILD_TYPE)
  24. message(STATUS "Setting build type to 'Release' as none was specified.")
  25. set(CMAKE_BUILD_TYPE
  26. "Release"
  27. CACHE STRING "Choose the type of build, recommanded options are: Debug or Release" FORCE
  28. )
  29. endif()
  30. set(BUILD_TYPES
  31. "Debug"
  32. "Release"
  33. "MinSizeRel"
  34. "RelWithDebInfo"
  35. )
  36. set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${BUILD_TYPES})
  37. endif()
  38. include(GNUInstallDirs)
  39. # Change the default output directory in the build structure. This is not stricly needed, but helps
  40. # running in Windows, such that all built executables have DLLs in the same folder as the .exe
  41. # files.
  42. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}")
  43. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}")
  44. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}")
  45. set(OpenGL_GL_PREFERENCE GLVND)
  46. set(CMAKE_POSITION_INDEPENDENT_CODE ON)
  47. set(CMAKE_C_VISIBILITY_PRESET hidden)
  48. set(CMAKE_CXX_VISIBILITY_PRESET hidden)
  49. set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
  50. if(MSVC)
  51. add_compile_options(/Gy /Gw /Oi)
  52. elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  53. add_compile_options(-fdata-sections -ffunction-sections)
  54. endif()
  55. # We default to shared library.
  56. set(BUILD_SHARED_LIBS
  57. ON
  58. CACHE BOOL "Build Mujoco as shared library."
  59. )
  60. option(MUJOCO_ENABLE_AVX "Build binaries that require AVX instructions, if possible." ON)
  61. option(MUJOCO_ENABLE_AVX_INTRINSICS "Make use of hand-written AVX intrinsics, if possible." ON)
  62. option(MUJOCO_ENABLE_RPATH "Enable RPath support when installing Mujoco." ON)
  63. mark_as_advanced(MUJOCO_ENABLE_RPATH)
  64. if(MUJOCO_ENABLE_AVX)
  65. include(CheckAvxSupport)
  66. get_avx_compile_options(AVX_COMPILE_OPTIONS)
  67. else()
  68. set(AVX_COMPILE_OPTIONS)
  69. endif()
  70. option(MUJOCO_BUILD_MACOS_FRAMEWORKS "Build libraries as macOS Frameworks" OFF)
  71. # Get some extra link options.
  72. include(MujocoLinkOptions)
  73. get_mujoco_extra_link_options(EXTRA_LINK_OPTIONS)
  74. if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT MSVC))
  75. set(EXTRA_COMPILE_OPTIONS
  76. -Werror
  77. -Wall
  78. -Wpedantic
  79. -Wimplicit-fallthrough
  80. -Wunused
  81. -Wvla
  82. -Wno-int-in-bool-context
  83. -Wno-sign-compare
  84. -Wno-unknown-pragmas
  85. )
  86. if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  87. # Set -Wimplicit-fallthrough=5 to only allow fallthrough annotation via __attribute__.
  88. set(EXTRA_COMPILE_OPTIONS ${EXTRA_COMPILE_OPTIONS} -Wimplicit-fallthrough=5
  89. -Wno-maybe-uninitialized
  90. )
  91. endif()
  92. endif()
  93. if(NOT CMAKE_INTERPROCEDURAL_OPTIMIZATION AND (CMAKE_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug"))
  94. set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
  95. endif()
  96. include(MujocoHarden)
  97. set(EXTRA_COMPILE_OPTIONS ${EXTRA_COMPILE_OPTIONS} ${MUJOCO_HARDEN_COMPILE_OPTIONS})
  98. set(EXTRA_LINK_OPTIONS ${EXTRA_LINK_OPTIONS} ${MUJOCO_HARDEN_LINK_OPTIONS})
  99. if(WIN32)
  100. add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE)
  101. endif()