65 lines
2.2 KiB
CMake
65 lines
2.2 KiB
CMake
cmake_minimum_required(VERSION 3.0.0)
|
||
project(第三章作业 VERSION 0.1.0 LANGUAGES C CXX)
|
||
|
||
include(CTest)
|
||
enable_testing()
|
||
|
||
aux_source_directory(./src SRC_LIST)
|
||
# aux_source_directory(./test TEST_LIST)
|
||
include_directories(./include)
|
||
|
||
add_executable(chapter3 ${SRC_LIST}) # 它好像是在这里添加了某个文件才会不给这个文件报错
|
||
if (CMAKE_BUILD_TYPE STREQUAL Debug)
|
||
add_executable(test_model ./test/test_model.cpp)
|
||
add_executable(test_view ./test/test_view.cpp)
|
||
add_executable(test_controller ./test/test_controller.cpp)
|
||
|
||
add_test(
|
||
NAME test_model
|
||
COMMAND $<TARGET_FILE:test_model>
|
||
)
|
||
|
||
add_test(
|
||
NAME test_view
|
||
COMMAND $<TARGET_FILE:test_view>
|
||
)
|
||
|
||
add_test(
|
||
NAME test_controller
|
||
COMMAND $<TARGET_FILE:test_controller>
|
||
)
|
||
|
||
add_definitions(-D_DEBUG)
|
||
# add_definitions(-D_HAS_STD_BYTE=0) 这个好像没用
|
||
endif()
|
||
|
||
if (CMAKE_BUILD_TYPE STREQUAL Release)
|
||
# 也可以set(CMAKE_CXX_FLAGS_RELEASE ...)
|
||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fexec-charset=GBK")
|
||
endif()
|
||
|
||
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
|
||
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
|
||
SET(EXECUTABLE_OUTPUT_PATH R:/)
|
||
include(CPack)
|
||
|
||
# 增加了安装的配置还是可能会有找不到库或者库不对的问题,
|
||
# 目前需要...\mingw64\bin里的libstdc++-6.dll、libgcc_s_seh-1.dll、libwinpthread-1.dll这三个文件,库的版本不对也可能运行出错,手动从编译并运行成功的设备上复制这三个文件到目标设备上和exe文件同一个目录中是可以运行的
|
||
install(CODE [[
|
||
file(GET_RUNTIME_DEPENDENCIES
|
||
RESOLVED_DEPENDENCIES_VAR RESOLVED_DEPS
|
||
UNRESOLVED_DEPENDENCIES_VAR UNRESOLVED_DEPS
|
||
# EXECUTABLES $<TARGET_FILE:chapter3> # 这样总是会出错
|
||
# file Failed to run dumpbin on:
|
||
# $<TARGET_FILE:chapter3>
|
||
EXECUTABLES R:/chapter3.exe # 所以只能改成这样
|
||
DIRECTORIES $<TARGET_FILE_DIR:chapter3>
|
||
PRE_INCLUDE_REGEXES $<TARGET_FILE_DIR:chapter3>
|
||
PRE_EXCLUDE_REGEXES "system32"
|
||
POST_INCLUDE_REGEXES $<TARGET_FILE_DIR:chapter3>
|
||
POST_EXCLUDE_REGEXES "system32"
|
||
)
|
||
foreach(DEP_LIB ${RESOLVED_DEPS})
|
||
file(INSTALL ${DEP_LIB} DESTINATION R:/bin)
|
||
endforeach()
|
||
]]) |