[CMake] Adds code to automatically get the target standard
cmake_minimum_required(VERSION 3.7)
+# Gets the Clava standard automatically from the provided target
+#
+# Parameter 1: _target - The target that we will query
+# Parameter 2: _std - The variable that will hold the standard flag string (output parameter)
+function(clava_get_target_std _target _std)
+ get_property(_cxxs TARGET ${_target} PROPERTY CXX_STANDARD)
+ get_property(_cxxe TARGET ${_target} PROPERTY CXX_EXTENSIONS)
+ get_property(_cs TARGET ${_target} PROPERTY C_STANDARD)
+ get_property(_ce TARGET ${_target} PROPERTY C_EXTENSIONS)
+
+ if(${_cxxs})
+ # C++ is on
+ if(${_cxxe})
+ # gnu is on
+ set(${_std} "-std gnu++${_cxxs}" PARENT_SCOPE)
+ else()
+ # gnu is off
+ set(${_std} "-std c++${_cxxs}" PARENT_SCOPE)
+ endif()
+ elseif(${_cs})
+ # C is on
+ if(${_ce})
+ # gnu is on
+ set(${_std} "-std gnu${_cs}" PARENT_SCOPE)
+ else()
+ # gnu is off
+ set(${_std} "-std c${_cs}" PARENT_SCOPE)
+ endif()
+ else()
+ # error?
+ # neither standard is explicitly defined, assume the user will provide one
+ set(${_std} "" PARENT_SCOPE)
+ endif()
+endfunction(clava_get_target_std)
+
# Applies a LARA file to the given target.
#
# Sources and includes of the target will be updated in order to point to the code generated by Clava.
@@ -21,6 +56,10 @@ function(clava_weave ORIG_TARGET ASPECT)
#message(STATUS "WEAVER_ARGS: " ${CLAVA_WEAVE_FLAGS})
#message(STATUS "JAVA_ARGS: " ${CLAVA_WEAVE_JAVA_FLAGS})
+ # Get standard automatically from the target and append to CLAVA_WEAVE_FLAGS
+ clava_get_target_std(${ORIG_TARGET} CLAVA_STD_FLAG)
+ set(CLAVA_WEAVE_FLAGS "${CLAVA_STD_FLAG} ${CLAVA_WEAVE_FLAGS}")
+
# Create aspect arguments
if(NOT ("${CLAVA_WEAVE_ARGS}" STREQUAL ""))
set(ASPECT_ARGS_FLAG "-av")
