수색…


패키지없는 간단한 접근법

실행 파일 (편집기)을 빌드하고 라이브러리 (강조 표시)에 링크하는 예제입니다. 프로젝트 구조는 간단합니다. 마스터 CMakeLists와 각 하위 프로젝트에 대한 디렉토리가 필요합니다.

CMakeLists.txt
editor/
    CMakeLists.txt
    src/
        editor.cpp
highlight/
    CMakeLists.txt
    include/
        highlight.h
    src/
        highlight.cpp

마스터 CMakeLists.txt에는 각 하위 프로젝트에 대한 전역 정의 및 add_subdirectory 호출이 포함되어 있습니다.

cmake_minimum_required(VERSION 3.0)
project(Example)

add_subdirectory(highlight)
add_subdirectory(editor)

라이브러리의 CMakeLists.txt는 소스와 디렉토리를 할당합니다. include_directories() target_include_directories() 대신 target_include_directories() 를 사용하면 include dir이 라이브러리 사용자에게 전파됩니다.

cmake_minimum_required(VERSION 3.0)
project(highlight)

add_library(${PROJECT_NAME} src/highlight.cpp)
target_include_directories(${PROJECT_NAME} PUBLIC include)

응용 프로그램의 CMakeLists.txt는 소스를 지정하고 강조 라이브러리를 연결합니다. hightlighter의 바이너리 및 포함 경로는 cmake가 automaticaly로 처리합니다.

cmake_minimum_required(VERSION 3.0)
project(editor)

add_executable(${PROJECT_NAME} src/editor.cpp)
target_link_libraries(${PROJECT_NAME} PUBLIC highlight)


Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow