cmake学习

学习写hello world
配置好cmake环境后
创建CMakeLists.txt
  1. PROJECT (HELLO)
  2. SET(SRC_LIST hello.c)
  3. MESSAGE(STATUS "This is BINARY dir " ${HELLO_BINARY_DIR})
  4. MESSAGE(STATUS "This is SOURCE dir "${HELLO_SOURCE_DIR})
  5. ADD_EXECUTABLE(hello ${SRC_LIST})
创建hello.c

  1. #include <stdio.h>

  2. int main()
  3. {
  4.     printf("Hello World. ");
  5.     return 0;
  6. }
运行cmake
  1. cmake .
  2. myfly@ubuntu:~/mycmake/hello$ cmake .
  3. CMake Warning (dev) in CMakeLists.txt:
  4.   Syntax Warning in cmake code at

  5.     /home/myfly/mycmake/hello/CMakeLists.txt:4:37

  6.   Argument not separated from preceding token by whitespace.
  7. This warning is for project developers.  Use -Wno-dev to suppress it.

  8. -- This is BINARY dir /home/myfly/mycmake/hello
  9. -- This is SOURCE dir /home/myfly/mycmake/hello
  10. -- Configuring done
  11. -- Generating done
  12. -- Build files have been written to: /home/myfly/mycmake/hello
运行make,然后运行hello
  1. make
  2. ./hello
  3. Hello World.




无欲速,无见小利。欲速,则不达;见小利,则大事不成。
原文地址:https://www.cnblogs.com/ch122633/p/7363240.html