我剛進入cmake是因爲我開始研究一個更大的項目。我需要添加模塊測試。有幾個嵌入式設備,每個嵌入式設備都有自己運行的應用程序。用於更大項目的cmake用普通代碼
大多數這些應用程序共享代碼。 所以代碼被分成模塊。問題是有些模塊在大多數其他模塊中使用。這些模塊是常見的,通用網絡和日誌。
的設備的簡化計劃(APP)具有以下結構:
.
|-- CMakeLists.txt (for app)
|-- LICENSE
|-- app
| |-- inc
| | |-- appfile1.hpp
| | `-- appfile2.hpp
| `-- src
| |-- appfile1.cpp
| |-- appfile2.cpp
| `-- main.cpp
|-- comp
| |-- comp1
| | |-- CMakeLists.txt (for test)
| | |-- comp
| | | |-- CMakeLists.txt (for lib)
| | | |-- intf
| | | | |-- comp1file.hpp
| | | | `-- comp1file.hpp
| | | `-- src
| | | |-- comp1file.cpp
| | | `-- comp1file.cpp
| | `-- test
| | `-- src
| | `-- comp1testfile.cpp
| |-- comp2
| | |-- CMakeLists.txt (for test)
| | |-- comp
| | | |-- CMakeLists.txt (for lib)
| | | |-- inc
| | | | `-- comp2file1.hpp
| | | |-- intf
| | | | |-- comp2file2.hpp
| | | | |-- comp2file3.hpp
| | | | |-- comp2file4.hpp
| | | `-- src
| | | |-- comp2file1.cpp
| | | |-- comp2file2.cpp
| | | `-- comp2file3.cpp
| | `-- test
| | |-- inc
| | | `-- comp2testfile.hpp
| | `-- src
| | `-- comp2testfile.cpp
| |-- common
| | |-- CMakeLists.txt (for test)
| | `-- comp
| | |-- inc
| | | |-- commonfile1.hpp
| | | `-- commonfile2.hpp
| | `-- src
| | `-- commonfile1.cpp
| |-- common-net
| | |-- CMakeLists.txt (for test)
| | |-- comp
| | | |-- inc
| | | | |-- netfile1.hpp
| | | | |-- netfile2.hpp
| | | | |-- netfile3.hpp
| | | | |-- netfile4.hpp
| | | | |-- netfile5.hpp
| | | `-- src
| | | |-- netfile1.cpp
| | | |-- netfile2.cpp
| | | |-- netfile3.cpp
| | | |-- netfile4.cpp
| | | |-- netfile5.cpp
| | `-- test
| | |-- inc
| | | |-- nettestfile1.hpp
| | `-- src
| | |-- nettestfile1.cpp
| | |-- nettestfile2.cpp
| | |-- nettestfile3.cpp
| |-- comp3
| | |-- CMakeLists.txt (for test)
| | |-- comp
| | | |-- CMakeLists.txt (for lib)
| | | |-- intf
| | | | |-- comp3file1.hpp
| | | | `-- comp3file2.hpp
| | | `-- src
| | | `-- comp3file1.cpp
| | `-- test
| | `-- src
| | `-- comp3testfile1.cpp
| |-- log
| | `-- comp
| | |-- inc
| | | |-- logfile1.hpp
| | | |-- logfile2.hpp
| | |-- intf
| | | |-- logfile3.hpp
| | | |-- logfile4.hpp
| | `-- src
| | |-- logfile1.cpp
| | |-- logfile2.cpp
| | |-- logfile3.cpp
| | `-- logfile4.cpp
| |-- comp4
| | |-- CMakeLists.txt (for test)
| | |-- comp
| | | |-- CMakeLists.txt (for lib)
| | | |-- intf
| | | | |-- comp4file1.hpp
| | | | |-- comp4file2.hpp
| | | | |-- comp4file3.hpp
| | | `-- src
| | | |-- comp4file1.cpp
| | | |-- comp4file2.cpp
| | | `-- comp4file3.cpp
| | `-- test
| | |-- inc
| | | |-- comp4testfile1.hpp
| | | `-- comp4testfile2.hpp
| | `-- src
| | |-- comp4testfile1.cpp
| | |-- comp4testfile2.cpp
| | |-- comp4testfile3.cpp
| | |-- comp4testfile4.cpp
| | `-- comp4testfile5.cpp
|-- gcc-4.8.cmake
|-- gcc-4.9.cmake
`-- gcc-default.cmake
我知道它有很多的它「補償」,但命名沒有達到我..
每個comp有2個CMakefiles: 最高級的是創建一個單元測試可執行文件來測試模塊。 comp中的一個是製作一個圖書館。以便它可以與應用CMakefile中的add_subdirectory一起使用。
問題是,很多模塊都依賴於通用的公共網和日誌。 目前這些部分不是作爲庫構建的。我猜是因爲如果在多個模塊中使用add_subdirectory會產生問題嗎?這是乾淨的嗎?
這會導致: 每個從屬模塊都包含comp CMakefile中的常見標題。 在頂層(應用程序CMakefile),常見的源被添加到可執行文件。 但是對於每個模塊測試,我還必須將常見源添加到測試可執行文件。
這對我來說似乎很陌生,我認爲出了問題。但我不知道如何幹淨地解決它?
看看項目樹和需要獨立測試每個模塊。 是在頂層添加源的方法還是沒有完成?
Ty爲鏈接是一個非常有用的閱讀。 – rinn2883