helpers_common.cmake 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # CMake common helper functions module
  2. # cmake-format: off
  3. # cmake-lint: disable=C0103
  4. # cmake-format: on
  5. include_guard(GLOBAL)
  6. # check_uuid: Helper function to check for valid UUID
  7. function(check_uuid uuid_string return_value)
  8. set(valid_uuid TRUE)
  9. set(uuid_token_lengths 8 4 4 4 12)
  10. set(token_num 0)
  11. string(REPLACE "-" ";" uuid_tokens ${uuid_string})
  12. list(LENGTH uuid_tokens uuid_num_tokens)
  13. if(uuid_num_tokens EQUAL 5)
  14. message(DEBUG "UUID ${uuid_string} is valid with 5 tokens.")
  15. foreach(uuid_token IN LISTS uuid_tokens)
  16. list(GET uuid_token_lengths ${token_num} uuid_target_length)
  17. string(LENGTH "${uuid_token}" uuid_actual_length)
  18. if(uuid_actual_length EQUAL uuid_target_length)
  19. string(REGEX MATCH "[0-9a-fA-F]+" uuid_hex_match ${uuid_token})
  20. if(NOT uuid_hex_match STREQUAL uuid_token)
  21. set(valid_uuid FALSE)
  22. break()
  23. endif()
  24. else()
  25. set(valid_uuid FALSE)
  26. break()
  27. endif()
  28. math(EXPR token_num "${token_num}+1")
  29. endforeach()
  30. else()
  31. set(valid_uuid FALSE)
  32. endif()
  33. message(DEBUG "UUID ${uuid_string} valid: ${valid_uuid}")
  34. set(${return_value}
  35. ${valid_uuid}
  36. PARENT_SCOPE)
  37. endfunction()
  38. if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/plugin-support.c.in")
  39. configure_file(src/plugin-support.c.in plugin-support.c @ONLY)
  40. add_library(plugin-support STATIC)
  41. target_sources(
  42. plugin-support
  43. PRIVATE plugin-support.c
  44. PUBLIC src/plugin-support.h)
  45. target_include_directories(plugin-support PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src")
  46. if(OS_LINUX
  47. OR OS_FREEBSD
  48. OR OS_OPENBSD)
  49. # add fPIC on Linux to prevent shared object errors
  50. set_property(TARGET plugin-support PROPERTY POSITION_INDEPENDENT_CODE ON)
  51. endif()
  52. endif()