Skip to content

Commit bbd6641

Browse files
committed
CMake updates to better handle C++ standard specification and propagation to apps consistently
1 parent c119193 commit bbd6641

File tree

3 files changed

+62
-4
lines changed

3 files changed

+62
-4
lines changed

proj/cmake/libcinder_target.cmake

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,43 @@ if( CINDER_MSW AND MSVC )
7979
endif()
8080
endif()
8181

82-
target_compile_features( cinder PUBLIC cxx_std_17 )
82+
# Determine C++ standard for Cinder (default 17, allow user override)
83+
if( CMAKE_CXX_STANDARD )
84+
set( CINDER_CXX_STANDARD ${CMAKE_CXX_STANDARD} )
85+
else()
86+
set( CINDER_CXX_STANDARD 17 )
87+
endif()
88+
89+
# Validate minimum
90+
if( CINDER_CXX_STANDARD LESS 17 )
91+
message( FATAL_ERROR "Cinder requires C++17 or later. CMAKE_CXX_STANDARD is set to ${CINDER_CXX_STANDARD}" )
92+
endif()
93+
94+
# Set C++ standard for cinder target
95+
target_compile_features( cinder PUBLIC cxx_std_${CINDER_CXX_STANDARD} )
96+
97+
# Determine CXX_EXTENSIONS: default OFF (prevents "namespace linux" issue)
98+
# Only enable if user explicitly sets CMAKE_CXX_EXTENSIONS=ON
99+
if( DEFINED CMAKE_CXX_EXTENSIONS )
100+
set( CINDER_CXX_EXTENSIONS ${CMAKE_CXX_EXTENSIONS} )
101+
else()
102+
set( CINDER_CXX_EXTENSIONS OFF )
103+
endif()
104+
83105
set_target_properties( cinder PROPERTIES
84-
CXX_STANDARD 17
106+
CXX_STANDARD ${CINDER_CXX_STANDARD}
85107
CXX_STANDARD_REQUIRED ON
86-
CXX_EXTENSIONS OFF
108+
CXX_EXTENSIONS ${CINDER_CXX_EXTENSIONS}
87109
)
88110

89111
# This file will contain all dependencies, includes, definition, compiler flags and so on..
90112
export( TARGETS cinder FILE ${PROJECT_BINARY_DIR}/${CINDER_LIB_DIRECTORY}/cinderTargets.cmake )
91113

92114
# And this command will generate a file on the ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}
93115
# that applications have to pull in order to link successfully with Cinder and its dependencies.
94-
# This specific cinderConfig.cmake file will just hold a path to the above mention
116+
# This specific cinderConfig.cmake file will just hold a path to the above mention
95117
# cinderTargets.cmake file which holds the actual info.
118+
# CINDER_CXX_STANDARD and CINDER_CXX_EXTENSIONS will be substituted into the template
96119
configure_file( ${CMAKE_CURRENT_LIST_DIR}/modules/cinderConfig.buildtree.cmake.in
97120
"${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/cinderConfig.cmake"
98121
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
if( NOT TARGET cinder${CINDER_LIB_SUFFIX} )
22
include( "${PROJECT_BINARY_DIR}/${CINDER_LIB_DIRECTORY}/cinderTargets.cmake" )
3+
4+
# Record the C++ standard and extensions setting Cinder was built with
5+
# These will be inherited by apps unless they explicitly override
6+
set( CINDER_CXX_STANDARD @CINDER_CXX_STANDARD@ )
7+
set( CINDER_CXX_EXTENSIONS @CINDER_CXX_EXTENSIONS@ )
38
endif()
49

510

proj/cmake/modules/cinderMakeApp.cmake

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,36 @@ function( ci_make_app )
129129
target_include_directories( ${ARG_APP_NAME} PUBLIC ${ARG_INCLUDES} )
130130
target_link_libraries( ${ARG_APP_NAME} PUBLIC cinder ${ARG_LIBRARIES} )
131131

132+
# Determine C++ standard: user override > Cinder's standard > 17
133+
if( CMAKE_CXX_STANDARD )
134+
set( APP_CXX_STANDARD ${CMAKE_CXX_STANDARD} )
135+
elseif( DEFINED CINDER_CXX_STANDARD )
136+
set( APP_CXX_STANDARD ${CINDER_CXX_STANDARD} )
137+
else()
138+
set( APP_CXX_STANDARD 17 )
139+
endif()
140+
141+
if( APP_CXX_STANDARD LESS 17 )
142+
message( FATAL_ERROR "Cinder requires C++17 or later. App is configured to use C++${APP_CXX_STANDARD}" )
143+
endif()
144+
145+
target_compile_features( ${ARG_APP_NAME} PUBLIC cxx_std_${APP_CXX_STANDARD} )
146+
147+
# Determine CXX_EXTENSIONS: inherit from Cinder, or default OFF (prevents "namespace linux" issue)
148+
if( DEFINED CMAKE_CXX_EXTENSIONS )
149+
set( APP_CXX_EXTENSIONS ${CMAKE_CXX_EXTENSIONS} )
150+
elseif( DEFINED CINDER_CXX_EXTENSIONS )
151+
set( APP_CXX_EXTENSIONS ${CINDER_CXX_EXTENSIONS} )
152+
else()
153+
set( APP_CXX_EXTENSIONS OFF )
154+
endif()
155+
156+
set_target_properties( ${ARG_APP_NAME} PROPERTIES
157+
CXX_STANDARD ${APP_CXX_STANDARD}
158+
CXX_STANDARD_REQUIRED ON
159+
CXX_EXTENSIONS ${APP_CXX_EXTENSIONS}
160+
)
161+
132162
if( MSVC )
133163
# Ignore Specific Default Libraries for Debug build
134164
set_target_properties( ${ARG_APP_NAME} PROPERTIES LINK_FLAGS_DEBUG "/NODEFAULTLIB:LIBCMT /NODEFAULTLIB:LIBCPMT" )

0 commit comments

Comments
 (0)