# nsmc --- n-sphere Monte Carlo method # Copyright © 2021 Arun I # Copyright © 2021 Murugesan Venkatapathi # # 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 . 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)