Skip to content

Commit 1c7e7b3

Browse files
Merge pull request #1624 from vikhik/master
Enforce using C++17 when linking against vsg in CMake
2 parents 4af6f13 + 8f1131c commit 1c7e7b3

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

INSTALL.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,22 +170,19 @@ To assist with setting up software to work with the VSG when you install the lib
170170

171171
find_package(vsg)
172172

173-
To select C++17 compilation you'll need:
174-
175-
set_property(TARGET mytargetname PROPERTY CXX_STANDARD 17)
176-
177173
To link your lib/application to required dependencies you'll need:
178174

179175
target_link_libraries(mytargetname vsg::vsg)
180176

181177
This will tell CMake to set up all the appropriate include paths, libs and any definitions (such as the VSG_SHARED_LIBRARY #define that is required under Windows with shared library builds to select the correct declspec().)
182178

179+
This will also tell CMake that your minimum C++ standard is 17.
180+
183181
For example, a bare minimum CMakeLists.txt file to compile a single file application would be:
184182

185183
cmake_minimum_required(VERSION 3.7)
186184
find_package(vsg REQUIRED)
187185
add_executable(myapp "myapp.cpp")
188-
set_property(TARGET myapp PROPERTY CXX_STANDARD 17)
189186
target_link_libraries(myapp vsg::vsg)
190187

191188
### Using VSG provided cmake macros within your own projects
@@ -218,7 +215,6 @@ For example, a bare minimum CMakeLists.txt file adding the mentioned cmake targe
218215
vsg_add_target_uninstall()
219216

220217
add_executable(myapp "myapp.cpp")
221-
set_property(TARGET myapp PROPERTY CXX_STANDARD 17)
222218
target_link_libraries(myapp vsg::vsg)
223219

224220
### Using VSG provided cmake macro to generate cmake support files

src/vsg/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ ASSIGN_SOURCE_GROUPS("Header Files" "${VSG_SOURCE_DIR}/include/vsg" ${HEADERS})
411411
set_property(TARGET vsg PROPERTY VERSION ${VSG_VERSION_MAJOR}.${VSG_VERSION_MINOR}.${VSG_VERSION_PATCH})
412412
set_property(TARGET vsg PROPERTY SOVERSION ${VSG_SOVERSION})
413413
set_property(TARGET vsg PROPERTY POSITION_INDEPENDENT_CODE ON)
414-
set_property(TARGET vsg PROPERTY CXX_STANDARD 17)
414+
target_compile_features(vsg PUBLIC cxx_std_17)
415415
if(WIN32)
416416
set_property(TARGET vsg PROPERTY RUNTIME_OUTPUT_NAME vsg-${VSG_SOVERSION})
417417
endif()

0 commit comments

Comments
 (0)