Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop CMake < 3.18 Support #661

Merged
merged 4 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/Draft-Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ jobs:
run: |
# Install ubuntu-20.04 packages
if [ "$OS" == 'ubuntu-20.04' ]; then
sudo apt-get install -y libglew-dev libglu1-mesa-dev libfontconfig1-dev libsdl2-dev libdevil-dev libfreetype-dev
sudo apt-get install -y libglew-dev libfontconfig1-dev libsdl2-dev libdevil-dev libfreetype-dev
fi
# Install Ubuntu 18.04 packages
if [ "$OS" == 'ubuntu-18.04' ]; then
sudo apt-get install -y libglew-dev libglu1-mesa-dev libfontconfig1-dev libsdl2-dev libdevil-dev libfreetype6-dev libgl1-mesa-dev
sudo apt-get install -y libglew-dev libfontconfig1-dev libsdl2-dev libdevil-dev libfreetype6-dev libgl1-mesa-dev
fi

- name: Configure cmake
Expand Down Expand Up @@ -340,7 +340,7 @@ jobs:
- name: Install Visualisation Dependencies (CentOS)
if: ${{ env.VISUALISATION == 'ON' }}
run: |
yum install -y mesa-libGLU-devel glew-devel fontconfig-devel SDL2-devel freetype-devel
yum install -y glew-devel fontconfig-devel SDL2-devel freetype-devel
# Build/Install DevIL from source.
yum install -y freeglut-devel
git clone --depth 1 https://github.com/DentonW/DevIL.git
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Manylinux2014.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jobs:
- name: Install Visualisation Dependencies (CentOS)
if: ${{ env.VISUALISATION == 'ON' }}
run: |
yum install -y mesa-libGLU-devel glew-devel fontconfig-devel SDL2-devel freetype-devel
yum install -y glew-devel fontconfig-devel SDL2-devel freetype-devel
# Build/Install DevIL from source.
yum install -y freeglut-devel
git clone --depth 1 https://github.com/DentonW/DevIL.git
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/Ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ jobs:
run: |
# Install ubuntu-20.04 packages
if [ "$OS" == 'ubuntu-20.04' ]; then
sudo apt-get install -y libglew-dev libglu1-mesa-dev libfontconfig1-dev libsdl2-dev libdevil-dev libfreetype-dev
sudo apt-get install -y libglew-dev libfontconfig1-dev libsdl2-dev libdevil-dev libfreetype-dev
fi
# Install Ubuntu 18.04 packages
if [ "$OS" == 'ubuntu-18.04' ]; then
sudo apt-get install -y libglew-dev libglu1-mesa-dev libfontconfig1-dev libsdl2-dev libdevil-dev libfreetype6-dev libgl1-mesa-dev
sudo apt-get install -y libglew-dev libfontconfig1-dev libsdl2-dev libdevil-dev libfreetype6-dev libgl1-mesa-dev
fi

- name: Configure cmake
Expand Down
51 changes: 17 additions & 34 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# CMake 3.15+ for Thrust/Cub support
cmake_minimum_required(VERSION VERSION 3.15 FATAL_ERROR)
# Minimum CMake version 3.18 for CUDA --std=c++17
cmake_minimum_required(VERSION VERSION 3.18 FATAL_ERROR)

# Emit a deprecation warning if CMAKE < 3.18 which is required for c++17 in the future.
set(CMAKE_MINIMUM_SUPPORTED_VERSION 3.18)
if(${CMAKE_VERSION} VERSION_LESS ${CMAKE_MINIMUM_SUPPORTED_VERSION})
message(DEPRECATION "Support for CMake < ${CMAKE_MINIMUM_SUPPORTED_VERSION} is deprecated and will be removed in a future release.")
endif()
project(FLAMEGPU LANGUAGES NONE)

# Find the root directory
get_filename_component(FLAMEGPU_ROOT ${CMAKE_CURRENT_SOURCE_DIR} REALPATH)

project(FLAMEGPU LANGUAGES NONE)
# Ensure this is not an in-source build
include(${FLAMEGPU_ROOT}/cmake/OutOfSourceOnly.cmake)

