3
0

LYWrappers_linux.cmake 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #
  2. # Copyright (c) Contributors to the Open 3D Engine Project.
  3. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. #
  5. # SPDX-License-Identifier: Apache-2.0 OR MIT
  6. #
  7. #
  8. set(LY_STRIP_DEBUG_SYMBOLS FALSE CACHE BOOL "Flag to strip debug symbols from the (non-debug) output binaries")
  9. set(LY_DEBUG_SYMBOLS_FILE_EXTENSION "dbg" CACHE STRING "Extension for generated debug symbol files")
  10. # Check if 'strip' is available so that debug symbols can be stripped from output libraries and executables.
  11. find_program(GNU_STRIP_TOOL strip)
  12. if (NOT GNU_STRIP_TOOL)
  13. message(WARNING "Unable to locate 'strip' tool needed to strip debug symbols from the output target(s). "
  14. "Debug symbols will not be removed from output libraries and executables.")
  15. endif()
  16. # Check if 'objcopy' is available so that debug symbols can be extracted from output libraries and executables.
  17. find_program(GNU_OBJCOPY objcopy)
  18. if (NOT GNU_OBJCOPY)
  19. message(WARNING "Unable to locate 'objcopy' tool needed to extract debug symbols from the output target(s). "
  20. "Debug symbols will not be removed from output libraries and executables. Make sure that "
  21. "'objcopy' is installed.")
  22. endif()
  23. function(ly_apply_platform_properties target)
  24. # Noop
  25. endfunction()
  26. function(ly_handle_custom_output_directory target output_subdirectory)
  27. if(output_subdirectory)
  28. set_target_properties(${target} PROPERTIES
  29. RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${output_subdirectory}
  30. LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${output_subdirectory}
  31. )
  32. foreach(conf ${CMAKE_CONFIGURATION_TYPES})
  33. string(TOUPPER ${conf} UCONF)
  34. set_target_properties(${target} PROPERTIES
  35. RUNTIME_OUTPUT_DIRECTORY_${UCONF} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY_${UCONF}}/${output_subdirectory}
  36. LIBRARY_OUTPUT_DIRECTORY_${UCONF} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY_${UCONF}}/${output_subdirectory}
  37. )
  38. endforeach()
  39. # Things like rc plugins are built into a subdirectory, but their
  40. # dependent libraries end up in the top-level build dir. Their rpath
  41. # needs to contain $ORIGIN in case they depend on other plugins, and
  42. # $ORIGIN/.. for the main dependencies.
  43. if(NOT IS_ABSOLUTE output_subdirectory)
  44. file(RELATIVE_PATH relative_path "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${output_subdirectory}" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
  45. set_target_properties(${target} PROPERTIES
  46. INSTALL_RPATH "$ORIGIN:$ORIGIN/${relative_path}"
  47. )
  48. endif()
  49. endif()
  50. endfunction()
  51. #! ly_apply_debug_strip_options: Apply debug stripping options to the target output for non-debug configurations.
  52. #
  53. #\arg:target Name of the target to perform a post-build stripping of any debug symbol)
  54. function(ly_apply_debug_strip_options target)
  55. if (NOT GNU_STRIP_TOOL OR NOT GNU_OBJCOPY)
  56. return()
  57. endif()
  58. # If the target is IMPORTED, then there is no post-build process
  59. get_target_property(is_imported ${target} IMPORTED)
  60. if (${is_imported})
  61. return()
  62. endif()
  63. # Check the target type
  64. get_target_property(target_type ${target} TYPE)
  65. # This script only supports executables, applications, modules, static libraries, and shared libraries
  66. if (NOT ${target_type} STREQUAL "STATIC_LIBRARY" AND
  67. NOT ${target_type} STREQUAL "MODULE_LIBRARY" AND
  68. NOT ${target_type} STREQUAL "SHARED_LIBRARY" AND
  69. NOT ${target_type} STREQUAL "EXECUTABLE" AND
  70. NOT ${target_type} STREQUAL "APPLICATION")
  71. return()
  72. endif()
  73. if (${LY_STRIP_DEBUG_SYMBOLS})
  74. set(DETACH_DEBUG_OPTION "DISCARD")
  75. else()
  76. set(DETACH_DEBUG_OPTION "DETACH")
  77. endif()
  78. add_custom_command(TARGET ${target} POST_BUILD
  79. COMMAND "${CMAKE_COMMAND}" -P "${LY_ROOT_FOLDER}/cmake/Platform/Linux/ProcessDebugSymbols.cmake"
  80. ${GNU_STRIP_TOOL}
  81. ${GNU_OBJCOPY}
  82. "$<TARGET_FILE:${target}>"
  83. ${LY_DEBUG_SYMBOLS_FILE_EXTENSION}
  84. ${target_type}
  85. ${DETACH_DEBUG_OPTION}
  86. COMMENT "Processing debug symbols ..."
  87. VERBATIM
  88. )
  89. endfunction()