Skip to content

Commit 43772ea

Browse files
committed
feat(cli): add vix.app generated CMake project support
1 parent 88b6ff3 commit 43772ea

8 files changed

Lines changed: 1653 additions & 21 deletions

File tree

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/**
2+
*
3+
* @file AppCMakeGenerator.hpp
4+
* @author Gaspard Kirira
5+
*
6+
* Copyright 2026, Gaspard Kirira. All rights reserved.
7+
* https://github.com/vixcpp/vix
8+
* Use of this source code is governed by a MIT license
9+
* that can be found in the License file.
10+
*
11+
* Vix.cpp
12+
*
13+
* CMake generator for simple vix.app projects.
14+
*
15+
*/
16+
17+
#ifndef VIX_CLI_APP_APP_CMAKE_GENERATOR_HPP
18+
#define VIX_CLI_APP_APP_CMAKE_GENERATOR_HPP
19+
20+
#include <filesystem>
21+
#include <string>
22+
23+
#include <vix/cli/app/AppManifest.hpp>
24+
25+
namespace vix::cli::app
26+
{
27+
namespace fs = std::filesystem;
28+
29+
/**
30+
* @brief Result returned after generating an internal CMake project.
31+
*/
32+
struct AppCMakeGenerateResult
33+
{
34+
/**
35+
* @brief Directory containing the generated CMakeLists.txt.
36+
*/
37+
fs::path sourceDir;
38+
39+
/**
40+
* @brief Path to the generated CMakeLists.txt file.
41+
*/
42+
fs::path cmakeListsPath;
43+
44+
/**
45+
* @brief Error message when generation failed.
46+
*/
47+
std::string error;
48+
49+
/**
50+
* @brief Returns true when the generation succeeded.
51+
*
52+
* @return true if the generated CMake project is ready.
53+
*/
54+
bool success() const;
55+
};
56+
57+
/**
58+
* @brief Builds the generated CMakeLists.txt content for a vix.app manifest.
59+
*
60+
* @param manifest Parsed vix.app manifest.
61+
* @param projectDir Original user project directory.
62+
* @return Generated CMakeLists.txt content.
63+
*/
64+
std::string generate_app_cmake_lists_content(
65+
const AppManifest &manifest,
66+
const fs::path &projectDir);
67+
68+
/**
69+
* @brief Generates an internal CMake project for a simple vix.app project.
70+
*
71+
* The generated project is written under:
72+
*
73+
* .vix/generated/app/CMakeLists.txt
74+
*
75+
* @param manifest Parsed vix.app manifest.
76+
* @param projectDir Original user project directory.
77+
* @return Generation result.
78+
*/
79+
AppCMakeGenerateResult generate_app_cmake_project(
80+
const AppManifest &manifest,
81+
const fs::path &projectDir);
82+
83+
} // namespace vix::cli::app
84+
85+
#endif // VIX_CLI_APP_APP_CMAKE_GENERATOR_HPP
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/**
2+
*
3+
* @file AppManifest.hpp
4+
* @author Gaspard Kirira
5+
*
6+
* Copyright 2026, Gaspard Kirira. All rights reserved.
7+
* https://github.com/vixcpp/vix
8+
* Use of this source code is governed by a MIT license
9+
* that can be found in the License file.
10+
*
11+
* Vix.cpp
12+
*
13+
* Simple application manifest model for generated CMake builds.
14+
*
15+
*/
16+
17+
#ifndef VIX_CLI_APP_APP_MANIFEST_HPP
18+
#define VIX_CLI_APP_APP_MANIFEST_HPP
19+
20+
#include <filesystem>
21+
#include <optional>
22+
#include <string>
23+
#include <vector>
24+
25+
namespace vix::cli::app
26+
{
27+
namespace fs = std::filesystem;
28+
29+
/**
30+
* @brief Describes the type of C++ target declared by vix.app.
31+
*/
32+
enum class AppTargetType
33+
{
34+
Executable,
35+
StaticLibrary,
36+
SharedLibrary
37+
};
38+
39+
/**
40+
* @brief Converts a target type to a stable text value.
41+
*
42+
* @param type Target type.
43+
* @return Stable target type string.
44+
*/
45+
std::string to_string(AppTargetType type);
46+
47+
/**
48+
* @brief Parses a target type from a text value.
49+
*
50+
* Supported values:
51+
* - executable
52+
* - static
53+
* - static-library
54+
* - shared
55+
* - shared-library
56+
* - library
57+
*
58+
* @param value Raw manifest value.
59+
* @return Parsed target type when valid.
60+
*/
61+
std::optional<AppTargetType> app_target_type_from_string(
62+
const std::string &value);
63+
64+
/**
65+
* @brief Simple C++ application manifest.
66+
*
67+
* This structure represents the content of a vix.app file.
68+
* It is intentionally small and exists only as a user-friendly
69+
* layer above the internal generated CMake project.
70+
*/
71+
struct AppManifest
72+
{
73+
/**
74+
* @brief Application or target name.
75+
*/
76+
std::string name;
77+
78+
/**
79+
* @brief Target type.
80+
*/
81+
AppTargetType type{AppTargetType::Executable};
82+
83+
/**
84+
* @brief C++ standard value.
85+
*
86+
* Example values:
87+
* - c++17
88+
* - c++20
89+
* - c++23
90+
*/
91+
std::string standard{"c++20"};
92+
93+
/**
94+
* @brief Source files relative to the project directory.
95+
*/
96+
std::vector<std::string> sources;
97+
98+
/**
99+
* @brief Include directories relative to the project directory.
100+
*/
101+
std::vector<std::string> includeDirs;
102+
103+
/**
104+
* @brief Preprocessor definitions.
105+
*/
106+
std::vector<std::string> defines;
107+
108+
/**
109+
* @brief CMake targets or libraries to link.
110+
*/
111+
std::vector<std::string> links;
112+
113+
/**
114+
* @brief Returns true when the manifest has the minimum valid fields.
115+
*
116+
* @return true if the manifest can be used.
117+
*/
118+
bool valid() const;
119+
};
120+
121+
/**
122+
* @brief Result returned when loading a vix.app file.
123+
*/
124+
struct AppManifestLoadResult
125+
{
126+
/**
127+
* @brief Parsed manifest.
128+
*/
129+
AppManifest manifest;
130+
131+
/**
132+
* @brief Error message when loading failed.
133+
*/
134+
std::string error;
135+
136+
/**
137+
* @brief Returns true when the load operation succeeded.
138+
*
139+
* @return true if the manifest was loaded successfully.
140+
*/
141+
bool success() const;
142+
};
143+
144+
/**
145+
* @brief Loads a vix.app file from disk.
146+
*
147+
* @param path Path to the vix.app file.
148+
* @return Load result containing either a manifest or an error.
149+
*/
150+
AppManifestLoadResult load_app_manifest(const fs::path &path);
151+
152+
} // namespace vix::cli::app
153+
154+
#endif // VIX_CLI_APP_APP_MANIFEST_HPP
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/**
2+
*
3+
* @file AppProjectResolver.hpp
4+
* @author Gaspard Kirira
5+
*
6+
* Copyright 2026, Gaspard Kirira. All rights reserved.
7+
* https://github.com/vixcpp/vix
8+
* Use of this source code is governed by a MIT license
9+
* that can be found in the License file.
10+
*
11+
* Vix.cpp
12+
*
13+
* Project resolver for CMake and vix.app based applications.
14+
*
15+
*/
16+
17+
#ifndef VIX_CLI_APP_APP_PROJECT_RESOLVER_HPP
18+
#define VIX_CLI_APP_APP_PROJECT_RESOLVER_HPP
19+
20+
#include <filesystem>
21+
#include <string>
22+
23+
namespace vix::cli::app
24+
{
25+
namespace fs = std::filesystem;
26+
27+
/**
28+
* @brief Describes which project input was selected.
29+
*/
30+
enum class AppProjectKind
31+
{
32+
Unknown,
33+
CMake,
34+
VixApp
35+
};
36+
37+
/**
38+
* @brief Converts a project kind to a stable string.
39+
*
40+
* @param kind Project kind.
41+
* @return Stable string value.
42+
*/
43+
std::string to_string(AppProjectKind kind);
44+
45+
/**
46+
* @brief Resolved project information used by build and run commands.
47+
*/
48+
struct AppProjectResolveResult
49+
{
50+
/**
51+
* @brief Selected project kind.
52+
*/
53+
AppProjectKind kind{AppProjectKind::Unknown};
54+
55+
/**
56+
* @brief Original user project directory.
57+
*
58+
* This is where the user runs Vix from, and where build directories
59+
* should still be created.
60+
*/
61+
fs::path userProjectDir;
62+
63+
/**
64+
* @brief CMake source directory passed to cmake -S.
65+
*
66+
* For normal CMake projects, this is the same as userProjectDir.
67+
* For vix.app projects, this is the generated internal CMake directory.
68+
*/
69+
fs::path cmakeSourceDir;
70+
71+
/**
72+
* @brief Path to the active CMakeLists.txt file.
73+
*/
74+
fs::path cmakeListsPath;
75+
76+
/**
77+
* @brief Path to vix.app when the project uses vix.app.
78+
*/
79+
fs::path appManifestPath;
80+
81+
/**
82+
* @brief Target name resolved from the project.
83+
*/
84+
std::string targetName;
85+
86+
/**
87+
* @brief True when CMakeLists.txt was generated from vix.app.
88+
*/
89+
bool generated{false};
90+
91+
/**
92+
* @brief Error message when resolution failed.
93+
*/
94+
std::string error;
95+
96+
/**
97+
* @brief Returns true when project resolution succeeded.
98+
*
99+
* @return true if the result is usable.
100+
*/
101+
bool success() const;
102+
};
103+
104+
/**
105+
* @brief Resolves a C++ project for Vix build or run.
106+
*
107+
* Resolution order:
108+
* 1. CMakeLists.txt
109+
* 2. vix.app
110+
*
111+
* If CMakeLists.txt exists, the current build behavior is preserved.
112+
* vix.app is used only when no CMakeLists.txt is present.
113+
*
114+
* @param base Directory to start from.
115+
* @return Resolved project result.
116+
*/
117+
AppProjectResolveResult resolve_app_project(const fs::path &base);
118+
119+
} // namespace vix::cli::app
120+
121+
#endif // VIX_CLI_APP_APP_PROJECT_RESOLVER_HPP

0 commit comments

Comments
 (0)