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

Remove <filesystem> fallback #64

Open
wants to merge 13 commits into
base: dev
Choose a base branch
from
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
strategy:
fail-fast: false
matrix:
cc: [gcc, clang]
cc: [gcc-9, clang]
runs-on: ubuntu-latest
env:
CC: ${{matrix.cc}}
Expand All @@ -28,9 +28,10 @@ jobs:
run: |
if [ $CC = clang ]; then
sudo apt-get install -y --no-install-recommends clang-9
export CXX=clang++
echo ::set-env name=CXX::clang++
else
sudo apt-get install -y --no-install-recommends $CC
echo ::set-env name=CXX::g++-9
fi
- name: Generate build files
run: |
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@
[submodule "libwololokingdoms/third_party/pcrio"]
path = libwololokingdoms/third_party/pcrio
url = https://github.com/sandsmark/pcrio
[submodule "libwololokingdoms/third_party/filesystem"]
path = libwololokingdoms/third_party/filesystem
url = https://github.com/gulrak/filesystem
11 changes: 1 addition & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.9.4)

set(Wololokingdoms_INSTALLER WololoKingdoms)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)

project(WololoKingdoms)

Expand Down Expand Up @@ -71,15 +71,6 @@ if (WIN32)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libwololokingdoms/third_party/genieutils/extern/win-iconv)
endif()

# check c++17 filesystem support
# (mingw's windows header has a bug and msvc doesn't have it)
include(HasWorkingFilesystem)
if (NOT WORKING_STD_FS)
message(WARNING "builtin filesystem is bad, falling back to gulrak/filesystem")
include_directories(libwololokingdoms/third_party/filesystem/include/)
add_definitions(-DUSE_USERLAND_FS)
endif()

if (WIN32)
add_definitions(-DNOMINMAX)
add_definitions(-DWIN32_LEAN_AND_MEAN)
Expand Down
146 changes: 70 additions & 76 deletions libwololokingdoms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,106 +18,98 @@ if (CMAKE_BUILD_TYPE EQUAL RELEASE)
check_ipo_supported(RESULT ENABLE_LTO OUTPUT error)
endif()

# dependencies:

if (WK_STATIC_BUILD)
set(GENIEUTILS_STATIC_BUILD 1)
# Set `GUTILS_STATIC` option for genieutils.
set(GUTILS_STATIC ON CACHE BOOL "")
endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_party/genieutils/)
# Create library
if (WK_STATIC_BUILD)
message(STATUS "Building libwololokingdoms as static library")
add_library(${Wololokingdoms_LIBRARY} STATIC)
else()
add_library(${Wololokingdoms_LIBRARY} SHARED)
endif()

# include directories:
target_include_directories(${Wololokingdoms_LIBRARY}
PRIVATE include/
)

# Dependencies

include_directories(include/)
include_directories(third_party/genieutils/include/)
include_directories(third_party/miniz)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_party/genieutils/)

target_include_directories(${Wololokingdoms_LIBRARY}
PRIVATE third_party/genieutils/include/
third_party/miniz
)
if (WIN32)
add_definitions(-DICONV_SECOND_ARGUMENT_IS_CONST)
include_directories(third_party/genieutils/extern/win-iconv)
target_include_directories(${Wololokingdoms_LIBRARY}
PRIVATE third_party/genieutils/extern/win-iconv
)
endif()

if (${ICONV_FOUND})
include(${ICONV_INCLUDE_DIR})
endif (${ICONV_FOUND})

if(NOT MSVC)
add_definitions(-Wall -Wsign-compare -Wextra -Wpedantic)
target_compile_options(${Wololokingdoms_LIBRARY} PRIVATE -Wall -Wsign-compare -Wextra -Wpedantic)
else()
add_definitions(/wd4244 /wd4018 /wd4267 /wd4996 /wd4800)
endif()

# check c++17 filesystem support
# (mingw's windows header has a bug and msvc doesn't have it)
include(HasWorkingFilesystem)
set(CMAKE_REQUIRED_FLAGS)
set(CMAKE_REQUIRED_LIBRARIES)
if (NOT WORKING_STD_FS)
message(WARNING "builtin filesystem is bad, falling back to gulrak/filesystem")
include_directories(third_party/filesystem/include/)
add_definitions(-DUSE_USERLAND_FS)
target_compile_options(${Wololokingdoms_LIBRARY} PRIVATE /wd4244 /wd4018 /wd4267 /wd4996 /wd4800)
endif()

