utils.cmake 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #############################################################
  2. function(set_bundle_dir)
  3. set(args SOURCES DEST EXCLUDE)
  4. include(CMakeParseArguments)
  5. cmake_parse_arguments(BD "" "" "${args}" ${ARGN})
  6. foreach(_BDIR ${BD_SOURCES})
  7. file(GLOB _DIRCONTENTS ${_BDIR}/*)
  8. foreach(_BDFILE ${_DIRCONTENTS})
  9. get_filename_component(_BDFILE_NAME ${_BDFILE} NAME)
  10. set(PROCESS_FILE 1)
  11. foreach(EX_FILE ${BD_EXCLUDE})
  12. string(REGEX MATCH ${EX_FILE} DID_MATCH ${_BDFILE})
  13. if(NOT "${DID_MATCH}" STREQUAL "")
  14. set(PROCESS_FILE 0)
  15. endif(NOT "${DID_MATCH}" STREQUAL "")
  16. endforeach(EX_FILE ${BD_EXCLUDE})
  17. if(PROCESS_FILE STREQUAL "1")
  18. if(IS_DIRECTORY ${_BDFILE})
  19. set_bundle_dir(SOURCES ${_BDFILE} DEST ${BD_DEST}/${_BDFILE_NAME} EXCLUDE ${BD_EXCLUDE})
  20. else(IS_DIRECTORY ${_BDFILE})
  21. #message("set_bundle_dir : setting package_location ${_BDFILE} = ${BD_DEST}")
  22. set_source_files_properties(${_BDFILE} PROPERTIES MACOSX_PACKAGE_LOCATION ${BD_DEST})
  23. get_property(BUNDLED_FILES GLOBAL PROPERTY CONFIG_BUNDLED_FILES)
  24. set_property(GLOBAL PROPERTY CONFIG_BUNDLED_FILES ${BUNDLED_FILES} ${_BDFILE})
  25. string(REPLACE "/" "\\\\" GNAME ${BD_DEST})
  26. source_group(${GNAME} FILES ${_BDFILE})
  27. endif(IS_DIRECTORY ${_BDFILE})
  28. endif()
  29. endforeach(_BDFILE ${_DIRCONTENTS})
  30. endforeach(_BDIR ${BD_SOURCES})
  31. endfunction(set_bundle_dir)
  32. #############################################################
  33. macro(find_all_sources DIRECTORY VARIABLE)
  34. aux_source_directory(${DIRECTORY} ${VARIABLE})
  35. file(GLOB headers ${DIRECTORY}/*h)
  36. list(APPEND ${VARIABLE} ${headers})
  37. endmacro()
  38. #############################################################
  39. # function to collect all the sources from sub-directories
  40. # into a single list
  41. function(add_sources)
  42. get_property(is_defined GLOBAL PROPERTY SRCS_LIST DEFINED)
  43. if(NOT is_defined)
  44. define_property(GLOBAL PROPERTY SRCS_LIST
  45. BRIEF_DOCS "List of source files"
  46. FULL_DOCS "List of source files to be compiled in one library")
  47. endif()
  48. # make absolute paths
  49. set(SRCS)
  50. foreach(s IN LISTS ARGN)
  51. if(NOT IS_ABSOLUTE "${s}")
  52. get_filename_component(s "${s}" ABSOLUTE)
  53. endif()
  54. list(APPEND SRCS "${s}")
  55. endforeach()
  56. string(REPLACE ${CMAKE_SOURCE_DIR}/src/ "" SUBDIR ${CMAKE_CURRENT_SOURCE_DIR})
  57. string(TOLOWER ${SUBDIR} SUBDIR)
  58. string(REPLACE "/" "\\\\" LIBNAME ${SUBDIR})
  59. source_group(${LIBNAME} FILES ${SRCS})
  60. # add it to the global list.
  61. set_property(GLOBAL APPEND PROPERTY SRCS_LIST ${SRCS})
  62. endfunction(add_sources)