LYWrappers_linux.cmake 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. # in script only mode, we have no compiler or compiler tools and are always in a situation
  11. # where a project is being built versus a pre-built version of the engine. This means that
  12. # stripping and copying should not be attempted.
  13. if (NOT O3DE_SCRIPT_ONLY)
  14. # Check if 'strip' is available so that debug symbols can be stripped from output libraries and executables.
  15. find_program(GNU_STRIP_TOOL strip)
  16. if (NOT GNU_STRIP_TOOL)
  17. message(WARNING "Unable to locate 'strip' tool needed to strip debug symbols from the output target(s). "
  18. "Debug symbols will not be removed from output libraries and executables.")
  19. endif()
  20. # Check if 'objcopy' is available so that debug symbols can be extracted from output libraries and executables.
  21. find_program(GNU_OBJCOPY objcopy)
  22. if (NOT GNU_OBJCOPY)
  23. message(WARNING "Unable to locate 'objcopy' tool needed to extract debug symbols from the output target(s). "
  24. "Debug symbols will not be removed from output libraries and executables. Make sure that "
  25. "'objcopy' is installed.")
  26. endif()
  27. endif()
  28. function(ly_apply_platform_properties target)
  29. # Noop
  30. endfunction()
  31. function(ly_handle_custom_output_directory target output_subdirectory)
  32. if(output_subdirectory)
  33. set_target_properties(${target} PROPERTIES
  34. RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${output_subdirectory}
  35. LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${output_subdirectory}
  36. )
  37. foreach(conf ${CMAKE_CONFIGURATION_TYPES})
  38. string(TOUPPER ${conf} UCONF)
  39. set_target_properties(${target} PROPERTIES
  40. RUNTIME_OUTPUT_DIRECTORY_${UCONF} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY_${UCONF}}/${output_subdirectory}
  41. LIBRARY_OUTPUT_DIRECTORY_${UCONF} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY_${UCONF}}/${output_subdirectory}
  42. )
  43. endforeach()
  44. # Things like rc plugins are built into a subdirectory, but their
  45. # dependent libraries end up in the top-level build dir. Their rpath
  46. # needs to contain $ORIGIN in case they depend on other plugins, and
  47. # $ORIGIN/.. for the main dependencies.
  48. if(NOT IS_ABSOLUTE output_subdirectory)
  49. file(RELATIVE_PATH relative_path "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${output_subdirectory}" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
  50. set_target_properties(${target} PROPERTIES
  51. INSTALL_RPATH "$ORIGIN:$ORIGIN/${relative_path}"
  52. )
  53. endif()
  54. endif()
  55. endfunction()
  56. #! ly_apply_debug_strip_options: Apply debug stripping options to the target output for non-debug configurations.
  57. #
  58. #\arg:target Name of the target to perform a post-build stripping of any debug symbol)
  59. function(ly_apply_debug_strip_options target)
  60. if (NOT GNU_STRIP_TOOL OR NOT GNU_OBJCOPY)
  61. return()
  62. endif()
  63. # If the target is IMPORTED, then there is no post-build process
  64. get_target_property(is_imported ${target} IMPORTED)
  65. if (${is_imported})
  66. return()
  67. endif()
  68. # Check the target type
  69. get_target_property(target_type ${target} TYPE)
  70. # This script only supports executables, applications, modules, static libraries, and shared libraries
  71. if (NOT ${target_type} STREQUAL "STATIC_LIBRARY" AND
  72. NOT ${target_type} STREQUAL "MODULE_LIBRARY" AND
  73. NOT ${target_type} STREQUAL "SHARED_LIBRARY" AND
  74. NOT ${target_type} STREQUAL "EXECUTABLE" AND
  75. NOT ${target_type} STREQUAL "APPLICATION")
  76. return()
  77. endif()
  78. if (${LY_STRIP_DEBUG_SYMBOLS})
  79. set(DETACH_DEBUG_OPTION "DISCARD")
  80. else()
  81. set(DETACH_DEBUG_OPTION "DETACH")
  82. endif()
  83. add_custom_command(TARGET ${target} POST_BUILD
  84. COMMAND "${CMAKE_COMMAND}" -P "${LY_ROOT_FOLDER}/cmake/Platform/Linux/ProcessDebugSymbols.cmake"
  85. ${GNU_STRIP_TOOL}
  86. ${GNU_OBJCOPY}
  87. "$<TARGET_FILE:${target}>"
  88. ${LY_DEBUG_SYMBOLS_FILE_EXTENSION}
  89. ${target_type}
  90. ${DETACH_DEBUG_OPTION}
  91. COMMENT "Processing debug symbols ..."
  92. VERBATIM
  93. )
  94. endfunction()