source

CMake 아래에 있는 여러 디렉토리

goodcode 2022. 7. 30. 19:14
반응형

CMake 아래에 있는 여러 디렉토리

현재 재귀적 메이크와 자동 툴을 사용하고 있으며, 다음과 같은 프로젝트를 위해 CMake로 이행하려고 합니다.

lx/ (project root)
    src/
        lx.c (contains main method)
        conf.c
        util/
            str.c
            str.h
            etc.c
            etc.h
        server/
            server.c
            server.h
            request.c
            request.h
        js/
            js.c
            js.h
            interp.c
            interp.h
    bin/
        lx (executable)

어떻게 하면 좋을까요?

lx/src 디렉토리보다 높은 소스가 없는 경우 lx/CMakeLists는 필요 없습니다.txt 파일.존재하는 경우는, 다음과 같이 됩니다.

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(lx)

add_subdirectory(src)
add_subdirectory(dir1)
add_subdirectory(dir2)

# And possibly other commands dealing with things
# directly in the "lx" directory

...서브 디렉토리가 라이브러리 의존관계 순서로 추가됩니다.다른 아무것도 의존하지 않는 라이브러리를 먼저 추가하고 다음으로 의존한 라이브러리를 추가하는 등의 작업을 수행해야 합니다.

lx/src/CMake Lists.txt

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(lx_exe)

add_subdirectory(util)
add_subdirectory(js)
add_subdirectory(server)

set(lx_source_files conf.c lx.c)
add_executable(lx ${lx_source_files})

target_link_libraries(lx server)
  # also transitively gets the "js" and "util" dependencies

lx/src/util/CMake Lists.txt

set(util_source_files
  etc.c
  etc.h
  str.c
  str.h
)
add_library(util ${util_source_files})

lx/src/js/CMake Lists.txt

set(js_source_files
  interp.c
  interp.h
  js.c
  js.h
)
add_library(js ${js_source_files})

target_link_libraries(js util)

lx/src/server/CMake Lists.txt

set(server_source_files
  request.c
  request.h
  server.c
  server.h
)
add_library(server ${server_source_files})

target_link_libraries(server js)
  # also transitively gets the "util" dependency

그런 다음 명령 프롬프트에서 다음을 수행합니다.

mkdir lx/bin
cd lx/bin

cmake ..
  # or "cmake ../src" if the top level
  # CMakeLists.txt is in lx/src

make

기본적으로 lx 실행 파일은 이 레이아웃을 사용하여 "lx/bin/src" 디렉토리에 저장됩니다.RUNTAM_OUTPUT_DIRECTORY 타깃속성과 set_property 명령을 사용하여 디렉토리의 종료를 제어할 수 있습니다.

http://www.cmake.org/cmake/help/cmake-2-8-docs.html#prop_tgt:RUNTIME_OUTPUT_DIRECTORY

http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:set_property

lib가 add_library를 통해 CMake 타깃으로 구축되어 있는 경우 target_link_libraries libs를 참조하거나 라이브러리 파일에 대한 풀 경로를 참조합니다.

"cmake --help-command target_link_libraries" 또는 기타 cmake 명령어 출력 및 cmake 명령어 온라인 매뉴얼도 참조하십시오.

http://www.cmake.org/cmake/help/cmake-2-8-docs.html#section_Commands

http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:target_link_libraries

Steinberg VST3 라이브러리에는 재사용 가능한 메서드가 있습니다.이 메서드는 서브디렉토리에 반복 루프가 발생하고 CMakeList가 포함되어 있는 경우 서브디렉토리를 추가합니다.txt 파일:

# add every sub directory of the current source dir if it contains a CMakeLists.txt
function(smtg_add_subdirectories)
    file(GLOB subDirectories RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *)
    foreach(dir ${subDirectories})
        if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${dir}")
            if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${dir}/CMakeLists.txt")
                add_subdirectory(${dir})
            endif()
        endif()
    endforeach(dir)
endfunction()

https://github.com/steinbergmedia/vst3_cmake/blob/master/modules/SMTG_AddSubDirectories.cmake

언급URL : https://stackoverflow.com/questions/6352123/multiple-directories-under-cmake

반응형