Skip to content

Commit 5994cbe

Browse files
authored
Merge pull request #269 from FloopCZ/cxx_17
Add C++17 support
2 parents f3bea44 + 353bfee commit 5994cbe

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

tensorflow_cc/CMakeLists.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ project(
66
VERSION ${version}
77
)
88

9-
# If enabled, bazel has to be installed.
109
option(ALLOW_CUDA "Try to find and use CUDA." ON)
1110
option(REQUIRE_CUDA "Make sure to find and use CUDA (implies ALLOW_CUDA)." OFF)
1211
set(LOCAL_RAM_RESOURCES 4096 CACHE STRING "The amount of local RAM resources passed to bazel scheduler (e.g., 4096).")
1312
set(LOCAL_CPU_RESOURCES HOST_CPUS CACHE STRING "The amount of local CPU cores passed to bazel scheduler (e.g., 2).")
1413
set(TENSORFLOW_TAG "v${version}" CACHE STRING "The tensorflow release tag to be checked out (default v${version}).")
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).")
14+
set(CMAKE_CXX_STANDARD 14 CACHE STRING "The C++ standard for building and linking the library (e.g., 14).")
1615

1716
# -------------
1817
# CMake Options
@@ -24,9 +23,6 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib")
2423
include(CMakePackageConfigHelpers)
2524
set(CMAKECFG_INSTALL_DIR lib/cmake/TensorflowCC)
2625

27-
set_property(CACHE TARGET_CXX_STANDARD PROPERTY STRINGS
28-
"cxx_std_11" "cxx_std_14" "cxx_std_17" "cxx_std_20")
29-
3026
# Configure the build_tensorflow script.
3127
configure_file("cmake/build_tensorflow.sh.in" "build_tensorflow.sh" @ONLY)
3228

@@ -41,7 +37,7 @@ include(TensorflowBase)
4137
# ------------------------------
4238

4339
add_library(tensorflow_cc INTERFACE)
44-
target_compile_features(tensorflow_cc INTERFACE ${TARGET_CXX_STANDARD})
40+
target_compile_features(tensorflow_cc INTERFACE "cxx_std_${CMAKE_CXX_STANDARD}")
4541

4642
# The include folders are sometimes contained under bazel-bin/bin/ and sometimes just bazel-bin.
4743
target_include_directories(

tensorflow_cc/cmake/build_tensorflow.sh.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ else
9393
export TF_NEED_CUDA=0
9494
fi
9595

96+
# set bazel options for c++17 standard if necessary
97+
cxx_std_opts=""
98+
if [ "@CMAKE_CXX_STANDARD@" == 17 ]; then
99+
echo "Using C++17 standard"
100+
cxx_std_opts="--config=c++17_gcc"
101+
fi
102+
96103
# configure and build
97104
./configure
98105
JVM_RAM_RESOURCES=$((@LOCAL_RAM_RESOURCES@ / 4))
@@ -103,6 +110,7 @@ bazel --host_jvm_args="-Xmx${JVM_RAM_RESOURCES}m" \
103110
--local_ram_resources=@LOCAL_RAM_RESOURCES@ \
104111
--local_cpu_resources=@LOCAL_CPU_RESOURCES@ \
105112
--discard_analysis_cache \
113+
$cxx_std_opts \
106114
$cuda_config_opts \
107115
tensorflow:libtensorflow_cc.so \
108116
tensorflow:install_headers

0 commit comments

Comments
 (0)