Skip to content

Commit

Permalink
[build] Fixed possibility to compile examples with C++03 standard (#1830
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ethouris authored Feb 26, 2021
1 parent 6012fdf commit 1dced8b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
16 changes: 9 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,6 @@ if (NOT ENABLE_CXX11)
if (ENABLE_STDCXX_SYNC)
message(FATAL_ERROR "ENABLE_STDCXX_SYNC is set, but C++11 is disabled by ENABLE_CXX11")
endif()
if (DEFINED USE_CXX_STD)
message(FATAL_ERROR "USE_CXX_STD can be set only when ENABLE_CXX11 is on")
endif()
elseif (ENABLE_STDCXX_SYNC)
add_definitions(-DENABLE_STDCXX_SYNC=1)
if (DEFINED USE_CXX_STD)
Expand Down Expand Up @@ -461,9 +458,14 @@ if (DEFINED USE_CXX_STD)

# Set this through independent flags
set (USE_CXX_STD_LIB ${STDCXX})
set (USE_CXX_STD_APP "")
set (FORCE_CXX_STANDARD 1)
message(STATUS "C++ STANDARD: library: C++${STDCXX}, but apps still at least C++11")
if (NOT ENABLE_APPS)
set (USE_CXX_STD_APP ${STDCXX})
message(STATUS "C++ STANDARD: library: C++${STDCXX}, apps disabled (examples will follow C++${STDCXX})")
else()
set (USE_CXX_STD_APP "")
message(STATUS "C++ STANDARD: library: C++${STDCXX}, but apps still at least C++11")
endif()
elseif (FORCE_CXX_STANDARD_GNUONLY)
# CMake is too old to handle CMAKE_CXX_STANDARD,
# use bare GNU options.
Expand Down Expand Up @@ -805,10 +807,10 @@ macro(srt_set_stdcxx targetname spec)
if (NOT "${stdcxxspec}" STREQUAL "")
if (FORCE_CXX_STANDARD_GNUONLY)
target_compile_options(${targetname} PRIVATE -std=c++${stdcxxspec})
#message(STATUS "C++ STD: ${targetname}: forced C++${stdcxxspec} standard - GNU option: -std=c++${stdcxxspec}")
message(STATUS "C++ STD: ${targetname}: forced C++${stdcxxspec} standard - GNU option: -std=c++${stdcxxspec}")
else()
set_target_properties(${targetname} PROPERTIES CXX_STANDARD ${stdcxxspec})
#message(STATUS "C++ STD: ${targetname}: forced C++${stdcxxspec} standard - portable way")
message(STATUS "C++ STD: ${targetname}: forced C++${stdcxxspec} standard - portable way")
endif()
else()
message(STATUS "APP: ${targetname}: using default C++ standard")
Expand Down
5 changes: 5 additions & 0 deletions docs/BuildOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,12 @@ when it is expected to be revived.

**`--use-c++-std=<standard>`**

Enforce using particular C++ standard when compiling. When using this option
remember that:

* Allowed values are: 98, 03, 11, 14, 17 and 20
* If you use 98/03 and `--enable-apps`, apps will be still using C++11
* This option is only supported on GNU and Clang compilers (will be ignored on others)

**`--use-gnustl`**

Expand Down
30 changes: 27 additions & 3 deletions docs/DevelopersGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,36 @@ Please see the following document for `configure` usage: [BuildOptions.md](./Bui

The build output is in the `_build` directory. The following applications can be found there.

* `srt-live-transmit` A sample application to transmit a live stream from source medium (UDP/SRT/`stdin`)
* `srt-live-transmit` - A sample application to transmit a live stream from source medium (UDP/SRT/`stdin`)
to the target medium (UDP/SRT/`stdout`). See [srt-live-transmit.md](./srt-live-transmit.md) for more info.
* `srt-file-transmit` A sample application to transmit files with SRT.
* `srt-tunnel` A sample application to set up an SRT tunnel for TCP traffic. See [srt-tunnel.md](./srt-tunnel.md) for more info.
* `srt-file-transmit` - A sample application to transmit files with SRT.
* `srt-tunnel` - A sample application to set up an SRT tunnel for TCP traffic. See [srt-tunnel.md](./srt-tunnel.md) for more info.
* `tests-srt` - unit testing application.

## Language standard requirements

The following conventions for the language standard are used in this project:

1. The SRT library requires C++03 (also known as C++98) standard.
2. The examples (to be enabled in cmake by `-DENABLE_EXAMPLES=1`) require either C++03 or C89 standard.
3. The following require C++11 standard:
* demo applications
* testing applications (to be enabled in cmake by `-DENABLE_TESTING=1`)
* unit tests (to be enabled in cmake by `-DENABLE_UNITTESTS=1`)

Note that C++11 standard will be enforced if you have enabled applications
and haven't specified the C++ standard explicitly. When you have an old compiler
that does not support C++11 and you want to compile as many parts as possible,
the simplest way is to use the following options (in cmake):

```
-DENABLE_APPS=0 -DUSE_CXX_STD=03 -DENABLE_EXAMPLES=1
```

Note also that there are several other options that, when enabled, may require
that the SRT library be compiled using C++11 standard (`-DENABLE_STDCXX_SYNC=1`
for example).

## Project Structure

The SRT installation has the following folders:
Expand Down

0 comments on commit 1dced8b

Please sign in to comment.