Skip to content

Commit

Permalink
Prefix CMake build options with OCCA (#733)
Browse files Browse the repository at this point in the history
  • Loading branch information
kris-rowe authored Dec 18, 2023
1 parent 7a364ea commit 7c2fe69
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 99 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ jobs:
os: ubuntu-22.04
CC: icx
CXX: icpx
FC: ifx
CXXFLAGS: -Wno-uninitialized
FC: ifx
OCCA_COVERAGE: 0
OCCA_FORTRAN_ENABLED: 1
useCMake: true
useoneAPI: true

Expand Down Expand Up @@ -114,9 +115,9 @@ jobs:
-DCMAKE_C_COMPILER=${CC} \
-DCMAKE_CXX_COMPILER=${CXX} \
-DCMAKE_Fortran_COMPILER=${FC} \
-DENABLE_TESTS=ON \
-DENABLE_EXAMPLES=ON \
-DENABLE_FORTRAN=ON
-DOCCA_ENABLE_TESTS=ON \
-DOCCA_ENABLE_EXAMPLES=ON \
-DOCCA_ENABLE_FORTRAN=${OCCA_FORTRAN_ENABLED}
- name: CMake configure
if: ${{ matrix.useCMake && matrix.useoneAPI}}
Expand All @@ -125,16 +126,15 @@ jobs:
OCCA_CXX: ${{ matrix.CXX }}
run: |
source /opt/intel/oneapi/setvars.sh
export SYCL_ROOT=/opt/intel/oneapi/compiler/latest
cmake -S . -B build \
-DCMAKE_BUILD_TYPE="RelWithDebInfo" \
-DCMAKE_INSTALL_PREFIX=install \
-DCMAKE_C_COMPILER=${CC} \
-DCMAKE_CXX_COMPILER=${CXX} \
-DCMAKE_Fortran_COMPILER=${FC} \
-DENABLE_TESTS=ON \
-DENABLE_EXAMPLES=ON \
-DENABLE_FORTRAN=ON
-DOCCA_ENABLE_TESTS=ON \
-DOCCA_ENABLE_EXAMPLES=ON \
-DOCCA_ENABLE_FORTRAN=${OCCA_FORTRAN_ENABLED}
- name: CMake build
if: ${{ matrix.useCMake && !matrix.useoneAPI}}
Expand Down
73 changes: 36 additions & 37 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ set(CMAKE_CXX_EXTENSIONS OFF)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

option(ENABLE_OPENMP "Build with OpenMP if available" ON)
option(ENABLE_CUDA "Build with CUDA if available" ON)
option(ENABLE_OPENCL "Build with OpenCL if available" ON)
option(ENABLE_HIP "Build with HIP if available" ON)
option(ENABLE_METAL "Build with Metal if available" ON)
option(ENABLE_DPCPP "Build with SYCL/DPCPP if available" ON)

option(ENABLE_TESTS "Build tests" OFF)
option(ENABLE_EXAMPLES "Build simple examples" OFF)
option(ENABLE_FORTRAN "Enable Fortran interface" OFF)

if(ENABLE_FORTRAN)
option(OCCA_ENABLE_OPENMP "Build with OpenMP if available" ON)
option(OCCA_ENABLE_CUDA "Build with CUDA if available" ON)
option(OCCA_ENABLE_OPENCL "Build with OpenCL if available" ON)
option(OCCA_ENABLE_HIP "Build with HIP if available" ON)
option(OCCA_ENABLE_METAL "Build with Metal if available" ON)
option(OCCA_ENABLE_DPCPP "Build with SYCL/DPCPP if available" ON)

option(OCCA_ENABLE_TESTS "Build tests" OFF)
option(OCCA_ENABLE_EXAMPLES "Build simple examples" OFF)
option(OCCA_ENABLE_FORTRAN "Enable Fortran interface" OFF)

if(OCCA_ENABLE_FORTRAN)
enable_language(Fortran)
endif()

Expand Down Expand Up @@ -80,11 +80,11 @@ message("-- System : ${CMAKE_SYSTEM}")
message("-- Build type : ${CMAKE_BUILD_TYPE}")
message("-- C flags : ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPER}}")
message("-- CXX flags : ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE_UPPER}}")
if(ENABLE_FORTRAN)
if(OCCA_ENABLE_FORTRAN)
message("-- F90 flags : ${CMAKE_Fortran_FLAGS} ${CMAKE_Fortran_FLAGS_${CMAKE_BUILD_TYPE_UPPER}}")
endif()

if(ENABLE_FORTRAN)
if(OCCA_ENABLE_FORTRAN)
set(CMAKE_Fortran_MODULE_DIRECTORY ${OCCA_BUILD_DIR}/mod)
endif()
#=======================================
Expand Down Expand Up @@ -116,7 +116,7 @@ target_compile_definitions(libocca PRIVATE -DUSE_CMAKE)
#=======================================

#---[ OpenMP ]--------------------------
if(ENABLE_OPENMP)
if(OCCA_ENABLE_OPENMP)
find_package(OpenMP)

if(OPENMP_CXX_FOUND)
Expand All @@ -128,14 +128,14 @@ if(ENABLE_OPENMP)
# Use the provided imported target OpenMP::OpenMP_CXX,
# (which wraps the CXX_INCLUDE_DIRS and CXX_LIBRARIES,) to make our package relocatable
target_link_libraries(libocca PRIVATE OpenMP::OpenMP_CXX)
else(OPENMP_CXX_FOUND)
else()
set(OCCA_OPENMP_ENABLED 0)
endif(OPENMP_CXX_FOUND)
endif(ENABLE_OPENMP)
endif()
endif()
#=======================================

#---[ CUDA ]----------------------------
if(ENABLE_CUDA)
if(OCCA_ENABLE_CUDA)
find_package(CUDAToolkit)

if(CUDAToolkit_FOUND)
Expand All @@ -146,15 +146,14 @@ if(ENABLE_CUDA)

# Use the provided imported target CUDA::cuda_driver, to make our package relocatable
target_link_libraries(libocca PRIVATE CUDA::cuda_driver)

else (CUDAToolkit_FOUND)
else()
set(OCCA_CUDA_ENABLED 0)
endif(CUDAToolkit_FOUND)
endif(ENABLE_CUDA)
endif()
endif()
#=======================================

#---[ OpenCL ]--------------------------
if(ENABLE_OPENCL)
if(OCCA_ENABLE_OPENCL)
find_package(OpenCLWrapper)

if(OpenCL_FOUND)
Expand All @@ -166,14 +165,14 @@ if(ENABLE_OPENCL)
# Use the provided imported target OpenCL::OpenCL,
# (which wraps the _INCLUDE_DIRS and _LIBRARIES,) to make our package relocatable
target_link_libraries(libocca PRIVATE OpenCL::OpenCL)
else (OpenCL_FOUND)
else()
set(OCCA_OPENCL_ENABLED 0)
endif(OpenCL_FOUND)
endif(ENABLE_OPENCL)
endif()
endif()
#=======================================

#---[ SYCL/DPCPP ]-----------------------
if(ENABLE_DPCPP)
if(OCCA_ENABLE_DPCPP)
find_package(DPCPP)

if(DPCPP_FOUND)
Expand All @@ -189,11 +188,11 @@ if(ENABLE_DPCPP)
else()
set(OCCA_DPCPP_ENABLED 0)
endif()
endif(ENABLE_DPCPP)
endif()
#=======================================

#---[ HIP ]-----------------------------
if(ENABLE_HIP)
if(OCCA_ENABLE_HIP)
find_package(HIP)

if(HIP_FOUND)
Expand All @@ -210,11 +209,11 @@ if(ENABLE_HIP)
else (HIP_FOUND)
set(OCCA_HIP_ENABLED 0)
endif(HIP_FOUND)
endif(ENABLE_HIP)
endif()
#=======================================

#---[ Metal ]---------------------------
if(ENABLE_METAL AND APPLE)
if(OCCA_ENABLE_METAL AND APPLE)
find_package(METAL)

if(METAL_FOUND)
Expand Down Expand Up @@ -257,7 +256,7 @@ file(
GLOB_RECURSE OCCA_SRC_cpp
RELATIVE ${OCCA_SOURCE_DIR} "src/*.cpp")

if(ENABLE_FORTRAN)
if(OCCA_ENABLE_FORTRAN)
file(GLOB_RECURSE OCCA_SRC_f90
RELATIVE ${OCCA_SOURCE_DIR} "src/*.f90")

Expand Down Expand Up @@ -287,14 +286,14 @@ target_sources(libocca PRIVATE ${OCCA_SRC})
install(TARGETS libocca EXPORT occaExport DESTINATION lib)
install(DIRECTORY include/ DESTINATION include)

if(ENABLE_TESTS)
if(OCCA_ENABLE_TESTS)
include(CTest)
add_subdirectory(tests)
endif(ENABLE_TESTS)
endif()

if(ENABLE_EXAMPLES)
if(OCCA_ENABLE_EXAMPLES)
add_subdirectory(examples)
endif(ENABLE_EXAMPLES)
endif()

add_subdirectory(bin)

Expand Down
20 changes: 10 additions & 10 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ OCCA uses the [CMake] build system. For convenience, the shell script `configure

Example
```shell
$ CC=clang CXX=clang++ ENABLE_OPENMP="OFF" ./configure-cmake.sh
$ CC=clang CXX=clang++ OCCA_ENABLE_OPENMP="OFF" ./configure-cmake.sh
```

| Build Parameter | Description | Default |
Expand All @@ -37,15 +37,15 @@ $ CC=clang CXX=clang++ ENABLE_OPENMP="OFF" ./configure-cmake.sh
| CXXFLAGS | C++ compiler flags | *empty* |
| CC | C11 compiler| `gcc` |
| CFLAGS | C compiler flags | *empty* |
| ENABLE_CUDA | Enable use of the CUDA backend | `ON`|
| ENABLE_HIP | Enable use of the HIP backend | `ON`|
| ENABLE_DPCPP | Enable use of the DPC++ backend | `ON`|
| ENABLE_OPENCL | Enable use of the OpenCL backend | `ON`|
| ENABLE_OPENMP | Enable use of the OpenMP backend | `ON`|
| ENABLE_METAL | Enable use of the Metal backend | `ON`|
| ENABLE_TESTS | Build OCCA's test harness | `ON` |
| ENABLE_EXAMPLES | Build OCCA examples | `ON` |
| ENABLE_FORTRAN | Build the Fortran language bindings | `OFF`|
| OCCA_ENABLE_CUDA | Enable use of the CUDA backend | `ON`|
| OCCA_ENABLE_HIP | Enable use of the HIP backend | `ON`|
| OCCA_ENABLE_DPCPP | Enable use of the DPC++ backend | `ON`|
| OCCA_ENABLE_OPENCL | Enable use of the OpenCL backend | `ON`|
| OCCA_ENABLE_OPENMP | Enable use of the OpenMP backend | `ON`|
| OCCA_ENABLE_METAL | Enable use of the Metal backend | `ON`|
| OCCA_ENABLE_TESTS | Build OCCA's test harness | `ON` |
| OCCA_ENABLE_EXAMPLES | Build OCCA examples | `ON` |
| OCCA_ENABLE_FORTRAN | Build the Fortran language bindings | `OFF`|
| FC | Fortran 90 compiler | `gfortran` |
| FFLAGS | Fortran compiler flags | *empty* |

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ For convenience, the shell script `configure-cmake.sh` has been provided to driv

The following demonstrates a typical sequence of shell commands to build, test, and install occa:
```shell
$ ./configure.sh
$ ./configure-cmake.sh
$ cmake --build build --parallel <number-of-threads>
$ ctest --test-dir build --output-on-failure
$ cmake --install build --prefix install
Expand Down
2 changes: 1 addition & 1 deletion cmake/SetCompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ set(CMAKE_C_FLAGS "${SUPPORTED_WARN_C_FLAGS} ${CMAKE_C_FLAGS}")
set_optional_c_flag(SUPPORTED_WERROR_C_FLAGS "-Werror")
set(CMAKE_C_FLAGS_DEBUG "${SUPPORTED_WERROR_C_FLAGS} ${CMAKE_C_FLAGS_DEBUG}")

if (ENABLE_FORTRAN)
if (OCCA_ENABLE_FORTRAN)
include(CheckFortranCompilerFlag)

function(set_optional_fortran_flag var)
Expand Down
39 changes: 21 additions & 18 deletions configure-cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#CC=
#CXX=
#FC=
#CFLAGS=
#CXXFLAGS
#FFLAGS=

# Default build parameters
: ${BUILD_DIR:=`pwd`/build}
Expand All @@ -13,15 +16,15 @@
: ${CXX:="g++"}
: ${FC:="gfortran"}

: ${ENABLE_DPCPP:="ON"}
: ${ENABLE_OPENCL:="ON"}
: ${ENABLE_CUDA:="ON"}
: ${ENABLE_HIP="ON"}
: ${ENABLE_OPENMP="ON"}
: ${ENABLE_METAL="ON"}
: ${ENABLE_FORTRAN="OFF"}
: ${ENABLE_TESTS="ON"}
: ${ENABLE_EXAMPLES="ON"}
: ${OCCA_ENABLE_DPCPP:="ON"}
: ${OCCA_ENABLE_OPENCL:="ON"}
: ${OCCA_ENABLE_CUDA:="ON"}
: ${OCCA_ENABLE_HIP="ON"}
: ${OCCA_ENABLE_OPENMP="ON"}
: ${OCCA_ENABLE_METAL="ON"}
: ${OCCA_ENABLE_FORTRAN="OFF"}
: ${OCCA_ENABLE_TESTS="ON"}
: ${OCCA_ENABLE_EXAMPLES="ON"}

cmake -S . -B ${BUILD_DIR} \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
Expand All @@ -32,12 +35,12 @@ cmake -S . -B ${BUILD_DIR} \
-DCMAKE_CXX_FLAGS="${CXXFLAGS}" \
-DCMAKE_C_FLAGS="${CFLAGS}" \
-DCMAKE_Fortran_FLAGS="${FFLAGS}" \
-DENABLE_OPENMP=${ENABLE_OPENMP} \
-DENABLE_OPENCL=${ENABLE_OPENCL} \
-DENABLE_DPCPP=${ENABLE_DPCPP} \
-DENABLE_CUDA=${ENABLE_CUDA} \
-DENABLE_HIP=${ENABLE_HIP} \
-DENABLE_METAL=${ENABLE_METAL} \
-DENABLE_FORTRAN=${ENABLE_FORTRAN} \
-DENABLE_TESTS=${ENABLE_TESTS} \
-DENABLE_EXAMPLES=${ENABLE_EXAMPLES}
-DOCCA_ENABLE_OPENMP=${OCCA_ENABLE_OPENMP} \
-DOCCA_ENABLE_OPENCL=${OCCA_ENABLE_OPENCL} \
-DOCCA_ENABLE_DPCPP=${OCCA_ENABLE_DPCPP} \
-DOCCA_ENABLE_CUDA=${OCCA_ENABLE_CUDA} \
-DOCCA_ENABLE_HIP=${OCCA_ENABLE_HIP} \
-DOCCA_ENABLE_METAL=${OCCA_ENABLE_METAL} \
-DOCCA_ENABLE_FORTRAN=${OCCA_ENABLE_FORTRAN} \
-DOCCA_ENABLE_TESTS=${OCCA_ENABLE_TESTS} \
-DOCCA_ENABLE_EXAMPLES=${OCCA_ENABLE_EXAMPLES}
36 changes: 18 additions & 18 deletions configure-sycl-nv-cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ CXX=clang++
: ${CXX:="g++"}
: ${FC:="gfortran"}

: ${ENABLE_DPCPP:="ON"}
: ${ENABLE_OPENCL:="OFF"}
: ${ENABLE_CUDA:="ON"}
: ${ENABLE_HIP="OFF"}
: ${ENABLE_OPENMP="OFF"}
: ${ENABLE_METAL="OFF"}
: ${ENABLE_FORTRAN="OFF"}
: ${ENABLE_TESTS="ON"}
: ${ENABLE_EXAMPLES="ON"}
: ${OCCA_ENABLE_DPCPP:="ON"}
: ${OCCA_ENABLE_OPENCL:="OFF"}
: ${OCCA_ENABLE_CUDA:="ON"}
: ${OCCA_ENABLE_HIP="OFF"}
: ${OCCA_ENABLE_OPENMP="OFF"}
: ${OCCA_ENABLE_METAL="OFF"}
: ${OCCA_ENABLE_FORTRAN="OFF"}
: ${OCCA_ENABLE_TESTS="ON"}
: ${OCCA_ENABLE_EXAMPLES="ON"}

cmake -S . -B ${BUILD_DIR} \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
Expand All @@ -39,12 +39,12 @@ cmake -S . -B ${BUILD_DIR} \
-DCMAKE_CXX_FLAGS="${CXXFLAGS}" \
-DCMAKE_C_FLAGS="${CFLAGS}" \
-DCMAKE_Fortran_FLAGS="${FFLAGS}" \
-DENABLE_OPENMP=${ENABLE_OPENMP} \
-DENABLE_OPENCL=${ENABLE_OPENCL} \
-DENABLE_DPCPP=${ENABLE_DPCPP} \
-DENABLE_CUDA=${ENABLE_CUDA} \
-DENABLE_HIP=${ENABLE_HIP} \
-DENABLE_METAL=${ENABLE_METAL} \
-DENABLE_FORTRAN=${ENABLE_FORTRAN} \
-DENABLE_TESTS=${ENABLE_TESTS} \
-DENABLE_EXAMPLES=${ENABLE_EXAMPLES}
-DOCCA_ENABLE_OPENMP=${OCCA_ENABLE_OPENMP} \
-DOCCA_ENABLE_OPENCL=${OCCA_ENABLE_OPENCL} \
-DOCCA_ENABLE_DPCPP=${OCCA_ENABLE_DPCPP} \
-DOCCA_ENABLE_CUDA=${OCCA_ENABLE_CUDA} \
-DOCCA_ENABLE_HIP=${OCCA_ENABLE_HIP} \
-DOCCA_ENABLE_METAL=${OCCA_ENABLE_METAL} \
-DOCCA_ENABLE_FORTRAN=${OCCA_ENABLE_FORTRAN} \
-DOCCA_ENABLE_TESTS=${OCCA_ENABLE_TESTS} \
-DOCCA_ENABLE_EXAMPLES=${OCCA_ENABLE_EXAMPLES}
Loading

0 comments on commit 7c2fe69

Please sign in to comment.