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

Format CMake #380

Merged
merged 2 commits into from
Oct 14, 2024
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
44 changes: 44 additions & 0 deletions .cmake-format.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"format": {
"disable": false,
"line_width": 80,
"tab_size": 2,
"use_tabchars": false,
"fractional_tab_policy": "use-space",
"max_subgroups_hwrap": 2,
"max_pargs_hwrap": 6,
"max_rows_cmdline": 2,
"separate_ctrl_name_with_space": false,
"separate_fn_name_with_space": false,
"dangle_parens": false,
"dangle_align": "prefix",
"min_prefix_chars": 4,
"max_prefix_chars": 10,
"max_lines_hwrap": 2,
"line_ending": "unix",
"command_case": "canonical",
"keyword_case": "unchanged",
"always_wrap": [],
"enable_sort": true,
"autosort": false,
"require_valid_layout": false,
"layout_passes": {}
},
"markup": {
"bullet_char": "*",
"enum_char": ".",
"first_comment_is_literal": false,
"literal_comment_pattern": null,
"fence_pattern": "^\\s*([`~]{3}[`~]*)(.*)$",
"ruler_pattern": "^\\s*[^\\w\\s]{3}.*[^\\w\\s]{3}$",
"explicit_trailing_pattern": "#<",
"hashruler_min_length": 10,
"canonicalize_hashrulers": false,
"enable_markup": true
},
"encode": {
"emit_byteorder_mark": false,
"input_encoding": "utf-8",
"output_encoding": "utf-8"
},
}
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ repos:
- id: clang-format
types_or: [c++]
args: ["-style=file", "-i"]

- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.13
hooks:
- id: cmake-format
38 changes: 21 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,32 @@ find_package(Finch QUIET)
if(ExaCA_REQUIRE_FINCH OR Finch_FOUND)
set(ExaCA_ENABLE_FINCH ON)
find_package(Finch REQUIRED COMPONENTS Finch::Core Finch::ScanPaths)
message( STATUS "Finch heat transfer enabled." )
message(STATUS "Finch heat transfer enabled.")
endif()

find_package(Kokkos 4.0 REQUIRED)
find_package(MPI REQUIRED)

if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24")
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24")
cmake_policy(SET CMP0135 NEW)
endif()
option(ExaCA_REQUIRE_EXTERNAL_JSON "Build without automatic JSON dependency download" OFF)
option(ExaCA_REQUIRE_EXTERNAL_JSON
"Build without automatic JSON dependency download" OFF)
if(ExaCA_REQUIRE_EXTERNAL_JSON)
find_package(nlohmann_json 3.10.0 REQUIRED)
else()
find_package(nlohmann_json 3.10.0 QUIET)
if(NOT NLOHMANN_JSON_FOUND)
include(FetchContent)
# Using most recent release here
FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz)
FetchContent_Declare(
json
URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz
)
FetchContent_MakeAvailable(json)
# Needs to be installed only in this case.
install(TARGETS nlohmann_json
install(
TARGETS nlohmann_json
EXPORT ExaCA_Targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
Expand All @@ -40,34 +45,32 @@ endif()

find_package(Git)
if(GIT_FOUND AND IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/.git)
EXECUTE_PROCESS(
COMMAND ${GIT_EXECUTABLE} log --pretty=format:%H -n 1
execute_process(
COMMAND ${GIT_EXECUTABLE} log --pretty=format:%H -n 1
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE ExaCA_GIT_COMMIT_HASH
)
OUTPUT_VARIABLE ExaCA_GIT_COMMIT_HASH)
else()
set(ExaCA_GIT_COMMIT_HASH "Not a git repository")
endif()
message(STATUS "ExaCA commit: ${ExaCA_GIT_COMMIT_HASH}")

# NOTE: this order is specifically used in the unit tests.
# FIXME: remove PTHREAD
# NOTE: this order is specifically used in the unit tests. FIXME: remove PTHREAD
set(EXACA_SUPPORTED_DEVICES SERIAL PTHREAD THREADS OPENMP CUDA HIP)

add_subdirectory(src)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/ExaCAconfig.cmakein
${CMAKE_CURRENT_BINARY_DIR}/ExaCAconfig.cmake @ONLY)
${CMAKE_CURRENT_BINARY_DIR}/ExaCAconfig.cmake @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ExaCAconfig.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ExaCA)
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ExaCA)

