Configurations_common.cmake 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. # All platforms and configurations end up including this file
  9. # Here we clean up the variables and add common compilation flags to all platforms. Each platform then will add their
  10. # own definitions. Common configurations can be shared by moving those configurations to the "Common" folder and making
  11. # each platform include them
  12. # Clear all
  13. set(O3DE_EXTRA_C_FLAGS "" CACHE STRING "Additional C Compiler flags to apply globally")
  14. set(O3DE_EXTRA_CXX_FLAGS "" CACHE STRING "Additional Cxx Compiler flags to apply globally")
  15. set(O3DE_EXTRA_LINK_OPTIONS "" CACHE STRING "Additional link options to apply globally")
  16. ly_set(CMAKE_C_FLAGS "${O3DE_EXTRA_C_FLAGS}")
  17. ly_set(CMAKE_CXX_FLAGS "${O3DE_EXTRA_CXX_FLAGS}")
  18. ly_set(LINK_OPTIONS "${O3DE_EXTRA_LINK_OPTIONS}")
  19. foreach(conf ${CMAKE_CONFIGURATION_TYPES})
  20. string(TOUPPER ${conf} UCONF)
  21. set(O3DE_EXTRA_C_FLAGS_${UCONF} "" CACHE STRING "Additional C Compiler flags to add globally when compiling in ${conf}")
  22. set(O3DE_EXTRA_CXX_FLAGS_${UCONF} "" CACHE STRING "Additional Cxx Compiler flags to add globally when compiling in ${conf}")
  23. set(O3DE_EXTRA_LINK_OPTIONS_${UCONF} "" CACHE STRING "Additional link options to add globally when linking in ${conf}")
  24. ly_set(CMAKE_C_FLAGS_${UCONF} "${O3DE_EXTRA_C_FLAGS_${UCONF}}")
  25. ly_set(CMAKE_CXX_FLAGS_${UCONF} "${O3DE_EXTRA_CXX_FLAGS_${UCONF}}")
  26. ly_set(LINK_OPTIONS_${UCONF} "${O3DE_EXTRA_LINK_OPTIONS_${UCONF}}")
  27. ly_set(LY_BUILD_CONFIGURATION_TYPE_${UCONF} ${conf})
  28. endforeach()
  29. # Common configurations
  30. ly_append_configurations_options(
  31. DEFINES
  32. # Since we disable exceptions, we need to define _HAS_EXCEPTIONS=0 so the STD does not add exception handling
  33. _HAS_EXCEPTIONS=0
  34. DEFINES_DEBUG
  35. _DEBUG # TODO: this should be able to removed since it gets added automatically by some compilation flags
  36. AZ_DEBUG_BUILD
  37. AZ_ENABLE_TRACING
  38. AZ_ENABLE_DEBUG_TOOLS
  39. AZ_BUILD_CONFIGURATION_TYPE="${LY_BUILD_CONFIGURATION_TYPE_DEBUG}"
  40. DEFINES_PROFILE
  41. _PROFILE
  42. AZ_PROFILE_BUILD
  43. NDEBUG
  44. AZ_ENABLE_TRACING
  45. AZ_ENABLE_DEBUG_TOOLS
  46. AZ_BUILD_CONFIGURATION_TYPE="${LY_BUILD_CONFIGURATION_TYPE_PROFILE}"
  47. DEFINES_RELEASE
  48. _RELEASE
  49. RELEASE
  50. AZ_RELEASE_BUILD
  51. NDEBUG
  52. AZ_BUILD_CONFIGURATION_TYPE="${LY_BUILD_CONFIGURATION_TYPE_RELEASE}"
  53. )
  54. # Ninja: parallel compile and link pool settings
  55. if(CMAKE_GENERATOR MATCHES "Ninja")
  56. set(LY_PARALLEL_COMPILE_JOBS "" CACHE STRING "Number of compile jobs to use (Defaults to not set)")
  57. set(LY_PARALLEL_LINK_JOBS "" CACHE STRING "Number of link jobs to use (Defaults to not set)")
  58. if(LY_PARALLEL_COMPILE_JOBS)
  59. set_property(GLOBAL APPEND PROPERTY JOB_POOLS compile_job_pool=${LY_PARALLEL_COMPILE_JOBS})
  60. ly_set(CMAKE_JOB_POOL_COMPILE compile_job_pool)
  61. endif()
  62. if(LY_PARALLEL_LINK_JOBS)
  63. set_property(GLOBAL APPEND PROPERTY JOB_POOLS link_job_pool=${LY_PARALLEL_LINK_JOBS})
  64. ly_set(CMAKE_JOB_POOL_LINK link_job_pool)
  65. endif()
  66. endif()
  67. set(CMAKE_POSITION_INDEPENDENT_CODE True)
  68. include(CheckPIESupported)
  69. check_pie_supported()
  70. # Determine if lld is installed to use as a default linker by supported platforms/configurations
  71. find_program(LLD_LINKER_INSTALLED lld)