上cmake文件+注释:
cmake_minimum_required(VERSION 2.8) # 定义工程名称 project ( mydemo ) # set 要在configure_file之前 set (USE_MYMATH OFF) set (var2 13) #指定var2的值 set (var3 "var3string") #指定var3的字符串值 set (var4 "VARTEST4") if(USE_MYMATH) set (var5 "VARTEST5") else () set (var5 "VARTEST55") endif() configure_file( "${PROJECT_SOURCE_DIR}/config.h.in" "${PROJECT_BINARY_DIR}/config.h" ) # 包含config.h这个目录 include_directories("${PROJECT_BINARY_DIR}") # 自定义编译选项,改了后要删除 CMakeCache.txt CMakeFiles 才能改变。不如直接用set #option (USE_MYMATH # "use mymath lib" ON) set (EXTRA_LIBS Crypt32) if (USE_MYMATH) include_directories("${PROJECT_SOURCE_DIR}/libs") add_subdirectory(libs) # 给个临时变量,否则禁止时此lib找不到.${}表示增加已有的 set (EXTRA_LIBS ${EXTRA_LIBS} MyLibs) endif() #message(">>> PROJECT_BINARY_DIR: ${PROJECT_BINARY_DIR}") aux_source_directory(. C_SRCS) # exe名称 add_executable(Demo ${C_SRCS}) target_link_libraries(Demo ${EXTRA_LIBS})