CMakeLists.txt 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. #
  2. # This is a CMake makefile. CMake is a tool that helps you build C++ programs.
  3. # You can download CMake from http://www.cmake.org. This CMakeLists.txt file
  4. # you are reading builds dlib's example programs.
  5. #
  6. # To compile this program all you need to do is ask cmake. You would type
  7. # these commands from within the directory containing this CMakeLists.txt
  8. # file:
  9. # mkdir build
  10. # cd build
  11. # cmake ..
  12. # cmake --build . --config Release
  13. #
  14. # The cmake .. command looks in the parent folder for a file named
  15. # CMakeLists.txt, reads it, and sets up everything needed to build program.
  16. # Also, note that CMake can generate Visual Studio or XCode project files. So
  17. # if instead you had written:
  18. # cd build
  19. # cmake .. -G Xcode
  20. #
  21. # You would be able to open the resulting Xcode project and compile and edit
  22. # the example programs within the Xcode IDE. CMake can generate a lot of
  23. # different types of IDE projects. Run the cmake -h command to see a list of
  24. # arguments to -G to see what kinds of projects cmake can generate for you. It
  25. # probably includes your favorite IDE in the list.
  26. cmake_minimum_required (VERSION 3.8)
  27. project(RvcFramework)
  28. set(CMAKE_CXX_STANDARD 11)
  29. option(BUILD_TESTING "Build the project tests." ON)
  30. set(BUILD_NUMBER 0)
  31. if ($ENV{BUILD_NUMBER})
  32. set(BUILD_NUMBER $ENV{BUILD_NUMBER})
  33. endif()
  34. set(RVC_COMPANY "CMB" CACHE STRING "China Merchants Bank")
  35. set(RVC_PRODUCT "VTM")
  36. set(RVC_AUTHOR "CCDG")
  37. set(RVC_COPYRIGHT "Copyright (C) 2020")
  38. set(RVC_DESCRIPTION "2020.01")
  39. set(RAW_VERSION_STRING "0.0.1-dev1")
  40. string(STRIP ${RAW_VERSION_STRING} RAW_VERSION_STRING)
  41. set(VERSION_REGEX "^.?([0-9]+)\\.([0-9]+)\\.([0-9]+)-?(.*)")
  42. string(REGEX REPLACE "${VERSION_REGEX}" "\\1" RVC_VERSION_MAJOR "${RAW_VERSION_STRING}")
  43. string(REGEX REPLACE "${VERSION_REGEX}" "\\2" RVC_VERSION_MINOR "${RAW_VERSION_STRING}")
  44. string(REGEX REPLACE "${VERSION_REGEX}" "\\3" RVC_VERSION_REVISION "${RAW_VERSION_STRING}")
  45. string(REGEX REPLACE "${VERSION_REGEX}" "\\4" RVC_VERSION_SUFFIX "${RAW_VERSION_STRING}")
  46. set(RVC_VERSION_BUILD "${BUILD_NUMBER}")
  47. set(RVC_API_VERSION "${RVC_VERSION_MAJOR}")
  48. set(RVC_VERSION "${RVC_VERSION_MAJOR}.${RVC_VERSION_MINOR}.${RVC_VERSION_REVISION}.${RVC_VERSION_BUILD}")
  49. if (RVC_VERSION_SUFFIX)
  50. set(RVC_VERSION_FULL "${RVC_VERSION}-${RVC_VERSION_SUFFIX}")
  51. else()
  52. set(RVC_VERSION_FULL "${RVC_VERSION}")
  53. endif()
  54. message("RVC_VERSION=${RVC_VERSION_FULL}")
  55. configure_file("${PROJECT_SOURCE_DIR}/version.h.in" "${PROJECT_BINARY_DIR}/version.h")
  56. include_directories(${PROJECT_BINARY_DIR})
  57. # 设置生成文件的存放路径
  58. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
  59. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
  60. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
  61. if(BUILD_TESTING)
  62. include(CTest)
  63. message(STATUS "build the tests.")
  64. enable_testing()
  65. set(GTEST_ROOT "${CMAKE_SOURCE_DIR}/third_party/gtest/googletest/include")
  66. set(GMOCK_ROOT "${CMAKE_SOURCE_DIR}/third_party/gtest/googlemock/include")
  67. if(MSVC)
  68. set(TESTING_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
  69. else()
  70. set(TESTING_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/Testing")
  71. endif()
  72. endif()
  73. # specifies what build type (configuration) will be built in this build tree
  74. if(NOT CMAKE_BUILD_TYPE)
  75. set(CMAKE_BUILD_TYPE "Debug")
  76. endif()
  77. # Turn on solution folders (2.8.4+)
  78. set_property(GLOBAL PROPERTY USE_FOLDERS ON)
  79. # 在 Windows 下用 "/" 会报错
  80. STRING(REGEX REPLACE "^([A-Z]*.)([/\\].*)" "\\1" CURRENT_DISK "${CMAKE_CURRENT_SOURCE_DIR}")
  81. message(STATUS "current disk: ${CURRENT_DISK}")
  82. set(OUTPUT_VERSION_PATH "${CURRENT_DISK}\\run\\version\\${RVC_VERSION}")
  83. message(STATUS "current OUTPUT_VERSION_PATH: ${OUTPUT_VERSION_PATH}")
  84. set(CMAKE_INSTALL_PREFIX "${OUTPUT_VERSION_PATH}")
  85. #set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install") # /${RVC_VERSION}
  86. # 如果使用绝对路径,会导致 CPack 因 CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION 失败
  87. # set(RVC_INCLUDE_PATH "${CMAKE_INSTALL_PREFIX}/include")
  88. # set(RVC_LIBRARY_PATH "${CMAKE_INSTALL_LIBDIR}")
  89. # set(RVC_RUNTIME_PATH "${CMAKE_INSTALL_BINDIR}")
  90. # set(RVC_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}/bin")
  91. set(RVC_INCLUDE_PATH "include")
  92. set(RVC_LIBRARY_PATH "lib")
  93. set(RVC_RUNTIME_PATH "bin")
  94. # set(RVC_MODULE_LIBRARY_PATH "${CMAKE_BINARY_DIR}/mod")
  95. macro(copy_output_on_build module_name output_subdir)
  96. set(target_name ${module_name})
  97. set(output_dir ${OUTPUT_VERSION_PATH}\\${output_subdir})
  98. if(NOT EXISTS ${output_dir} OR NOT IS_DIRECTORY ${output_dir})
  99. endif()
  100. add_custom_command(TARGET ${target_name} PRE_BUILD
  101. COMMAND ${CMAKE_COMMAND}
  102. ARGS -E make_directory ${output_dir})
  103. add_custom_command(TARGET ${target_name} POST_BUILD
  104. COMMAND ${CMAKE_COMMAND} -E copy
  105. $<TARGET_FILE:${target_name}>
  106. ${OUTPUT_VERSION_PATH}/${output_subdir}
  107. )
  108. endmacro(copy_output_on_build)
  109. if (CMAKE_BUILD_TYPE STREQUAL Debug OR CMAKE_CONFIGURATION_TYPES STREQUAL Debug)
  110. message(STATUS "debug type")
  111. endif()
  112. if(${CMAKE_GENERATOR} MATCHES "Visual Studio*")
  113. if(NOT CMAKE_GENERATOR_PLATFORM)
  114. message(STATUS "set win32 platform default")
  115. set(CMAKE_GENERATOR_PLATFORM "Win32")
  116. else()
  117. message(STATUS ${CMAKE_GENERATOR_PLATFORM})
  118. endif()
  119. endif()
  120. set(CPACK_SYSTEM_NAME "${CMAKE_SYSTEM_NAME}-${CMAKE_GENERATOR_PLATFORM}")
  121. set(CPACK_TOPLEVEL_TAG "${CMAKE_SYSTEM_NAME}-${CMAKE_GENERATOR_PLATFORM}")
  122. if(WIN32)
  123. # dll rc version
  124. string(TIMESTAMP RC_VERSION_YEAR "%Y")
  125. set(RC_VERSION_AUTHOR ${RVC_AUTHOR})
  126. set(RC_VERSION_COMPANY ${RVC_COMPANY})
  127. set(RC_VERSION_PRODUCT ${RVC_PRODUCT})
  128. set(RC_VERSION_PATCH ${BUILD_NUMBER})
  129. set(RC_VERSION_DESCRIPTION "${RVC_VERSION_FULL} ${CPACK_SYSTEM_NAME}")
  130. endif(WIN32)
  131. if(BUILD_SHARED_LIBS)
  132. message(STATUS "build shared libs")
  133. endif(BUILD_SHARED_LIBS)
  134. include_directories(Common)
  135. add_subdirectory(third_party)
  136. add_subdirectory(libtoolkit)
  137. add_subdirectory(RvcComm)
  138. add_subdirectory(spbase)
  139. add_subdirectory(spshell)
  140. add_subdirectory(sphost)
  141. if(BUILD_TESTING)
  142. add_subdirectory(test)
  143. endif()
  144. # 会直接复制文件夹
  145. install(DIRECTORY Common DESTINATION ${RVC_INCLUDE_PATH} COMPONENT headers FILES_MATCHING PATTERN "*.h")
  146. install(FILES "${PROJECT_BINARY_DIR}/version.h" DESTINATION "${RVC_INCLUDE_PATH}/Common" COMPONENT headers)
  147. set(CPACK_SOURCE_IGNORE_FILES "/\\\\.git/;/\\\\.gitignore;/CMakeCache.txt")
  148. string(TOLOWER ${CMAKE_PROJECT_NAME} CMAKE_PROJECT_NAME_lower)
  149. set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME_lower}-${RVC_VERSION_FULL}-${CPACK_SYSTEM_NAME}")
  150. set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME_lower}-${RVC_VERSION_FULL}-${CPACK_SYSTEM_NAME}")
  151. # 设置软件包名
  152. set(CPACK_PACKAGE_NAME "RvcFramework")
  153. set(CPACK_PACKAGE_VENDOR "RVC-CCDG")
  154. # 设置软件包版本
  155. set(CPACK_PACKAGE_VERSION ${RVC_VERSION_FULL})
  156. set(CPACK_PACKAGE_VERSION_MAJOR ${RVC_VERSION_MAJOR})
  157. set(CPACK_PACKAGE_VERSION_MINOR ${RVC_VERSION_MINOR})
  158. set(CPACK_PACKAGE_VERSION_PATCH ${RVC_VERSION_REVISION})
  159. set(CPACK_COMPONENTS_ALL headers libraries)
  160. if(MSVC)
  161. if( NOT CPACK_GENERATOR)
  162. set(CPACK_GENERATOR "ZIP")
  163. message(STATUS "set zip package file type")
  164. endif()
  165. if(CPACK_GENERATOR MATCHES "NSIS")
  166. set(CPACK_PACKAGE_INSTALL_DIRECTORY "C:\\\\Run")
  167. endif()
  168. endif(MSVC)
  169. if(MSVC)
  170. if(MSVC_RUNTIME STREQUAL "dynamic")
  171. message(STATUS "dynamic format")
  172. # the INSTALL command is not called. The user can use the variable
  173. # CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS to use a custom install command and install them however they want.
  174. set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP TRUE)
  175. include(InstallRequiredSystemLibraries)
  176. install(PROGRAMS ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS}
  177. DESTINATION ${RVC_RUNTIME_PATH}
  178. COMPONENT libraries)
  179. else()
  180. include(InstallRequiredSystemLibraries)
  181. endif()
  182. endif()
  183. include(CPack)
  184. function(package_static_libs output_library)
  185. get_target_property(libtype ${output_library} TYPE)
  186. if(NOT libtype STREQUAL "STATIC_LIBRARY" OR NOT libtype STREQUAL "EXECUTABLE ")
  187. message(FATAL_ERROR "can only process static library or execuate program.")
  188. endif()
  189. get_target_property(libfile ${output_library} LOCATION)
  190. endfunction()