Skip to content

Commit

Permalink
Modified cmake files and add option to install files.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiri Hnidek committed Mar 3, 2015
1 parent 7e62dfb commit b1e93c5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
42 changes: 37 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ cmake_minimum_required (VERSION 2.6)

# Build type
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Debug' as none was specified.")
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo")
Expand All @@ -15,8 +15,8 @@ project (Daemon)

# The version number
set (${PROJECT_NAME}_VERSION_MAJOR 0)
set (${PROJECT_NAME}_VERSION_MINOR 1)
set (${PROJECT_NAME}_PATCH_LEVEL 0)
set (${PROJECT_NAME}_VERSION_MINOR 0)
set (${PROJECT_NAME}_PATCH_LEVEL 1)

set (${PROJECT_NAME}_VERSION
"${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}")
Expand All @@ -29,4 +29,36 @@ set (CMAKE_MODULE_PATH
set (EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin/)

# Set up required subdirectories
add_subdirectory (src)
add_subdirectory (src)

# Directory with configuration files
set (DAEMON_CONF_DIR "/etc/daemon")

# Macro for installing configuration files
function(install_conf src dest)
if(NOT IS_ABSOLUTE "${src}")
set(src "${CMAKE_CURRENT_SOURCE_DIR}/${src}")
endif()
get_filename_component(src_name "${src}" NAME)
if (NOT IS_ABSOLUTE "${dest}")
set(dest "${CMAKE_INSTALL_PREFIX}/${dest}")
endif()
install(CODE "
if(NOT EXISTS \"\$ENV{DESTDIR}${dest}/${src_name}\")
#file(INSTALL \"${src}\" DESTINATION \"${dest}\")
message(STATUS \"Installing: \$ENV{DESTDIR}${dest}/${src_name}\")
execute_process(COMMAND \${CMAKE_COMMAND} -E copy \"${src}\"
\"\$ENV{DESTDIR}${dest}/${src_name}\"
RESULT_VARIABLE copy_result
ERROR_VARIABLE error_output)
if(copy_result)
message(FATAL_ERROR \${error_output})
endif()
else()
message(STATUS \"Skipping : \$ENV{DESTDIR}${dest}/${src_name}\")
endif()
")
endfunction(install_conf)

# Install configuration file
install_conf (./daemon.conf ${DAEMON_CONF_DIR})
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ if (CMAKE_COMPILER_IS_GNUCC)
endif (CMAKE_COMPILER_IS_GNUCC)

add_executable (daemon ${daemon_src})

# The rule to install daemon binary
install (TARGETS daemon
RUNTIME
DESTINATION bin)

0 comments on commit b1e93c5

Please sign in to comment.