set (Tutorial_VERSION_MAJOR 1)
set (Tutorial_VERSION_MINOR 0)
# configure a header file to pass some of the CMake settings
# to the source code
configure_file (
"${PROJECT_SOURCE_DIR}/TutorialConfig.h.in"
"${PROJECT_BINARY_DIR}/TutorialConfig.h"
)
include(CTest) # 引入ctest
# does the application run
add_test (TutorialRuns Tutorial 25) # add_test為主要測試用的函式 其內容為add_test(<name> <command> [<arg>...])
# does it sqrt of 25
add_test (TutorialComp25 Tutorial 25)
set_tests_properties (TutorialComp25 PROPERTIES PASS_REGULAR_EXPRESSION "25 is 5")
有關PASS_REGULAR_EXPRESSION 用來 verify that the output of the test contains certain strings
#define a macro to simplify adding tests, then use it
macro (do_test arg result)
add_test (TutorialComp${arg} Tutorial ${arg})
set_tests_properties (TutorialComp${arg}
PROPERTIES PASS_REGULAR_EXPRESSION ${result})
endmacro (do_test)
# do a bunch of result based tests
do_test (25 "25 is 5")
do_test (-25 "-25 is 0")
4.檢查平台作業系統是否有特定函式
include (CheckFunctionExists)
check_function_exists (log HAVE_LOG)
check_function_exists (exp HAVE_EXP)
If more than one command is specified they will be executed in order. The optional ARGS argument is for backward compatibility and will be ignored.
6.建立一個可發佈的專案
building installation packages that support binary installations and package management features as found in cygwin, debian, RPMs etc
在cmakeList.txt最後面加入以下
# build a CPack driven installer package
include (InstallRequiredSystemLibraries)
set (CPACK_RESOURCE_FILE_LICENSE
"${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
set (CPACK_PACKAGE_VERSION_MAJOR "${Tutorial_VERSION_MAJOR}")
set (CPACK_PACKAGE_VERSION_MINOR "${Tutorial_VERSION_MINOR}")
include (CPack)
然後一樣執行cmake .
然後
To build a binary distribution you would run:
cpack --config CPackConfig.cmake
To create a source distribution you would type
cpack --config CPackSourceConfig.cmake