2013-06-29 68 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