diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 9b142df..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,20 +0,0 @@ -project(TestTemplate) - -cmake_minimum_required(VERSION 2.8) -include(ExternalProject) - -ExternalProject_Add( - sparrow_input - PREFIX ${PROJECT_SOURCE_DIR}/.. - GIT_REPOSITORY Lendemor:lum1ere%40@https://git.epicsparrow.com/epicsparrow/SparrowInput.git -) - -EXTERNALProject_get_property(sparrow_input install_dir) - -MESSAGE(STATUS ${install_dir}) - -add_library(sparrow_input) - -include(template.cmake) - - diff --git a/resource.cmake b/resource.cmake new file mode 100644 index 0000000..1d3dfc0 --- /dev/null +++ b/resource.cmake @@ -0,0 +1,22 @@ +# Subfile for cmaketemplate : +# Generate a .cpp file with given resource file +# + +include_directories( + ${CMAKE_TEMPLATE_PATH}/resource #bad but necessary for resource.h + ) + +add_executable(SparrowResource ${CMAKE_TEMPLATE_PATH}/resource/main.cpp) + +#SET (RESOURCE_PATH ${CMAKE_CURRENT_SOURCE_DIR}${RESOURCE_DIRS}) +#MESSAGE(${RESOURCE_PATH}) + +#SET(CMAKE_VERBOSE_MAKEFILE ON) + +add_custom_command( + OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${RESOURCE_DST_FILE} + COMMAND SparrowResource + ARGS ${CMAKE_CURRENT_SOURCE_DIR}/${RESOURCE_DST_FILE} ${RES_SRC_FILE} + DEPENDS ${RES_SRC_FILE} + COMMENT "Generating resource file" + ) diff --git a/resource/CMakeLists.txt b/resource/CMakeLists.txt index c3177ee..4754a52 100644 --- a/resource/CMakeLists.txt +++ b/resource/CMakeLists.txt @@ -1,8 +1,10 @@ project(SparrowResource) cmake_minimum_required(VERSION 2.8) +set(CMAKE_TEMPLATE_PATH "..") + # choose source file set(EXEC_SRC_LIST main.cpp) -include(../template.cmake) +include(${CMAKE_TEMPLATE_PATH}/template.cmake) diff --git a/resource/test/plop.txt b/resource/test/plop.txt deleted file mode 100644 index 1c8a3a1..0000000 --- a/resource/test/plop.txt +++ /dev/null @@ -1 +0,0 @@ -Hello World ! \ No newline at end of file diff --git a/template.cmake b/template.cmake index dd35ae1..d348674 100644 --- a/template.cmake +++ b/template.cmake @@ -13,8 +13,17 @@ set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) +if(NOT CMAKE_TEMPLATE_PATH) + MESSAGE(WARNING "CMAKE_TEMPLATE_PATH not set. Using default value \"../cmaketemplate\"...") + SET(CMAKE_TEMPLATE_PATH "../cmaketemplate") +endif() + +include(${CMAKE_TEMPLATE_PATH}/resource.cmake) + +MESSAGE(${PROJECT_BINARY_DIR}) + configure_file ( - "../cmaketemplate/SparrowConfig.h.in" + "${CMAKE_TEMPLATE_PATH}/SparrowConfig.h.in" "${PROJECT_BINARY_DIR}/Version.h" ) @@ -356,7 +365,7 @@ endif() include_directories( ${INCLUDE_PATHS} - ${EXTRA_INCLUDE} + ${EXTRA_INCLUDES} ) if(LIB_SRC_LIST) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..b14c410 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,17 @@ +project(SparrowTest) +cmake_minimum_required(VERSION 2.8) + +set(CMAKE_TEMPLATE_PATH "..") + +#SET(RESOURCE_DIRS /shaders) + +#SET(RES_SRC_FILE ${CMAKE_CURRENT_SOURCE_DIR}/plop.txt ${CMAKE_CURRENT_SOURCE_DIR}/plop2.txt) +FILE(GLOB RES_SRC_FILE plop.txt plop2.txt) +SET(RESOURCE_DST_FILE res.cpp) + +MESSAGE(${RES_SRC_FILE}) + +# choose source file +set(EXEC_SRC_LIST test.cpp ${RESOURCE_DST_FILE}) + +include(${CMAKE_TEMPLATE_PATH}/template.cmake) diff --git a/resource/test/README b/test/README similarity index 100% rename from resource/test/README rename to test/README diff --git a/test/plop.txt b/test/plop.txt new file mode 100644 index 0000000..d7407a1 --- /dev/null +++ b/test/plop.txt @@ -0,0 +1 @@ +Hello World ! diff --git a/test/plop2.txt b/test/plop2.txt new file mode 100644 index 0000000..4a927de --- /dev/null +++ b/test/plop2.txt @@ -0,0 +1,2 @@ +This is a tessst +fefea diff --git a/test/res.cpp b/test/res.cpp new file mode 100644 index 0000000..2dab7e3 --- /dev/null +++ b/test/res.cpp @@ -0,0 +1,30 @@ +#include +#include + +namespace Resource { +std::unordered_map *resourceFilesData; + +const char data0[] = { + 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,0x72,0x6c,0x64,0x20,0x21,0xa +}; + +const char data1[] = { + 0x54,0x68,0x69,0x73,0x20,0x69,0x73,0x20,0x61,0x20,0x74,0x65,0x73,0x73,0x73,0x74,0xa,0x66,0x65,0x66,0x65,0x61,0xa +}; + +void initResourceData() +{ + resourceFilesData = new std::unordered_map(); + (*resourceFilesData)["/data/Qt_workspace/cmaketemplate/test/plop.txt"] = data0; + (*resourceFilesData)["/data/Qt_workspace/cmaketemplate/test/plop2.txt"] = data1; + +} + +const char* get(const std::string &fileName) +{ + if(resourceFilesData->count(fileName) > 0) + return (*resourceFilesData)[fileName]; + else + return NULL; +} +} diff --git a/resource/test/test.cpp b/test/test.cpp similarity index 61% rename from resource/test/test.cpp rename to test/test.cpp index bef77bc..95b6f97 100644 --- a/resource/test/test.cpp +++ b/test/test.cpp @@ -1,5 +1,5 @@ #include -#include "resource.h" +#include "../resource/resource.h" using namespace std; @@ -7,9 +7,9 @@ int main() { cout << "Resource test" << endl; Resource::initResourceData(); - const char *str = Resource::get("plop.txt"); + const char *str = Resource::get("/data/Qt_workspace/cmaketemplate/test/plop.txt"); if(str != NULL) cout << str << endl; else cout << "nope" << endl; -} \ No newline at end of file +} diff --git a/test/test.exe b/test/test.exe new file mode 100644 index 0000000..1dcf15a Binary files /dev/null and b/test/test.exe differ