2011-06-02 134 views
13

我是cmake的新手,我試圖在保留目錄結構的同時安裝.hpp文件。cmake glob在保留目錄結構的同時包含

到目前爲止,我有

FILE(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp" 
    "${CMAKE_CURRENT_SOURCE_DIR}/include/MyLib/*.hpp" 
    "${CMAKE_CURRENT_SOURCE_DIR}/include/MyLib/detail/*.hpp" 

install (FILES ${files} DESTINATION include) 

所有文件被發現,但目錄層次結構是扁平的。我試圖仿效

FWIW的bjam命令

install headers 
    : ../include/EnsembleLearning.hpp 
     [ glob ../include/MyLib/*.hpp ] 
     [ glob ../include/MyLib/detail/*.hpp ] 
    : <install-source-root>../include ; 

回答

14

可以使用CMake的install命令的目錄變種。此命令將保留複製的目錄結構:

install(DIRECTORY include/ DESTINATION include 
      FILES_MATCHING PATTERN "*.hpp") 

如果要複製的目錄中包含不應該安裝的子目錄,你必須明確排除那些具有PAT排除選項:

install(DIRECTORY include/ DESTINATION include 
      FILES_MATCHING PATTERN "*.hpp" 
      PATTERN "include/MyOtherLib" EXCLUDE) 
+0

+1好極了,這正是我一直在尋找的,謝謝! – Tom 2011-06-03 05:30:37

+0

這對目前cmake-2.8.5不適用。要麼沒有安裝文件,要麼我省略了FILES_MATCHING行,所有的東西都被安裝了。有任何想法嗎? – MKroehnert 2011-07-18 15:28:43

+0

適用於cmake-2.8.5。你可以發佈一些代碼嗎? – sakra 2011-07-18 17:45:57