blob: b4fae28a052f44dfbf3d7c808b73d651c615162c (
plain)
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
|
# nsmc --- n-sphere Monte Carlo method
# Copyright © 2021 Arun I <arunisaac@systemreboot.net>
# Copyright © 2021 Murugesan Venkatapathi <murugesh@iisc.ac.in>
#
# This file is part of nsmc.
#
# nsmc is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# nsmc is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License
# along with nsmc. If not, see <https://www.gnu.org/licenses/>.
cmake_minimum_required(VERSION 3.10)
project(nsmc VERSION 0.1.0)
find_package(GSL REQUIRED)
find_program(SC NAMES sc REQUIRED)
find_program(INDENT NAMES indent)
# TODO: Maybe, support other versions of guile such as 2.2.
pkg_check_modules(GUILE guile-3.0)
pkg_get_variable(GUILD guile-3.0 guild)
include(GNUInstallDirs)
function(change_extension var filename extension)
get_filename_component(basename ${filename} NAME_WE)
get_filename_component(dirname ${filename} DIRECTORY)
set(${var} ${dirname}/${basename}.${extension} PARENT_SCOPE)
endfunction()
# Generate C source files from SC source files, and optionally indent
# them.
file(GLOB SC_SOURCES "src/*.sc")
foreach(sc_source ${SC_SOURCES})
get_filename_component(source_basename ${sc_source} NAME_WE)
set(c_file ${source_basename}.c)
if(${INDENT} STREQUAL INDENT-NOTFOUND)
add_custom_command(
OUTPUT ${c_file}
COMMAND ${SC} ${sc_source} ${c_file}
DEPENDS ${sc_source} src/macros/macros.sc
VERBATIM)
else()
add_custom_command(
OUTPUT ${c_file}
COMMAND ${SC} ${sc_source} ${c_file}
COMMAND ${INDENT} ${c_file}
DEPENDS ${sc_source} src/macros/macros.sc
VERBATIM)
endif()
list(APPEND C_SOURCES ${c_file})
endforeach()
include_directories("include")
# Build and install shared library with headers.
add_library(nsmc SHARED extent-sampling.c gaussian-nd-random.c integrands.c nd-random.c oracles.c utils.c)
target_link_libraries(nsmc -lgsl -lgslcblas)
set_target_properties(nsmc PROPERTIES
PUBLIC_HEADER "include/extent-sampling.h;include/gaussian-nd-random.h;include/nd-random.h;include/oracles.h")
install(TARGETS nsmc LIBRARY
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/nsmc)
# Build executables
add_executable(volume-bodies volume-bodies.c)
target_link_libraries(volume-bodies nsmc)
add_executable(integral integral.c)
target_link_libraries(integral nsmc -lm)
add_executable(spheroid spheroid.c)
target_link_libraries(spheroid nsmc)
# Build and install scheme wrapper.
if(${GUILE_FOUND})
configure_file(scm/nsmc/load-libs.scm.in scm/nsmc/load-libs.scm)
set(SCM_WRAPPER_PATH scm/nsmc/wrap.scm)
change_extension(SCM_WRAPPER_GO_PATH ${SCM_WRAPPER_PATH} go)
add_custom_command(
OUTPUT ${SCM_WRAPPER_GO_PATH}
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/${SCM_WRAPPER_PATH} ${CMAKE_BINARY_DIR}/${SCM_WRAPPER_PATH}
COMMAND ${GUILD} compile ${CMAKE_BINARY_DIR}/${SCM_WRAPPER_PATH} -o ${CMAKE_BINARY_DIR}/${SCM_WRAPPER_GO_PATH}
DEPENDS ${SCM_WRAPPER_PATH}
VERBATIM)
add_custom_target(scheme ALL DEPENDS ${SCM_WRAPPER_GO_PATH})
string(REPLACE "." ";" GUILE_VERSION_LIST ${GUILE_VERSION})
list(GET GUILE_VERSION_LIST 0 GUILE_MAJOR_VERSION)
list(GET GUILE_VERSION_LIST 1 GUILE_MINOR_VERSION)
install(FILES ${CMAKE_BINARY_DIR}/scm/nsmc/load-libs.scm
DESTINATION ${CMAKE_INSTALL_DATADIR}/guile/site/${GUILE_MAJOR_VERSION}.${GUILE_MINOR_VERSION}/nsmc)
install(FILES ${CMAKE_BINARY_DIR}/${SCM_WRAPPER_PATH}
DESTINATION ${CMAKE_INSTALL_DATADIR}/guile/site/${GUILE_MAJOR_VERSION}.${GUILE_MINOR_VERSION}/nsmc)
install(FILES ${CMAKE_BINARY_DIR}/${SCM_WRAPPER_GO_PATH}
DESTINATION ${CMAKE_INSTALL_LIBDIR}/guile/site/${GUILE_MAJOR_VERSION}.${GUILE_MINOR_VERSION}/site-ccache/nsmc)
endif()
# Configure environment wrapper script.
configure_file(pre-inst-env.in pre-inst-env @ONLY)
|