File: CMakeLists.txt

package info (click to toggle)
gau2grid 1.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 564 kB
  • sloc: python: 4,914; makefile: 30
file content (171 lines) | stat: -rw-r--r-- 8,664 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)

project(gau2grid
        VERSION 1.3.1
        LANGUAGES C)
set(gau2grid_AUTHORS      "Daniel G. A. Smith")
set(gau2grid_DESCRIPTION  "Fast computation of a gaussian and its derivative on a grid")
set(gau2grid_URL          "https://github.com/dgasmith/gau2grid")
set(gau2grid_LICENSE      "BSD 3-clause")

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)


#############################  Options: Build How?  #############################
include(psi4OptionsTools)
option_with_default(MAX_AM "The maximum gaussian angular momentum to compile" 8)
option_with_default(SPHERICAL_ORDER "The order for the spherical basis functions. Options: cca, gaussian" "gaussian")
option_with_default(CARTESIAN_ORDER "The order for the cartesian basis functions. Options: row, molden" "row")

option_with_default(MAX_AM "The maximum gaussian angular momentum to compile" 8)
option_with_default(CMAKE_BUILD_TYPE "Build type (Release or Debug)" Release)
option_with_flags(ENABLE_XHOST "Enables processor-specific optimization" ON
                  "-xHost" "-march=native")

option_with_default(BUILD_FPIC "Libraries will be compiled with position independent code" ON)
option_with_print(BUILD_SHARED_LIBS "Build final library as shared, not static" ON)
option_with_default(ENABLE_GENERIC "Enables mostly static linking of system libraries for shared library" OFF)

# Warnings
if((${BUILD_SHARED_LIBS}) AND NOT ${BUILD_FPIC})
    message(FATAL_ERROR "BUILD_SHARED_LIBS ON and BUILD_FPIC OFF are incompatible, as shared library requires position independent code")
endif()
if(NOT ((${SPHERICAL_ORDER} STREQUAL "cca") OR (${SPHERICAL_ORDER} STREQUAL "gaussian")))
    message(FATAL_ERROR "SPHERICAL_ORDER must be 'cca' or 'gaussian': ${SPHERICAL_ORDER}")
endif()
if(NOT ((${CARTESIAN_ORDER} STREQUAL "row") OR (${CARTESIAN_ORDER} STREQUAL "molden")))
    message(FATAL_ERROR "CARTESIAN_ORDER must be 'row' or 'molden': ${CARTESIAN_ORDER}")
endif()

# Install
option_with_default(CMAKE_INSTALL_LIBDIR "Directory to which libraries installed" lib)
option_with_default(PYMOD_INSTALL_LIBDIR "Location within CMAKE_INSTALL_LIBDIR to which python modules are installed
                                          Must start with: / . Used to imitate python install: /python3.6/site-packages ." /)
option_with_print(INSTALL_PYMOD "Additionally installs as independent python module in PYMOD_INSTALL_LIBDIR" OFF)
option_with_default(NATIVE_PYTHON_INSTALL "For INSTALL_PYMOD=ON, install in Python manner to PYTHON_EXECUTABLE's site-packages rather than Linux manner to prefix. Overrides CMAKE_INSTALL_PREFIX, CMAKE_INSTALL_LIBDIR, PYMOD_INSTALL_LIBDIR. Only Py module installed." OFF)

########################  Process & Validate Options  ##########################
include(autocmake_safeguards)
include(custom_color_messages)
include(custom_static_library)

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
    set(CMAKE_INSTALL_PREFIX "/usr/local/gau2grid" CACHE PATH "Install path" FORCE)
endif()
message(STATUS "gau2grid install: ${CMAKE_INSTALL_PREFIX}")

#  <<  Python  >>
set(Python_ADDITIONAL_VERSIONS 3.7 3.6 3.5)  # adjust with CMake minimum FindPythonInterp
find_package(PythonLibsNew 2.7 REQUIRED)
message(STATUS "${Cyan}Found Python ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}${ColourReset}: ${PYTHON_EXECUTABLE} (found version ${PYTHON_VERSION_STRING})")


################################  Main Project  ################################
add_custom_command(
    OUTPUT  gau2grid.h gau2grid_orbital.c gau2grid_phi.c gau2grid_deriv1.c gau2grid_deriv2.c gau2grid_spherical.c gau2grid_helper.c
    COMMAND ${PYTHON_EXECUTABLE} -c "import sys; \
                                     sys.path.append('${CMAKE_SOURCE_DIR}'); \
                                     import gau2grid as gg; \
                                     gg.c_gen.generate_c_gau2grid(${MAX_AM}, path='${CMAKE_CURRENT_BINARY_DIR}', cartesian_order='${CARTESIAN_ORDER}', spherical_order='${SPHERICAL_ORDER}')"
    DEPENDS gau2grid/c_generator.py
            gau2grid/c_generator.py
            gau2grid/codegen.py
            gau2grid/c_pragma.py
            gau2grid/c_util_generator.py
            gau2grid/c_wrapper.py
            gau2grid/docs_generator.py
            gau2grid/np_generator.py
            gau2grid/order.py
            gau2grid/python_reference.py
            gau2grid/RSH.py
            gau2grid/utility.py
    VERBATIM)

set(sources_list ${CMAKE_CURRENT_BINARY_DIR}/gau2grid_phi.c
                 ${CMAKE_CURRENT_BINARY_DIR}/gau2grid_orbital.c
                 ${CMAKE_CURRENT_BINARY_DIR}/gau2grid_deriv1.c
                 ${CMAKE_CURRENT_BINARY_DIR}/gau2grid_deriv2.c
                 ${CMAKE_CURRENT_BINARY_DIR}/gau2grid_spherical.c
                 ${CMAKE_CURRENT_BINARY_DIR}/gau2grid_helper.c)

add_library(gg ${sources_list})
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "PGI")
    set_target_properties(gg PROPERTIES COMPILE_FLAGS "-c11")
