From 097651da070f4b3cf871f56405a6759638ad173a Mon Sep 17 00:00:00 2001 From: Presburger Date: Mon, 29 Jun 2020 11:16:07 +0800 Subject: [PATCH] fix crash bug in windows and add new filesystem --- .gitmodules | 3 +++ 3rdparty/filesystem | 1 + CMakeLists.txt | 21 +++++++++++++-------- boost.sh | 36 ------------------------------------ decoder.command | 5 +++++ mingw-w64-x86_64.cmake | 23 ----------------------- src/decoder.cpp | 32 +++++++++++++++++++++++++------- src/seed.hpp | 10 ++++++++++ 8 files changed, 57 insertions(+), 74 deletions(-) create mode 160000 3rdparty/filesystem delete mode 100644 boost.sh create mode 100755 decoder.command delete mode 100644 mingw-w64-x86_64.cmake diff --git a/.gitmodules b/.gitmodules index e69de29..3b1b485 100644 --- a/.gitmodules +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "3rdparty/filesystem"] + path = 3rdparty/filesystem + url = https://github.com/gulrak/filesystem.git diff --git a/3rdparty/filesystem b/3rdparty/filesystem new file mode 160000 index 0000000..3605e86 --- /dev/null +++ b/3rdparty/filesystem @@ -0,0 +1 @@ +Subproject commit 3605e869150032ffdd9eae3db93e12f8711a0c82 diff --git a/CMakeLists.txt b/CMakeLists.txt index b42e083..7ea7e78 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,16 +1,21 @@ cmake_minimum_required(VERSION 2.9) project(qmc-decoder) -set(CMAKE_FIND_ROOT_PATH "${PROJECT_SOURCE_DIR}/usr") set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -pipe -std=c++11") -if(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Android" AND NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++") + +if (MSVC) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Od") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17") +else(MSVC) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -pipe -std=c++11") +endif() + +if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static -pthread -static-libgcc -static-libstdc++") endif() -find_package(Boost 1.56 REQUIRED COMPONENTS - filesystem) -include_directories(${Boost_INCLUDE_DIRS}) + +include_directories(3rdparty/filesystem/include) aux_source_directory(src SRC) add_executable(decoder ${SRC}) -target_link_libraries(decoder Boost::filesystem) diff --git a/boost.sh b/boost.sh deleted file mode 100644 index a69dd15..0000000 --- a/boost.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash - -cd $(dirname $0) - -basedir=$(pwd) - -mkdir usr - -wget https://dl.bintray.com/boostorg/release/1.72.0/source/boost_1_72_0.tar.gz - -tar -zxvf boost_1_72_0.tar.gz - -cd boost_1_72_0 - - -./bootstrap.sh --with-toolset=gcc --with-icu --with-libraries=filesystem \ ---prefix=$basedir/usr - -ismingw="$1" - -if [ "$ismingw" == "true" ];then - sed -i 's/using gcc ;/using gcc : : x86_64-w64-mingw32-g++ ;/g' project-config.jam -fi - -./b2 variant=release \ - debug-symbols=off \ - link=static \ - cflags="${CPPFLAGS} ${CFLAGS} -fPIC -O2" \ - cxxflags="${CPPFLAGS} ${CXXFLAGS} -std=c++11 -fPIC -O2" \ - --with-filesystem \ - install - -cd .. -rm -rf boost_1_72_0* - - diff --git a/decoder.command b/decoder.command new file mode 100755 index 0000000..46cd82f --- /dev/null +++ b/decoder.command @@ -0,0 +1,5 @@ +#!/bin/bash +cd $(dirname $0) +if [ -f decoder ]; then +./decoder +fi diff --git a/mingw-w64-x86_64.cmake b/mingw-w64-x86_64.cmake deleted file mode 100644 index 8b3bd24..0000000 --- a/mingw-w64-x86_64.cmake +++ /dev/null @@ -1,23 +0,0 @@ -# Sample toolchain file for building for Windows from an Ubuntu Linux system. -# -# Typical usage: -# *) install cross compiler: `sudo apt-get install mingw-w64` -# *) cd build -# *) cmake -DCMAKE_TOOLCHAIN_FILE=~/mingw-w64-x86_64.cmake .. - -set(CMAKE_SYSTEM_NAME Windows) -set(TOOLCHAIN_PREFIX x86_64-w64-mingw32) - -# cross compilers to use for C, C++ and Fortran -set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc) -set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++) -set(CMAKE_Fortran_COMPILER ${TOOLCHAIN_PREFIX}-gfortran) -set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres) - -# target environment on the build host system -set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX}) - -# modify default behavior of FIND_XXX() commands -set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) -set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) \ No newline at end of file diff --git a/src/decoder.cpp b/src/decoder.cpp index 63259ad..5ef4d96 100644 --- a/src/decoder.cpp +++ b/src/decoder.cpp @@ -1,5 +1,13 @@ +/* + * Author: mayusheng - mayusheng@huawei.com + * Last modified: 2020-06-29 10:56 + * Filename: decoder.cpp + * + * Description: qmc file auto decode + * + * + */ #include -#include #include #include #include @@ -7,7 +15,17 @@ #include "seed.hpp" -namespace fs = boost::filesystem; +#if defined(__cplusplus) && __cplusplus >= 201703L && defined(__has_include) +#if __has_include() +#define GHC_USE_STD_FS +#include +namespace fs = std::filesystem; +#endif +#endif +#ifndef GHC_USE_STD_FS +#include +namespace fs = ghc::filesystem; +#endif namespace { void close_file(std::FILE* fp) { std::fclose(fp); } @@ -31,9 +49,9 @@ smartFilePtr openFile(const std::string& aPath, openMode aOpenMode) { int newSize = MultiByteToWideChar(CP_UTF8, 0, aPath.c_str(), aPath.length(), const_cast(aPath_w.c_str()), aPath_w.size()); - filePathW.resize(newSize); - std::FILE* fp = - _wfopen(aPath_w.c_str(), aOpenMode == openMode::read ? L"rb" : L"wb"); + aPath_w.resize(newSize); + std::FILE* fp = NULL; + _wfopen_s(&fp, aPath_w.c_str(), aOpenMode == openMode::read ? L"rb" : L"wb"); #endif return smartFilePtr(fp, &close_file); } @@ -114,7 +132,7 @@ int main(int argc, char** argv) { } if ((fs::status(fs::path(".")).permissions() & fs::perms::owner_write) == - fs::perms::no_perms) { + fs::perms::none) { std::cerr << "please check if you have the write permissions on this dir." << std::endl; return -1; @@ -125,7 +143,7 @@ int main(int argc, char** argv) { auto file_path = p.path().string(); if ((fs::status(p).permissions() & fs::perms::owner_read) != - fs::perms::no_perms && + fs::perms::none && fs::is_regular_file(p) && regex_match(file_path, qmc_regex)) { qmc_paths.emplace_back(std::move(file_path)); } diff --git a/src/seed.hpp b/src/seed.hpp index f7ab255..6a4eab8 100644 --- a/src/seed.hpp +++ b/src/seed.hpp @@ -1,7 +1,17 @@ +/* + * Author: mayusheng - mayusheng@huawei.com + * Last modified: 2020-06-29 10:57 + * Filename: seed.hpp + * + * Description: + * + * + */ #ifndef SEED_H #define SEED_H #include +#include namespace qmc_decoder { class seed {