# Install data files
file(GLOB MATERIALS examples/Materials/*)
file(GLOB SUBSTRATE examples/Substrate/GrainOrientation*.csv)
install(FILES ${MATERIALS}
DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/ExaCA)
DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/ExaCA)
install(FILES ${SUBSTRATE}
DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/ExaCA)
DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/ExaCA)

option(ExaCA_ENABLE_TESTING "Build unit tests" OFF)

Expand Down Expand Up @@ -100,10 +103,11 @@ add_subdirectory(analysis)

# clang-format
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
find_package( CLANG_FORMAT 10)
find_package(CLANG_FORMAT 10)
if(CLANG_FORMAT_FOUND)
file(GLOB_RECURSE FORMAT_SOURCES *.[c,h]pp)
add_custom_target(format
add_custom_target(
format
COMMAND ${CLANG_FORMAT_EXECUTABLE} -i -style=file ${FORMAT_SOURCES}
DEPENDS ${FORMAT_SOURCES})
endif()
4 changes: 2 additions & 2 deletions analysis/bin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ target_link_libraries(ExaCA-GrainAnalysis ExaCA-Analysis)
install(TARGETS ExaCA-GrainAnalysis DESTINATION ${CMAKE_INSTALL_BINDIR})

# Symlink for backwards compatibility
add_custom_target(grain_analysis ALL
COMMAND ${CMAKE_COMMAND} -E create_symlink ExaCA-GrainAnalysis grain_analysis)
add_custom_target(grain_analysis ALL COMMAND ${CMAKE_COMMAND} -E create_symlink
ExaCA-GrainAnalysis grain_analysis)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/grain_analysis
DESTINATION ${CMAKE_INSTALL_BINDIR})
12 changes: 7 additions & 5 deletions analysis/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ add_library(ExaCA::Analysis ALIAS ExaCA-Analysis)

target_link_libraries(ExaCA-Analysis PUBLIC ExaCA-Core)

target_include_directories(ExaCA-Analysis PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_include_directories(
ExaCA-Analysis
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

install(TARGETS ExaCA-Analysis
install(
TARGETS ExaCA-Analysis
EXPORT ExaCA_Targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
4 changes: 2 additions & 2 deletions analysis/unit_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include(${TEST_HARNESS_DIR}/test_harness.cmake)

ExaCA_add_tests(PACKAGE ExaCA-Analysis NAMES Utils KokkosUtils)
ExaCA_add_tests(PACKAGE ExaCA-Analysis NAMES RepresentativeRegion)
exaca_add_tests(PACKAGE ExaCA-Analysis NAMES Utils KokkosUtils)
exaca_add_tests(PACKAGE ExaCA-Analysis NAMES RepresentativeRegion)
4 changes: 2 additions & 2 deletions bin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ target_link_libraries(ExaCA ExaCA-Core)
install(TARGETS ExaCA DESTINATION ${CMAKE_INSTALL_BINDIR})

# Symlink for backwards compatibility
add_custom_target(ExaCA-Kokkos ALL
COMMAND ${CMAKE_COMMAND} -E create_symlink ExaCA ExaCA-Kokkos)
add_custom_target(ExaCA-Kokkos ALL COMMAND ${CMAKE_COMMAND} -E create_symlink
ExaCA ExaCA-Kokkos)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ExaCA-Kokkos
DESTINATION ${CMAKE_INSTALL_BINDIR})

Expand Down
60 changes: 31 additions & 29 deletions cmake/FindCLANG_FORMAT.cmake
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
# Find clang-format
#
# CLANG_FORMAT_EXECUTABLE - Path to clang-format executable
# CLANG_FORMAT_FOUND - True if the clang-format executable was found.
# CLANG_FORMAT_VERSION - The version of clang-format found
# CLANG_FORMAT_EXECUTABLE - Path to clang-format executable CLANG_FORMAT_FOUND
# - True if the clang-format executable was found. CLANG_FORMAT_VERSION -
# The version of clang-format found
#

find_program(CLANG_FORMAT_EXECUTABLE
NAMES clang-format
clang-format-10
clang-format-9
clang-format-8
clang-format-7
clang-format-6.0
clang-format-5.0
clang-format-4.0
clang-format-3.9
clang-format-3.8
clang-format-3.7
clang-format-3.6
clang-format-3.5
clang-format-3.4
clang-format-3.3
DOC "clang-format executable")
find_program(
CLANG_FORMAT_EXECUTABLE
NAMES clang-format
clang-format-10
clang-format-9
clang-format-8
clang-format-7
clang-format-6.0
clang-format-5.0
clang-format-4.0
clang-format-3.9
clang-format-3.8
clang-format-3.7
clang-format-3.6
clang-format-3.5
clang-format-3.4
clang-format-3.3
DOC "clang-format executable")
mark_as_advanced(CLANG_FORMAT_EXECUTABLE)

# Extract version from command "clang-format -version"
if(CLANG_FORMAT_EXECUTABLE)
execute_process(COMMAND ${CLANG_FORMAT_EXECUTABLE} -version
OUTPUT_VARIABLE clang_format_version
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
COMMAND ${CLANG_FORMAT_EXECUTABLE} -version
OUTPUT_VARIABLE clang_format_version
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)

if(clang_format_version MATCHES "^.*clang-format version .*")
# clang_format_version sample: "clang-format version 3.9.1-4ubuntu3~16.04.1
# (tags/RELEASE_391/rc2)"
string(REGEX
REPLACE "^.*clang-format version ([.0-9]+).*"
"\\1"
CLANG_FORMAT_VERSION
"${clang_format_version}")
string(REGEX REPLACE "^.*clang-format version ([.0-9]+).*" "\\1"
CLANG_FORMAT_VERSION "${clang_format_version}")
# CLANG_FORMAT_VERSION sample: "3.9.1"
else()
set(CLANG_FORMAT_VERSION 0.0)
Expand All @@ -49,4 +48,7 @@ endif()
include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set CLANG_FORMAT_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args(CLANG_FORMAT REQUIRED_VARS CLANG_FORMAT_EXECUTABLE VERSION_VAR CLANG_FORMAT_VERSION)
find_package_handle_standard_args(
CLANG_FORMAT
REQUIRED_VARS CLANG_FORMAT_EXECUTABLE
VERSION_VAR CLANG_FORMAT_VERSION)
25 changes: 13 additions & 12 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,32 @@ file(GLOB EXACA_SOURCES GLOB *.cpp)

install(FILES ${EXACA_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CAconfig.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CAconfig.hpp
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

add_library(ExaCA-Core ${EXACA_SOURCES})
add_library(ExaCA::Core ALIAS ExaCA-Core)

target_link_libraries(ExaCA-Core PUBLIC
MPI::MPI_CXX
Kokkos::kokkos
nlohmann_json::nlohmann_json
)
target_link_libraries(ExaCA-Core PUBLIC MPI::MPI_CXX Kokkos::kokkos
nlohmann_json::nlohmann_json)
if(ExaCA_ENABLE_FINCH)
target_link_libraries(ExaCA-Core PUBLIC Finch::Core Finch::ScanPaths)
endif()

target_include_directories(ExaCA-Core PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_include_directories(
ExaCA-Core
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

install(TARGETS ExaCA-Core
install(
TARGETS ExaCA-Core
EXPORT ExaCA_Targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})

install(EXPORT ExaCA_Targets
install(
EXPORT ExaCA_Targets
FILE ExaCA_Targets.cmake
NAMESPACE ExaCA::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ExaCA)
49 changes: 36 additions & 13 deletions unit_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,48 @@
include(${TEST_HARNESS_DIR}/test_harness.cmake)

##--------------------------------------------------------------------------##
## Install example files used in tests
##--------------------------------------------------------------------------##
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../examples/Inp_SmallDirSolidification.json
# --------------------------------------------------------------------------##
# Install example files used in tests
# --------------------------------------------------------------------------##
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/../examples/Inp_SmallDirSolidification.json
${CMAKE_CURRENT_BINARY_DIR}/Inp_SmallDirSolidification.json COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../examples/Inp_DirSolidification.json
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/../examples/Inp_DirSolidification.json
${CMAKE_CURRENT_BINARY_DIR}/Inp_DirSolidification.json COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../examples/Inp_TwoGrainDirSolidification.json
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/../examples/Inp_TwoGrainDirSolidification.json
${CMAKE_CURRENT_BINARY_DIR}/Inp_TwoGrainDirSolidification.json COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../examples/Inp_SpotMelt.json
${CMAKE_CURRENT_BINARY_DIR}/Inp_SpotMelt.json COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../examples/Inp_SmallEquiaxedGrain.json
${CMAKE_CURRENT_BINARY_DIR}/Inp_SpotMelt.json COPYONLY)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/../examples/Inp_SmallEquiaxedGrain.json
${CMAKE_CURRENT_BINARY_DIR}/Inp_SmallEquiaxedGrain.json COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../examples/Materials/Inconel625.json
${CMAKE_CURRENT_BINARY_DIR}/Inconel625.json COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../examples/Materials/Inconel625_Quadratic.json
${CMAKE_CURRENT_BINARY_DIR}/Inconel625.json COPYONLY)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/../examples/Materials/Inconel625_Quadratic.json
${CMAKE_CURRENT_BINARY_DIR}/Inconel625_Quadratic.json COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../examples/Materials/SS316.json
${CMAKE_CURRENT_BINARY_DIR}/SS316.json COPYONLY)
${CMAKE_CURRENT_BINARY_DIR}/SS316.json COPYONLY)

ExaCA_add_tests(PACKAGE ExaCA-Core NAMES InterfacialResponse Inputs Orientation Parse Print)
exaca_add_tests(
PACKAGE
ExaCA-Core
NAMES
InterfacialResponse
Inputs
Orientation
Parse
Print)

ExaCA_add_tests(MPI PACKAGE ExaCA-Core NAMES CellData Grid Interface Nucleation Temperature Update)
exaca_add_tests(
MPI
PACKAGE
ExaCA-Core
NAMES
CellData
Grid
Interface
Nucleation
Temperature
Update)
Loading
Loading