CMake---基础练习2
# t2/ CMakeLists.txt cmake_minimum_required(VERSION 2.8) #1 #PROJECT (HELLO) #SET(SRC_LIST main.c) #MESSAGE(STATUS "This is BINARY dir" ${HELLO_BINARY_DIR}) #MESSAGE(STATUS "This is SOURCE dir" ${HELLO_SOURCE_DIR}) #ADD_EXECUTABLE(hello ${SRC_LIST}) #2 #PROJECT(HELLO) #ADD_EXECUTABLE(hello main.c) PROJECT(HELLO) ADD_SUBDIRECTORY(src bin)
//main.c #include <stdio.h> int main() { printf("Hello World from t1 Main!\n "); return 0; }
# t2/src/CMakeLists.txt
ADD_EXECUTABLE(hello main.c)
u@u160406:~/learn_Cmake/cmake/t2$ ls build CMakeLists.txt src u@u160406:~/learn_Cmake/cmake/t2$ tree . ├── build ├── CMakeLists.txt └── src ├── CMakeLists.txt └── main.c 2 directories, 3 files u@u160406:~/learn_Cmake/cmake/t2$ cd build u@u160406:~/learn_Cmake/cmake/t2/build$ cmake .. -- The C compiler identification is GNU 5.4.0 -- The CXX compiler identification is GNU 5.4.0 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Configuring done -- Generating done -- Build files have been written to: /home/u/learn_Cmake/cmake/t2/build u@u160406:~/learn_Cmake/cmake/t2/build$ make Scanning dependencies of target hello [ 50%] Building C object bin/CMakeFiles/hello.dir/main.c.o [100%] Linking C executable hello [100%] Built target hello u@u160406:~/learn_Cmake/cmake/t2/build$ cd bin u@u160406:~/learn_Cmake/cmake/t2/build/bin$ ./hello Hello World from t1 Main! u@u160406:~/learn_Cmake/cmake/t2/build/bin$
【. . . . . .本博客仅作个人生活、工作、学习等的日常记录。说明: (1) 内容有参考其他博主、网页等,有因“懒”直接粘贴来,会备注出处。若遇雷同,或忘备注,并无故意抄袭之意,请诸“原主”谅解,很感谢您的辛勤"笔记"可供本人参考学习。 (2) 如遇同行,有参考学习者,因个人学识有限,不保证所写内容完全正确。您对本博文有任何的意见或建议,欢迎留言,感谢指正。 (3) 若您认为本主的全博客还不错,可以点击关注,便于互相学习。 (4) 感谢您的阅读,希望对您有一定的帮助。欢迎转载或分享,但请注明出处,谢谢。. . . . . .】
【作者: Carole0904 ; 出处: https://www.cnblogs.com/carle-09/ 】