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.\n");
  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.




posted @ 2017-08-15 09:12  习惯就好233  阅读(845)  评论(0编辑  收藏  举报