helpers_common.cmake 1.7 KB

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