# Don't create installation scripts (and hide CMAKE_INSTALL_PREFIX from cmake-gui)
set(CMAKE_SKIP_INSTALL_RULES TRUE)
Expand All @@ -17,38 +16,23 @@ set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" CACHE INTERNAL "" FORCE)
# If sufficiently new and working CXX / CUDA compilers are not available, then documentation only build is the only option.
set(DOCUMENTATION_ONLY_BUILD OFF)

# Check if CXX is available, if so enable it.
# Check compiler functionailty, as there are known issues in some cases, but version checks are not always sufficient.
include(./cmake/CheckCompilerFunctionality.cmake)
# If this returned a negative result, set the docs only build.
if(NOT CheckCompilerFunctionality_RESULT)
set(DOCUMENTATION_ONLY_BUILD ON)
message(STATUS "Documentation-only build: due to Compiler compatability version. See prior warnings.")
endif()

# If the checks passed, enable CXX and CUDA languages
include(CheckLanguage)
check_language(CXX)
if(CMAKE_CXX_COMPILER)
enable_language(CXX)
else()
set(DOCUMENTATION_ONLY_BUILD ON)
message(STATUS "Documentation-only build: CXX compiler required for compilation.")
endif()
# Check if CUDA is available, if so enable it.
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
enable_language(CUDA)
else()
set(DOCUMENTATION_ONLY_BUILD ON)
message(STATUS "Documentation-only build: CUDA toolkit required for compilation.")
endif()

# The CXX host compiler must be sufficiently new for certain build options.
# Additionally, there are some known bad versions which do not agree with CUDA when used to build FLAMEGPU
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# g++ 6 is the minimum required G++ version (if it is supported by the current NVCC)
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6)
set(DOCUMENTATION_ONLY_BUILD ON)
message(STATUS "Documentation-only build: GCC/G++ >= 6 is required for compilation.")
endif()
# GCC 10.3 and 11.1 contain a bug in <chrono> which is exposed by CUDA (or just when used on its own). Block these versions.
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100102
if(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 10.3.0 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 11.1.0)
set(DOCUMENTATION_ONLY_BUILD ON)
message(STATUS "Documentation-only build: GCC ${CMAKE_CXX_COMPILER_VERSION} is incompatible with CUDA due to a GCC bug.")
endif()
endif()

# CUDA 10.0 is the current minimum working but deprecated verison, which will be removed.
Expand All @@ -69,8 +53,7 @@ endif()
# If CUDA is not available, or the minimum version is too low only build the docs.
if(DOCUMENTATION_ONLY_BUILD)
# Not able to build code, so just make docs
get_filename_component(FLAMEGPU_ROOT ${CMAKE_CURRENT_SOURCE_DIR} REALPATH)
include(./cmake/doxygen.cmake)
include(./cmake/dependencies/doxygen.cmake)
if(${BUILD_API_DOCUMENTATION})
create_doxygen_target("${FLAMEGPU_ROOT}" "${CMAKE_CURRENT_BINARY_DIR}" "")
endif()
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ This is used to build the FLAMEGPU2 library, examples, tests and documentation.
Building FLAME GPU has the following requirements. There are also optional dependencies which are required for some components, such as Documentation or Python bindings.

