C99 Clion 项目目录结构 CMakeLists.txt

发布时间 2023-08-09 16:25:12作者: vx_guanchaoguo0

简单helle目录如下

.
├── CMakeLists.txt
├── hello
│   └── hello.c
└── main.c

main.c

#include "hello//hello.c"

int main() {
    print_hello();
    return 0;
}

hello.c

#include <stdio.h>

static void print_hello();

void print_hello() {
    printf("Hello\n");
}

CMakeLists.txt 默认是设置

cmake_minimum_required(VERSION 3.10)
project(HelloProject C)
include_directories(hello)
add_executable(main main.c hello/hello.c)

CMakeLists.txt 指定编译目录

cmake_minimum_required(VERSION 3.10)
project(HelloProject C)

include_directories(hello)

set(EXECUTABLE_NAME hello_executable)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)

add_executable(${EXECUTABLE_NAME} main.c hello/hello.c)