MujocoHarden.cmake 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # Copyright 2022 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. option(MUJOCO_HARDEN "Enable build hardening for MuJoCo." OFF)
  15. if(MUJOCO_HARDEN
  16. AND NOT
  17. CMAKE_CXX_COMPILER_ID
  18. MATCHES
  19. ".*Clang.*"
  20. )
  21. message(FATAL_ERROR "MUJOCO_HARDEN is only supported when building with Clang")
  22. endif()
  23. if(MUJOCO_HARDEN)
  24. set(MUJOCO_HARDEN_COMPILE_OPTIONS -D_FORTIFY_SOURCE=2 -fstack-protector)
  25. if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  26. set(MUJOCO_HARDEN_LINK_OPTIONS -Wl,-bind_at_load)
  27. elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
  28. set(MUJOCO_HARDEN_LINK_OPTIONS -Wl,-z,relro -Wl,-z,now)
  29. endif()
  30. else()
  31. set(MUJOCO_HARDEN_COMPILE_OPTIONS "")
  32. set(MUJOCO_HARDEN_LINK_OPTIONS "")
  33. endif()