Unverified Commit 1f3e3837 authored by James Lamb's avatar James Lamb Committed by GitHub
Browse files

[c++] default to C++17 for most builds (#7016)

* [c++] default to C++17 for most builds

* more updates

* fix formatting
parent 6368375b
...@@ -28,7 +28,7 @@ repos: ...@@ -28,7 +28,7 @@ repos:
- id: cpplint - id: cpplint
args: args:
- --recursive - --recursive
- --filter=-build/c++11,-build/include_subdir,-build/include_what_you_use,-build/header_guard,-whitespace/indent_namespace,-whitespace/line_length - --filter=-build/include_subdir,-build/include_what_you_use,-build/header_guard,-whitespace/indent_namespace,-whitespace/line_length
- repo: local - repo: local
hooks: hooks:
- id: check-omp-pragmas - id: check-omp-pragmas
......
...@@ -36,13 +36,7 @@ endif() ...@@ -36,13 +36,7 @@ endif()
project(lightgbm LANGUAGES C CXX) project(lightgbm LANGUAGES C CXX)
if(USE_CUDA) set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 17)
elseif(BUILD_CPP_TEST)
set(CMAKE_CXX_STANDARD 14)
else()
set(CMAKE_CXX_STANDARD 11)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules") list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules")
...@@ -72,22 +66,19 @@ endif() ...@@ -72,22 +66,19 @@ endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.8.2") if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.8.2")
message(FATAL_ERROR "Insufficient gcc version") message(FATAL_ERROR "Insufficient gcc version (${CMAKE_CXX_COMPILER_VERSION})")
endif() endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.8") if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.8")
message(FATAL_ERROR "Insufficient Clang version") message(FATAL_ERROR "Insufficient Clang version (${CMAKE_CXX_COMPILER_VERSION})")
endif() endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.1.0") if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.1.0")
message(FATAL_ERROR "Insufficient AppleClang version") message(FATAL_ERROR "Insufficient AppleClang version (${CMAKE_CXX_COMPILER_VERSION})")
endif() endif()
elseif(MSVC) elseif(MSVC)
if(MSVC_VERSION LESS 1900) if(MSVC_VERSION LESS 1900)
message( message(FATAL_ERROR "Insufficient MSVC version (${MSVC_VERSION})")
FATAL_ERROR
"The compiler ${CMAKE_CXX_COMPILER} doesn't support required C++11 features. Please use a newer MSVC."
)
endif() endif()
endif() endif()
......
...@@ -67,13 +67,20 @@ The steps above should work on most systems, but users with highly-customized en ...@@ -67,13 +67,20 @@ The steps above should work on most systems, but users with highly-customized en
To change the compiler used when installing the CRAN package, you can create a file `~/.R/Makevars` which overrides `CC` (`C` compiler) and `CXX` (`C++` compiler). To change the compiler used when installing the CRAN package, you can create a file `~/.R/Makevars` which overrides `CC` (`C` compiler) and `CXX` (`C++` compiler).
For example, to use `gcc` instead of `clang` on Mac, you could use something like the following: For example, to use `gcc-14` instead of `clang` on macOS, you could use something like the following:
```make ```make
# ~/.R/Makevars # ~/.R/Makevars
CC=gcc-8 CC=gcc-14
CXX=g++-8 CC17=gcc-14
CXX11=g++-8 CXX=g++-14
CXX17=g++-14
```
To check the values R is using, run the following:
```shell
R CMD config --all
``` ```
### Installing from Source with CMake <a id="install"></a> ### Installing from Source with CMake <a id="install"></a>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment