Skip to content

Commit

Permalink
cpp 17 / std::filesystem (#6844)
Browse files Browse the repository at this point in the history
#changelog #utils
  • Loading branch information
ofTheo authored Mar 10, 2022
1 parent 5e46cfe commit fab4482
Show file tree
Hide file tree
Showing 29 changed files with 103 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-msys2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: windows-latest
strategy:
matrix:
mingw: [MINGW64,MINGW32]
mingw: [MINGW64, MINGW32]
defaults:
run:
shell: msys2 {0}
Expand Down
4 changes: 4 additions & 0 deletions addons/ofxPoco/src/ofxXmlPoco.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include <numeric>

#define byte _priv_byte

#include <Poco/DOM/Document.h>
#include <Poco/DOM/DocumentFragment.h>
#include <Poco/DOM/Element.h>
Expand All @@ -26,6 +28,8 @@
#include <Poco/DOM/NamedNodeMap.h>
#include <Poco/DOM/ChildNodesList.h>

#undef byte

class ofxXmlPoco{

public:
Expand Down
1 change: 1 addition & 0 deletions libs/openFrameworks/3d/of3dUtils.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "ofConstants.h"
#include "ofFileUtils.h"
#include "glm/fwd.hpp"

/// \brief Draws x,y,z axes representing the current reference frame.
Expand Down
1 change: 1 addition & 0 deletions libs/openFrameworks/sound/ofSoundBaseTypes.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "ofConstants.h"
#include "ofFileUtils.h"
#include <functional>

class ofSoundBuffer;
Expand Down
17 changes: 10 additions & 7 deletions libs/openFrameworks/utils/ofConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@
// This enables glm's old behavior of initializing with non garbage values
#define GLM_FORCE_CTOR_INIT

// Set to 1 to use std filesystem instead of boost's
// If you are building with c++17 or newer std filesystem will be enabled by default
#ifndef OF_USING_STD_FS
#define OF_USING_STD_FS 0
#if __cplusplus >= 201703L
#define OF_USING_STD_FS 1
#else
// Set to 1 to force std filesystem instead of boost's
#define OF_USING_STD_FS 0
#endif
#endif

//-------------------------------
Expand Down Expand Up @@ -463,17 +468,15 @@ std::unique_ptr<T> make_unique(Args&&... args) {
# else
# define OF_USE_EXPERIMENTAL_FS 0

namespace std {
namespace filesystem {
class path;
}
}
#include <filesystem>

# endif
#else
# if !_MSC_VER
# define BOOST_NO_CXX11_SCOPED_ENUMS
# define BOOST_NO_SCOPED_ENUMS
# endif
# include <boost/filesystem.hpp>
namespace boost {
namespace filesystem {
class path;
Expand Down
1 change: 1 addition & 0 deletions libs/openFrameworks/utils/ofFileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#ifndef TARGET_WIN32
#include <pwd.h>
#include <sys/stat.h>
#include <unistd.h>
#endif

#include "ofUtils.h"
Expand Down
20 changes: 0 additions & 20 deletions libs/openFrameworks/utils/ofFileUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,6 @@
#include "ofConstants.h"
#include <fstream>

#if OF_USING_STD_FS
# if __cplusplus < 201703L
# include <experimental/filesystem>
namespace std {
namespace filesystem = experimental::filesystem;
}
# else
# include <filesystem>
# endif
#else
# if !_MSC_VER
# define BOOST_NO_CXX11_SCOPED_ENUMS
# define BOOST_NO_SCOPED_ENUMS
# endif
# include <boost/filesystem.hpp>
namespace std {
namespace filesystem = boost::filesystem;
}
#endif

//----------------------------------------------------------
// ofBuffer
//----------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions libs/openFrameworks/utils/ofUtils.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "ofConstants.h"
#include "ofFileUtils.h"
#include "utf8.h"
#include <bitset> // For ofToBinary.
#include <chrono>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
################################################################################
################################################################################
# CONFIGURE CORE PLATFORM MAKEFILE
# This file has linux common rules for all the platforms (x86_64, i386,armv6l
# and armv7l)
Expand Down Expand Up @@ -64,7 +64,7 @@ PLATFORM_REQUIRED_ADDONS = ofxEmscripten
################################################################################

# Code Generation Option Flags (http://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html)
PLATFORM_CFLAGS = -Wall -std=c++14 -Wno-warn-absolute-paths
PLATFORM_CFLAGS = -Wall -std=c++17 -Wno-warn-absolute-paths


################################################################################
Expand Down
3 changes: 2 additions & 1 deletion libs/openFrameworksCompiled/project/ios/CoreOF.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ OF_CORE_FRAMEWORKS = -framework AudioToolbox -framework Accelerate -framework AV

// once all libraries are compiled for libc++ / all architectures
CLANG_CXX_LIBRARY = libc++
CLANG_CXX_LANGUAGE_STANDARD = c++11
CLANG_CXX_LANGUAGE_STANDARD = c++17
IPHONEOS_DEPLOYMENT_TARGET = 13.0
Original file line number Diff line number Diff line change
Expand Up @@ -2858,8 +2858,6 @@
<string>YES</string>
<key>GCC_WARN_NON_VIRTUAL_DESTRUCTOR</key>
<string>YES</string>
<key>IPHONEOS_DEPLOYMENT_TARGET</key>
<string>8.0</string>
<key>LIBRARY_SEARCH_PATHS</key>
<array>
<string>$(inherited)</string>
Expand Down Expand Up @@ -2902,8 +2900,6 @@
<string>YES</string>
<key>GCC_WARN_NON_VIRTUAL_DESTRUCTOR</key>
<string>YES</string>
<key>IPHONEOS_DEPLOYMENT_TARGET</key>
<string>8.0</string>
<key>LIBRARY_SEARCH_PATHS</key>
<array>
<string>$(inherited)</string>
Expand Down Expand Up @@ -3070,8 +3066,6 @@
<string>YES</string>
<key>GCC_WARN_UNUSED_FUNCTION</key>
<string>YES</string>
<key>IPHONEOS_DEPLOYMENT_TARGET</key>
<string>8.0</string>
<key>OBJROOT</key>
<string>$(SRCROOT)/../../lib/ios/build/debug</string>
<key>ONLY_ACTIVE_ARCH</key>
Expand Down Expand Up @@ -3149,8 +3143,6 @@
<string>YES</string>
<key>GCC_WARN_UNUSED_FUNCTION</key>
<string>YES</string>
<key>IPHONEOS_DEPLOYMENT_TARGET</key>
<string>8.0</string>
<key>OBJROOT</key>
<string>$(SRCROOT)/../../lib/ios/build/release</string>
<key>ONLY_ACTIVE_ARCH</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ PLATFORM_DEFINES += USE_VCHIQ_ARM
# Note: Leave a leading space when adding list items with the += operator
################################################################################

#c++ 17 support - comment out two lines below to use c++11
PLATFORM_CFLAGS += -std=c++17
PLATFORM_LDFLAGS += -lstdc++fs

PLATFORM_CFLAGS += -march=armv6
PLATFORM_CFLAGS += -mfpu=vfp
PLATFORM_CFLAGS += -mfloat-abi=hard
Expand Down Expand Up @@ -265,11 +269,11 @@ endif

PLATFORM_CFLAGS += --sysroot=$(SYSROOT)

PLATFORM_HEADER_SEARCH_PATHS += $(SYSROOT)/usr/include/c++/4.9
PLATFORM_HEADER_SEARCH_PATHS += $(SYSROOT)/usr/include/$(GCC_PREFIX)/c++/4.9
PLATFORM_HEADER_SEARCH_PATHS += $(SYSROOT)/usr/include/c++
PLATFORM_HEADER_SEARCH_PATHS += $(SYSROOT)/usr/include/$(GCC_PREFIX)/c++/7

PLATFORM_LIBRARY_SEARCH_PATHS += $(SYSROOT)/usr/lib/$(GCC_PREFIX)
PLATFORM_LIBRARY_SEARCH_PATHS += $(SYSROOT)/usr/lib/gcc/$(GCC_PREFIX)/4.9
PLATFORM_LIBRARY_SEARCH_PATHS += $(SYSROOT)/usr/lib/gcc/$(GCC_PREFIX)/7

PLATFORM_LDFLAGS += --sysroot=$(SYSROOT)
PLATFORM_LDFLAGS += -Xlinker -rpath-link=$(SYSROOT)/usr/lib/$(GCC_PREFIX)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,12 @@ ifeq ($(CROSS_COMPILING),1)
SYSROOT=$(RPI_ROOT)

PLATFORM_CFLAGS += --sysroot=$(SYSROOT)

#c++ 17 support - comment out two lines below to use c++11
PLATFORM_CFLAGS += -std=c++17
PLATFORM_LDFLAGS += -lstdc++fs

PLATFORM_HEADER_SEARCH_PATHS += $(SYSROOT)/usr/include/c++/4.9
PLATFORM_HEADER_SEARCH_PATHS += $(SYSROOT)/usr/include/c++/7

PLATFORM_LIBRARY_SEARCH_PATHS += $(SYSROOT)/usr/lib/$(GCC_PREFIX)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ PLATFORM_DEFINES += USE_VCHIQ_ARM
# Note: Leave a leading space when adding list items with the += operator
################################################################################

#c++ 17 support - comment out two lines below to use c++11
PLATFORM_CFLAGS += -std=c++17
PLATFORM_LDFLAGS += -lstdc++fs

PLATFORM_CFLAGS += -march=armv7-a
PLATFORM_CFLAGS += -mfpu=vfp
PLATFORM_CFLAGS += -mfloat-abi=hard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ ifeq ($(CROSS_COMPILING),1)
SYSROOT=$(RPI_ROOT)

PLATFORM_CFLAGS += --sysroot=$(SYSROOT)

#c++ 17 support - comment out two lines below to use c++11
PLATFORM_CFLAGS += -std=c++17
PLATFORM_LDFLAGS += -lstdc++fs

PLATFORM_HEADER_SEARCH_PATHS += $(SYSROOT)/usr/include/c++/4.9
PLATFORM_HEADER_SEARCH_PATHS += $(SYSROOT)/usr/include/c++/7

PLATFORM_LIBRARY_SEARCH_PATHS += $(SYSROOT)/usr/lib/$(GCC_PREFIX)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ PLATFORM_REQUIRED_ADDONS =
ifeq ($(CXX),g++)
GCC_MAJOR_EQ_4 := $(shell expr `gcc -dumpversion | cut -f1 -d.` \= 4)
GCC_MAJOR_GT_4 := $(shell expr `gcc -dumpversion | cut -f1 -d.` \> 4)
GCC_MAJOR_GTEQ_6 := $(shell expr `gcc -dumpversion | cut -f1 -d.` \>= 6)
GCC_MAJOR_GTEQ_9 := $(shell expr `gcc -dumpversion | cut -f1 -d.` \>= 8)
GCC_MINOR_GTEQ_7 := $(shell expr `gcc -dumpversion | cut -f2 -d.` \<= 7)
GCC_MINOR_GTEQ_9 := $(shell expr `gcc -dumpversion | cut -f2 -d.` \>= 9)
ifeq ("$(GCC_MAJOR_EQ_4)","1")
Expand All @@ -157,6 +159,10 @@ ifeq ($(CXX),g++)
PLATFORM_CFLAGS = -Wall -Werror=return-type -DGCC_HAS_REGEX
PLATFORM_CXXFLAGS = -Wall -Werror=return-type -std=c++14 -DGCC_HAS_REGEX
endif
# c++17 for gcc 6 and newer
ifeq ("$(GCC_MAJOR_GTEQ_6)","1")
PLATFORM_CXXFLAGS = -Wall -Werror=return-type -std=c++17 -DGCC_HAS_REGEX
endif
else
ifeq ($(CXX),g++-5)
PLATFORM_CFLAGS = -Wall -Werror=return-type -DGCC_HAS_REGEX
Expand Down Expand Up @@ -188,7 +194,12 @@ endif

PLATFORM_LDFLAGS = -Wl,-rpath=./libs:./bin/libs -Wl,--as-needed -Wl,--gc-sections


# gcc 6,7,8 need special file system linking with -lstdc++fs. gcc 9 onwards doesn't
ifeq ("$(GCC_MAJOR_GTEQ_6)","1")
ifeq ("$(GCC_MAJOR_GTEQ_9)","0")
PLATFORM_LDFLAGS += -lstdc++fs
endif
endif


################################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
##########################################################################################

MINGW_PREFIX ?= /mingw32
PLATFORM_CFLAGS += -std=gnu++14 -DUNICODE -D_UNICODE
PLATFORM_CFLAGS += -std=gnu++17 -DUNICODE -D_UNICODE
#PLATFORM_CFLAGS += -IC:/msys64/mingw32/include/gstreamer-1.0 -DOF_VIDEO_PLAYER_GSTREAMER
ifdef USE_CCACHE
CC = ccache $(MINGW_PREFIX)/bin/gcc
Expand Down Expand Up @@ -62,7 +62,8 @@ PLATFORM_RUN_COMMAND = cd bin;./$(BIN_NAME)
# Note: Be sure to leave a leading space when using a += operator to add items to the list
##########################################################################################

#PLATFORM_DEFINES = OF_USING_STD_FS
PLATFORM_DEFINES =

ifeq ($(OF_USE_POCO),1)
PLATFORM_DEFINES += POCO_STATIC
endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ ifndef MAC_OS_STD_LIB
MAC_OS_STD_LIB = libc++
endif

ifndef MAC_OS_CPP_VER
MAC_OS_CPP_VER = -std=c++11
endif

# Link against libstdc++ to silence tr1/memory errors on latest versions of osx
PLATFORM_CFLAGS = -stdlib=$(MAC_OS_STD_LIB)

Expand Down Expand Up @@ -139,7 +143,7 @@ endif
PLATFORM_CFLAGS += -mmacosx-version-min=$(MAC_OS_MIN_VERSION)

PLATFORM_CXXFLAGS += -x objective-c++
PLATFORM_CXXFLAGS += -std=c++11
PLATFORM_CXXFLAGS += $(MAC_OS_CPP_VER)

ifeq ($(USE_GST),1)
PLATFORM_CFLAGS += -I/Library/Frameworks/Gstreamer.framework/Headers
Expand Down
3 changes: 2 additions & 1 deletion libs/openFrameworksCompiled/project/tvOS/CoreOF.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ OF_CORE_FRAMEWORKS = -framework AudioToolbox -framework Accelerate -framework AV

// once all libraries are compiled for libc++ / all architectures
CLANG_CXX_LIBRARY = libc++
CLANG_CXX_LANGUAGE_STANDARD = c++11
CLANG_CXX_LANGUAGE_STANDARD = c++17
TVOS_DEPLOYMENT_TARGET = 13.0
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,6 @@
<dict>
<key>ALWAYS_SEARCH_USER_PATHS</key>
<string>YES</string>
<key>CLANG_CXX_LANGUAGE_STANDARD</key>
<string>c++0x</string>
<key>CLANG_CXX_LIBRARY</key>
<string>libc++</string>
<key>CLANG_ENABLE_MODULES</key>
Expand Down Expand Up @@ -529,7 +527,7 @@
<key>SYMROOT</key>
<string>$(SRCROOT)/../../lib/tvOS/</string>
<key>TVOS_DEPLOYMENT_TARGET</key>
<string>9.0</string>
<string>13.0</string>
</dict>
<key>isa</key>
<string>XCBuildConfiguration</string>
Expand All @@ -544,8 +542,6 @@
<dict>
<key>ALWAYS_SEARCH_USER_PATHS</key>
<string>YES</string>
<key>CLANG_CXX_LANGUAGE_STANDARD</key>
<string>c++0x</string>
<key>CLANG_CXX_LIBRARY</key>
<string>libc++</string>
<key>CLANG_ENABLE_MODULES</key>
Expand Down Expand Up @@ -609,7 +605,7 @@
<key>SYMROOT</key>
<string>$(SRCROOT)/../../lib/tvOS/</string>
<key>TVOS_DEPLOYMENT_TARGET</key>
<string>9.0</string>
<string>13.0</string>
<key>VALIDATE_PRODUCT</key>
<string>YES</string>
</dict>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<WarningLevel>Level1</WarningLevel>
<CompileAs>CompileAsCpp</CompileAs>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand All @@ -111,6 +113,8 @@
<WarningLevel>Level3</WarningLevel>
<BrowseInformation>false</BrowseInformation>
<CompileAs>CompileAsCpp</CompileAs>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
Expand All @@ -121,6 +125,8 @@
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand All @@ -131,6 +137,8 @@
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<WarningLevel>Level1</WarningLevel>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
Expand Down
Loading

0 comments on commit fab4482

Please sign in to comment.