else()
    set_target_properties(gg PROPERTIES COMPILE_FLAGS "-std=c11")
endif()
set_target_properties(gg PROPERTIES POSITION_INDEPENDENT_CODE ${BUILD_FPIC}
                                    SOVERSION 1)  # bump whenever interface has changes or removals

if(${BUILD_SHARED_LIBS})
    target_link_libraries(gg PRIVATE ${LIBC_INTERJECT})
endif()


###################################  Install  ##################################
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

set(PN ${PROJECT_NAME})

target_include_directories(gg INTERFACE
                           $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

# GNUInstallDirs "DATADIR" wrong here; CMake search path wants "share".
set(CMAKECONFIG_INSTALL_DIR "share/cmake/${PN}")
configure_package_config_file(cmake/${PN}Config.cmake.in
                              "${CMAKE_CURRENT_BINARY_DIR}/${PN}Config.cmake"
                              INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR})
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PN}ConfigVersion.cmake
                                 VERSION ${${PN}_VERSION}
                                 COMPATIBILITY AnyNewerVersion)

# Install our files
if(NOT(${INSTALL_PYMOD} AND ${NATIVE_PYTHON_INSTALL}))
    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/gau2grid.h
                  ${CMAKE_CURRENT_BINARY_DIR}/gau2grid_pragma.h
                  DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PN})

    install(TARGETS gg
            EXPORT "${PN}Targets"
            ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
            LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})

    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PN}Config.cmake
                  ${CMAKE_CURRENT_BINARY_DIR}/${PN}ConfigVersion.cmake
            DESTINATION ${CMAKECONFIG_INSTALL_DIR})
    install(EXPORT "${PN}Targets"
            NAMESPACE "${PN}::"
            DESTINATION ${CMAKECONFIG_INSTALL_DIR})
endif()

if(${INSTALL_PYMOD})
    if(${NATIVE_PYTHON_INSTALL})
        execute_process(COMMAND ${PYTHON_EXECUTABLE} -c
                        "import sys; print(sys.prefix);"
                        OUTPUT_VARIABLE CMAKE_INSTALL_PREFIX
                        OUTPUT_STRIP_TRAILING_WHITESPACE)
        execute_process(COMMAND ${PYTHON_EXECUTABLE} -c
                        "from distutils import sysconfig as s; import os; import sys; cmake_install_prefix = sys.prefix; prefix_lib = s.get_config_var('LIBDIR'); print(prefix_lib.replace(os.path.commonpath([prefix_lib, cmake_install_prefix]), '').strip('/'));"
                        OUTPUT_VARIABLE CMAKE_INSTALL_LIBDIR
                        OUTPUT_STRIP_TRAILING_WHITESPACE)
        execute_process(COMMAND ${PYTHON_EXECUTABLE} -c
                        "from distutils import sysconfig as s; import os; prefix_lib = s.get_config_var('LIBDIR'); spdir = s.get_python_lib(plat_specific=True); print(spdir.replace(os.path.commonpath([prefix_lib, spdir]), ''));"
                        OUTPUT_VARIABLE PYMOD_INSTALL_LIBDIR
                        OUTPUT_STRIP_TRAILING_WHITESPACE)
    endif()

    execute_process(COMMAND ${PYTHON_EXECUTABLE} -c
                    "from numpy import distutils; print(distutils.misc_util.get_shared_lib_extension(is_python_ext=False))"
                    OUTPUT_VARIABLE PYLIB_EXTENSION
                    OUTPUT_STRIP_TRAILING_WHITESPACE)

    install(DIRECTORY gau2grid
            DESTINATION ${CMAKE_INSTALL_LIBDIR}${PYMOD_INSTALL_LIBDIR}
            USE_SOURCE_PERMISSIONS
            FILES_MATCHING PATTERN "*.py")

    install(FILES $<TARGET_FILE:gg>
            DESTINATION ${CMAKE_INSTALL_LIBDIR}${PYMOD_INSTALL_LIBDIR}/gau2grid
            RENAME "gg${PYLIB_EXTENSION}")
endif()