2024-07-07 09:55:19 +08:00
|
|
|
cmake_minimum_required(VERSION 3.20)
|
2023-01-20 15:37:58 +08:00
|
|
|
|
2024-07-08 16:00:43 +08:00
|
|
|
option(BUILD_PHPHCALC_LIB "Option to build phph calculation module" OFF)
|
|
|
|
option(BUILD_PHONONCALC_LIB "Option to build phonon calculation module" OFF)
|
2024-07-14 11:51:13 +08:00
|
|
|
option(BUILD_RECGRID_LIB "Option to build reciprocal space grid module" OFF)
|
2024-07-08 16:00:43 +08:00
|
|
|
option(BUILD_GRIDSYS_LIB "Option to build gridsys module" OFF)
|
|
|
|
option(PHONO3PY_WITH_Fortran "enable fortran interface" OFF)
|
2024-04-21 13:02:09 +08:00
|
|
|
option(PHONO3PY_USE_OMP "Option to search OpenMP library" ON)
|
2024-07-08 16:00:43 +08:00
|
|
|
option(PHONO3PY_USE_MTBLAS "Use multithread BLAS if it exists" ON)
|
|
|
|
option(PHONO3PY_WITH_TESTS "build unit tests" OFF)
|
2024-07-07 09:55:19 +08:00
|
|
|
option(BUILD_SHARED_LIBS "Option to build shared library" OFF)
|
|
|
|
|
2024-07-08 16:00:43 +08:00
|
|
|
if(PHONO3PY_WITH_Fortran)
|
2024-07-07 09:55:19 +08:00
|
|
|
enable_language(Fortran)
|
2024-07-08 16:00:43 +08:00
|
|
|
set(BUILD_GRIDSYS_LIB ON)
|
2023-01-30 17:33:48 +08:00
|
|
|
endif()
|
2024-07-07 09:55:19 +08:00
|
|
|
|
2024-07-08 16:00:43 +08:00
|
|
|
if(PHONO3PY_WITH_TESTS)
|
2024-07-07 09:55:19 +08:00
|
|
|
set(BUILD_SHARED_LIBS ON)
|
2024-07-08 16:00:43 +08:00
|
|
|
set(BUILD_GRIDSYS_LIB ON)
|
2024-07-07 09:55:19 +08:00
|
|
|
endif()
|
|
|
|
|
2024-07-08 16:00:43 +08:00
|
|
|
if((NOT BUILD_PHPHCALC_LIB)
|
|
|
|
AND (NOT BUILD_PHONONCALC_LIB)
|
|
|
|
AND (NOT BUILD_GRIDSYS_LIB))
|
2024-07-07 09:55:19 +08:00
|
|
|
set(BUILD_NANOBIND_MODULE ON)
|
|
|
|
message(STATUS "Build nanobind module of ${SKBUILD_PROJECT_NAME}")
|
|
|
|
else()
|
|
|
|
set(BUILD_NANOBIND_MODULE OFF)
|
2023-01-20 15:37:58 +08:00
|
|
|
endif()
|
|
|
|
|
2024-07-07 09:55:19 +08:00
|
|
|
if(BUILD_NANOBIND_MODULE)
|
|
|
|
project(${SKBUILD_PROJECT_NAME})
|
|
|
|
set(DEV_MODULE Development.Module)
|
|
|
|
find_package(
|
|
|
|
Python 3.8 REQUIRED
|
|
|
|
COMPONENTS Interpreter ${DEV_MODULE}
|
|
|
|
OPTIONAL_COMPONENTS Development.SABIModule)
|
|
|
|
else()
|
|
|
|
project(phono3py C)
|
|
|
|
set(CMAKE_MACOSX_RPATH 1)
|
|
|
|
set(CMAKE_C_FLAGS_RELEASE "-Wall -O2")
|
|
|
|
set(CMAKE_C_FLAGS_DEBUG "-g -DLAGWARNING -DTHMWARNING")
|
|
|
|
|
|
|
|
# Version numbers
|
|
|
|
file(READ ${PROJECT_SOURCE_DIR}/phono3py/version.py version_file)
|
|
|
|
string(REGEX MATCH "__version__.*([0-9]+)[.]([0-9]+)[.]([0-9]+)"
|
|
|
|
phono3py_version ${version_file})
|
|
|
|
set(MAJOR_VERSION ${CMAKE_MATCH_1})
|
|
|
|
set(MINOR_VERSION ${CMAKE_MATCH_2})
|
|
|
|
set(MICRO_VERSION ${CMAKE_MATCH_3})
|
|
|
|
set(SERIAL "${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}")
|
|
|
|
set(SOSERIAL "1")
|
|
|
|
include(GNUInstallDirs)
|
|
|
|
endif()
|
2023-01-20 15:37:58 +08:00
|
|
|
|
2024-07-07 09:55:19 +08:00
|
|
|
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
|
|
|
set(CMAKE_BUILD_TYPE
|
|
|
|
Release
|
|
|
|
CACHE STRING "Choose the type of build." FORCE)
|
|
|
|
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
|
|
|
|
"MinSizeRel" "RelWithDebInfo")
|
|
|
|
endif()
|
2023-01-20 15:37:58 +08:00
|
|
|
|
2021-02-21 20:23:38 +08:00
|
|
|
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
|
2022-08-28 06:59:41 +08:00
|
|
|
message(STATUS "CMAKE_SYSTEM_PREFIX_PATH: ${CMAKE_SYSTEM_PREFIX_PATH}")
|
2021-02-21 20:23:38 +08:00
|
|
|
|
2024-07-07 11:43:00 +08:00
|
|
|
if(USE_CONDA_PATH AND DEFINED ENV{CONDA_PREFIX})
|
2024-07-07 09:55:19 +08:00
|
|
|
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)
|
2022-08-28 06:59:41 +08:00
|
|
|
else()
|
2024-07-07 09:55:19 +08:00
|
|
|
set(MY_INCLUDES ${PROJECT_SOURCE_DIR}/c)
|
2022-08-28 06:59:41 +08:00
|
|
|
endif()
|
|
|
|
|
2024-04-21 13:02:09 +08:00
|
|
|
if(PHONO3PY_USE_OMP)
|
2024-07-07 09:55:19 +08:00
|
|
|
message(STATUS "Find OpenMP library")
|
|
|
|
find_package(OpenMP)
|
2023-01-20 15:37:58 +08:00
|
|
|
|
2024-07-07 09:55:19 +08:00
|
|
|
if(OpenMP_FOUND)
|
|
|
|
message(STATUS "OpenMP libs: ${OpenMP_C_LIBRARIES}")
|
|
|
|
message(STATUS "OpenMP flags: ${OpenMP_C_FLAGS}")
|
|
|
|
endif()
|
2024-07-08 10:19:55 +08:00
|
|
|
else()
|
|
|
|
message(STATUS "OpenMP is not used.")
|
|
|
|
set(OpenMP_FOUND OFF) # cmake-lint: disable=C0103
|
2021-02-22 09:24:25 +08:00
|
|
|
endif()
|
|
|
|
|
2024-07-08 16:00:43 +08:00
|
|
|
if(BUILD_PHPHCALC_LIB
|
|
|
|
OR BUILD_PHONONCALC_LIB
|
2024-07-07 09:55:19 +08:00
|
|
|
OR BUILD_NANOBIND_MODULE)
|
|
|
|
find_package(BLAS REQUIRED) # set BLAS_LIBRARIES
|
2022-08-28 06:59:41 +08:00
|
|
|
|
2024-07-07 09:55:19 +08:00
|
|
|
if(BLAS_FOUND)
|
|
|
|
message(STATUS "BLAS libs: ${BLAS_LIBRARIES}")
|
|
|
|
message(STATUS "BLAS flags: ${BLAS_LINKER_FLAGS}")
|
2024-04-21 13:02:09 +08:00
|
|
|
endif()
|
2023-01-20 15:37:58 +08:00
|
|
|
|
2024-07-07 09:55:19 +08:00
|
|
|
find_package(LAPACK REQUIRED) # set LAPACK_LIBRARIES
|
2021-02-22 09:24:25 +08:00
|
|
|
|
2024-07-07 09:55:19 +08:00
|
|
|
if(LAPACK_FOUND)
|
|
|
|
message(STATUS "LAPACK libs: ${LAPACK_LIBRARIES}")
|
|
|
|
message(STATUS "LAPACK flags: ${LAPACK_LINKER_FLAGS}")
|
|
|
|
endif()
|
2023-01-20 15:37:58 +08:00
|
|
|
|
|
|
|
if(BLAS_LIBRARIES MATCHES "libmkl")
|
2024-07-08 16:00:43 +08:00
|
|
|
message(STATUS "MKL detected: Set C-macro MKL_LAPACKE.")
|
2024-07-07 09:55:19 +08:00
|
|
|
|
2024-07-08 16:00:43 +08:00
|
|
|
if(PHONO3PY_USE_MTBLAS)
|
|
|
|
message(
|
|
|
|
STATUS "Set C-macro MULTITHREADED_BLAS to avoid nested OpenMP calls."
|
|
|
|
)
|
2024-07-07 09:55:19 +08:00
|
|
|
endif()
|
2022-09-02 17:35:24 +08:00
|
|
|
endif()
|
2023-01-20 15:37:58 +08:00
|
|
|
|
|
|
|
if(BLAS_LIBRARIES MATCHES "libopenblas")
|
2024-07-08 16:00:43 +08:00
|
|
|
message(STATUS "OpenBLAS detected.")
|
2023-01-20 15:37:58 +08:00
|
|
|
|
2024-07-08 16:00:43 +08:00
|
|
|
if(PHONO3PY_USE_MTBLAS)
|
|
|
|
message(
|
|
|
|
STATUS "Set C-macro MULTITHREADED_BLAS to avoid nested OpenMP calls."
|
|
|
|
)
|
2024-07-07 09:55:19 +08:00
|
|
|
endif()
|
2024-04-21 13:02:09 +08:00
|
|
|
endif()
|
2024-07-07 09:55:19 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# ###################################################################################
|
2024-07-14 11:51:13 +08:00
|
|
|
# Reciprocal space grid library #
|
|
|
|
# ###################################################################################
|
|
|
|
if(BUILD_RECGRID_LIB
|
|
|
|
OR BUILD_PHPHCALC_LIB
|
|
|
|
OR BUILD_NANOBIND_MODULE)
|
|
|
|
# Source code
|
|
|
|
set(SOURCES_PHPHCALC
|
|
|
|
${PROJECT_SOURCE_DIR}/c/bzgrid.c ${PROJECT_SOURCE_DIR}/c/grgrid.c
|
|
|
|
${PROJECT_SOURCE_DIR}/c/lagrid.c ${PROJECT_SOURCE_DIR}/c/snf3x3.c
|
|
|
|
${PROJECT_SOURCE_DIR}/c/recgrid.c)
|
|
|
|
|
|
|
|
if(BUILD_SHARED_LIBS)
|
|
|
|
# Shared library
|
|
|
|
add_library(recgrid_lib SHARED ${SOURCES_PHPHCALC})
|
|
|
|
else()
|
|
|
|
# Static link library
|
|
|
|
add_library(recgrid_lib STATIC ${SOURCES_PHPHCALC})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT BUILD_NANOBIND_MODULE)
|
|
|
|
if(BUILD_SHARED_LIBS)
|
|
|
|
set_property(TARGET recgrid_lib PROPERTY VERSION ${SERIAL})
|
|
|
|
set_property(TARGET recgrid_lib PROPERTY SOVERSION ${SOSERIAL})
|
|
|
|
install(TARGETS recgrid_lib LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
|
|
|
else()
|
|
|
|
set_property(TARGET recgrid_lib PROPERTY VERSION ${SERIAL})
|
|
|
|
set_property(TARGET recgrid_lib PROPERTY SOVERSION ${SOSERIAL})
|
|
|
|
set_property(TARGET recgrid_lib PROPERTY OUTPUT_NAME recgrid_lib)
|
|
|
|
install(TARGETS recgrid_lib ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Header file
|
|
|
|
install(FILES ${PROJECT_SOURCE_DIR}/c/recgrid.h
|
|
|
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# ###################################################################################
|
|
|
|
# Ph-ph calculation library #
|
2024-07-07 09:55:19 +08:00
|
|
|
# ###################################################################################
|
2024-07-08 16:00:43 +08:00
|
|
|
if(BUILD_PHPHCALC_LIB OR BUILD_NANOBIND_MODULE)
|
2024-07-07 09:55:19 +08:00
|
|
|
# Source code
|
|
|
|
set(SOURCES_PHPHCALC
|
|
|
|
${PROJECT_SOURCE_DIR}/c/collision_matrix.c
|
|
|
|
${PROJECT_SOURCE_DIR}/c/fc3.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/lapack_wrapper.c
|
|
|
|
${PROJECT_SOURCE_DIR}/c/phono3py.c
|
2024-07-14 14:13:11 +08:00
|
|
|
${PROJECT_SOURCE_DIR}/c/funcs.c
|
2024-07-07 09:55:19 +08:00
|
|
|
${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/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_LIBS)
|
|
|
|
# Shared library
|
|
|
|
add_library(phphcalc_lib SHARED ${SOURCES_PHPHCALC})
|
2024-07-08 10:19:55 +08:00
|
|
|
|
|
|
|
if(OpenMP_FOUND)
|
2024-07-14 11:51:13 +08:00
|
|
|
target_link_libraries(
|
|
|
|
phphcalc_lib PRIVATE recgrid_lib BLAS::BLAS LAPACK::LAPACK
|
|
|
|
OpenMP::OpenMP_C)
|
2024-07-08 10:19:55 +08:00
|
|
|
else()
|
2024-07-14 11:51:13 +08:00
|
|
|
target_link_libraries(phphcalc_lib PRIVATE recgrid_lib BLAS::BLAS
|
|
|
|
LAPACK::LAPACK)
|
2024-07-08 10:19:55 +08:00
|
|
|
endif()
|
|
|
|
|
2024-07-07 09:55:19 +08:00
|
|
|
target_include_directories(phphcalc_lib PRIVATE ${MY_INCLUDES})
|
|
|
|
|
|
|
|
if(BLAS_LIBRARIES MATCHES "libmkl")
|
2024-07-08 16:00:43 +08:00
|
|
|
if(PHONO3PY_USE_MTBLAS)
|
2024-07-07 09:55:19 +08:00
|
|
|
target_compile_definitions(
|
|
|
|
phphcalc_lib PRIVATE MKL_LAPACKE MULTITHREADED_BLAS
|
|
|
|
THM_EPSILON=1e-10)
|
|
|
|
else()
|
|
|
|
target_compile_definitions(phphcalc_lib PRIVATE MKL_LAPACKE
|
|
|
|
THM_EPSILON=1e-10)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(BLAS_LIBRARIES MATCHES "libopenblas")
|
2024-07-08 16:00:43 +08:00
|
|
|
if(PHONO3PY_USE_MTBLAS)
|
2024-07-07 09:55:19 +08:00
|
|
|
target_compile_definitions(phphcalc_lib PRIVATE MULTITHREADED_BLAS
|
|
|
|
THM_EPSILON=1e-10)
|
|
|
|
else()
|
|
|
|
target_compile_definitions(phphcalc_lib PRIVATE THM_EPSILON=1e-10)
|
|
|
|
endif()
|
|
|
|
endif()
|
2024-04-21 13:02:09 +08:00
|
|
|
else()
|
2024-07-07 09:55:19 +08:00
|
|
|
# Static link library
|
|
|
|
add_library(phphcalc_lib STATIC ${SOURCES_PHPHCALC})
|
2024-07-08 10:19:55 +08:00
|
|
|
|
|
|
|
if(OpenMP_FOUND)
|
2024-07-14 11:51:13 +08:00
|
|
|
target_link_libraries(phphcalc_lib recgrid_lib BLAS::BLAS LAPACK::LAPACK
|
2024-07-08 10:19:55 +08:00
|
|
|
OpenMP::OpenMP_C)
|
|
|
|
else()
|
2024-07-14 11:51:13 +08:00
|
|
|
target_link_libraries(phphcalc_lib recgrid_lib BLAS::BLAS LAPACK::LAPACK)
|
2024-07-08 10:19:55 +08:00
|
|
|
endif()
|
|
|
|
|
2024-07-07 09:55:19 +08:00
|
|
|
target_include_directories(phphcalc_lib PRIVATE ${MY_INCLUDES})
|
|
|
|
|
|
|
|
if(BLAS_LIBRARIES MATCHES "libmkl")
|
2024-07-08 16:00:43 +08:00
|
|
|
if(PHONO3PY_USE_MTBLAS)
|
2024-07-07 09:55:19 +08:00
|
|
|
target_compile_definitions(
|
|
|
|
phphcalc_lib PRIVATE MKL_LAPACKE MULTITHREADED_BLAS
|
|
|
|
THM_EPSILON=1e-10)
|
|
|
|
else()
|
|
|
|
target_compile_definitions(phphcalc_lib PRIVATE MKL_LAPACKE
|
|
|
|
THM_EPSILON=1e-10)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(BLAS_LIBRARIES MATCHES "libopenblas")
|
2024-07-08 16:00:43 +08:00
|
|
|
if(PHONO3PY_USE_MTBLAS)
|
2024-07-07 09:55:19 +08:00
|
|
|
target_compile_definitions(phphcalc_lib PRIVATE MULTITHREADED_BLAS
|
|
|
|
THM_EPSILON=1e-10)
|
|
|
|
else()
|
|
|
|
target_compile_definitions(phphcalc_lib PRIVATE THM_EPSILON=1e-10)
|
|
|
|
endif()
|
|
|
|
endif()
|
2024-04-21 13:02:09 +08:00
|
|
|
endif()
|
2023-01-22 11:01:04 +08:00
|
|
|
|
2024-07-07 09:55:19 +08:00
|
|
|
if(NOT BUILD_NANOBIND_MODULE)
|
|
|
|
if(BUILD_SHARED_LIBS)
|
|
|
|
set_property(TARGET phphcalc_lib PROPERTY VERSION ${SERIAL})
|
|
|
|
set_property(TARGET phphcalc_lib PROPERTY SOVERSION ${SOSERIAL})
|
|
|
|
install(TARGETS phphcalc_lib LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
|
|
|
else()
|
|
|
|
set_property(TARGET phphcalc_lib PROPERTY VERSION ${SERIAL})
|
|
|
|
set_property(TARGET phphcalc_lib PROPERTY SOVERSION ${SOSERIAL})
|
|
|
|
set_property(TARGET phphcalc_lib PROPERTY OUTPUT_NAME phphcalc_lib)
|
|
|
|
install(TARGETS phphcalc_lib ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Header file
|
|
|
|
install(FILES ${PROJECT_SOURCE_DIR}/c/phono3py.h
|
|
|
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
|
|
|
endif()
|
2021-02-21 20:23:38 +08:00
|
|
|
endif()
|
2021-02-22 09:24:25 +08:00
|
|
|
|
2024-07-07 09:55:19 +08:00
|
|
|
# ###################################################################################
|
2024-07-14 11:51:13 +08:00
|
|
|
# Phonon calculation library #
|
2024-07-07 09:55:19 +08:00
|
|
|
# ###################################################################################
|
2024-07-08 16:00:43 +08:00
|
|
|
if(BUILD_PHONONCALC_LIB OR BUILD_NANOBIND_MODULE)
|
2024-07-07 09:55:19 +08:00
|
|
|
# Source code
|
|
|
|
set(SOURCES_PHONONCALC
|
|
|
|
${PROJECT_SOURCE_DIR}/c/dynmat.c ${PROJECT_SOURCE_DIR}/c/lapack_wrapper.c
|
|
|
|
${PROJECT_SOURCE_DIR}/c/phonon.c ${PROJECT_SOURCE_DIR}/c/phononcalc.c)
|
|
|
|
|
|
|
|
if(BUILD_SHARED_LIBS)
|
|
|
|
# Shared library
|
|
|
|
add_library(phononcalc_lib SHARED ${SOURCES_PHONONCALC})
|
2024-07-08 10:19:55 +08:00
|
|
|
|
|
|
|
if(OpenMP_FOUND)
|
|
|
|
target_link_libraries(phononcalc_lib BLAS::BLAS LAPACK::LAPACK
|
|
|
|
OpenMP::OpenMP_C)
|
|
|
|
else()
|
|
|
|
target_link_libraries(phononcalc_lib BLAS::BLAS LAPACK::LAPACK)
|
|
|
|
endif()
|
|
|
|
|
2024-07-07 09:55:19 +08:00
|
|
|
target_include_directories(phononcalc_lib PRIVATE ${MY_INCLUDES})
|
|
|
|
|
|
|
|
if(BLAS_LIBRARIES MATCHES "libmkl")
|
|
|
|
target_compile_definitions(phononcalc_lib PRIVATE MKL_LAPACKE
|
|
|
|
MULTITHREADED_BLAS)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(BLAS_LIBRARIES MATCHES "libopenblas")
|
|
|
|
target_compile_definitions(phononcalc_lib PRIVATE MULTITHREADED_BLAS)
|
|
|
|
endif()
|
2023-01-20 15:37:58 +08:00
|
|
|
|
2024-07-07 09:55:19 +08:00
|
|
|
else()
|
|
|
|
# Static link library
|
|
|
|
add_library(phononcalc_lib STATIC ${SOURCES_PHONONCALC})
|
2024-07-08 10:19:55 +08:00
|
|
|
|
|
|
|
if(OpenMP_FOUND)
|
|
|
|
target_link_libraries(phononcalc_lib PRIVATE BLAS::BLAS LAPACK::LAPACK
|
|
|
|
OpenMP::OpenMP_C)
|
|
|
|
else()
|
|
|
|
target_link_libraries(phononcalc_lib PRIVATE BLAS::BLAS LAPACK::LAPACK)
|
|
|
|
endif()
|
|
|
|
|
2024-07-07 09:55:19 +08:00
|
|
|
target_include_directories(phononcalc_lib PRIVATE ${MY_INCLUDES})
|
|
|
|
|
|
|
|
if(BLAS_LIBRARIES MATCHES "libmkl")
|
|
|
|
target_compile_definitions(phononcalc_lib PRIVATE MKL_LAPACKE
|
|
|
|
MULTITHREADED_BLAS)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(BLAS_LIBRARIES MATCHES "libopenblas")
|
|
|
|
target_compile_definitions(phononcalc_lib PRIVATE MULTITHREADED_BLAS)
|
|
|
|
endif()
|
2023-01-20 15:37:58 +08:00
|
|
|
endif()
|
|
|
|
|
2024-07-07 09:55:19 +08:00
|
|
|
if(NOT BUILD_NANOBIND_MODULE)
|
|
|
|
if(BUILD_SHARED_LIBS)
|
|
|
|
set_property(TARGET phononcalc_lib PROPERTY VERSION ${SERIAL})
|
|
|
|
set_property(TARGET phononcalc_lib PROPERTY SOVERSION ${SOSERIAL})
|
|
|
|
install(TARGETS phononcalc_lib
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
|
|
|
|
|
|
|
else()
|
|
|
|
set_property(TARGET phononcalc_lib PROPERTY VERSION ${SERIAL})
|
|
|
|
set_property(TARGET phononcalc_lib PROPERTY SOVERSION ${SOSERIAL})
|
|
|
|
set_property(TARGET phononcalc_lib PROPERTY OUTPUT_NAME phononcalc_lib)
|
|
|
|
install(TARGETS phononcalc_lib
|
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Header file
|
|
|
|
install(FILES ${PROJECT_SOURCE_DIR}/c/phononcalc.h
|
|
|
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
2022-09-02 17:35:24 +08:00
|
|
|
endif()
|
2021-02-22 09:24:25 +08:00
|
|
|
endif()
|
2021-04-07 20:51:06 +08:00
|
|
|
|
2024-07-07 09:55:19 +08:00
|
|
|
# ###################################################################################
|
2024-07-14 11:51:13 +08:00
|
|
|
# gridsys #
|
2024-07-07 09:55:19 +08:00
|
|
|
# ###################################################################################
|
2024-07-08 16:00:43 +08:00
|
|
|
if(BUILD_GRIDSYS_LIB)
|
2024-07-07 09:55:19 +08:00
|
|
|
# Source code
|
|
|
|
set(SOURCES_GRIDSYS
|
|
|
|
${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/niggli.c
|
2024-07-14 14:13:11 +08:00
|
|
|
${PROJECT_SOURCE_DIR}/c/funcs.c
|
2024-07-07 09:55:19 +08:00
|
|
|
${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_LIBS)
|
|
|
|
# Shared library
|
|
|
|
add_library(gridsys SHARED ${SOURCES_GRIDSYS})
|
2024-07-08 10:19:55 +08:00
|
|
|
|
|
|
|
if(OpenMP_FOUND)
|
|
|
|
target_link_libraries(gridsys PRIVATE OpenMP::OpenMP_C)
|
|
|
|
endif()
|
|
|
|
|
2024-07-07 09:55:19 +08:00
|
|
|
target_include_directories(gridsys PRIVATE ${MY_INCLUDES})
|
|
|
|
target_compile_definitions(gridsys PRIVATE THM_EPSILON=1e-10)
|
|
|
|
set_property(TARGET gridsys PROPERTY VERSION ${SERIAL})
|
|
|
|
set_property(TARGET gridsys PROPERTY SOVERSION ${SOSERIAL})
|
|
|
|
install(TARGETS gridsys LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
|
|
|
else()
|
|
|
|
# Static link library
|
|
|
|
add_library(gridsys_static STATIC ${SOURCES_GRIDSYS})
|
2024-07-08 10:19:55 +08:00
|
|
|
|
|
|
|
if(OpenMP_FOUND)
|
|
|
|
target_link_libraries(gridsys_static PRIVATE OpenMP::OpenMP_C)
|
|
|
|
endif()
|
|
|
|
|
2024-07-07 09:55:19 +08:00
|
|
|
target_include_directories(gridsys_static PRIVATE ${MY_INCLUDES})
|
|
|
|
target_compile_definitions(gridsys_static PRIVATE THM_EPSILON=1e-10)
|
|
|
|
set_property(TARGET gridsys_static PROPERTY VERSION ${SERIAL})
|
|
|
|
set_property(TARGET gridsys_static PROPERTY SOVERSION ${SOSERIAL})
|
|
|
|
set_property(TARGET gridsys_static PROPERTY OUTPUT_NAME gridsys)
|
|
|
|
install(TARGETS gridsys_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Header file
|
|
|
|
install(FILES ${PROJECT_SOURCE_DIR}/c/gridsys.h
|
|
|
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
2023-01-20 15:37:58 +08:00
|
|
|
endif()
|
|
|
|
|
2024-07-08 16:00:43 +08:00
|
|
|
if(PHONO3PY_WITH_Fortran)
|
2024-07-07 09:55:19 +08:00
|
|
|
add_subdirectory(fortran)
|
2023-01-21 11:20:52 +08:00
|
|
|
endif()
|
2023-01-30 17:33:48 +08:00
|
|
|
|
2024-07-08 16:00:43 +08:00
|
|
|
if(PHONO3PY_WITH_TESTS)
|
|
|
|
if(PHONO3PY_WITH_Fortran)
|
2024-07-07 09:55:19 +08:00
|
|
|
set(LIB_MOD_DIR ${CMAKE_CURRENT_BINARY_DIR}/fortran)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
add_subdirectory(ctest)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(BUILD_NANOBIND_MODULE)
|
|
|
|
set_target_properties(phphcalc_lib PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
|
|
|
set_target_properties(phononcalc_lib PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
|
|
|
|
|
|
|
execute_process(
|
|
|
|
COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
OUTPUT_VARIABLE NB_DIR)
|
|
|
|
list(APPEND CMAKE_PREFIX_PATH "${NB_DIR}")
|
|
|
|
find_package(nanobind CONFIG REQUIRED)
|
2024-07-08 09:54:28 +08:00
|
|
|
nanobind_add_module(_phono3py STABLE_ABI ${PROJECT_SOURCE_DIR}/c/phono3py.h
|
|
|
|
${PROJECT_SOURCE_DIR}/c/_phono3py.cpp)
|
|
|
|
nanobind_add_module(_phononcalc STABLE_ABI ${PROJECT_SOURCE_DIR}/c/phononcalc.h
|
|
|
|
${PROJECT_SOURCE_DIR}/c/_phononcalc.cpp)
|
2024-07-14 11:51:13 +08:00
|
|
|
nanobind_add_module(_recgrid STABLE_ABI ${PROJECT_SOURCE_DIR}/c/recgrid.h
|
|
|
|
${PROJECT_SOURCE_DIR}/c/_recgrid.cpp)
|
2024-07-07 09:55:19 +08:00
|
|
|
|
2024-07-08 10:19:55 +08:00
|
|
|
target_link_libraries(_phono3py PRIVATE phphcalc_lib)
|
|
|
|
target_link_libraries(_phononcalc PRIVATE phononcalc_lib)
|
2024-07-14 11:51:13 +08:00
|
|
|
target_link_libraries(_recgrid PRIVATE recgrid_lib)
|
2024-07-07 09:55:19 +08:00
|
|
|
|
|
|
|
target_compile_definitions(_phono3py PRIVATE THM_EPSILON=1e-10)
|
|
|
|
install(TARGETS _phono3py LIBRARY DESTINATION ${SKBUILD_PROJECT_NAME})
|
2024-07-08 09:54:28 +08:00
|
|
|
install(TARGETS _phononcalc LIBRARY DESTINATION ${SKBUILD_PROJECT_NAME})
|
2024-07-14 11:51:13 +08:00
|
|
|
install(TARGETS _recgrid LIBRARY DESTINATION ${SKBUILD_PROJECT_NAME})
|
2023-01-30 17:33:48 +08:00
|
|
|
endif()
|