用于存放学校的作业便于复习。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.2 KiB

  1. cmake_minimum_required(VERSION 3.0.0)
  2. project(第三章作业 VERSION 0.1.0 LANGUAGES C CXX)
  3. include(CTest)
  4. enable_testing()
  5. aux_source_directory(./src SRC_LIST)
  6. # aux_source_directory(./test TEST_LIST)
  7. include_directories(./include)
  8. add_executable(chapter3 ${SRC_LIST}) # 它好像是在这里添加了某个文件才会不给这个文件报错
  9. if (CMAKE_BUILD_TYPE STREQUAL Debug)
  10. add_executable(test_model ./test/test_model.cpp)
  11. add_executable(test_view ./test/test_view.cpp)
  12. add_executable(test_controller ./test/test_controller.cpp)
  13. add_test(
  14. NAME test_model
  15. COMMAND $<TARGET_FILE:test_model>
  16. )
  17. add_test(
  18. NAME test_view
  19. COMMAND $<TARGET_FILE:test_view>
  20. )
  21. add_test(
  22. NAME test_controller
  23. COMMAND $<TARGET_FILE:test_controller>
  24. )
  25. add_definitions(-D_DEBUG)
  26. # add_definitions(-D_HAS_STD_BYTE=0) 这个好像没用
  27. endif()
  28. if (CMAKE_BUILD_TYPE STREQUAL Release)
  29. # 也可以set(CMAKE_CXX_FLAGS_RELEASE ...)
  30. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fexec-charset=GBK")
  31. endif()
  32. set(CPACK_PROJECT_NAME ${PROJECT_NAME})
  33. set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
  34. SET(EXECUTABLE_OUTPUT_PATH R:/)
  35. include(CPack)
  36. # 增加了安装的配置还是可能会有找不到库或者库不对的问题,
  37. # 目前需要...\mingw64\bin里的libstdc++-6.dll、libgcc_s_seh-1.dll、libwinpthread-1.dll这三个文件,库的版本不对也可能运行出错,手动从编译并运行成功的设备上复制这三个文件到目标设备上和exe文件同一个目录中是可以运行的
  38. install(CODE [[
  39. file(GET_RUNTIME_DEPENDENCIES
  40. RESOLVED_DEPENDENCIES_VAR RESOLVED_DEPS
  41. UNRESOLVED_DEPENDENCIES_VAR UNRESOLVED_DEPS
  42. # EXECUTABLES $<TARGET_FILE:chapter3> # 这样总是会出错
  43. # file Failed to run dumpbin on:
  44. # $<TARGET_FILE:chapter3>
  45. EXECUTABLES R:/chapter3.exe # 所以只能改成这样
  46. DIRECTORIES $<TARGET_FILE_DIR:chapter3>
  47. PRE_INCLUDE_REGEXES $<TARGET_FILE_DIR:chapter3>
  48. PRE_EXCLUDE_REGEXES "system32"
  49. POST_INCLUDE_REGEXES $<TARGET_FILE_DIR:chapter3>
  50. POST_EXCLUDE_REGEXES "system32"
  51. )
  52. foreach(DEP_LIB ${RESOLVED_DEPS})
  53. file(INSTALL ${DEP_LIB} DESTINATION R:/bin)
  54. endforeach()
  55. ]])