-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from CExA-project/improve-cmake
Improve cmake
- Loading branch information
Showing
7 changed files
with
187 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# https://jonathanhamberg.com/post/cmake-embedding-git-hash/ | ||
|
||
find_package(Git QUIET) | ||
|
||
set(CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_DIR}) | ||
set(pre_configure_file ${CURRENT_LIST_DIR}/KokkosFFT_Version_Info.hpp.in) | ||
set(post_configure_file ${CMAKE_BINARY_DIR}/KokkosFFT_Version_Info.hpp) | ||
|
||
FUNCTION(check_git_write git_hash git_clean_status) | ||
FILE( | ||
WRITE | ||
${CMAKE_BINARY_DIR}/git-state.txt | ||
"${git_hash}-${git_clean_status}") | ||
ENDFUNCTION() | ||
|
||
FUNCTION(check_git_read git_hash) | ||
if(EXISTS ${CMAKE_BINARY_DIR}/git-state.txt) | ||
FILE(STRINGS ${CMAKE_BINARY_DIR}/git-state.txt CONTENT) | ||
LIST(GET CONTENT 0 var) | ||
|
||
message(DEBUG "Cached Git hash: ${var}") | ||
SET(${git_hash} ${var} PARENT_SCOPE) | ||
else() | ||
SET(${git_hash} "INVALID" PARENT_SCOPE) | ||
endif() | ||
ENDFUNCTION() | ||
|
||
FUNCTION(check_git_version) | ||
if(NOT Git_FOUND OR NOT EXISTS ${KOKKOSFFT_TOP_SOURCE_DIR}/.git) | ||
configure_file(${pre_configure_file} ${post_configure_file} @ONLY) | ||
return() | ||
endif() | ||
|
||
# Get the current working branch | ||
execute_process( | ||
COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD | ||
WORKING_DIRECTORY ${KOKKOSFFT_TOP_SOURCE_DIR} | ||
OUTPUT_VARIABLE GIT_BRANCH | ||
OUTPUT_STRIP_TRAILING_WHITESPACE) | ||
|
||
# Get the latest commit description | ||
execute_process( | ||
COMMAND ${GIT_EXECUTABLE} show -s --format=%s | ||
WORKING_DIRECTORY ${KOKKOSFFT_TOP_SOURCE_DIR} | ||
OUTPUT_VARIABLE GIT_COMMIT_DESCRIPTION | ||
OUTPUT_STRIP_TRAILING_WHITESPACE) | ||
|
||
# Get the latest commit date | ||
execute_process( | ||
COMMAND ${GIT_EXECUTABLE} log -1 --format=%cI | ||
WORKING_DIRECTORY ${KOKKOSFFT_TOP_SOURCE_DIR} | ||
OUTPUT_VARIABLE GIT_COMMIT_DATE | ||
OUTPUT_STRIP_TRAILING_WHITESPACE) | ||
|
||
# Check if repo is dirty / clean | ||
execute_process( | ||
COMMAND ${GIT_EXECUTABLE} diff-index --quiet HEAD -- | ||
WORKING_DIRECTORY ${KOKKOSFFT_TOP_SOURCE_DIR} | ||
RESULT_VARIABLE IS_DIRTY | ||
OUTPUT_STRIP_TRAILING_WHITESPACE) | ||
|
||
if(IS_DIRTY EQUAL 0) | ||
set(GIT_CLEAN_STATUS "CLEAN") | ||
else() | ||
set(GIT_CLEAN_STATUS "DIRTY") | ||
endif() | ||
|
||
# Get the latest abbreviated commit hash of the working branch | ||
execute_process( | ||
COMMAND ${GIT_EXECUTABLE} log -1 --format=%h | ||
WORKING_DIRECTORY ${KOKKOSFFT_TOP_SOURCE_DIR} | ||
OUTPUT_VARIABLE GIT_COMMIT_HASH | ||
OUTPUT_STRIP_TRAILING_WHITESPACE) | ||
|
||
check_git_read(GIT_HASH_CACHE) | ||
|
||
# Only update the version header if the hash has changed. This will | ||
# prevent us from rebuilding the project more than we need to. | ||
if(NOT "${GIT_COMMIT_HASH}-${GIT_CLEAN_STATUS}" STREQUAL ${GIT_HASH_CACHE} | ||
OR NOT EXISTS ${post_configure_file}) | ||
# Set the GIT_HASH_CACHE variable so the next build won't have | ||
# to regenerate the source file. | ||
check_git_write(${GIT_COMMIT_HASH} ${GIT_CLEAN_STATUS}) | ||
|
||
configure_file(${pre_configure_file} ${post_configure_file} @ONLY) | ||
message(STATUS "Configured git information in ${post_configure_file}") | ||
endif() | ||
ENDFUNCTION() | ||
|
||
FUNCTION(check_version_info) | ||
add_custom_target( | ||
AlwaysCheckGitInBenchmark COMMAND ${CMAKE_COMMAND} | ||
-DRUN_CHECK_GIT_VERSION=1 | ||
-DKOKKOSFFT_TOP_SOURCE_DIR=${DKOKKOSFFT_TOP_SOURCE_DIR} | ||
-P ${CURRENT_LIST_DIR}/KokkosFFT_Git_Hash.cmake | ||
BYPRODUCTS ${post_configure_file}) | ||
|
||
add_dependencies(PerformanceTest_Benchmark AlwaysCheckGitInBenchmark) | ||
check_git_version() | ||
ENDFUNCTION() | ||
|
||
# This is used to run this function from an external cmake process. | ||
if(RUN_CHECK_GIT_VERSION) | ||
check_git_version() | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
function(get_tpls_list tpls_list) | ||
if(Kokkos_ENABLE_CUDA) | ||
list(APPEND tpls_list CUFFT) | ||
elseif(Kokkos_ENABLE_HIP) | ||
list(APPEND tpls_list HIPFFT) | ||
elseif(Kokkos_ENABLE_SYCL) | ||
list(APPEND tpls_list ONEMKL) | ||
elseif(Kokkos_ENABLE_OPENMP) | ||
list(APPEND tpls_list FFTW_OPENMP) | ||
elseif(Kokkos_ENABLE_THREADS) | ||
list(APPEND tpls_list FFTW_THREADS) | ||
elseif(Kokkos_ENABLE_SERIAL) | ||
list(APPEND tpls_list FFTW) | ||
endif() | ||
|
||
if(KokkosFFT_ENABLE_HOST_AND_DEVICE) | ||
if(Kokkos_ENABLE_OPENMP) | ||
list(APPEND tpls_list FFTW_OPENMP) | ||
elseif(Kokkos_ENABLE_THREADS) | ||
list(APPEND tpls_list FFTW_THREADS) | ||
else() | ||
list(APPEND tpls_list FFTW) | ||
endif() | ||
endif() | ||
|
||
set(${tpls_list} ${${tpls_list}} PARENT_SCOPE) | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
function(check_minimum_required_kokkos kokkos_required_version) | ||
if(${Kokkos_VERSION} STREQUAL "") | ||
message(FATAL_ERROR "Kokkos_VERSION not set. Cannot check Kokkos satisfies the minimum required version.") | ||
else() | ||
if(${Kokkos_VERSION} VERSION_GREATER_EQUAL ${kokkos_required_version}) | ||
message(STATUS "Found Kokkos version ${Kokkos_VERSION} at ${Kokkos_DIR}") | ||
else() | ||
message(FATAL_ERROR "Kokkos FFT ${KOKKOSFFT_VERSION} requires ${kokkos_required_version} or later.") | ||
endif() | ||
endif() | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters