Skip to content

Commit

Permalink
Fix cmake for intel & clang compilers (#403)
Browse files Browse the repository at this point in the history
* Updating cmakelists. In the future we should make more use of macros

* fixing template instantations

* fix gitignore
  • Loading branch information
landinjm authored Jan 15, 2025
1 parent c32e0b0 commit fad394c
Show file tree
Hide file tree
Showing 72 changed files with 732 additions and 5,412 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ build/*
CMakeFiles/
CMakeCache.txt
*.cmake
!cmake/*.cmake
Makefile
.ninja*
build.ninja
Expand Down
52 changes: 42 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
# Adapted from the ASPECT CMake file
##

cmake_minimum_required(VERSION 3.3.0)

project(prisms_pf)
cmake_minimum_required(VERSION 3.8.0)

file(STRINGS "${CMAKE_SOURCE_DIR}/VERSION" PRISMS_PF_VERSION LIMIT_COUNT 1)

Expand All @@ -27,6 +25,14 @@ if(EXISTS ${CMAKE_SOURCE_DIR}/CMakeCache.txt)
"Please delete the file before running cmake again.")
endif()

# Print the current cmake version
message(STATUS "CMake version: ${CMAKE_VERSION}")

# Set the standard to C++17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# Setup the build type (debug, release, debugrelease)
if("${CMAKE_BUILD_TYPE}" STREQUAL "")
set(CMAKE_BUILD_TYPE "DebugRelease"
Expand Down Expand Up @@ -93,12 +99,41 @@ if(NOT DEAL_II_WITH_P4EST)
set(DEALII_INSTALL_VALID OFF)
endif()

if(NOT DEAL_II_WITH_MPI)
message(SEND_ERROR
"\n**deal.II was built without support for MPI!\n"
)
set(DEALII_INSTALL_VALID OFF)
endif()

if(NOT DEALII_INSTALL_VALID)
message(FATAL_ERROR
"\nPRISMS-PF requires a deal.II installation with certain features enabled!\n"
)
endif()

# Optional deal.II packages
set(PRISMS_PF_WITH_ZLIB OFF CACHE BOOL "Whether the user wants to compile PRISMS-PF with deal.II's zlib dependency, or not.")
message(STATUS "Using PRISMS_PF_WITH_ZLIB = '${PRISMS_PF_WITH_ZLIB}'")
if(PRISMS_PF_WITH_ZLIB)
if(DEAL_II_WITH_ZLIB)
message(STATUS " Found deal.II installation with zlib")
else()
message(FATAL_ERROR "deal.II installation with zlib not found. Disable PRISMS_PF_WITH_ZLIB or recompile deal.II with zlib.")
endif()
endif()

set(PRISMS_PF_WITH_SUNDIALS OFF CACHE BOOL "Whether the user wants to compile PRISMS-PF with deal.II's SUNDIALS dependency, or not.")
message(STATUS "Using PRISMS_PF_WITH_SUNDIALS = '${PRISMS_PF_WITH_SUNDIALS}'")
if(PRISMS_PF_WITH_SUNDIALS)
if(DEAL_II_WITH_SUNDIALS)
message(STATUS " Found deal.II installation with SUNDIALS")
else()
message(FATAL_ERROR "deal.II installation with SUNDIALS not found. Disable PRISMS_PF_WITH_SUNDIALS or recompile deal.II with SUNDIALS.")
endif()
endif()

# Load deal.II cached variables
deal_ii_initialize_cached_variables()

# Caliper
Expand All @@ -108,7 +143,7 @@ if(PRISMS_PF_WITH_CALIPER)
find_package(CALIPER)
if(${CALIPER_FOUND})
include_directories(${CALIPER_INCLUDE_DIR})
message(STATUS "Caliper found at ${CALIPER_DIR}")
message(STATUS " Caliper found at ${CALIPER_DIR}")
else()
message(FATAL_ERROR "Caliper not found. Disable PRISMS_PF_WITH_CALIPER or specify a hint to your installation directory with CALIPER_DIR")
endif()
Expand All @@ -128,6 +163,8 @@ message(STATUS "Configuring PRISMS-PF build targets")
message(STATUS "=========================================================")
message(STATUS "")

project(prisms_pf CXX)

# Generate config.h to enable and disable certain features within the source code.
set(PRISMS_PF_SOURCE_DIR ${CMAKE_SOURCE_DIR})

Expand All @@ -137,12 +174,7 @@ configure_file(
)

# Collect source files
file(GLOB_RECURSE PRISMS_PF_SOURCE_FILES "src/*.cc" "include/*.h")
file(GLOB_RECURSE PRISMS_PF_UNIT_TEST_FILES "unit_tests/*.cc" "contrib/catch/catch.hpp")

# Setup include directories
include_directories(BEFORE ${CMAKE_BINARY_DIR}/include include)
include_directories(AFTER contrib/catch)
add_subdirectory(src)

# Test stuff goes here

Expand Down
138 changes: 3 additions & 135 deletions applications/CHAC_anisotropy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,137 +3,11 @@
# Adapted from the ASPECT CMake file
##

cmake_minimum_required(VERSION 3.3.0)
cmake_minimum_required(VERSION 3.8.0)

project(myapp)
include(${CMAKE_SOURCE_DIR}/../../cmake/setup_application.cmake)

message(STATUS "")
message(STATUS "=========================================================")
message(STATUS "Configuring PRISMS-PF application")
message(STATUS "=========================================================")
message(STATUS "")

# Setup the build type (debug, release, debugrelease)
if("${CMAKE_BUILD_TYPE}" STREQUAL "")
set(CMAKE_BUILD_TYPE "DebugRelease"
CACHE STRING
"Choose the type of build, options are: Debug, Release and DebugRelease."
FORCE)
endif()

# Convert build type into the debug and release builds, which may or may
# not be built.
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release" OR
"${CMAKE_BUILD_TYPE}" STREQUAL "Debug" OR
"${CMAKE_BUILD_TYPE}" STREQUAL "DebugRelease" )
message(STATUS "Setting up PRISMS-PF application for ${CMAKE_BUILD_TYPE} mode.")
else()
message(FATAL_ERROR
"CMAKE_BUILD_TYPE must either be 'Release', 'Debug', or 'DebugRelease', but is set to '${CMAKE_BUILD_TYPE}'.")
endif()

if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug" OR
"${CMAKE_BUILD_TYPE}" STREQUAL "DebugRelease")
set(PRISMS_PF_BUILD_DEBUG "ON")
else()
set(PRISMS_PF_BUILD_DEBUG "OFF")
endif()

if("${CMAKE_BUILD_TYPE}" STREQUAL "Release" OR
"${CMAKE_BUILD_TYPE}" STREQUAL "DebugRelease")
set(PRISMS_PF_BUILD_RELEASE "ON")
else()
set(PRISMS_PF_BUILD_RELEASE "OFF")
endif()

# Find deal.II installation
find_package(deal.II 9.6.0 QUIET
HINTS ${DEAL_II_DIR} $ENV{DEAL_II_DIR}
)
if(NOT ${deal.II_FOUND})
message(FATAL_ERROR "\n*** Could not find a recent version of deal.II. ***\n"
"You may want to either pass a flag -DDEAL_II_DIR=/path/to/deal.II to cmake "
"or set an environment variable \"DEAL_II_DIR\" that contains a path to a "
"recent version of deal.II."
)
endif()

message(STATUS "Found deal.II version ${DEAL_II_PACKAGE_VERSION} at '${deal.II_DIR}'")

set(DEALII_INSTALL_VALID ON)

if(NOT DEAL_II_WITH_P4EST)
message(SEND_ERROR
"\n**deal.II was built without support for p4est!\n"
)
set(DEALII_INSTALL_VALID OFF)
endif()

if(NOT DEALII_INSTALL_VALID)
message(FATAL_ERROR
"\nPRISMS-PF requires a deal.II installation with certain features enabled!\n"
)
endif()

deal_ii_initialize_cached_variables()

# Make and ninja build options
if(CMAKE_GENERATOR MATCHES "Ninja")
set(_make_command "$ ninja")
else()
set(_make_command " $ make")
endif()

# Debug and release targets
if(${DEAL_II_BUILD_TYPE} MATCHES "DebugRelease")
add_custom_target(release
COMMAND ${CMAKE_COMMAND} -D CMAKE_BUILD_TYPE=Release .
COMMAND ${CMAKE_COMMAND} -E echo "***"
COMMAND ${CMAKE_COMMAND} -E echo "*** Switched to Release mode. Now recompile with: ${_make_command}"
COMMAND ${CMAKE_COMMAND} -E echo "***"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
VERBATIM
COMMENT "switching to RELEASE mode..."
)

add_custom_target(debug
COMMAND ${CMAKE_COMMAND} -D CMAKE_BUILD_TYPE=Debug .
COMMAND ${CMAKE_COMMAND} -E echo "***"
COMMAND ${CMAKE_COMMAND} -E echo "*** Switched to Debug mode. Now recompile with: ${_make_command}"
COMMAND ${CMAKE_COMMAND} -E echo "***"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
VERBATIM
COMMENT "switching to DEBUG mode..."
)

add_custom_target(debugrelease
COMMAND ${CMAKE_COMMAND} -D CMAKE_BUILD_TYPE=DebugRelease .
COMMAND ${CMAKE_COMMAND} -E echo "***"
COMMAND ${CMAKE_COMMAND} -E echo "*** Switched to Debug and Release mode. Now recompile with: ${_make_command}"
COMMAND ${CMAKE_COMMAND} -E echo "***"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
VERBATIM
COMMENT "switching to DEBUG/RELEASE mode..."
)
endif()

# Add distclean target to clean build
add_custom_target(distclean
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target clean
COMMAND ${CMAKE_COMMAND} -E remove_directory CMakeFiles
COMMAND ${CMAKE_COMMAND} -E remove
CMakeCache.txt cmake_install.cmake Makefile
build.ninja rules.ninja .ninja_deps .ninja_log
COMMENT "distclean invoked"
)

# Add postprocess.cc and nucleation.cc if they exist
if(EXISTS "postprocess.cc")
add_definitions(-DPOSTPROCESS_FILE_EXISTS)
endif()
if(EXISTS "nucleation.cc")
add_definitions(-DNUCLEATION_FILE_EXISTS)
endif()
project(myapp CXX)

# Set location of files
include_directories(${CMAKE_SOURCE_DIR}/../../include)
Expand All @@ -143,12 +17,6 @@ include_directories(${CMAKE_SOURCE_DIR})
# Set the location of the main.cc file
set(TARGET_SRC "${CMAKE_SOURCE_DIR}/../main.cc")

# Check if there has been updates to main library
set(dir ${PROJECT_SOURCE_DIR}/../..)
EXECUTE_PROCESS(COMMAND "rm" "CMakeCache.txt" WORKING_DIRECTORY ${dir})
EXECUTE_PROCESS(COMMAND "cmake" "CMakeLists.txt" WORKING_DIRECTORY ${dir})
EXECUTE_PROCESS(COMMAND "make" WORKING_DIRECTORY ${dir})

# Set targets & link libraries for the build type
if(${PRISMS_PF_BUILD_DEBUG} STREQUAL "ON")
add_executable(main_debug ${TARGET_SRC})
Expand Down
Loading

0 comments on commit fad394c

Please sign in to comment.