Utils.cmake 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. macro(source_group_by_dir source_files)
  2. if(MSVC)
  3. set(sgbd_cur_dir ${CMAKE_CURRENT_SOURCE_DIR})
  4. foreach(sgbd_file ${${source_files}})
  5. string(REGEX REPLACE ${sgbd_cur_dir}/\(.*\) \\1 sgbd_fpath ${sgbd_file})
  6. string(REGEX REPLACE "\(.*\)/.*" \\1 sgbd_group_name ${sgbd_fpath})
  7. string(COMPARE EQUAL ${sgbd_fpath} ${sgbd_group_name} sgbd_nogroup)
  8. string(REPLACE "/" "\\" sgbd_group_name ${sgbd_group_name})
  9. if(sgbd_nogroup)
  10. set(sgbd_group_name "\\")
  11. endif(sgbd_nogroup)
  12. source_group(${sgbd_group_name} FILES ${sgbd_file})
  13. endforeach(sgbd_file)
  14. endif(MSVC)
  15. endmacro()
  16. macro(rel_source_group_by_dir source_files root_path)
  17. if(MSVC)
  18. set(sgbd_cur_dir ${CMAKE_CURRENT_SOURCE_DIR})
  19. foreach(sgbd_file ${${source_files}})
  20. file(RELATIVE_PATH rel_file ${root_path} ${sgbd_file})
  21. string(REGEX REPLACE ${sgbd_cur_dir}/\(.*\) \\1 sgbd_fpath ${rel_file})
  22. string(REGEX REPLACE "\(.*\)/.*" \\1 sgbd_group_name ${sgbd_fpath})
  23. string(COMPARE EQUAL ${sgbd_fpath} ${sgbd_group_name} sgbd_nogroup)
  24. string(REPLACE "/" "\\" sgbd_group_name ${sgbd_group_name})
  25. if(sgbd_nogroup)
  26. set(sgbd_group_name "\\")
  27. endif(sgbd_nogroup)
  28. source_group(${sgbd_group_name} FILES ${sgbd_file})
  29. endforeach(sgbd_file)
  30. endif(MSVC)
  31. endmacro()
  32. macro(INSTALL_NUGET target id version)
  33. if (CMAKE_GENERATOR MATCHES "Visual Studio.*")
  34. unset(nuget_cmd)
  35. list(APPEND nuget_cmd install ${id} -Prerelease -Version ${version} -OutputDirectory ${CMAKE_BINARY_DIR}/packages)
  36. #message("excute nuget install:${nuget_cmd}")
  37. execute_process(COMMAND ${PROJECT_SOURCE_DIR}/scripts/nuget.exe ${nuget_cmd} ENCODING AUTO)
  38. target_link_libraries(${target} ${CMAKE_BINARY_DIR}/packages/${id}.${version}/build/native/${id}.targets)
  39. else()
  40. message(FATAL_ERROR "INSTALL_NUGET noly use in Visual Studio")
  41. endif()
  42. endmacro()
  43. macro(SET_DIR name path)
  44. set(${name}_DIR ${path})
  45. if(EXISTS ${path}/${SYS}/include)
  46. set(${name}_INCLUDE_DIR ${path}/${SYS}/include)
  47. else()
  48. set(${name}_INCLUDE_DIR ${path}/include)
  49. endif()
  50. if(EXISTS ${path}/${SYS}/${CPU}/static)
  51. set(${name}_STATIC_LIB_DIR ${path}/${SYS}/${CPU}/static)
  52. else()
  53. set(${name}_STATIC_LIB_DIR ${path}/${SYS}/static)
  54. ENDIF()
  55. if(EXISTS ${path}/${SYS}/${CPU}/lib)
  56. set(${name}_LIB_DIR ${path}/${SYS}/${CPU}/lib)
  57. set(${name}_LIB_DIR_DEBUG ${path}/${SYS}/${CPU}/lib/Debug)
  58. set(${name}_LIB_DIR_RELEASE ${path}/${SYS}/${CPU}/lib/Release)
  59. elseif(EXISTS ${path}/${SYS}/lib)
  60. set(${name}_LIB_DIR ${path}/${SYS}/lib)
  61. set(${name}_LIB_DIR_DEBUG ${path}/${SYS}/lib/Debug)
  62. set(${name}_LIB_DIR_RELEASE ${path}/${SYS}/lib/Release)
  63. elseif(EXISTS ${path}/library)
  64. set(${name}_LIB_DIR ${path}/library)
  65. set(${name}_LIB_DIR_DEBUG ${path}/library/Debug)
  66. set(${name}_LIB_DIR_RELEASE ${path}/library/Release)
  67. else()
  68. set(${name}_LIB_DIR ${path}/lib)
  69. set(${name}_LIB_DIR_DEBUG ${path}/lib/Debug)
  70. set(${name}_LIB_DIR_RELEASE ${path}/lib/Release)
  71. endif()
  72. IF(MSVC)
  73. set(${name}_BIN_DIR ${path}/${SYS}/bin)
  74. set(${name}_BIN_DIR_DEBUG ${path}/${SYS}/bin/Debug)
  75. set(${name}_BIN_DIR_RELEASE ${path}/${SYS}/bin/Release)
  76. ELSE()
  77. set(${name}_BIN_DIR ${path}/${SYS}/lib)
  78. set(${name}_BIN_DIR_DEBUG ${path}/${SYS}/lib)
  79. set(${name}_BIN_DIR_RELEASE ${path}/${SYS}/lib)
  80. ENDIF()
  81. set(${name}_SRC_DIR ${path}/src)
  82. endmacro()