0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

CMakeでフォルダをまたいでビルドする

Posted at

引っかかったところの個人的メモです。

前提

以下のようなフォルダ構成のアプリケーションをCMakeでビルドする

  • app
    • component1
      • include
        • component1.h
      • src
        • component1.cpp
      • CMakeList.txt
    • component2
        - include
        - component2.h
        - src
        - component2.cpp
        - CMakeList.txt
    • main.cpp
    • CMakeList.txt

やりたいこと

トップのCMakeLists.txtにてadd_subdirectoryをコールし、component1, component2をリンクする。
※component1はcomponent2に依存する

実装

CMakeList.txt(概要のみ)
add_subdirectory(component2)
add_subdirectory(component1 ${CMAKE_CURRENT_SOURCE_DIR}/component2)
add_executable(main main.cpp)
target_link_library(main component1 component2)

解説

subdirectory側では、基本的に上位階層を参照することができません。
そこで、2行目add_subdirectoryの第2パラメータ。これでcomponent1にcomponent2のパスを渡すことができるようになります。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?