Update cmake recipe for c modules

This commit is contained in:
Atsushi Togo 2023-01-20 16:37:58 +09:00
parent 9fad93726e
commit b48db9189a
4 changed files with 261 additions and 169 deletions

2
.clang-format Normal file
View File

@ -0,0 +1,2 @@
BasedOnStyle: Google
IndentWidth: 4

View File

@ -35,3 +35,24 @@ repos:
hooks:
- id: isort
name: isort (python)
- repo: https://github.com/Takishima/cmake-pre-commit-hooks
rev: v1.5.3
hooks:
- id: clang-format
args:
- '-B_build-pre-commit'
- '-DWITH_Fortran=ON'
- '-DWITH_TESTS=ON'
- '-i'
stages: [manual]
- id: clang-tidy
args:
- '-B_build-pre-commit'
- '-DWITH_Fortran=ON'
- '-DWITH_TESTS=ON'
# - '--'
# - '-I/Users/togo/.miniforge/envs/dev/include'
# - '-I/Users/togo/.miniforge/envs/dev/include/python3.10'
# - '-I/Users/togo/.miniforge/envs/dev/lib/python3.10/site-packages/numpy/core/include'
stages: [manual]

View File

@ -1,19 +1,36 @@
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.15)
cmake_policy(SET CMP0007 NEW)
project(phono3py C)
option(USE_OpenMP "Option to search OpenMP library" ON)
# Sanity check if project is imported
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
option(WITH_TESTS "build unit tests" ON)
else()
option(WITH_TESTS "build unit tests" OFF)
endif()
option(BUILD_SHARED_LIBRARIES "Option to build shared library" OFF)
if(WITH_TESTS)
set(BUILD_SHARED_LIBRARIES ON)
endif()
set(CMAKE_MACOSX_RPATH 1)
set(CMAKE_C_FLAGS_RELEASE "-Wall -O2")
set(CMAKE_C_FLAGS_DEBUG "-g -DLAGWARNING -DTHMWARNING")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_BUILD_TYPE Release)
endif(NOT CMAKE_BUILD_TYPE)
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "CMAKE_SYSTEM_PREFIX_PATH: ${CMAKE_SYSTEM_PREFIX_PATH}")
include(GNUInstallDirs)
# set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Version numbers
file(READ ${PROJECT_SOURCE_DIR}/phono3py/version.py version_file)
@ -24,199 +41,219 @@ set(phono3py_micro_version ${CMAKE_MATCH_3})
set(serial "${phono3py_major_version}.${phono3py_minor_version}.${phono3py_micro_version}")
set(soserial "1")
if (USE_CONDA_PATH)
message(STATUS "$ENV{CONDA_PREFIX}")
set(CMAKE_MODULE_PATH $ENV{CONDA_PREFIX})
set(MY_INCLUDES $ENV{CONDA_PREFIX}/include ${PROJECT_SOURCE_DIR}/c)
link_directories($ENV{CONDA_PREFIX}/lib)
if(USE_CONDA_PATH)
message(STATUS "$ENV{CONDA_PREFIX}")
set(CMAKE_MODULE_PATH $ENV{CONDA_PREFIX})
set(MY_INCLUDES $ENV{CONDA_PREFIX}/include ${PROJECT_SOURCE_DIR}/c)
link_directories($ENV{CONDA_PREFIX}/lib)
else()
set(MY_INCLUDES ${PROJECT_SOURCE_DIR}/c)
set(MY_INCLUDES ${PROJECT_SOURCE_DIR}/c)
endif()
option(USE_OpenMP "Option to search OpenMP library" ON)
if (USE_OpenMP)
message(STATUS "Find OpenMP library")
find_package(OpenMP)
if (OpenMP_FOUND)
message(STATUS "OpenMP libs: ${OpenMP_C_LIBRARIES}")
message(STATUS "OpenMP flags: ${OpenMP_C_FLAGS}")
endif()
if(USE_OpenMP)
message(STATUS "Find OpenMP library")
find_package(OpenMP)
if(OpenMP_FOUND)
message(STATUS "OpenMP libs: ${OpenMP_C_LIBRARIES}")
message(STATUS "OpenMP flags: ${OpenMP_C_FLAGS}")
endif()
endif()
if (PHONO3PY OR PHONONMOD)
find_package(BLAS REQUIRED) # set BLAS_LIBRARIES
if (BLAS_FOUND)
message(STATUS "BLAS libs: ${BLAS_LIBRARIES}")
message(STATUS "BLAS flags: ${BLAS_LINKER_FLAGS}")
endif()
find_package(LAPACK REQUIRED) # set LAPACK_LIBRARIES
if (LAPACK_FOUND)
message(STATUS "LAPACK libs: ${LAPACK_LIBRARIES}")
message(STATUS "LAPACK flags: ${LAPACK_LINKER_FLAGS}")
endif()
if(PHONO3PY OR PHONONMOD)
find_package(BLAS REQUIRED) # set BLAS_LIBRARIES
if(BLAS_FOUND)
message(STATUS "BLAS libs: ${BLAS_LIBRARIES}")
message(STATUS "BLAS flags: ${BLAS_LINKER_FLAGS}")
endif()
find_package(LAPACK REQUIRED) # set LAPACK_LIBRARIES
if(LAPACK_FOUND)
message(STATUS "LAPACK libs: ${LAPACK_LIBRARIES}")
message(STATUS "LAPACK flags: ${LAPACK_LINKER_FLAGS}")
endif()
endif()
if (PHONO3PY OR PHONONMOD)
if (BLAS_LIBRARIES MATCHES "libmkl")
message(STATUS "MKL detected: Set C-macros MKL_LAPACKE MULTITHREADED_BLAS")
endif()
if (BLAS_LIBRARIES MATCHES "libopenblas")
message(STATUS "OpenBLAS detected: Set C-macro MULTITHREADED_BLAS")
endif()
if(PHONO3PY OR PHONONMOD)
if(BLAS_LIBRARIES MATCHES "libmkl")
message(STATUS "MKL detected: Set C-macros MKL_LAPACKE MULTITHREADED_BLAS")
endif()
if(BLAS_LIBRARIES MATCHES "libopenblas")
message(STATUS "OpenBLAS detected: Set C-macro MULTITHREADED_BLAS")
endif()
endif()
############
# ###########
# phono3py #
############
if (PHONO3PY)
# Source code
set(SOURCES_PHONO3PY
${PROJECT_SOURCE_DIR}/c/bzgrid.c
${PROJECT_SOURCE_DIR}/c/collision_matrix.c
${PROJECT_SOURCE_DIR}/c/fc3.c
${PROJECT_SOURCE_DIR}/c/grgrid.c
${PROJECT_SOURCE_DIR}/c/imag_self_energy_with_g.c
${PROJECT_SOURCE_DIR}/c/interaction.c
${PROJECT_SOURCE_DIR}/c/isotope.c
${PROJECT_SOURCE_DIR}/c/lagrid.c
${PROJECT_SOURCE_DIR}/c/lapack_wrapper.c
${PROJECT_SOURCE_DIR}/c/phono3py.c
${PROJECT_SOURCE_DIR}/c/phonoc_utils.c
${PROJECT_SOURCE_DIR}/c/pp_collision.c
${PROJECT_SOURCE_DIR}/c/real_self_energy.c
${PROJECT_SOURCE_DIR}/c/real_to_reciprocal.c
${PROJECT_SOURCE_DIR}/c/reciprocal_to_normal.c
${PROJECT_SOURCE_DIR}/c/snf3x3.c
${PROJECT_SOURCE_DIR}/c/tetrahedron_method.c
${PROJECT_SOURCE_DIR}/c/triplet.c
${PROJECT_SOURCE_DIR}/c/triplet_grid.c
${PROJECT_SOURCE_DIR}/c/triplet_iw.c)
# ###########
if(PHONO3PY)
# Source code
set(SOURCES_PHONO3PY
${PROJECT_SOURCE_DIR}/c/bzgrid.c
${PROJECT_SOURCE_DIR}/c/collision_matrix.c
${PROJECT_SOURCE_DIR}/c/fc3.c
${PROJECT_SOURCE_DIR}/c/grgrid.c
${PROJECT_SOURCE_DIR}/c/imag_self_energy_with_g.c
${PROJECT_SOURCE_DIR}/c/interaction.c
${PROJECT_SOURCE_DIR}/c/isotope.c
${PROJECT_SOURCE_DIR}/c/lagrid.c
${PROJECT_SOURCE_DIR}/c/lapack_wrapper.c
${PROJECT_SOURCE_DIR}/c/phono3py.c
${PROJECT_SOURCE_DIR}/c/phonoc_utils.c
${PROJECT_SOURCE_DIR}/c/pp_collision.c
${PROJECT_SOURCE_DIR}/c/real_self_energy.c
${PROJECT_SOURCE_DIR}/c/real_to_reciprocal.c
${PROJECT_SOURCE_DIR}/c/reciprocal_to_normal.c
${PROJECT_SOURCE_DIR}/c/snf3x3.c
${PROJECT_SOURCE_DIR}/c/tetrahedron_method.c
${PROJECT_SOURCE_DIR}/c/triplet.c
${PROJECT_SOURCE_DIR}/c/triplet_grid.c
${PROJECT_SOURCE_DIR}/c/triplet_iw.c)
if (BUILD_SHARED_LIBRARIES)
# Shared library
add_library(ph3py SHARED ${SOURCES_PHONO3PY})
target_link_libraries(ph3py m ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${OpenMP_C_LIBRARIES})
target_include_directories(ph3py PRIVATE ${MY_INCLUDES})
target_compile_options(ph3py PRIVATE ${OpenMP_C_FLAGS})
if (BLAS_LIBRARIES MATCHES "libmkl")
target_compile_definitions(ph3py PRIVATE MKL_LAPACKE THM_EPSILON=1e-10)
if(BUILD_SHARED_LIBRARIES)
# Shared library
add_library(ph3py SHARED ${SOURCES_PHONO3PY})
target_link_libraries(ph3py m ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${OpenMP_C_LIBRARIES})
target_include_directories(ph3py PRIVATE ${MY_INCLUDES})
target_compile_options(ph3py PRIVATE ${OpenMP_C_FLAGS})
if(BLAS_LIBRARIES MATCHES "libmkl")
target_compile_definitions(ph3py PRIVATE MKL_LAPACKE THM_EPSILON=1e-10)
endif()
if(BLAS_LIBRARIES MATCHES "libopenblas")
target_compile_definitions(ph3py PRIVATE THM_EPSILON=1e-10)
endif()
set_property(TARGET ph3py PROPERTY VERSION ${serial})
set_property(TARGET ph3py PROPERTY SOVERSION ${soserial})
install(TARGETS ph3py LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
if (BLAS_LIBRARIES MATCHES "libopenblas")
target_compile_definitions(ph3py PRIVATE THM_EPSILON=1e-10)
# Static link library
add_library(ph3py_static STATIC ${SOURCES_PHONO3PY})
target_link_libraries(ph3py_static m ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${OpenMP_C_LIBRARIES})
target_include_directories(ph3py_static PRIVATE ${MY_INCLUDES})
target_compile_options(ph3py_static PRIVATE ${OpenMP_C_FLAGS})
if(BLAS_LIBRARIES MATCHES "libmkl")
target_compile_definitions(ph3py_static PRIVATE MKL_LAPACKE THM_EPSILON=1e-10)
endif()
set_property(TARGET ph3py PROPERTY VERSION ${serial})
set_property(TARGET ph3py PROPERTY SOVERSION ${soserial})
install(TARGETS ph3py LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
# Static link library
add_library(ph3py_static STATIC ${SOURCES_PHONO3PY})
target_link_libraries(ph3py_static m ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${OpenMP_C_LIBRARIES})
target_include_directories(ph3py_static PRIVATE ${MY_INCLUDES})
target_compile_options(ph3py_static PRIVATE ${OpenMP_C_FLAGS})
if (BLAS_LIBRARIES MATCHES "libmkl")
target_compile_definitions(ph3py_static PRIVATE MKL_LAPACKE THM_EPSILON=1e-10)
endif()
if (BLAS_LIBRARIES MATCHES "libopenblas")
target_compile_definitions(ph3py_static PRIVATE THM_EPSILON=1e-10)
endif()
set_property(TARGET ph3py_static PROPERTY VERSION ${serial})
set_property(TARGET ph3py_static PROPERTY SOVERSION ${soserial})
set_property(TARGET ph3py_static PROPERTY OUTPUT_NAME ph3py)
install(TARGETS ph3py_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
if(BLAS_LIBRARIES MATCHES "libopenblas")
target_compile_definitions(ph3py_static PRIVATE THM_EPSILON=1e-10)
endif()
# Header file
install(FILES ${PROJECT_SOURCE_DIR}/c/phono3py.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
set_property(TARGET ph3py_static PROPERTY VERSION ${serial})
set_property(TARGET ph3py_static PROPERTY SOVERSION ${soserial})
set_property(TARGET ph3py_static PROPERTY OUTPUT_NAME ph3py)
install(TARGETS ph3py_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
# Header file
install(FILES ${PROJECT_SOURCE_DIR}/c/phono3py.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()
#############
# ############
# phononmod #
#############
if (PHONONMOD)
# Source code
set(SOURCES_PHONONMOD
${PROJECT_SOURCE_DIR}/c/dynmat.c
${PROJECT_SOURCE_DIR}/c/lapack_wrapper.c
${PROJECT_SOURCE_DIR}/c/phonon.c
${PROJECT_SOURCE_DIR}/c/phononmod.c)
# ############
if(PHONONMOD)
# Source code
set(SOURCES_PHONONMOD
${PROJECT_SOURCE_DIR}/c/dynmat.c
${PROJECT_SOURCE_DIR}/c/lapack_wrapper.c
${PROJECT_SOURCE_DIR}/c/phonon.c
${PROJECT_SOURCE_DIR}/c/phononmod.c)
if (BUILD_SHARED_LIBRARIES)
# Shared library
add_library(phmod SHARED ${SOURCES_PHONONMOD})
target_link_libraries(phmod m ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${OpenMP_C_LIBRARIES})
target_include_directories(phmod PRIVATE ${MY_INCLUDES})
target_compile_options(phmod PRIVATE ${OpenMP_C_FLAGS})
if (BLAS_LIBRARIES MATCHES "libmkl")
target_compile_definitions(phmod PRIVATE MKL_LAPACKE MULTITHREADED_BLAS)
if(BUILD_SHARED_LIBRARIES)
# Shared library
add_library(phmod SHARED ${SOURCES_PHONONMOD})
target_link_libraries(phmod m ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${OpenMP_C_LIBRARIES})
target_include_directories(phmod PRIVATE ${MY_INCLUDES})
target_compile_options(phmod PRIVATE ${OpenMP_C_FLAGS})
if(BLAS_LIBRARIES MATCHES "libmkl")
target_compile_definitions(phmod PRIVATE MKL_LAPACKE MULTITHREADED_BLAS)
endif()
if(BLAS_LIBRARIES MATCHES "libopenblas")
target_compile_definitions(phmod PRIVATE MULTITHREADED_BLAS)
endif()
set_property(TARGET phmod PROPERTY VERSION ${serial})
set_property(TARGET phmod PROPERTY SOVERSION ${soserial})
install(TARGETS phmod LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
if (BLAS_LIBRARIES MATCHES "libopenblas")
target_compile_definitions(phmod PRIVATE MULTITHREADED_BLAS)
# Static link library
add_library(phmod_static STATIC ${SOURCES_PHONONMOD})
target_link_libraries(phmod_static m ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${OpenMP_C_LIBRARIES})
target_include_directories(phmod_static PRIVATE ${MY_INCLUDES})
target_compile_options(phmod_static PRIVATE ${OpenMP_C_FLAGS})
if(BLAS_LIBRARIES MATCHES "libmkl")
target_compile_definitions(phmod_static PRIVATE MKL_LAPACKE MULTITHREADED_BLAS)
endif()
set_property(TARGET phmod PROPERTY VERSION ${serial})
set_property(TARGET phmod PROPERTY SOVERSION ${soserial})
install(TARGETS phmod LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
# Static link library
add_library(phmod_static STATIC ${SOURCES_PHONONMOD})
target_link_libraries(phmod_static m ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${OpenMP_C_LIBRARIES})
target_include_directories(phmod_static PRIVATE ${MY_INCLUDES})
target_compile_options(phmod_static PRIVATE ${OpenMP_C_FLAGS})
if (BLAS_LIBRARIES MATCHES "libmkl")
target_compile_definitions(phmod_static PRIVATE MKL_LAPACKE MULTITHREADED_BLAS)
endif()
if (BLAS_LIBRARIES MATCHES "libopenblas")
target_compile_definitions(phmod_static PRIVATE MULTITHREADED_BLAS)
endif()
set_property(TARGET phmod_static PROPERTY VERSION ${serial})
set_property(TARGET phmod_static PROPERTY SOVERSION ${soserial})
set_property(TARGET phmod_static PROPERTY OUTPUT_NAME phmod)
install(TARGETS phmod_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
if(BLAS_LIBRARIES MATCHES "libopenblas")
target_compile_definitions(phmod_static PRIVATE MULTITHREADED_BLAS)
endif()
# Header file
install(FILES ${PROJECT_SOURCE_DIR}/c/phononmod.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
set_property(TARGET phmod_static PROPERTY VERSION ${serial})
set_property(TARGET phmod_static PROPERTY SOVERSION ${soserial})
set_property(TARGET phmod_static PROPERTY OUTPUT_NAME phmod)
install(TARGETS phmod_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
# Header file
install(FILES ${PROJECT_SOURCE_DIR}/c/phononmod.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()
########
# #######
# grid #
########
if (GRIDSYS)
# Source code
set(SOURCES_GRIDSYSMOD
${PROJECT_SOURCE_DIR}/c/bzgrid.c
${PROJECT_SOURCE_DIR}/c/grgrid.c
${PROJECT_SOURCE_DIR}/c/gridsys.c
${PROJECT_SOURCE_DIR}/c/lagrid.c
${PROJECT_SOURCE_DIR}/c/phonoc_utils.c
${PROJECT_SOURCE_DIR}/c/snf3x3.c
${PROJECT_SOURCE_DIR}/c/tetrahedron_method.c
${PROJECT_SOURCE_DIR}/c/triplet.c
${PROJECT_SOURCE_DIR}/c/triplet_grid.c
${PROJECT_SOURCE_DIR}/c/triplet_iw.c)
# #######
if(GRIDSYS)
# Source code
set(SOURCES_GRIDSYSMOD
${PROJECT_SOURCE_DIR}/c/bzgrid.c
${PROJECT_SOURCE_DIR}/c/grgrid.c
${PROJECT_SOURCE_DIR}/c/gridsys.c
${PROJECT_SOURCE_DIR}/c/lagrid.c
${PROJECT_SOURCE_DIR}/c/phonoc_utils.c
${PROJECT_SOURCE_DIR}/c/snf3x3.c
${PROJECT_SOURCE_DIR}/c/tetrahedron_method.c
${PROJECT_SOURCE_DIR}/c/triplet.c
${PROJECT_SOURCE_DIR}/c/triplet_grid.c
${PROJECT_SOURCE_DIR}/c/triplet_iw.c)
if (BUILD_SHARED_LIBRARIES)
# Shared library
add_library(gridsysmod SHARED ${SOURCES_GRIDSYSMOD})
target_link_libraries(gridsysmod m ${OpenMP_C_LIBRARIES})
target_include_directories(gridsysmod PRIVATE ${MY_INCLUDES})
target_compile_options(gridsysmod PRIVATE ${OpenMP_C_FLAGS})
target_compile_definitions(gridsysmod PRIVATE THM_EPSILON=1e-10)
set_property(TARGET gridsysmod PROPERTY VERSION ${serial})
set_property(TARGET gridsysmod PROPERTY SOVERSION ${soserial})
install(TARGETS gridsysmod LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
if(BUILD_SHARED_LIBRARIES)
# Shared library
add_library(gridsysmod SHARED ${SOURCES_GRIDSYSMOD})
target_link_libraries(gridsysmod m ${OpenMP_C_LIBRARIES})
target_include_directories(gridsysmod PRIVATE ${MY_INCLUDES})
target_compile_options(gridsysmod PRIVATE ${OpenMP_C_FLAGS})
target_compile_definitions(gridsysmod PRIVATE THM_EPSILON=1e-10)
set_property(TARGET gridsysmod PROPERTY VERSION ${serial})
set_property(TARGET gridsysmod PROPERTY SOVERSION ${soserial})
install(TARGETS gridsysmod LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
# Static link library
add_library(gridsysmod_static STATIC ${SOURCES_GRIDSYSMOD})
target_link_libraries(gridsysmod_static m ${OpenMP_C_LIBRARIES})
target_include_directories(gridsysmod_static PRIVATE ${MY_INCLUDES})
target_compile_options(gridsysmod_static PRIVATE ${OpenMP_C_FLAGS})
target_compile_definitions(gridsysmod_static PRIVATE THM_EPSILON=1e-10)
set_property(TARGET gridsysmod_static PROPERTY VERSION ${serial})
set_property(TARGET gridsysmod_static PROPERTY SOVERSION ${soserial})
set_property(TARGET gridsysmod_static PROPERTY OUTPUT_NAME gridsysmod)
install(TARGETS gridsysmod_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
# Static link library
add_library(gridsysmod_static STATIC ${SOURCES_GRIDSYSMOD})
target_link_libraries(gridsysmod_static m ${OpenMP_C_LIBRARIES})
target_include_directories(gridsysmod_static PRIVATE ${MY_INCLUDES})
target_compile_options(gridsysmod_static PRIVATE ${OpenMP_C_FLAGS})
target_compile_definitions(gridsysmod_static PRIVATE THM_EPSILON=1e-10)
set_property(TARGET gridsysmod_static PROPERTY VERSION ${serial})
set_property(TARGET gridsysmod_static PROPERTY SOVERSION ${soserial})
set_property(TARGET gridsysmod_static PROPERTY OUTPUT_NAME gridsysmod)
install(TARGETS gridsysmod_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
# Header file
install(FILES ${PROJECT_SOURCE_DIR}/c/gridsys.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# Header file
install(FILES ${PROJECT_SOURCE_DIR}/c/gridsys.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()
if(WITH_TESTS)
add_subdirectory(ctest)
endif()

32
ctest/CMakeLists.txt Normal file
View File

@ -0,0 +1,32 @@
enable_language(CXX)
enable_testing()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
find_package(GTest)
if(NOT GTest_FOUND)
# pthread (required for GoogleTest)
# https://stackoverflow.com/questions/1620918/cmake-and-libpthread
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
# Fetch GoogleTest
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/refs/tags/release-1.12.1.tar.gz
URL_HASH MD5=e82199374acdfda3f425331028eb4e2a
)
FetchContent_MakeAvailable(googletest)
endif()
foreach(TESTCASE IN ITEMS
test_kpoints
)
add_executable(${TESTCASE} ${TESTCASE}.cpp)
target_link_libraries(${TESTCASE}
PUBLIC gridsysmod
PRIVATE GTest::gtest GTest::gtest_main)
gtest_discover_tests(${TESTCASE})
endforeach()