構建 – 如何使用CMake收集原始檔?
ofollow,noindex" target="_blank">CMake documentation 明確宣告檔案(GLOB …)不是
建議收集原始檔進行構建,但不會
提到實際推薦的方法.
手動指定每個原始檔有一點點手動
對我來說.那麼,收集原始檔的方法是什麼呢?
檔案(GLOB …)?
手冊確實是推薦的方法.通過建議不要使用GLOB,文件只是針對依賴於檔案的構建系統進行警告.例如,您要新增一個測試可執行檔案,因此您可以建立mytest.cpp.哎呀.現在你的圖書館編譯了. AUX_SOURCE_DIRECTORY的文件(與原始檔的globbing類似的目的)給出以下警告:
It is tempting to use this command to avoid writing the list of sourcefiles for a library or executable target. While this seems to work,there is no way for CMake to generate a build system that knows when anew source file has been added. Normally the generated build systemknows when it needs to rerun CMake because the CMakeLists.txt file ismodified to add a new source. When the source is just added to thedirectory without modifying this file, one would have to manuallyrerun CMake to generate a build system incorporating the new file.
如果您確定要使用目錄的所有內容,並且不打算新增新的目錄,那麼一定要使用GLOB.
此外,不要忘記手動列出檔案不必涉及所有檔名的打字.你可以做,例如,ls * .cpp>> CMakeLists.txt,然後使用您的編輯器將檔案列表移動到檔案中正確的位置.
http://stackoverflow.com/questions/10914607/how-to-collect-source-files-with-cmake-without-globbing