cmake入门 step1 (一行cmake语句)

文件树:

├── build
├── CMakeLists.txt
├── hello.c

CMakeLists.txt

ADD_EXECUTABLE(hello hello.c)

hello.c

#include
int main()
{
    printf("hello world ^_^ \n");
    return 0;
}

执行命令

cd build
cmake ..
make
./hello

输出结果

hello world ^_^

可以尝试添加打印一些信息

PROJECT(project1)
MESSAGE(STATUS "The BINARY dir is ${PROJECT_BINARY_DIR}")
MESSAGE(STATUS "The SOURCE dir is ${PROJECT_SOURCE_DIR}")
SET(SRC_LIST hello.c)
MESSAGE(STATUS "The SOURCE list is ${SRC_LIST}")

ADD_EXECUTABLE(hello hello.c)

执行cmake 会出现

-- The BINARY dir is /home/chuny/test/step1/build
-- The SOURCE dir is /home/chuny/test/step1
-- The SOURCE dir is hello.c

你可能感兴趣的:(编程)