Skip to content

Commit

Permalink
Fix up a few cmake and link things
Browse files Browse the repository at this point in the history
1. Make fmt work from the vendored fmt
2. Add the cmake flags so we can use std::filesystem back to 10.13
   in the fs::space and modify the create_directories to use a path
   at least
3. Vendor in CLI11
  • Loading branch information
baconpaul committed Oct 10, 2024
1 parent c294261 commit 5e107cd
Show file tree
Hide file tree
Showing 5 changed files with 11,043 additions and 24 deletions.
23 changes: 6 additions & 17 deletions cli/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
add_executable(clap-wrapper-cli
project(clap-wrapper-cli)
add_executable(${PROJECT_NAME}
src/main.cpp
)

CPMAddPackage(NAME CL11
GITHUB_REPOSITORY CLIUtils/CLI11
GIT_TAG v2.4.2)

# TODO: deduplicate this with the vendored fmt -
# for some reason, the cli won't link
# if we include the vendored version
CPMAddPackage(
NAME fmt
GITHUB_REPOSITORY fmtlib/fmt
GIT_TAG 11.0.2
OPTIONS
"FMT_INSTALL ON"
)

target_link_libraries(clap-wrapper-cli PUBLIC CLI11::CLI11 fmt::fmt)
target_include_directories(${PROJECT_NAME} PRIVATE ../libs/fmt )
target_include_directories(${PROJECT_NAME} PRIVATE ../libs/CLI11 )
target_link_libraries(${PROJECT_NAME} PRIVATE clap-wrapper-compile-options-public)
target_link_libraries(${PROJECT_NAME} PRIVATE clap-wrapper-shared-detail)
19 changes: 12 additions & 7 deletions cli/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
#include <fstream>
#include <stdexcept>
#include <CLI/CLI.hpp>

#define FMT_HEADER_ONLY
#include <fmt/format.h>

#include "detail/clap/fsutil.h"


// rationale against using std::filesystem is that
// it requires macOS 10.15, but our min supported version is 10.13 atm
#ifdef _WIN32
Expand Down Expand Up @@ -48,15 +53,15 @@ std::string get_absolute_path(const std::string& path)
* Creates a directory if it doesn't exist.
* @param path Path of the directory to create.
*/
void create_directory(const std::string& path)
void create_directory(const fs::path& path)
{
if (CREATE_DIRECTORY(path.c_str()) != 0)
try
{
if (!DIRECTORY_EXISTS)
{
throw std::runtime_error("Failed to create directory: " + path +
" Error: " + std::strerror(errno));
}
fs::create_directories(path);
}
catch (fs::filesystem_error &fs)
{
throw fs;
}
}

Expand Down
Loading

0 comments on commit 5e107cd

Please sign in to comment.