2013-06-29 197 views
5

我希望Cmake爲我制定安裝規則,同時自動安裝配置和其他東西。我看着this question,但補充說:CMake安裝:安裝配置文件

add_executable(solshare_stats.conf solshare_stats.conf)

我的CMakeLists.txt文件只給了我警告和錯誤:

CMake Error: CMake can not determine linker language for target:solshare_stats.conf 
CMake Error: Cannot determine link language for target "solshare_stats.conf". 
... 
make[2]: *** No rule to make target `CMakeFiles/solshare_stats.conf.dir/build'. Stop. 
make[1]: *** [CMakeFiles/solshare_stats.conf.dir/all] Error 2 
make: *** [all] Error 2 

如何添加配置,初始化和/或日誌文件向CMake安裝規則?

這裏是我的完整的CMakeLists.txt文件:

project(solshare_stats) 
cmake_minimum_required(VERSION 2.8) 
aux_source_directory(. SRC_LIST) 
add_executable(${PROJECT_NAME} ${SRC_LIST}) 
add_executable(solshare_stats.conf solshare_stats.conf) 
target_link_libraries(solshare_stats mysqlcppconn) 
target_link_libraries(solshare_stats wiringPi) 
if(UNIX) 
    if(CMAKE_COMPILER_IS_GNUCXX) 
     SET(CMAKE_EXE_LINKER_FLAGS "-s") 
     SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -Wall -std=c++0x") 
    endif() 
    install(TARGETS solshare_stats DESTINATION /usr/bin COMPONENT binaries) 
    install(TARGETS solshare_stats.conf DESTINATION /etc/solshare_stats COMPONENT config) 
endif() 

回答

8

.conf文件應包含在你定義的可執行的目標,而不是在一個單獨的呼叫add_executable

add_executable(${PROJECT_NAME} ${SRC_LIST} solshare_stats.conf) 


然後您需要使用install(FILE ...)而不是install(TARGET ...)

install(TARGETS solshare_stats DESTINATION /usr/bin COMPONENT binaries) 
install(FILES solshare_stats.conf DESTINATION etc/solshare_stats COMPONENT config) 


這樣做

add_executable(${PROJECT_NAME} ${SRC_LIST}) 
add_executable(solshare_stats.conf solshare_stats.conf) 

你說你要創建2名的可執行文件,一個名爲 「solshare_stats」,另一個叫 「solshare_stats.conf」。

第二個目標的唯一源文件是實際的文件「solshare_stats.conf」。由於這個目標文件中沒有任何源文件有一個可以給出關於該語言的想法的後綴(例如「.cc」或「.cpp」意味着C++,「.asm」意味着彙編語言),因此不能推導出任何語言,因此CMake錯誤。

+0

我應該更改爲install()調用以使其工作?因爲使用當前的install()命令,我得到這個錯誤:'安裝TARGETS給定的目標「solshare_stats.conf」,這個目錄中不存在。「 – Cheiron

+0

對不起,我只是補充一點! – Fraser

+3

完成。順便說一下,通常傳遞一個相對路徑作爲'DESTINATION'參數,這樣'CMAKE_INSTALL_PREFIX'得到遵守。 – Fraser