if (WIN32)
add_definitions(-DUNICODE)
add_definitions(-D_UNICODE)
target_compile_definitions(${Wololokingdoms_LIBRARY}
PRIVATE UNICODE _UNICODE
)
endif()

#------------------------------------------------------------------------------#
# Source files:
#------------------------------------------------------------------------------#
set(ALL_SRC
libwololokingdoms.cpp
fs.cpp
base64.cpp
md5.cpp
wk_xml.cpp
string_helpers.cpp
zr_map_creator.cpp
drs_creator.cpp
missing_strings.cpp
fixes/addunits.cpp
fixes/ai900unitidfix.cpp
fixes/aztecbonusfix.cpp
fixes/balance.cpp
fixes/berbersutfix.cpp
fixes/burmesefix.cpp
fixes/cuttingfix.cpp
fixes/demoshipfix.cpp
fixes/disablenonworkingunits.cpp
fixes/ethiopiansfreepikeupgradefix.cpp
fixes/feitoriafix.cpp
fixes/houseattackfix.cpp
fixes/hotkeysfix.cpp
fixes/khmerfix.cpp
fixes/malayfix.cpp
fixes/maliansfreeminingupgradefix.cpp
fixes/nomadsfix.cpp
fixes/portuguesefix.cpp
fixes/queuetechs.cpp
fixes/separateshipgraphics.cpp
fixes/siegetowerfix.cpp
fixes/slavteambonusfix.cpp
fixes/smallfixes.cpp
fixes/splituniquetechicons.cpp
fixes/tricklebuildingfix.cpp
fixes/uprootingfix.cpp
fixes/vietfix.cpp
wkconverter.cpp
third_party/miniz/miniz.c
target_sources(${Wololokingdoms_LIBRARY} PRIVATE
libwololokingdoms.cpp
base64.cpp
md5.cpp
wk_xml.cpp
string_helpers.cpp
zr_map_creator.cpp
drs_creator.cpp
missing_strings.cpp
fixes/addunits.cpp
fixes/ai900unitidfix.cpp
fixes/aztecbonusfix.cpp
fixes/balance.cpp
fixes/berbersutfix.cpp
fixes/burmesefix.cpp
fixes/cuttingfix.cpp
fixes/demoshipfix.cpp
fixes/disablenonworkingunits.cpp
fixes/ethiopiansfreepikeupgradefix.cpp
fixes/feitoriafix.cpp
fixes/houseattackfix.cpp
fixes/hotkeysfix.cpp
fixes/khmerfix.cpp
fixes/malayfix.cpp
fixes/maliansfreeminingupgradefix.cpp
fixes/nomadsfix.cpp
fixes/portuguesefix.cpp
fixes/queuetechs.cpp
fixes/separateshipgraphics.cpp
fixes/siegetowerfix.cpp
fixes/slavteambonusfix.cpp
fixes/smallfixes.cpp
fixes/splituniquetechicons.cpp
fixes/tricklebuildingfix.cpp
fixes/uprootingfix.cpp
fixes/vietfix.cpp
wkconverter.cpp
third_party/miniz/miniz.c
)

#------------------------------------------------------------------------------#
# Executeable:
#------------------------------------------------------------------------------#

if (WK_STATIC_BUILD)
message(STATUS "Building libwololokingdoms as static library")
add_library(${Wololokingdoms_LIBRARY} STATIC ${ALL_SRC})
else()
add_library(${Wololokingdoms_LIBRARY} SHARED ${ALL_SRC})
target_link_libraries(${Wololokingdoms_LIBRARY} genieutils)
endif()
target_link_libraries(${Wololokingdoms_LIBRARY} genieutils)

install(TARGETS ${Wololokingdoms_LIBRARY}
LIBRARY DESTINATION lib
Expand All @@ -131,5 +123,7 @@ install(

if(ENABLE_LTO)
message(STATUS "Building libwololokingdoms with link time optimization")
set_property(TARGET ${Wololokingdoms_LIBRARY} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
set_target_properties(${Wololokingdoms_LIBRARY}
PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE
)
endif()
29 changes: 17 additions & 12 deletions libwololokingdoms/caseless.h
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
#pragma once
#include <fs.h>
#include <filesystem>

#ifdef _WIN32

/**
* Windows is already case insensitive.
*/
namespace cfs = fs;
namespace cfs = std::filesystem;

#else
#include "./string_helpers.h"
#include <map>

// Remember the casing of previously used paths.
static std::map<fs::path, fs::path> caseless_directories = {};
static std::map<fs::path, std::map<fs::path, fs::path>> caseless_files = {};
static std::map<std::filesystem::path, std::filesystem::path>
caseless_directories = {};
static std::map<std::filesystem::path,
std::map<std::filesystem::path, std::filesystem::path>>
caseless_files = {};

/**
* Case-insensitively find a file path.
*/
static const fs::path& caseless(fs::path const& input) {
static const std::filesystem::path&
caseless(std::filesystem::path const& input) {
std::string inputs = input.string();
fs::path linput = tolower(inputs);
std::filesystem::path linput = string_to_lower(inputs);
if (caseless_directories.find(linput) != caseless_directories.end()) {
return caseless_directories[linput];
}
Expand All @@ -39,32 +43,33 @@ static const fs::path& caseless(fs::path const& input) {
auto filename = linput.filename();
if (caseless_files.find(parent) == caseless_files.end()) {
// Invalid path, trying to use a nonexistent directory
if (!fs::is_directory(parent)) {
if (!std::filesystem::is_directory(parent)) {
return input;
}

caseless_directories[parent_path] = parent;
auto& cached_dir = caseless_files[parent];
for (auto& entry : fs::directory_iterator(parent)) {
for (auto& entry : std::filesystem::directory_iterator(parent)) {
auto basename = entry.path().filename();
cached_dir[tolower(basename.string())] = parent / basename;
cached_dir[string_to_lower(basename.string())] = parent / basename;
}
}

auto& directory = caseless_files[parent];
if (directory.find(filename) == directory.end()) {
// Creates a new file, use the casing used in the fs call
// Creates a new file, use the casing used in the std::filesystem call
directory[filename] = parent / input.filename();
}

return directory[filename];
}

/**
* Case-insensitive wrappers around fs methods, for use on case sensitive file
* systems.
* Case-insensitive wrappers around std::filesystem methods, for use on case
* sensitive file systems.
*/
namespace cfs {
namespace fs = std::filesystem;
using path = fs::path;
using copy_options = fs::copy_options;
static path resolve [[maybe_unused]] (const path& p) { return caseless(p); }
Expand Down
16 changes: 0 additions & 16 deletions libwololokingdoms/cmake/HasWorkingFilesystem.cmake

This file was deleted.

16 changes: 9 additions & 7 deletions libwololokingdoms/drs_creator.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include <fs.h>
#include <filesystem>
#include <iostream>
#include <map>
#include <vector>
Expand All @@ -20,12 +20,13 @@ class DRSCreatorTableEntry {
uint32_t size_ = 0;
// Owned by this object
std::istream* stream_ = nullptr;
fs::path filename_;
std::filesystem::path filename_;

public:
inline DRSCreatorTableEntry(uint32_t id, std::istream* data)
: id_(id), stream_(data) {}
inline DRSCreatorTableEntry(uint32_t id, const fs::path& filename)
inline DRSCreatorTableEntry(uint32_t id,
const std::filesystem::path& filename)
: id_(id), filename_(filename) {}
inline DRSCreatorTableEntry(DRSCreatorTableEntry&& entry)
: id_(entry.id_), stream_(entry.stream_),
Expand Down Expand Up @@ -53,7 +54,7 @@ class DRSCreatorTable {

public:
inline void addFile(uint32_t id, std::istream* data);
inline void addFile(uint32_t id, const fs::path& filename);
inline void addFile(uint32_t id, const std::filesystem::path& filename);

private:
inline void setOffset(uint32_t offset);
Expand All @@ -73,15 +74,16 @@ class DRSCreator {

inline void addFile(DRSTableType table, uint32_t id, std::istream* data);
inline void addFile(DRSTableType table, uint32_t id,
const fs::path& filename);
const std::filesystem::path& filename);
void commit();
};

inline void DRSCreatorTable::addFile(uint32_t id, std::istream* data) {
files_.push_back(DRSCreatorTableEntry(id, data));
}

inline void DRSCreatorTable::addFile(uint32_t id, const fs::path& filename) {
inline void DRSCreatorTable::addFile(uint32_t id,
const std::filesystem::path& filename) {
files_.push_back(DRSCreatorTableEntry(id, filename));
}

Expand All @@ -91,6 +93,6 @@ inline void DRSCreator::addFile(DRSTableType table, uint32_t id,
}

inline void DRSCreator::addFile(DRSTableType table, uint32_t id,
const fs::path& filename) {
const std::filesystem::path& filename) {
tables_[table].addFile(id, filename);
}
6 changes: 0 additions & 6 deletions libwololokingdoms/fs.cpp

This file was deleted.

Loading