diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index 6683bd5..0a3ed17 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -10,6 +10,7 @@ jobs: matrix: os: [ubuntu-16.04, windows-latest] buildType: [Debug, Release] + standalone: [Boost, Standalone] shared_lib: [ON, OFF] generator: ['Visual Studio 16 2019', 'MinGW Makefiles', 'Unix Makefiles'] exclude: @@ -33,11 +34,12 @@ jobs: key: ${{matrix.os}}-${{matrix.generator}}-${{env.BOOST_VERSION}} # Install newer CMake to be able to find Boost - name: Install CMake - if: runner.os == 'Linux' && ! matrix.standalone + if: runner.os == 'Linux' && matrix.standalone == 'Boost' run: wget -qO- https://cmake.org/files/v3.14/cmake-3.14.0-Linux-x86_64.tar.gz | sudo tar --strip-components=1 -xzC /usr/local # Install Boost, no wget on Windows -.- - name: Download Boost shell: cmake -P {0} + if: matrix.standalone == 'Boost' id: downloadBoost run: | string(REPLACE "." "_" filename boost_$ENV{BOOST_VERSION}) @@ -54,7 +56,7 @@ jobs: endif() - name: Build Boost shell: bash - if: steps.downloadBoost.outputs.update == 1 + if: matrix.standalone == 'Boost' && steps.downloadBoost.outputs.update == 1 working-directory: ${{env.DEP_DIR}}/build run: | 7z x boost.7z > /dev/null @@ -67,6 +69,14 @@ jobs: cd "$DEP_DIR" # Workaround for "Device or resource busy" error if ! rm -r build; then sleep 30s; rm -r build || true; fi + - name: Create standalone + if: matrix.standalone == 'Standalone' + shell: bash + run: | + bash tools/create_standalone.sh "$PWD/../nowide_standalone" + rm -rf * + cp -r ../nowide_standalone/* . + mkdir build - name: Configure working-directory: build run: cmake .. -DBoost_DEBUG=ON -DCMAKE_BUILD_TYPE=${{matrix.buildType}} -DBUILD_SHARED_LIBS=${{matrix.shared_lib}} -DCMAKE_INSTALL_PREFIX=${{runner.workspace}}/../install -G "${{matrix.generator}}" -DCMAKE_SH="CMAKE_SH-NOTFOUND" -DBoost_NO_BOOST_CMAKE=ON diff --git a/CMakeLists.txt b/CMakeLists.txt index 2529b14..f874dac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,9 @@ # Builds the libraries for Boost.Nowide -# Automatically detects if build as standalone or as "part of boost" (with boost namespace) # # Options: # BOOST_NOWIDE_INSTALL -# BOOST_NOWIDE_BUILD_TESTS -# BOOST_NOWIDE_SYSTEM_INCLUDE +# BOOST_NOWIDE_WERROR +# BUILD_TESTING # # Created target: Boost::nowide # @@ -24,13 +23,6 @@ endif() list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_CURRENT_SOURCE_DIR}/cmake) -# Find out if we are beeing build as standalone or boost version -if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/include/nowide) - set(BOOST_NOWIDE_STANDALONE ON) -else() - set(BOOST_NOWIDE_STANDALONE OFF) -endif() - if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY) # Make sure all binarys (especially exe/dll) are in one directory for tests to work set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) @@ -59,20 +51,16 @@ target_compile_definitions(boost_nowide PUBLIC BOOST_NOWIDE_NO_LIB) target_include_directories(boost_nowide PUBLIC include) boost_add_warnings(boost_nowide pedantic ${BOOST_NOWIDE_WERROR}) -if(BOOST_NOWIDE_STANDALONE) - target_compile_features(boost_nowide PUBLIC cxx_std_11) +if(BOOST_SUPERPROJECT_SOURCE_DIR) + target_link_libraries(boost_nowide PUBLIC Boost::config Boost::smart_ptr Boost::static_assert) + set(BOOST_NOWIDE_INSTALL OFF) # smart_ptr does not support installation else() - if(BOOST_SUPERPROJECT_SOURCE_DIR) - target_link_libraries(boost_nowide PUBLIC Boost::config Boost::smart_ptr Boost::static_assert) - set(BOOST_NOWIDE_INSTALL OFF) # smart_ptr does not support installation - else() - # Default boost libs are static on windows and dynamic on linux - if(WIN32 AND NOT DEFINED Boost_USE_STATIC_LIBS) - set(Boost_USE_STATIC_LIBS ON) - endif() - find_package(Boost 1.56 REQUIRED) - target_link_libraries(boost_nowide PUBLIC Boost::boost) + # Default boost libs are static on windows and dynamic on linux + if(WIN32 AND NOT DEFINED Boost_USE_STATIC_LIBS) + set(Boost_USE_STATIC_LIBS ON) endif() + find_package(Boost 1.56 REQUIRED) + target_link_libraries(boost_nowide PUBLIC Boost::boost) endif() if(BUILD_TESTING) diff --git a/Config.cmake.in b/Config.cmake.in index a0787e4..05dcc7b 100644 --- a/Config.cmake.in +++ b/Config.cmake.in @@ -1,21 +1,18 @@ @PACKAGE_INIT@ -set(_boost_nowide_standalone @BOOST_NOWIDE_STANDALONE@) set(_boost_nowide_superproject "@BOOST_SUPERPROJECT_SOURCE_DIR@") -if(NOT _boost_nowide_standalone) - include(CMakeFindDependencyMacro) - if(_boost_nowide_superproject) - foreach(dep IN ITEMS boost_config boost_smart_ptr boost_static_assert) - find_dependency(${dep}) - endforeach() - else() - # Default boost libs are static on windows and dynamic on linux - if(WIN32 AND "${Boost_USE_STATIC_LIBS}" STREQUAL "") - set(Boost_USE_STATIC_LIBS ON) - endif() - find_dependency(Boost 1.56) - endif() +include(CMakeFindDependencyMacro) +if(_boost_nowide_superproject) +foreach(dep IN ITEMS boost_config boost_smart_ptr boost_static_assert) + find_dependency(${dep}) +endforeach() +else() +# Default boost libs are static on windows and dynamic on linux +if(WIN32 AND "${Boost_USE_STATIC_LIBS}" STREQUAL "") + set(Boost_USE_STATIC_LIBS ON) +endif() +find_dependency(Boost 1.56) endif() include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") diff --git a/include/boost/nowide/config.hpp b/include/boost/nowide/config.hpp index 0114473..34d65ad 100644 --- a/include/boost/nowide/config.hpp +++ b/include/boost/nowide/config.hpp @@ -23,7 +23,7 @@ #endif // BOOST_NOWIDE_SOURCE #else #define BOOST_NOWIDE_DECL -#endif // DYN_LINK +#endif // BOOST_NOWIDE_DYN_LINK // // Automatically link to the correct build variant where possible. diff --git a/include/boost/nowide/cstdlib.hpp b/include/boost/nowide/cstdlib.hpp index 657222e..d6034f3 100644 --- a/include/boost/nowide/cstdlib.hpp +++ b/include/boost/nowide/cstdlib.hpp @@ -9,7 +9,7 @@ #define BOOST_NOWIDE_CSTDLIB_HPP_INCLUDED #include -#if !BOOST_WINDOWS +#if !defined(BOOST_WINDOWS) #include #endif diff --git a/include/boost/nowide/integration/filesystem.hpp b/include/boost/nowide/filesystem.hpp similarity index 100% rename from include/boost/nowide/integration/filesystem.hpp rename to include/boost/nowide/filesystem.hpp diff --git a/src/cstdlib.cpp b/src/cstdlib.cpp index 8fbda07..52540d0 100644 --- a/src/cstdlib.cpp +++ b/src/cstdlib.cpp @@ -18,7 +18,7 @@ #include -#if !BOOST_WINDOWS +#if !defined(BOOST_WINDOWS) namespace boost { namespace nowide { int setenv(const char* key, const char* value, int overwrite) diff --git a/standalone/config.hpp b/standalone/config.hpp index 43bdc6a..8a07e20 100644 --- a/standalone/config.hpp +++ b/standalone/config.hpp @@ -1,31 +1,50 @@ // // Copyright (c) 2012 Artyom Beilis (Tonkikh) +// Copyright (c) 2020 Alexander Grund // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // -#ifndef NOWIDE_CONFIG_H_INCLUDED -#define NOWIDE_CONFIG_H_INCLUDED +#ifndef NOWIDE_CONFIG_HPP_INCLUDED +#define NOWIDE_CONFIG_HPP_INCLUDED + +#include #if(defined(__WIN32) || defined(_WIN32) || defined(WIN32)) && !defined(__CYGWIN__) #define NOWIDE_WINDOWS #endif #ifdef _MSC_VER -#define NOWIDE_MSVC +#define NOWIDE_MSVC _MSC_VER +#endif + +#ifdef __GNUC__ +#define BOOST_SYMBOL_VISIBLE __attribute__((__visibility__("default"))) +#endif + +#ifndef BOOST_SYMBOL_VISIBLE +#define BOOST_SYMBOL_VISIBLE #endif #ifdef NOWIDE_WINDOWS -#if defined(DLL_EXPORT) || defined(NOWIDE_EXPORT) -#ifdef NOWIDE_SOURCE -#define NOWIDE_DECL __declspec(dllexport) +#define BOOST_SYMBOL_EXPORT __declspec(dllexport) +#define BOOST_SYMBOL_IMPORT __declspec(dllimport) #else -#define NOWIDE_DECL __declspec(dllimport) -#endif // NOWIDE_SOURCE -#endif // DYN_LINK +#define BOOST_SYMBOL_EXPORT BOOST_SYMBOL_VISIBLE +#define BOOST_SYMBOL_IMPORT #endif +#if defined(BOOST_NOWIDE_DYN_LINK) +#ifdef BOOST_NOWIDE_SOURCE +#define BOOST_NOWIDE_DECL BOOST_SYMBOL_EXPORT +#else +#define BOOST_NOWIDE_DECL BOOST_SYMBOL_IMPORT +#endif // BOOST_NOWIDE_SOURCE +#else +#define BOOST_NOWIDE_DECL +#endif // BOOST_NOWIDE_DYN_LINK + #ifndef NOWIDE_DECL #define NOWIDE_DECL #endif @@ -39,4 +58,24 @@ #define BOOST_NOWIDE_USE_FILEBUF_REPLACEMENT 0 #endif +#if defined(__GNUC__) && __GNUC__ >= 7 +#define BOOST_NOWIDE_FALLTHROUGH __attribute__((fallthrough)) +#else +#define BOOST_NOWIDE_FALLTHROUGH +#endif + +// MSVC 2015 (1900) has reasonable C++11 support (especially auto-generated move ctors) +#if __cplusplus >= 201103L || (defined(NOWIDE_MSVC) && NOWIDE_MSVC >= 1900) +#define BOOST_NOWIDE_CXX11 1 +#else +#define BOOST_NOWIDE_CXX11 0 +#endif + +#if !defined(BOOST_LIKELY) +#define BOOST_LIKELY(x) x +#endif +#if !defined(BOOST_UNLIKELY) +#define BOOST_UNLIKELY(x) x +#endif + #endif diff --git a/standalone/convert b/standalone/convert deleted file mode 100755 index b8dba46..0000000 --- a/standalone/convert +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash - -rm -fr nowide nowide_standalone/{CMakeLists.txt,nowide,src,test} nowide_standalone.zip boost_nowide boost_nowide.zip -mkdir -p nowide/nowide -mkdir -p nowide/src -mkdir -p nowide/test - -cp ../include/boost/nowide/*.hpp nowide/nowide -cp ../src/*.cpp nowide/src -cp ../test/*.cpp ../test/*.hpp nowide/test -cp ./*.hpp nowide/nowide/ - -SOURCES="nowide/test/* nowide/src/* nowide/nowide/*" - - -sed 's/BOOST_NOWIDE_/NOWIDE_/g' -i $SOURCES -sed 's/BOOST_/NOWIDE_/g' -i $SOURCES -sed 's/boost::nowide::/nowide::/g' -i $SOURCES -sed 's/boost::nowide/nowide/g' -i $SOURCES -sed 's/boost::/nowide::/g' -i $SOURCES -sed 's/namespace boost {//' -i $SOURCES -sed 's/} *\/\/ *namespace boost//' -i $SOURCES -sed 's/ + +namespace nowide { +typedef std::uint32_t uint32_t; +typedef std::uint16_t uint16_t; +typedef std::uint8_t uint8_t; +} // namespace nowide + +#endif diff --git a/standalone/run_convert_and_build.sh b/standalone/run_convert_and_build.sh deleted file mode 100755 index 75e4c66..0000000 --- a/standalone/run_convert_and_build.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -export WINEPATH="/usr/lib/gcc/i686-w64-mingw32/5.3-win32/;/usr/lib/gcc/i686-w64-mingw32/5" - -rm -fr /tmp/nwlin /tmp/nw - -pushd . -./convert && mkdir nowide/build && cd nowide/build && cmake -DCMAKE_TOOLCHAIN_FILE=../../MinGW.cmake -DCMAKE_INSTALL_PREFIX=/tmp/nw -DRUN_WITH_WINE=ON .. && make && make test && make install -popd - -pushd . -./convert && mkdir nowide/build && cd nowide/build && cmake -DLIBDIR=lin64 -DCMAKE_INSTALL_PREFIX=/tmp/nwlin .. && make && make test && make install -popd - - - - - diff --git a/standalone/static_assert.hpp b/standalone/static_assert.hpp new file mode 100644 index 0000000..b772f30 --- /dev/null +++ b/standalone/static_assert.hpp @@ -0,0 +1,7 @@ +#ifndef NOWIDE_STATIC_ASSERT_HPP +#define NOWIDE_STATIC_ASSERT_HPP + +#define NOWIDE_STATIC_ASSERT(c) static_assert(c, #c) +#define NOWIDE_STATIC_ASSERT_MSG(c, msg) static_assert(c, msg) + +#endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4e64e3f..317b2c2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -31,14 +31,8 @@ else() boost_nowide_add_test(test_internal_fstream_cxx11 SRC test_fstream_cxx11.cpp DEFINITIONS BOOST_NOWIDE_USE_FILEBUF_REPLACEMENT=1) endif() -if(NOT BOOST_NOWIDE_STANDALONE) - if(NOT BOOST_SUPERPROJECT_SOURCE_DIR) - find_package(Boost 1.56 REQUIRED COMPONENTS filesystem system) - endif() - boost_nowide_add_test(test_fs LIBRARIES Boost::filesystem) -endif() - if(NOT BOOST_SUPERPROJECT_SOURCE_DIR) - find_package(Boost 1.56 REQUIRED COMPONENTS chrono) + find_package(Boost 1.56 REQUIRED COMPONENTS filesystem system chrono) endif() +boost_nowide_add_test(test_fs LIBRARIES Boost::filesystem) boost_nowide_add_test(benchmark_fstream COMPILE_ONLY DEFINITIONS BOOST_NOWIDE_USE_FILEBUF_REPLACEMENT=1 LIBRARIES Boost::chrono) diff --git a/test/test_fs.cpp b/test/test_fs.cpp index 068416e..b7e0571 100644 --- a/test/test_fs.cpp +++ b/test/test_fs.cpp @@ -8,8 +8,8 @@ #include #include +#include #include -#include #include #include diff --git a/tools/create_standalone.sh b/tools/create_standalone.sh new file mode 100644 index 0000000..f8dd4fc --- /dev/null +++ b/tools/create_standalone.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +set -euo pipefail + +cd "$(dirname "$0")/.." + +if ! [ -e "tools/create_standalone.sh" ]; then + echo "Could not change to repo root" + exit 1 +fi + +targetFolder="${1:-nowide_standalone}" + +# If target folder exists fail, unless it is the default in which case it is removed +if [ -e "$targetFolder" ]; then + if [[ "$targetFolder" == "nowide_standalone" ]]; then + rm -r "$targetFolder" + else + echo "Target folder $targetFolder exists" + exit 1 + fi +fi + +mkdir -p "$targetFolder"/include + +cp -r include/boost/nowide "$targetFolder"/include +cp -r src test cmake CMakeLists.txt "$targetFolder" +cp standalone/*.hpp "$targetFolder"/include/nowide +mv "$targetFolder/cmake/BoostAddOptions.cmake" "$targetFolder/cmake/NowideAddOptions.cmake" +mv "$targetFolder/cmake/BoostAddWarnings.cmake" "$targetFolder/cmake/NowideAddWarnings.cmake" +find "$targetFolder" -name 'Jamfile*' -delete + +SOURCES=$(find "$targetFolder" -type f -not -name '*.txt' -not -name '*.cmake') + +sed 's/BOOST_NOWIDE_/NOWIDE_/g' -i $SOURCES +sed 's/BOOST_/NOWIDE_/g' -i $SOURCES +sed 's/boost::nowide/nowide/g' -i $SOURCES +sed 's/boost::chrono/std::chrono/g' -i $SOURCES +sed 's/boost::milli/std::milli/g' -i $SOURCES +sed 's/boost::/nowide::/g' -i $SOURCES +sed '/namespace boost/d' -i $SOURCES +sed 's/