如何自己建设淘宝网站首页优化网络
双笙子佯谬老师的【公开课】现代CMake高级教程课程笔记
第 6 章:输出与变量
在运行 cmake -B build 时,打印字符串(用于调试)
message("Hello world!")
❯ cmake --build buildHello world!
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/h/Code/lessonCode/CMakeLession/build
message(STATUS “…”) 表示信息类型是状态信息,有 – 前缀
message(STATUS "Hello world!")
❯ cmake --build build-- Hello world!
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/h/Code/lessonCode/CMakeLession/build
message(WARNING “…”) 表示是警告信息
message(STATUS "Hello world!")
message(WARNING "This is a warning sign!")
❯ cmake --build build-- Hello world!
CMake Warning at CMakeLists.txt:2 (message):This is a warning sign!-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/h/Code/lessonCode/CMakeLession/build
message(AUTHOR_WARNING “…”) 表示是仅仅给项目作者看的警告信息
message(STATUS "Hello world!")
message(AUTHOR_WARNING "This is a warning sign!")
❯ cmake --build build-- Hello world!
CMake Warning (dev) at CMakeLists.txt:2 (message):This is a warning sign!
This warning is for project developers. Use -Wno-dev to suppress it.-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/h/Code/lessonCode/CMakeLession/build
AUTHOR_WARNING 的不同之处:可以通过 -Wno-dev 关闭
message(STATUS "Hello world!")
message(FATAL_ERROR "This is an error message!")
message(STATUS "after error...")
❯ cmake -B build -Wno-dev
-- Hello world!
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/h/Code/lessonCode/CMakeLession/build
message(FATAL_ERROR “…”) 表示是错误信息,会终止 CMake 的运行
❯ cmake --build build
-- Hello world!
CMake Error at CMakeLists.txt:2 (message):This is an error message!-- Configuring incomplete, errors occurred!
See also "/mnt/h/Code/lessonCode/CMakeLession/build/CMakeFiles/CMakeOutput.log".
gmake: *** [Makefile:138: cmake_check_build_system] Error 1
message(SEND_ERROR “…”) 表示是错误信息,但之后的语句仍继续执行
message(STATUS "Hello world!")
message(SEND_ERROR "This is an error message!")
message(STATUS "after error...")
❯ cmake --build build
-- Hello world!
CMake Error at CMakeLists.txt:2 (message):This is an error message!-- after error...
-- Configuring incomplete, errors occurred!
See also "/mnt/h/Code/lessonCode/CMakeLession/build/CMakeFiles/CMakeOutput.log".
gmake: *** [Makefile:138: cmake_check_build_system] Error 1
message 可以用于打印变量
set(myvar "hello world!")
message("myvar is ${myvar}")
❯ cmake --build build
myvar is hello world!
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/h/Code/lessonCode/CMakeLession/build
如果 set 没加引号会怎样?会变成分号分割的列表
set(myvar hello world)
其实等价于:
set(myvar "hello;world")
set(myvar hello world!)
message("myvar is ${myvar}")
❯ cmake --build build
myvar is hello;world!
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/h/Code/lessonCode/CMakeLession/build
如果 message 没加引号会怎样?会把列表里的字符串当成他的关键字
set(myvar FATAL_ERROR hello)
message("${myvar}")
❯ cmake --build build
FATAL_ERROR;hello
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/h/Code/lessonCode/CMakeLession/build
结论:除非确实需要列表,建议始终在你不确定的地方加上引号,例如:
set(sources "main.cpp" "mylib.cpp" "C:/Program Files/a.cpp")
message("${sources}")