+ [CMake](https://cmake.org/download/) `>= 3.18`
+ CMake `>= 3.15` currently works, but support will be dropped in a future release.
+ [CUDA](https://developer.nvidia.com/cuda-downloads) `>= 11.0` and a [Compute Capability](https://developer.nvidia.com/cuda-gpus) `>= 3.5` NVIDIA GPU.
+ CUDA `>= 10.0` currently works, but support will be dropped in a future release.
+ C++17 capable C++ compiler (host), compatible with the installed CUDA version
Expand Down
80 changes: 80 additions & 0 deletions cmake/CheckCompilerFunctionality.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Define a cmake function which checks that CUDA and the host compiler are functional.
function(CheckCompilerFunctionality)
# If the result variable is already defined, this has already been called once, so don't check agian.
if(DEFINED CheckCompilerFunctionality_RESULT)
return()
endif()

# Ensure that required languages are avialable.
# Enabling the languages must however be perfomed in file scope, so do this in the root cmake after docs only checks have been found.
include(CheckLanguage)
check_language(CXX)
if(NOT CMAKE_CXX_COMPILER)
message(WARNING "CXX Language Support Not Found")
set(CheckCompilerFunctionality_RESULT "NO" PARENT_SCOPE)
return()
endif()
enable_language(CXX)
check_language(CUDA)
if(NOT CMAKE_CUDA_COMPILER)
message(WARNING "CUDA Language Support Not Found")
set(CheckCompilerFunctionality_RESULT "NO" PARENT_SCOPE)
return()
endif()
enable_language(CUDA)

# Original releases of GCC 10.3.0 and 11.1.0 included a bug preventing the use of <chrono> in <nvcc>.
# This was patched in subsequent versions, and backported in the release branches, but the broken version is still distributed in some cases (i.e. Ubuntu 20.04, but not 21.04).
# See https://github.com/FLAMEGPU/FLAMEGPU2/issues/575, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100102
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# CUDA must be available.
enable_language(CUDA)
# Try to compile the test case file for inclusion of chrono.
try_compile(
GCC_CUDA_STDCHRONO
"${CMAKE_CURRENT_BINARY_DIR}/try_compile"
"${CMAKE_CURRENT_LIST_DIR}/CheckCompilerFunctionality/CheckStdChrono.cu"
CXX_STANDARD 14
CUDA_STANDARD 14
CXX_STANDARD_REQUIRED "ON"
CMAKE_FLAGS
-DCMAKE_CUDA_ARCHITECTURES="OFF"
)
# If an error occured while building the simple
if(NOT GCC_CUDA_STDCHRONO)
# If the GCC versions is known to be bad, give an appropriate error
if(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 10.3.0 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 11.1.0)
message(WARNING
"GCC ${CMAKE_CXX_COMPILER_VERSION} is incompatible with CUDA due to a bug in the <chrono> implementation.\n"
" Please use an alternative GCC, or a patched version of GCC ${CMAKE_CXX_COMPILER_VERSION}.\n"
" \n"
" See the following for more information:\n"
" https://github.com/FLAMEGPU/FLAMEGPU2/issues/575\n"
" https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100102\n")
else()
# If the gcc version is not a known problem, emit a generic error.
message(WARNING
"<std::chrono> not usable with ${CMAKE_CUDA_COMPILER_ID} ${CMAKE_CUDA_COMPILER_VERSION} and ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}.")
endif()
# Set the result variable to a false-like value
set(CheckCompilerFunctionality_RESULT "NO" PARENT_SCOPE)
return()
endif()
endif()

# GCC > 6 is required for building the test suite with c++14.
# When C++14 is dropped, this change can be replaced, as C++14 requires GCC 7 (or maybe 8 for __cpp_deduction_guides >= 201611)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6)
set(DOCUMENTATION_ONLY_BUILD ON)
message(WARNING "GCC/G++ >= 6 is required for compilation.")
set(CheckCompilerFunctionality_RESULT "NO" PARENT_SCOPE)
return()
endif()

# If we made it this far, set the result variable to be truthy
set(CheckCompilerFunctionality_RESULT "YES" PARENT_SCOPE)
endfunction()


# Call the function imediately, so the file only needs to be included.
CheckCompilerFunctionality()
7 changes: 7 additions & 0 deletions cmake/CheckCompilerFunctionality/CheckStdChrono.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Including chrono is enough to trigger the compilation error being tested for. See:
// https://github.com/FLAMEGPU/FLAMEGPU2/issues/575
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100102
#include <chrono>

// CMake try_compile performs a link step, so main is required
int main() { return 0; }
19 changes: 19 additions & 0 deletions cmake/OutOfSourceOnly.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Define a cmake function which emits a fatal error if the source directory and binary directory are the same.
function(EnforceOutOfSourceBuilds)
# Resolve paths before comparioson to ensure comparions are accurate
get_filename_component(source_dir "${CMAKE_SOURCE_DIR}" REALPATH)
get_filename_component(binary_dir "${CMAKE_BINARY_DIR}" REALPATH)

if("${source_dir}" STREQUAL "${binary_dir}")
message(FATAL_ERROR
" In-source CMake builds are not allowed.\n"
" Use a build directory i.e. cmake -B build.\n"
" You may have to clear/delete the generated CMakeCache.txt and CMakeFiles/:\n"
" ${binary_dir}/CMakeCache.txt\n"
" ${binary_dir}/CMakeFiles/\n")
endif()
endfunction()

# Call the function imediately, so the file only needs to be included.
EnforceOutOfSourceBuilds()

Loading