# should we use our own math functions? option (USE_MYMATH "Use tutorial provided math implementation" ON)
# The version number. 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" )
# add the binary tree to the search path for include files # so that we will find TutorialConfig.h include_directories("${PROJECT_BINARY_DIR}")
if (USE_MYMATH) include_directories ("${PROJECT_SOURCE_DIR}/MathFunctions") add_subdirectory (MathFunctions) set (EXTRA_LIBS ${EXTRA_LIBS} MathFunctions) endif (USE_MYMATH)
# add the executable add_executable(Tutorial main.cpp) target_link_libraries (Tutorial ${EXTRA_LIBS})
include(CTest) # does it sqrt of 25 add_test (TutorialComp25 Tutorial 25) set_tests_properties (TutorialComp25 PROPERTIES PASS_REGULAR_EXPRESSION "25 is 5") # does it handle negative numbers #add_test (TutorialNegative Tutorial -25) #set_tests_properties (TutorialNegative PROPERTIES PASS_REGULAR_EXPRESSION "-25 is 0")
# does it handle small numbers add_test (TutorialSmall Tutorial 0.0001) set_tests_properties (TutorialSmall PROPERTIES PASS_REGULAR_EXPRESSION "0.0001 is 0.01")
# does the usage message work? add_test (TutorialUsage Tutorial) set_tests_properties (TutorialUsage PROPERTIES PASS_REGULAR_EXPRESSION "Usage:.*number")
#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_test (81"81 is 9") # do a bunch of result based tests do_test (25"25 is 5") do_test (-25"-25 is 0")
Store in an output variable a substring of a given string. If length
is -1 the remainder of the string starting at begin will be returned. If
string is shorter than length then end of string is used instead.
string(STRIP <string> <output variable>)
Store in an output variable a substring of a given string with
leading and trailing spaces removed.
Compute a
cryptographic hash of the input string. The supported
<HASH> algorithm names are: 很多
STREQUAL
make VERBOSE=1
可以将cmake中定义的变量打印
Object Libraries
The OBJECT library type is also not linked to. It defines a
non-archival collection of object files resulting from compiling the
given source files. The object files collection can be used as source
inputs to other targets:
OBJECT libraries may only be used locally as sources in a buildsystem
– they may not be installed, exported, or used in the right hand side of
target_link_libraries(). They also may not be used as the
TARGET in a use of the
add_custom_command(TARGET) command signature.
Although object libraries may not be named directly in calls to the
target_link_libraries() command, they can be “linked”
indirectly by using an Interface Library whose
INTERFACE_SOURCES target property is set to name
$<TARGET_OBJECTS:objlib>.