Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake install: installing configuration files

Tags:

cmake

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()
like image 836
Cheiron Avatar asked Jun 29 '13 15:06

Cheiron


People also ask

Where does CMake install files?

Install directory used by install. If “make install” is invoked or INSTALL is built, this directory is prepended onto all install directories. This variable defaults to /usr/local on UNIX and c:/Program Files on Windows.

What is CMake config file?

A config-file package is a set of files provided by upstreams for downstreams to use. CMake searches in a number of locations for package configuration files, as described in the find_package() documentation.

How do I add installation prefix to CMake?

cmake: Add `--prefix` option to set CMAKE_INSTALL_PREFIX. Classically the primary way of specifying the install directory is via CMAKE_INSTALL_PREFIX . With the introduction of cmake --install we added --prefix to override the existing CMAKE_INSTALL_PREFIX .


1 Answers

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.

like image 129
Fraser Avatar answered Oct 04 '22 05:10

Fraser