Skip to content

Support data list in .cmake file #1442

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ All notable changes to this project will be documented in this file.
- Added support for all four validators in wxRuby3 0.9.3 and up.
- Non-derived C++ class headers now support protected: class methods in addition to the public: ones that were already supported.
- New Data List form allowing you to embed text, xml and binary files into your application.
- Any generated .cmake file will also include a separate list of data files that can be used in the `add_custom_command` and `add_custom_target` commands of a CMakeLists.txt file.
- Images list has a new auto_add property that will automatically add new images to the list when they are added to any control.

### Changed
Expand Down
26 changes: 26 additions & 0 deletions src/generate/gen_cmake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,32 @@ int WriteCMakeFile(Node* parent_node, std::vector<tt_string>& updated_files, std
out.emplace_back();
out.emplace_back(")");

if (auto* data_form = Project.getDataForm(); data_form && data_form->getChildCount())
{
out.emplace_back();
out.emplace_back();
var_name = Project.as_string(prop_cmake_varname);
var_name += "_data";
out.at(out.size() - 1) << "set (" << var_name;
out.emplace_back();

for (auto& iter: data_form->getChildNodePtrs())
{
tt_string base_file = iter->as_string(prop_data_file);
if (base_file.size())
{
base_file.make_relative(cur_dir);
base_file.backslashestoforward();

out.emplace_back();
out.at(out.size() - 1) << " ${CMAKE_CURRENT_LIST_DIR}/" << base_file;
}
}

out.emplace_back();
out.emplace_back(")");
}

// flag == 2 if a temporary file is being written
if (flag == 2)
{
Expand Down
16 changes: 16 additions & 0 deletions src/project/project_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,22 @@ Node* ProjectHandler::getImagesForm()
return m_ImagesForm;
}

Node* ProjectHandler::getDataForm()
{
if (!m_DataForm)
{
if (m_project_node->getChildCount() > 0 && m_project_node->getChild(0)->isGen(gen_Data))
{
m_DataForm = m_project_node->getChild(0);
}
else if (m_project_node->getChildCount() > 1 && m_project_node->getChild(1)->isGen(gen_Data))
{
m_DataForm = m_project_node->getChild(1);
}
}
return m_DataForm;
}

int ProjectHandler::get_WidgetsMinorVersion()
{
tt_string_view version = m_project_node->as_string(prop_wxWidgets_version);
Expand Down
5 changes: 5 additions & 0 deletions src/project/project_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ class ProjectHandler
// either return that Node* or nullptr if no ImagesList class is found.
Node* getImagesForm();

// This will assume any Data class will be the first or second child of the project, and
// will either return that Node* or nullptr if no Data class is found.
Node* getDataForm();

// Sets project property value only if the property exists, returns false if it doesn't
// exist.
template <typename T>
Expand All @@ -201,6 +205,7 @@ class ProjectHandler
Node* m_form_BundleBitmaps { nullptr };
Node* m_form_Animation { nullptr };
Node* m_ImagesForm { nullptr };
Node* m_DataForm { nullptr };

tt_string m_projectFile;
tt_string m_projectPath;
Expand Down