13

I want CMake to make install rules for me which also automatically install configuration and other things. I looked at this question, but adding:

add_executable(solshare_stats.conf solshare_stats.conf)

to my CMakeLists.txt file only gave me warnings and errors:

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

How do I add configuration, init and/or logfiles to CMake install rules?

Here is my complete CMakeLists.txt file:

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()
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Cheiron
  • 3,620
  • 4
  • 32
  • 63

1 Answers1

16

The .conf file should be included in the add_executable where you define your executable target, not in a separate call:

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


Then you need to use install(FILE ...) rather than install(TARGET ...):

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


By doing

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

you're saying you want to create 2 executables, one called "solshare_stats" and another called "solshare_stats.conf".

The second target's only source file is the actual file "solshare_stats.conf". Since none of the source files in this target have a suffix which gives an idea about the language (e.g ".cc" or ".cpp" implies C++, ".asm" implies assembler), no language can be deduced, hence the CMake error.

Fraser
  • 74,704
  • 20
  • 238
  • 215
  • And what should I change to the install() calls for this to work? Because with the current install() commands I get this error: `install TARGETS given target "solshare_stats.conf" which does not exist in this directory.` – Cheiron Jun 29 '13 at 16:15
  • Sorry - I'll just add that! – Fraser Jun 29 '13 at 16:22
  • 3
    Done. By the way, it's usual to pass a relative path as the `DESTINATION` argument so that the `CMAKE_INSTALL_PREFIX` is honoured. – Fraser Jun 29 '13 at 16:24