forked from DCMTK/dcmtk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcxx11.dox
139 lines (107 loc) · 5.27 KB
/
cxx11.dox
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*!
\page cxx11_support C++11 support in DCMTK
You may compile DCMTK with C++11 support enabled. This may increase performance
since some operations can be performed in a more efficient manner, e.g.
utilizing
<a href="http://en.cppreference.com/w/cpp/language/move_constructor">move semantics</a>.
To create a C++11 build of DCMTK, you simply need to set the appropriate
compiler-flags while building it (e.g. -std=c++11). This will however not
enable DCMTK to use available C++11 features that aren't implicitly used by
legacy code. This is especially important regarding some C++11 classes DCMTK
directly supports, for example:
\li OFunique_ptr (std::unique_ptr)
\li OFshared_ptr (std::shared_ptr)
\li OFnumeric_limits (std::numeric_limits)
\li OFtuple (std::tuple)
\li OFerror_code (std::error_code)
Since not every compiler supports C++11, legacy implementations for the
respective functionality have been created, which are enabled <i>by default</i>.
If you use C++11 in your project, you may want to use the native C++11 classes
and features instead, so you don't need to convert your objects to use them
with DCMTK. To do so, you need to configure DCMTK to use the C++11 STL, which
is described below.
<h1>Enabling DCMTK to use C++11</h1>
By enabling DCMTK to use C++11, you gain the following advantages:
\li DCMTK will use available C++11 features instead of its only legacy
implementations. These are probably more efficient and complete.
\li The enabling of C++11 becomes part of DCMTK's configuration, which allows
DCMTK to assist you when checking for API/ABI (in-)compatibility between
C++11 and non C++11 builds.
Trying to include a DCMTK build with C++11 enabled from a non C++11
environment will give you the following error message:
@verbatim
DCMTK was configured to use C++11 features, but your compiler does not or was not configured to provide them.
@endverbatim
To reduce DCMTK's implementation complexity, C++11 shall only be used if your
compiler <i>conforms closely</i> to the C++11 Standard. As far as we know,
this is currently true for the following compilers:
\li GNU C++ Compiler (g++) Version 4.8.1 or later.
\li Clang (clang++) Version 3.3 or later.
To enable the C++11 STL, different steps are necessary on CMake and GNU
Autoconf, see the appropriate section below:
<h2>CMake</h2>
Request building with C++11 features by setting the option
<kbd>DCMTK_ENABLE_CXX11</kbd> to <i>On</i>, for example via:
@verbatim
cmake ... -DDCMTK_ENABLE_CXX11:BOOL=ON ...
@endverbatim
CMake detects the C++11 compilers and knows how to enable C++11 features on
Clang, GCC and Intel compilers. You can override the assumed compiler flags
(for example to enable C++14 instead) by modifying
<kbd>DCMTK_CXX11_FLAGS</kbd>, for example:
@verbatim
cmake ... -DDCMTK_ENABLE_CXX11:BOOL=ON -DDCMTK_CXX11_FLAGS=-std=c++14 ...
@endverbatim
CMake will then perform basic checks to ensure the compiler is configured
correctly and conforms closely enough to C++11 standard. If everything
works CMake will print something like this:
@verbatim
-- Checking whether the compiler supports C++11
-- Checking whether the compiler supports C++11 -- yes
-- Info: C++11 features enabled
@endverbatim
<h3>Unsupported Compilers</h3>
If our CMake setup does not know how to enable C++11 on your compiler, it will
simply assume that no configuration is required (e.g. for Visual Studio). If
this is not appropriate you have to set <kbd>DCMTK_CXX11_FLAGS</kbd> manually
as mentioned above.
If you enable C++11 via <kbd>DCMTK_ENABLE_CXX11</kbd> for an unsupported
compiler, CMake will simply set the flags provided via
<kbd>DCMTK_CXX11_FLAGS</kbd> (if any) and still run the C++11 compatibility
test to the compiler conforms closely enough to the C++11 standard for being
able to compile DCMTK. If it doesn't, CMake will give an output similar to
this one:
@verbatim
-- Checking whether the compiler supports C++11
-- Checking whether the compiler supports C++11 -- no
-- Info: C++11 features disabled
@endverbatim
At this point you will not be able to enable C++11 features for the given
compiler, since building DCMTK would fail if you did. If you are sure that
your compiler supports C++11, you should try setting different flags as
<kbd>DCMTK_CXX11_FLAGS</kbd>.
<h2>GNU Autoconf</h2>
Our GNU Autoconf setup understands the switches <kbd>\--enable-cxx11</kbd>,
and <kbd>\--disable-cxx11</kbd> that may be used to configure DCMTK to use
C++11 features. If you run
@verbatim
configure --enable-cxx11
@endverbatim
our Autoconf script will try to determine the required compiler flags for
enabling C++11 features (if any) and perform configuration tests to ensure
the compiler conforms closely enough to the C++11 standard. If everything
works it will give you an output similar to this one:
@verbatim
checking whether to enable C++11 support...
checking whether c++ supports C++11 features by default... no
checking whether c++ supports C++11 features with -std=c++11... yes
checking whether to enable C++11 support... yes
@endverbatim
Otherwise, it will still disable C++11 features with an output like this:
@verbatim
checking whether to enable C++11 support...
checking whether c++ supports C++11 features by default... no
checking whether c++ supports C++11 features with -std=c++11... no
checking whether to enable C++11 support... no
@endverbatim
*/