DolphinCompileDefinitions.cmake 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # Add C or C++ compile definitions to the current scope
  2. #
  3. # dolphin_compile_definitions(def [def ...] [DEBUG_ONLY | RELEASE_ONLY])
  4. #
  5. # Can optionally add the definitions to Debug or Release configurations only, use this so we can
  6. # target multi-configuration generators like Visual Studio or Xcode.
  7. # Release configurations means NOT Debug, so it will work for RelWithDebInfo or MinSizeRel too.
  8. # The definitions are added to the COMPILE_DEFINITIONS folder property.
  9. # Supports generator expressions, unlike add_definitions()
  10. #
  11. # Examples:
  12. # dolphin_compile_definitions(FOO) -> -DFOO
  13. # dolphin_compile_definitions(_DEBUG DEBUG_ONLY) -> -D_DEBUG
  14. # dolphin_compile_definitions(NDEBUG RELEASE_ONLY) -> -DNDEBUG
  15. # dolphin_compile_definitions($<$<COMPILE_LANGUAGE:C>:THISISONLYFORC>)
  16. function(dolphin_compile_definitions)
  17. set(defs ${ARGN})
  18. list(GET defs -1 last_def)
  19. list(REMOVE_AT defs -1)
  20. set(genexp_config_test "1")
  21. if(last_def STREQUAL "DEBUG_ONLY")
  22. set(genexp_config_test "$<CONFIG:Debug>")
  23. elseif(last_def STREQUAL "RELEASE_ONLY")
  24. set(genexp_config_test "$<NOT:$<CONFIG:Debug>>")
  25. else()
  26. list(APPEND defs ${last_def})
  27. endif()
  28. set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS
  29. "$<${genexp_config_test}:${defs}>")
  30. endfunction()