我希望CMake为我制定安装规则,它也会自动安装配置和其他东西。我看了this question,但又添加了:
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()
答案 0 :(得分:13)
.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错误。