# zh @ li in ~/tmp/hello [22:45:26] $ tree . ├── CMakeLists.txt └── subhello └── CMakeLists.txt
1 directory, 2 files
# zh @ li in ~/tmp/hello [22:45:27] $ cat CMakeLists.txt cmake_minimum_required(VERSION 3.9) project(hello VERSION 0.1.2.3 DESCRIPTION "an hello program" LANGUAGES C HOMEPAGE_URL “https://www.hello.com”)
add_subdirectory(subhello)
# zh @ li in ~/tmp/hello [22:45:34] $ cat subhello/CMakeLists.txt cmake_minimum_required(VERSION 3.9) project(subhello VERSION 3.2.1.0 DESCRIPTION "an subhello program" LANGUAGES C HOMEPAGE_URL “https://www.subhello.com”)
hello_DESCRIPTION # PROJECT_DESCRIPTION = an hello program subhello_DESCRIPTION # PROJECT_DESCRIPTION = an subhello program PROJECT_DESCRIPTION # PROJECT_DESCRIPTION = an subhello program CMAKE_PROJECT_DESCRIPTION # CMAKE_PROJECT_DESCRIPTION = an hello program # 顶层
# zh @ li in ~/li/tmp/hello [11:19:03] $ tree . └── CMakeLists.txt
0 directories, 1 file
# zh @ li in ~/li/tmp/hello [11:19:04] $ cat CMakeLists.txt cmake_minimum_required(VERSION 3.9) project(hello VERSION 0.1.2.3 DESCRIPTION "an hello program" LANGUAGES C)
# zh @ li in ~/li/tmp/hello [19:44:41] $ cat CMakeLists.txt cmake_minimum_required(VERSION 3.9) project(hello VERSION 0.1.2.3 DESCRIPTION "an hello program" LANGUAGES C)
FILE(GLOB SRC_FILES "src/*.c")
add_executable(${PROJECT_NAME}${SRC_FILES})
# zh @ li in ~/li/tmp/hello [19:44:43] $ cat src/main.c #include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { printf("hello world\n"); return 0; }
# zh @ li in ~/li/tmp/hello [19:44:46] $ mkdir build && cd build && cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchain_x86.cmake .. -- The C compiler identification is GNU 11.2.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /usr/bin/gcc - skipped -- Detecting C compile features -- Detecting C compile features - done -- Configuring done -- Generating done -- Build files have been written to: /home/zh/li/tmp/hello/build
# zh @ li in ~/li/tmp/hello/build [19:44:53] $ make [ 50%] Building C object CMakeFiles/hello.dir/src/main.c.o [100%] Linking C executable hello [100%] Built target hello