Move cmake code to generate a C++ source file from a binary data file into a helper module

This commit is contained in:
Robert Knight 2011-08-29 17:40:25 +01:00
parent 3c836c2d0c
commit 761a4c5d3b
3 changed files with 27 additions and 6 deletions

View file

@ -1,6 +1,7 @@
project(updater)
cmake_minimum_required(VERSION 2.6)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
include_directories(external)
include_directories(external/TinyThread/source)

View file

@ -0,0 +1,21 @@
# Convert a binary data file into a C++
# source file for embedding into an application binary
#
# Currently only implemented for Unix. Requires the 'xxd'
# tool to be installed.
#
# INPUT_FILE : The name of the binary data file to be converted into a C++
# source file.
#
# CPP_FILE : The path of the C++ source file to be generated.
# See the documentation for xxd for information on
# the structure of the generated source file.
#
# INPUT_FILE_TARGET : The name of the target which generates INPUT_FILE
#
function (generate_cpp_resource_file INPUT_FILE CPP_FILE INPUT_FILE_TARGET)
add_custom_command(OUTPUT ${CPP_FILE}
COMMAND xxd -i ${INPUT_FILE} ${CPP_FILE}
DEPENDS ${INPUT_FILE_TARGET})
endfunction()

View file

@ -2,6 +2,7 @@
add_subdirectory(tests)
find_package(Threads REQUIRED)
include(GenerateCppResourceFile)
if (UNIX)
add_definitions(-Wall -Werror -Wconversion)
@ -60,13 +61,11 @@ if (ENABLE_GTK)
# embed the GTK helper library into the updater binary.
# At runtime it will be extracted and loaded if the
# GTK libraries are available
set(GTK_UPDATER_LIB libupdatergtk.so)
set(GTK_BIN_FILE ${CMAKE_CURRENT_BINARY_DIR}/libupdatergtk.cpp)
add_custom_command(OUTPUT ${GTK_BIN_FILE}
COMMAND xxd -i ${GTK_UPDATER_LIB} ${GTK_BIN_FILE}
DEPENDS updatergtk)
set(SOURCES ${SOURCES} UpdateDialogGtkWrapper.cpp ${GTK_BIN_FILE})
set(GTK_BIN_CPP_FILE ${CMAKE_CURRENT_BINARY_DIR}/libupdatergtk.cpp)
generate_cpp_resource_file(${GTK_UPDATER_LIB} ${GTK_BIN_CPP_FILE} updatergtk)
set(SOURCES ${SOURCES} UpdateDialogGtkWrapper.cpp ${GTK_BIN_CPP_FILE})
set(HEADERS ${HEADERS} UpdateDialogGtkWrapper.h)
endif()