diff --git a/.clangd b/.clangd index f476fa1..f64a904 100644 --- a/.clangd +++ b/.clangd @@ -1,9 +1,2 @@ CompileFlags: - CompilationDatabase: "build/Debug" - -Index: - Background: Skip # Disables background indexing if it crashes during idle time - -Diagnostics: - ClangTidy: - Remove: ["*"] # Disables Clang-Tidy checks if a specific rule causes the crash \ No newline at end of file + CompilationDatabase: "build/Debug" \ No newline at end of file diff --git a/Makefile b/Makefile index 5419c62..3a45959 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,13 @@ +SHELL := /bin/zsh + .PHONY: build .PHONY: test config: - @cmake -S . -B build/Debug -G Ninja -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_STANDARD=23 -DCMAKE_CXX_STANDARD_REQUIRED=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-Wall -Wextra -Wconversion -Wshadow -fno-exceptions" -DCMAKE_TOOLCHAIN_FILE=deps/build/Debug/generators/conan_toolchain.cmake -DBUILD_TESTING=ON + @cmake -S . -B build/Debug -G Ninja -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_STANDARD=23 -DCMAKE_CXX_STANDARD_REQUIRED=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-Wall -Wextra -Wconversion -Wshadow -fno-exceptions $(CPPFLAGS)" -DCMAKE_EXE_LINKER_FLAGS="$(LDFLAGS)" -DCMAKE_TOOLCHAIN_FILE=deps/build/Debug/generators/conan_toolchain.cmake -DBUILD_TESTING=ON config-rel: - @cmake -S . -B build/Release -G Ninja -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_STANDARD=23 -DCMAKE_CXX_STANDARD_REQUIRED=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-Wall -Wextra -Wconversion -Wshadow -fno-exceptions" -DCMAKE_TOOLCHAIN_FILE=deps/build/Release/generators/conan_toolchain.cmake -DBUILD_TESTING=ON + @cmake -S . -B build/Release -G Ninja -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_STANDARD=23 -DCMAKE_CXX_STANDARD_REQUIRED=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-Wall -Wextra -Wconversion -Wshadow -fno-exceptions $(CPPFLAGS)" -DCMAKE_EXE_LINKER_FLAGS="$(LDFLAGS)" -DCMAKE_TOOLCHAIN_FILE=deps/build/Release/generators/conan_toolchain.cmake -DBUILD_TESTING=ON build: @cmake --build build/Debug --parallel diff --git a/src/conan.cpp b/src/conan.cpp index 64ba514..0644292 100644 --- a/src/conan.cpp +++ b/src/conan.cpp @@ -231,6 +231,9 @@ std::optional install(const config::GojoConfig& cfg, } } + std::println(MAGENTA("Installing conan dependencies...\n")); + std::fflush(stdout); + constexpr std::string_view cmd_str { "conan install . " "--deployer=full_deploy " @@ -240,6 +243,23 @@ std::optional install(const config::GojoConfig& cfg, "-s build_type={}" }; + std::string build_type {}; + std::stringstream ss { cfg.dep_build_types }; + while (std::getline(ss, build_type, ',')) { + const std::string cmd { + std::format(cmd_str, cfg.project_name, build_type) + }; + + std::filesystem::current_path(cfg.project_root); + auto result { utils::execute_command(cmd, !verbose) }; + if (!result.success) { + return std::make_optional( + std::format("{}\nfailed to install conan dependencies", + result.output) + ); + } + } +/* // In order to download the packages in debug and release mode, we have // to install two times, one for each build type. // Kinda sucks... @@ -269,7 +289,7 @@ std::optional install(const config::GojoConfig& cfg, rel_result.output) ); } - +*/ std::fflush(stdout); std::println( GREEN("\nDependencies installed successfully\n") diff --git a/src/config.cpp b/src/config.cpp index d601210..9b3270e 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -107,6 +107,7 @@ constexpr std::string_view GENERATOR { "generator" }; constexpr std::string_view MULTI_CONFIG { "multi-config generator" }; constexpr std::string_view BUILD_TYPE { "build type" }; constexpr std::string_view PKG_MAN { "package manager" }; +constexpr std::string_view PKG_BUILD_TYPE { "dependency build types" }; constexpr std::string_view SRC_EXT { "source file extension" }; constexpr std::string_view HDR_EXT { "header file extension" }; constexpr std::string_view FMT_STYLE { "clang-format style" }; @@ -170,6 +171,10 @@ R"(--- # Options: none, conan, vcpkg {}={} +# Options: Debug, Release, RelWithDebInfo, MinSizeRel +# Note: any of the above options can be combined in a comma separated list +{}={} + # Options (C): c # Options (C++): cpp, cc, cxx, c++ {}={} @@ -391,6 +396,25 @@ read_from_file(const std::filesystem::path& cfg_file) { std::getline(ss, cfg.pkg_manager); result = validate_config_values(label, cfg.pkg_manager, PKG_MANAGERS); } + else if (label == PKG_BUILD_TYPE) { + if (cfg.pkg_manager == "none") { + cfg.dep_build_types = ""; + continue; + } + + std::getline(ss, cfg.dep_build_types); + if (cfg.dep_build_types.empty()) { + cfg.dep_build_types = "Debug,Release"; + result.success = true; + } + else { + std::stringstream ss2 { cfg.dep_build_types }; + std::string build_type {}; + while (std::getline(ss2, build_type, ',')) { + result = validate_config_values(PKG_BUILD_TYPE, build_type, BUILD_TYPES); + } + } + } else if (label == SRC_EXT) { std::getline(ss, cfg.src_ext); if (cfg.project_lang == "C++") { @@ -514,6 +538,7 @@ std::optional write_to_file(const GojoConfig& cfg, MULTI_CONFIG, cfg.multi_config ? "true" : "false", BUILD_TYPE, cfg.build_type, PKG_MAN, cfg.pkg_manager, + PKG_BUILD_TYPE, cfg.dep_build_types, SRC_EXT, cfg.src_ext, HDR_EXT, cfg.hdr_ext, FMT_STYLE, cfg.fmt_style, @@ -566,6 +591,7 @@ create_template(const std::filesystem::path& project_root) { MULTI_CONFIG, "", BUILD_TYPE, "", PKG_MAN, "", + PKG_BUILD_TYPE, "", SRC_EXT, "", HDR_EXT, "", FMT_STYLE, "", diff --git a/src/config.hpp b/src/config.hpp index 1ef5f15..43af21a 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -30,6 +30,7 @@ struct GojoConfig { std::string generator; std::string build_type; std::string pkg_manager; + std::string dep_build_types; std::string src_ext; std::string hdr_ext; std::string fmt_style; @@ -60,6 +61,7 @@ const GojoConfig DEFAULT = { .generator = "system default", .build_type = "Debug", .pkg_manager = "none", + .dep_build_types = "", .src_ext = "cpp", .hdr_ext = "hpp", .fmt_style = "google", diff --git a/src/gojo.cpp b/src/gojo.cpp index b122829..16e6c40 100644 --- a/src/gojo.cpp +++ b/src/gojo.cpp @@ -12,6 +12,7 @@ #include "src/utils.hpp" +// TODO: Create system to modify files in place constexpr std::string_view VERSION_STRING { "gojo version 1.0.0-beta" }; int main(const int argc, const char* argv[]) { @@ -64,7 +65,25 @@ int main(const int argc, const char* argv[]) { else if (command == "refresh") { result = commands::refresh(args, std::nullopt); } + else if (command == "dep") { + // TODO: Implement + // gojo dep search + // gojo dep install [version] + // gojo dep add [version] + // gojo dep remove + // gojo dep uninstall + } + else if (command == "set") { + // TODO: Implement + // gojo set + } + else if (command == "publish") { + // TODO: Implement + // gojo publish + } else if (command == "install") { + // TODO: refactor + // gojo install . [--replace|-r] result = commands::install(args); } else if (command == "profile") { diff --git a/src/literals.hpp b/src/literals.hpp index 52d07bb..f591dfe 100644 --- a/src/literals.hpp +++ b/src/literals.hpp @@ -463,6 +463,17 @@ open source toolchains. Below is an explanation of each field: package manager is used, this value is set to '{3}none{0}'. The command {1}gojo{0} {4}install{0} has no effect if no package manager is used. + - {2}dependency build types{0} + This field determines the build type(s) that your dependendencies should + build with. If this field is left empty, and a package manager is being + used, the default value is '{3}Debug,Release{0}'. The value for this field + must be a comma separated list of one or more build types, the selection + being the same as the {2}build type{0} field. This is used to make + switching between build types easier - the dependencies are built with the + defined build_type(s) at installation time rather than when the project + switches its build type. Each dependency should be built with the same + build type as your project. + - {2}source file extension{0} This field determines the file extension for C++ source code files. This field is not used for C projects. This field is only used during project