Browse Source

fixes for eth_add_resources

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
6315351b7a
  1. 6
      cmake/EthUtils.cmake
  2. 23
      cmake/scripts/resource.cpp.in
  3. 26
      cmake/scripts/resource.h.in
  4. 36
      cmake/scripts/resource.hpp.in
  5. 10
      cmake/scripts/resources.cmake

6
cmake/EthUtils.cmake

@ -64,7 +64,11 @@ endmacro()
# Creates C resources file from files # Creates C resources file from files
function(eth_add_resources TARGET RESOURCE_FILE) function(eth_add_resources TARGET RESOURCE_FILE)
add_custom_command(TARGET ${TARGET} PRE_BUILD
add_custom_target("${TARGET}.resources"
COMMAND ${CMAKE_COMMAND} -DETH_RES_FILE="${RESOURCE_FILE}" -P "${ETH_SCRIPTS_DIR}/resources.cmake" COMMAND ${CMAKE_COMMAND} -DETH_RES_FILE="${RESOURCE_FILE}" -P "${ETH_SCRIPTS_DIR}/resources.cmake"
) )
add_dependencies(${TARGET} "${TARGET}.resources")
endfunction() endfunction()

23
cmake/scripts/resource.cpp.in

@ -1,23 +0,0 @@
// this file is autogenerated, do not modify!!!
#include <iostream>
#include <sstream>
#include "${ETH_RESOURCE_NAME}.h"
using namespace std;
using namespace dev;
using namespace dev::eth;
${ETH_RESOURCE_NAME}::${ETH_RESOURCE_NAME}()
{
${ETH_RESULT_DATA}
${ETH_RESULT_INIT}
}
string ${ETH_RESOURCE_NAME}::loadResourceAsString(string _name)
{
ostringstream bistream;
bistream.write(eth_resources[_name], eth_sizes[_name]);
return bistream.str();
}

26
cmake/scripts/resource.h.in

@ -1,26 +0,0 @@
// this file is autogenerated, do not modify!!!
#pragma once
#include <string>
#include <unordered_map>
namespace dev
{
namespace eth
{
class ${ETH_RESOURCE_NAME}
{
public:
${ETH_RESOURCE_NAME}();
std::string loadResourceAsString(std::string _name):
private:
std::unordered_map <std::string, const char*> m_resources;
std::unordered_map <std::string, unsigned> m_sizes;
};
}
}

36
cmake/scripts/resource.hpp.in

@ -0,0 +1,36 @@
// this file is autogenerated, do not modify!!!
#pragma once
#include <string>
#include <sstream>
#include <map>
namespace dev
{
namespace eth
{
class ${ETH_RESOURCE_NAME}
{
public:
${ETH_RESOURCE_NAME}()
{
${ETH_RESULT_DATA}
${ETH_RESULT_INIT}
}
std::string loadResourceAsString(std::string _name)
{
std::ostringstream bistream;
bistream.write(m_resources[_name], m_sizes[_name]);
return bistream.str();
}
private:
std::map <std::string, const char*> m_resources;
std::map <std::string, unsigned> m_sizes;
};
}
}

10
cmake/scripts/resources.cmake

@ -44,17 +44,15 @@ foreach(resource ${ETH_RESOURCES})
set(ETH_RESULT_DATA "${ETH_RESULT_DATA} static const unsigned char eth_${resource}[] = {\n // ${filename}\n ${filedata}\n};\n") set(ETH_RESULT_DATA "${ETH_RESULT_DATA} static const unsigned char eth_${resource}[] = {\n // ${filename}\n ${filedata}\n};\n")
# append init resources # append init resources
set(ETH_RESULT_INIT "${ETH_RESULT_INIT} eth_resources[\"${resource}\"] = (char const*)eth_${resource};\n") set(ETH_RESULT_INIT "${ETH_RESULT_INIT} m_resources[\"${resource}\"] = (char const*)eth_${resource};\n")
set(ETH_RESULT_INIT "${ETH_RESULT_INIT} eth_sizes[\"${resource}\"] = sizeof(eth_${resource});\n") set(ETH_RESULT_INIT "${ETH_RESULT_INIT} m_sizes[\"${resource}\"] = sizeof(eth_${resource});\n")
endforeach(resource) endforeach(resource)
set(ETH_DST_NAME "${ETH_RESOURCE_LOCATION}/${ETH_RESOURCE_NAME}") set(ETH_DST_NAME "${ETH_RESOURCE_LOCATION}/${ETH_RESOURCE_NAME}")
configure_file("${CMAKE_CURRENT_LIST_DIR}/resource.cpp.in" "${ETH_DST_NAME}.cpp.tmp") configure_file("${CMAKE_CURRENT_LIST_DIR}/resource.hpp.in" "${ETH_DST_NAME}.hpp.tmp")
configure_file("${CMAKE_CURRENT_LIST_DIR}/resource.h.in" "${ETH_DST_NAME}.h.tmp")
include("${CMAKE_CURRENT_LIST_DIR}/../EthUtils.cmake") include("${CMAKE_CURRENT_LIST_DIR}/../EthUtils.cmake")
replace_if_different("${ETH_DST_NAME}.cpp.tmp" "${ETH_DST_NAME}.cpp") replace_if_different("${ETH_DST_NAME}.hpp.tmp" "${ETH_DST_NAME}.hpp")
replace_if_different("${ETH_DST_NAME}.h.tmp" "${ETH_DST_NAME}.h")

Loading…
Cancel
Save