Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
64 lines (56 loc) · 1.92 KB
/
Copy pathmain.cpp
File metadata and controls
64 lines (56 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "sob.hpp"
#ifdef _MSVC_LANG
#define SOPHO_CPP_VER _MSVC_LANG
#else
#define SOPHO_CPP_VER __cplusplus
#endif
// Helper function to convert version number to string
constexpr const char* get_cpp_standard_name()
{
if (SOPHO_CPP_VER > 202002L)
return "C++23 (or newer)";
if (SOPHO_CPP_VER == 202002L)
return "C++20";
if (SOPHO_CPP_VER == 201703L)
return "C++17";
if (SOPHO_CPP_VER == 201402L)
return "C++14";
if (SOPHO_CPP_VER == 201103L)
return "C++11";
if (SOPHO_CPP_VER == 199711L)
return "C++98";
return "Unknown/Pre-standard";
}
struct GxxContext
{
static constexpr std::string_view cxx{"g++"};
static constexpr sopho::StaticString obj_prefix{" -o "};
static constexpr sopho::StaticString obj_postfix{".o"};
static constexpr sopho::StaticString bin_prefix{" -o "};
static constexpr sopho::StaticString build_prefix{"build/"};
};
struct ClContext
{
static constexpr std::string_view cxx{"cl"};
static constexpr sopho::StaticString obj_prefix{" /Fo:"};
static constexpr sopho::StaticString obj_postfix{".obj"};
static constexpr sopho::StaticString bin_prefix{" /Fe:"};
static constexpr sopho::StaticString build_prefix{"build/"};
static constexpr std::array<std::string_view, 1> cxxflags{"/std:c++17"};
};
using MainSource = sopho::Source<sopho::StaticString{"main.cpp"}>;
using Main = sopho::Target<std::tuple<MainSource>, sopho::StaticString{"main"}>;
#if defined(_MSC_VER)
using CxxContext = ClContext;
#elif defined(__GNUC__)
using CxxContext = GxxContext;
#else
#endif
int main()
{
sopho::single_header_generator("include/sob.hpp");
std::cout << get_cpp_standard_name() << std::endl;
auto commands = sopho::CxxToolchain<CxxContext>::CxxBuilder<Main>::build();
sopho::write_compile_commands_json("compile_commands.json", commands);
return 0;
}