Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fallback to boost_filesystem if no filesystem lib is present #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
21 changes: 19 additions & 2 deletions cpp/ycm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,19 @@ if ( UNIX AND NOT ( APPLE OR SYSTEM_IS_OPENBSD OR HAIKU ) )
endif()

# Check if we need to add -lstdc++fs or -lc++fs or nothing
file( WRITE ${CMAKE_CURRENT_BINARY_DIR}/main.cpp "#include <filesystem>\nint main( int argc, char ** argv ) {\n std::filesystem::path p( argv[ 0 ] );\n return p.string().length();\n}" )
file( WRITE ${CMAKE_CURRENT_BINARY_DIR}/main.cpp "#if defined(USE_BOOST_FS)\n#include <boost/filesystem.hpp>\nnamespace fs = boost::filesystem;\n#else\n#include <filesystem>\nnamespace fs = std::filesystem;\n#endif\nint main( int argc, char ** argv ) {\n fs::path p( argv[ 0 ] );\n return p.parent_path().string().length();\n}" )
try_compile( STD_FS_NO_LIB_NEEDED ${CMAKE_CURRENT_BINARY_DIR}
SOURCES ${CMAKE_CURRENT_BINARY_DIR}/main.cpp
CXX_STANDARD 17
CXX_STANDARD_REQUIRED TRUE
CXX_EXTENSIONS ${NEEDS_EXTENSIONS} )
try_compile( STD_FS_NEEDS_BOOSTFS ${CMAKE_CURRENT_BINARY_DIR}
SOURCES ${CMAKE_CURRENT_BINARY_DIR}/main.cpp
CXX_STANDARD 17
CXX_STANDARD_REQUIRED TRUE
CXX_EXTENSIONS ${NEEDS_EXTENSIONS}
COMPILE_DEFINITIONS -DUSE_BOOST_FS
LINK_LIBRARIES boost_system boost_filesystem)
try_compile( STD_FS_NEEDS_STDCXXFS ${CMAKE_CURRENT_BINARY_DIR}
SOURCES ${CMAKE_CURRENT_BINARY_DIR}/main.cpp
CXX_STANDARD 17
Expand All @@ -299,12 +306,19 @@ file( REMOVE ${CMAKE_CURRENT_BINARY_DIR}/main.cpp )

if( ${STD_FS_NEEDS_STDCXXFS} )
set( STD_FS_LIB stdc++fs )
set( STD_FS_DEFINES "" )
elseif( ${STD_FS_NEEDS_CXXFS} )
set( STD_FS_LIB c++fs )
set( STD_FS_DEFINES "" )
elseif( ${STD_FS_NO_LIB_NEEDED} )
set( STD_FS_LIB "" )
set( STD_FS_DEFINES "" )
elseif( ${STD_FS_NEEDS_BOOSTFS} )
message( STATUS "Using boost_filesystem" )
set( STD_FS_LIB boost_system boost_filesystem )
set( STD_FS_DEFINES -DUSE_BOOST_FS )
else()
message( FATAL_ERROR "Unknown compiler - C++17 filesystem library missing" )
message( FATAL_ERROR "Unknown compiler - C++17 filesystem library and boost_filesystem both missing" )
endif()

# Check if Abseil supports this environment
Expand Down Expand Up @@ -347,6 +361,9 @@ if ( USE_CLANG_COMPLETER AND NOT LIBCLANG_TARGET )
"your configuration" )
endif()

target_compile_definitions( ${PROJECT_NAME}
PUBLIC ${STD_FS_DEFINES}
)
target_link_libraries( ${PROJECT_NAME}
PUBLIC ${Python3_LIBRARIES}
PUBLIC ${LIBCLANG_TARGET}
Expand Down
1 change: 0 additions & 1 deletion cpp/ycm/ClangCompleter/TranslationUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

#include <algorithm>
#include <cstdlib>
#include <filesystem>
#include <memory>

using std::unique_lock;
Expand Down
3 changes: 0 additions & 3 deletions cpp/ycm/IdentifierUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@
#include "Utils.h"

#include <array>
#include <filesystem>
#include <functional>
#include <string_view>
#include <utility>

namespace YouCompleteMe {

namespace fs = std::filesystem;

namespace {

// List of languages Universal Ctags supports:
Expand Down
4 changes: 2 additions & 2 deletions cpp/ycm/IdentifierUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

#include "IdentifierDatabase.h"

#include <filesystem>
#include "Utils.h"

namespace YouCompleteMe {

YCM_EXPORT FiletypeIdentifierMap ExtractIdentifiersFromTagsFile(
const std::filesystem::path &path_to_tag_file );
const fs::path &path_to_tag_file );

} // namespace YouCompleteMe

Expand Down
3 changes: 0 additions & 3 deletions cpp/ycm/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@
#include "Utils.h"

#include <cmath>
#include <filesystem>
#include <fstream>
#include <limits>
#include <string>
#include <vector>

namespace fs = std::filesystem;

namespace YouCompleteMe {

std::vector< std::string > ReadUtf8File( const fs::path &filepath ) {
Expand Down
7 changes: 6 additions & 1 deletion cpp/ycm/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@

#include <algorithm>
#include <cmath>
#include <filesystem>
#include <limits>
#include <string>
#include <string_view>
#include <type_traits>
#include <vector>

#if defined(USE_BOOST_FS)
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
#else
#include <filesystem>
namespace fs = std::filesystem;
#endif

namespace YouCompleteMe {

Expand Down
2 changes: 0 additions & 2 deletions cpp/ycm/tests/IdentifierUtils_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@

#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <filesystem>

namespace YouCompleteMe {

namespace fs = std::filesystem;
using ::testing::ElementsAre;
using ::testing::ContainerEq;
using ::testing::IsEmpty;
Expand Down
12 changes: 0 additions & 12 deletions cpp/ycm/tests/TestUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,6 @@

#include <whereami.c>

namespace std {

namespace filesystem {

void PrintTo( const fs::path &path, std::ostream *os ) {
*os << path;
}

} // namespace filesystem

} // namespace std

namespace YouCompleteMe {

std::ostream& operator<<( std::ostream& os, const CodePointTuple &code_point ) {
Expand Down
4 changes: 1 addition & 3 deletions cpp/ycm/tests/TestUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@

#include "Character.h"
#include "CodePoint.h"
#include "Utils.h"
#include "Word.h"

#include <filesystem>
#include <gmock/gmock.h>
#include <string>
#include <vector>

using ::testing::PrintToString;

namespace fs = std::filesystem;

namespace YouCompleteMe {

// Tuple-like structures to help writing tests for CodePoint, Character, and
Expand Down