generate_cppgir.cmake 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # This file is part of Desktop App Toolkit,
  2. # a set of libraries for developing nice desktop applications.
  3. #
  4. # For license and copyright information please follow this link:
  5. # https://github.com/desktop-app/legal/blob/master/LEGAL
  6. function(generate_cppgir target_name gir)
  7. set(cppgir_loc ${cmake_helpers_loc}/external/glib/cppgir)
  8. # cppgir generates all the dependent headers everytime, better to have a global folder
  9. set(gen_dst ${CMAKE_BINARY_DIR}/gen)
  10. file(MAKE_DIRECTORY ${gen_dst})
  11. set(gen_timestamp ${gen_dst}/${target_name}_cppgir.timestamp)
  12. set(ignore_files
  13. ${cppgir_loc}/data/cppgir.ignore
  14. ${cppgir_loc}/data/cppgir_unix.ignore
  15. )
  16. set(gir_path)
  17. if (IS_ABSOLUTE "${gir}")
  18. set(gir_path ${gir})
  19. endif()
  20. add_custom_command(
  21. OUTPUT
  22. ${gen_timestamp}
  23. COMMAND
  24. CppGir::cppgir
  25. --debug
  26. 1
  27. --class
  28. --class-full
  29. --expected
  30. --ignore
  31. "$<JOIN:${ignore_files},:>"
  32. --output
  33. ${gen_dst}
  34. ${gir}
  35. COMMAND
  36. echo 1> ${gen_timestamp}
  37. COMMENT "Generating C++ wrapper for ${gir} (${target_name})"
  38. DEPENDS
  39. CppGir::cppgir
  40. ${ignore_files}
  41. ${gir_path}
  42. )
  43. generate_target(${target_name} cppgir ${gen_timestamp} "" ${gen_dst})
  44. get_target_property(target_type ${target_name} TYPE)
  45. if (${target_type} STREQUAL "INTERFACE_LIBRARY")
  46. target_link_libraries(${target_name} INTERFACE CppGir::gi)
  47. target_compile_definitions(${target_name} INTERFACE GI_INLINE)
  48. else()
  49. target_link_libraries(${target_name} PUBLIC CppGir::gi)
  50. target_compile_definitions(${target_name} PUBLIC GI_INLINE)
  51. endif()
  52. endfunction()