Skip to content

Commit

Permalink
Update cmake to cpp 17 (#511)
Browse files Browse the repository at this point in the history
* Update cmake to cpp 17

* Update Cmake based on torch version

* Default cpp version 14
  • Loading branch information
ezerhouni authored Dec 6, 2023
1 parent 1c4fe27 commit 03ba173
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ if(NOT CMAKE_BUILD_TYPE)
endif()
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")

set(CMAKE_CXX_STANDARD 14 CACHE STRING "The C++ version to be used.")
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14 CACHE STRING "The C++ version to be used.")
endif()
set(CMAKE_CXX_EXTENSIONS OFF)

option(SHERPA_ENABLE_TESTS "Whether to build tests" OFF)
Expand Down
13 changes: 12 additions & 1 deletion cmake/cmake_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import setuptools
from setuptools.command.build_ext import build_ext

import torch

def is_for_pypi():
ans = os.environ.get("SHERPA_IS_FOR_PYPI", None)
Expand All @@ -24,6 +24,11 @@ def is_windows():
return platform.system() == "Windows"


def get_pytorch_version():
# if it is 1.7.1+cuda101, then strip +cuda101
return torch.__version__.split("+")[0]


try:
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel

Expand Down Expand Up @@ -77,6 +82,12 @@ def build_extension(self, ext: setuptools.extension.Extension):
print(f"Setting PYTHON_EXECUTABLE to {sys.executable}")
cmake_args += f" -DPYTHON_EXECUTABLE={sys.executable}"

major, minor = get_pytorch_version().split(".")[:2]
major = int(major)
minor = int(minor)
if major == 2 and minor >= 1:
extra_cmake_args += f" -DCMAKE_CXX_STANDARD=17 "

cmake_args += extra_cmake_args

if is_windows():
Expand Down

0 comments on commit 03ba173

Please sign in to comment.