2013-06-29 10 views
5

Desidero che Cmake crei delle regole di installazione che installino automaticamente anche la configurazione e altre cose. Ho guardato this question, ma aggiungendo:Installazione di CMake: installazione dei file di configurazione

add_executable(solshare_stats.conf solshare_stats.conf)

al mio file CMakeLists.txt mi ha dato solo avvertimenti ed errori:

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 

Come faccio ad aggiungere config, init e/o file di log a CMake installare le regole?

Ecco il mio file completo 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() 

risposta

8

Il file .conf dovrebbe essere incluso nel add_executable cui è possibile definire il vostro target eseguibile, non in una chiamata separata:

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


Quindi è necessario utilizzare install(FILE ...) anziché install(TARGET ...):

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


Facendo

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

che stai dicendo che si desidera creare 2 eseguibili, uno chiamato "solshare_stats" e un altro chiamato "solshare_stats.conf".

L'unico file sorgente del secondo target è il file "solshare_stats.conf". Poiché nessuno dei file sorgente in questo target ha un suffisso che dà un'idea del linguaggio (ad esempio ".cc" o ".cpp" implica C++, ".asm" implica l'assemblatore), non è possibile dedurre alcun linguaggio, quindi il CMake errore.

+0

E cosa devo cambiare per le chiamate install() affinché funzioni? Perché con i comandi di installazione corrente() ottengo questo errore: 'installa TARGETS dato il target" solshare_stats.conf "che non esiste in questa directory. – Cheiron

+0

Scusate - aggiungerò che! – Fraser

+3

Fatto. A proposito, è normale passare un percorso relativo come argomento 'DESTINATION' in modo che il' CMAKE_INSTALL_PREFIX' sia onorato. – Fraser