Permalink
Browse files

patches: add odb include cmakelists

  • Loading branch information...
1 parent 839ef6e commit 2e9154c4474d5a7f9e504c8025a8f11919ebbd4f @mcraveiro mcraveiro committed Mar 31, 2013
Showing with 179 additions and 0 deletions.
  1. +179 −0 patches/odb_include_cmakelists.patch
@@ -0,0 +1,179 @@
+diff --git a/projects/cpp/include/dogen/cpp/types/formatters/include_cmakelists.hpp b/projects/cpp/include/dogen/cpp/types/formatters/include_cmakelists.hpp
+index 234c854..193aa36 100644
+--- a/projects/cpp/include/dogen/cpp/types/formatters/include_cmakelists.hpp
++++ b/projects/cpp/include/dogen/cpp/types/formatters/include_cmakelists.hpp
+@@ -47,7 +47,8 @@ public:
+ include_cmakelists& operator=(const include_cmakelists&) = default;
+
+ public:
+- include_cmakelists(std::ostream& stream);
++ include_cmakelists(std::ostream& stream, const bool odb_enabled,
++ const std::string odb_folder);
+
+ public:
+ void format(const cmakelists_view_model& vm);
+@@ -55,6 +56,8 @@ public:
+ private:
+ std::ostream& stream_;
+ indenter indenter_;
++ const bool odb_enabled_;
++ const std::string odb_folder_;
+ };
+
+ } } }
+diff --git a/projects/cpp/src/types/formatters/include_cmakelists.cpp b/projects/cpp/src/types/formatters/include_cmakelists.cpp
+index ac14462..9f1344b 100644
+--- a/projects/cpp/src/types/formatters/include_cmakelists.cpp
++++ b/projects/cpp/src/types/formatters/include_cmakelists.cpp
+@@ -36,7 +36,10 @@ namespace cpp {
+ namespace formatters {
+
+ include_cmakelists::
+-include_cmakelists(std::ostream& stream) : stream_(stream) { }
++include_cmakelists(std::ostream& stream, const bool odb_enabled,
++ const std::string odb_folder) : stream_(stream),
++ odb_enabled_(odb_enabled),
++ odb_folder_(odb_folder) {}
+
+ void include_cmakelists::format(const cmakelists_view_model& vm) {
+ const std::string mn(vm.model_name().empty() ?
+@@ -72,17 +75,115 @@ void include_cmakelists::format(const cmakelists_view_model& vm) {
+ << std::endl << "# MA 02110-1301, USA." << std::endl
+ << "#" << std::endl
+ << "add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src)" << std::endl
++ << std::endl;
++
++ positive_indenter_scope s(indenter_);
++ stream_ << "install(" << std::endl
++ << indenter_ << "DIRECTORY include/" << std::endl
++ << indenter_ << "DESTINATION include/" << std::endl
++ << indenter_ << "COMPONENT headers" << std::endl
++ << indenter_ << "FILES_MATCHING PATTERN \"*.hpp\")"
++ << std::endl << std::endl;
++
++ if (!odb_enabled_)
++ return;
++
++ stream_ << "set(include_dir \"${CMAKE_CURRENT_SOURCE_DIR}/include/"
++ << vm.product_name() << "/" << vm.model_name() << "\")"
++ << std::endl;
++
++ stream_ << "set(all_odb_files \"\")" << std::endl;
++ stream_ << "file(GLOB_RECURSE all_odb_files RELATIVE" << std::endl
++ << indenter_ << "\"${include_dir}/" << odb_folder_
++ << "/\"" << std::endl
++ << indenter_ << "\"${include_dir}/" << odb_folder_
++ << "/*_pragmas.hpp\")"
++ << std::endl << std::endl;
++
++ stream_ << "set(src_odb_dir \"${CMAKE_CURRENT_SOURCE_DIR}/src/"
++ << odb_folder_ << "/\")"
+ << std::endl
+- << "install(" << std::endl;
++ << "if(NOT EXISTS \"${src_odb_dir}\")" << std::endl
++ << indenter_ << "file(MAKE_DIRECTORY \"${src_odb_dir}\")"
++ << std::endl
++ << "endif()" << std::endl << std::endl;
++
++ stream_ << "add_custom_target(codegen_" << vm.model_name()
++ << "_" << odb_folder_ << std::endl
++ << indenter_ << "WORKING_DIRECTORY ${CMAKE_BINARY_DIR}" << std::endl
++ << indenter_
++ << "COMMAND mv ${CMAKE_CURRENT_SOURCE_DIR}/include/"
++ << vm.product_name() << "/"
++ << vm.model_name() << "/"
++ << odb_folder_ << "/*.cpp" << std::endl
++ << indenter_ << "${src_odb_dir})" << std::endl << std::endl;
++
++ stream_ << "set(ignore_file false)" << std::endl
++ << "foreach(odb_file ${all_odb_files})" << std::endl;
++
++ stream_ << indenter_ << "if (odb_file MATCHES \"all_pragmas.hpp\")"
++ << std::endl;
++ {
++ positive_indenter_scope s(indenter_);
++ stream_ << indenter_ << "set(ignore_file true)" << std::endl;
++ }
++
++ stream_ << indenter_ << "endif()" << std::endl << std::endl
++ << indenter_ << "message(STATUS \"${odb_file}\")" << std::endl
++ << indenter_ << "if(NOT ignore_file)" << std::endl;
+
+ {
+ positive_indenter_scope s(indenter_);
+- stream_ << indenter_ << "DIRECTORY include/" << std::endl
+- << indenter_ << "DESTINATION include/" << std::endl
+- << indenter_ << "COMPONENT headers" << std::endl
+- << indenter_ << "FILES_MATCHING PATTERN \"*.hpp\")"
++ stream_ << indenter_ << "set(type_name \"\")" << std::endl
++ << indenter_ << "string(REPLACE \"_pragmas.hpp\" \"\""
++ << " type_name ${odb_file})" << std::endl << std::endl;
++
++ stream_ << indenter_ << "set(pfh_dir \"$ENV{PFH_LOCATION}\")"
++ << std::endl
++ << indenter_ << "set(target_name \"codegen_"
++ << vm.model_name() << "_odb_${type_name}\")" << std::endl
++ << indenter_ << "message(STATUS \"${target_name}\")"
++ << std::endl
++ << indenter_ << "add_custom_target(${target_name}"
+ << std::endl;
++
++ {
++ positive_indenter_scope s(indenter_);
++ stream_ << indenter_ << "WORKING_DIRECTORY ${CMAKE_BINARY_DIR}"
++ << std::endl
++ << indenter_ << "COMMAND odb" << std::endl
++ << indenter_
++ << "--options-file ${CMAKE_CURRENT_SOURCE_DIR}/"
++ << "options.odb"
++ << std::endl
++ << indenter_ << "--std c++11" << std::endl
++ << indenter_
++ << "--output-dir ${CMAKE_CURRENT_SOURCE_DIR}/include/"
++ << vm.product_name() << "/" << vm.model_name()
++ << "/" << odb_folder_ << "/" << std::endl
++ << indenter_
++ << "--odb-epilogue '#include \""
++ << vm.product_name() << "/" << vm.model_name()
++ << "/" << odb_folder_ << "/${odb_file}\"'" << std::endl
++ << indenter_
++ << "-I ${pfh_dir}/include -I ${CMAKE_CURRENT_SOURCE_DIR}"
++ << "/include" << std::endl
++ << indenter_
++ << "${include_dir}/types/${type_name}.hpp)" << std::endl;
++ }
++
++ stream_ << indenter_
++ << "add_dependencies(codegen_" << vm.model_name()
++ << "_odb ${target_name})" << std::endl;
+ }
++ stream_ << indenter_ << "endif()" << std::endl
++ << indenter_
++ << "add_dependencies(codegen_" << vm.model_name() << "_odb "
++ << "codegen_" << vm.model_name() << ")"
++ << std::endl
++ << indenter_ << "set(ignore_file false)" << std::endl;
++
++ stream_ << "endforeach()" << std::endl;
+ }
+
+ } } }
+diff --git a/projects/cpp/src/types/generator.cpp b/projects/cpp/src/types/generator.cpp
+index 4f0ac1b..ad17ca3 100644
+--- a/projects/cpp/src/types/generator.cpp
++++ b/projects/cpp/src/types/generator.cpp
+@@ -106,10 +106,13 @@ generator::value_type generator::generate_cmakelists() const {
+ r.insert(std::make_pair(vm.file_path(), stream.str()));
+
+ if (!settings_.split_project()) {
++ const auto f(settings_.enabled_facets());
++ const bool odb_enabled(f.find(config::cpp_facet_types::odb) != f.end());
+ stream.str("");
+ vm.file_path(locator_.absolute_path(vm.file_name()));
+ log_formating_view(vm.file_path().string());
+- formatters::include_cmakelists inc(stream);
++ formatters::include_cmakelists inc(stream, odb_enabled,
++ settings_.odb_facet_folder());
+ inc.format(vm);
+ r.insert(std::make_pair(vm.file_path(), stream.str()));
+ }

0 comments on commit 2e9154c

Please sign in to comment.