Skip to content

Commit d4a7ff2

Browse files
authored
Ability to choose between CXX standards (FloopCZ#185)
Ability to choose between CXX standards and not stuck in C++11 only
2 parents 775609e + ac413e5 commit d4a7ff2

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

tensorflow_cc/CMakeLists.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ option(ALLOW_CUDA "When building the shared library, try to find and use CUDA."
1212
option(TENSORFLOW_STATIC "Build static library." ON)
1313
set(TENSORFLOW_TAG "v1.15.0" CACHE STRING "The tensorflow release tag to be checked out (default v1.15.0).")
1414
option(SYSTEM_PROTOBUF "Use system protobuf instead of static protobuf from contrib/makefile." OFF)
15+
set(TARGET_CXX_STANDARD "cxx_std_11" CACHE STRING "C++ standard to be enforced when linking to TensorflowCC targets (e.g., cxx_std_11).")
1516

1617
# -------------
1718
# CMake Options
@@ -23,6 +24,9 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib")
2324
include(CMakePackageConfigHelpers)
2425
set(CMAKECFG_INSTALL_DIR lib/cmake/TensorflowCC)
2526

27+
set_property(CACHE TARGET_CXX_STANDARD PROPERTY STRINGS
28+
"cxx_std_11" "cxx_std_14" "cxx_std_17" "cxx_std_20")
29+
2630
# Configure the build_tensorflow script.
2731
configure_file("cmake/build_tensorflow.sh.in" "build_tensorflow.sh" @ONLY)
2832

@@ -58,10 +62,8 @@ endif()
5862

5963
if(TENSORFLOW_SHARED)
6064
add_library(tensorflow_cc_shared INTERFACE)
61-
target_compile_options(
62-
tensorflow_cc_shared INTERFACE
63-
"$<$<COMPILE_LANGUAGE:CXX>:-std=c++11>"
64-
)
65+
target_compile_features(tensorflow_cc_shared INTERFACE ${TARGET_CXX_STANDARD})
66+
6567
add_dependencies(
6668
tensorflow_cc_shared
6769
tensorflow_shared
@@ -109,10 +111,8 @@ endif()
109111

110112
if(TENSORFLOW_STATIC)
111113
add_library(tensorflow_cc_static INTERFACE)
112-
target_compile_options(
113-
tensorflow_cc_static INTERFACE
114-
"$<$<COMPILE_LANGUAGE:CXX>:-std=c++11>"
115-
)
114+
target_compile_features(tensorflow_cc_static INTERFACE ${TARGET_CXX_STANDARD})
115+
116116
add_dependencies(
117117
tensorflow_cc_static
118118
tensorflow_static

0 commit comments

Comments
 (0)