diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e5abfe..6580a61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/cmake/modules/GenerateCppResourceFile.cmake b/cmake/modules/GenerateCppResourceFile.cmake new file mode 100644 index 0000000..d8207f5 --- /dev/null +++ b/cmake/modules/GenerateCppResourceFile.cmake @@ -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() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3a6aabd..ebcc1cd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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()