Skip to content

Commit

Permalink
Merge pull request #26 from rk-lindsey/develop
Browse files Browse the repository at this point in the history
Update main from develop: Sync BB/GH; Add CI; Conda compatibility
  • Loading branch information
rk-lindsey authored Jan 14, 2022
2 parents 5ff5668 + 03f5688 commit 7ca7d39
Show file tree
Hide file tree
Showing 28 changed files with 461 additions and 262 deletions.
39 changes: 28 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,53 @@ jobs:
- name: Set up environment (Linux)
if: contains(matrix.os, 'ubuntu')
run: |
echo "ROOTFOLDER=${PWD}" >> $GITHUB_ENV
echo "SOURCEDIR=${PWD}" >> $GITHUB_ENV
echo "WORKDIR=${PWD}" >> $GITHUB_ENV
echo "FC=gfortran" >> $GITHUB_ENV
echo "CC=gcc" >> $GITHUB_ENV
echo "CXX=g++" >> $GITHUB_ENV
sudo apt-get update
sudo apt-get install cmake ninja-build
- name: Set up environment (OSX)
if: contains(matrix.os, 'macos')
run: |
echo "ROOTFOLDER=${PWD}" >> $GITHUB_ENV
echo "SOURCEDIR=${PWD}" >> $GITHUB_ENV
echo "WORKDIR=${PWD}" >> $GITHUB_ENV
echo "FC=gfortran-9" >> $GITHUB_ENV
echo "CC=gcc-9" >> $GITHUB_ENV
echo "CXX=g++-9" >> $GITHUB_ENV
brew install ninja
- name: Configure build
run: >-
cmake -B _build -G Ninja
-DCMAKE_INSTALL_PREFIX=${ROOTFOLDER}/_install
-DWITH_FORTRAN08_API=1
run: |
mkdir ${WORKDIR}/_build
cd ${WORKDIR}/_build
cmake -G Ninja -DCMAKE_INSTALL_PREFIX=${WORKDIR}/_install -DWITH_FORTRAN08_API=1 -DTEST_LABELS="minimal" ${SOURCEDIR}
cd -
- name: Build project
run: |
cmake --build _build
cd ${WORKDIR}/_build
ninja all
cd -
- name: Test project
run: |
cd ${WORKDIR}/_build
ctest
cd -
- name: Install project
run: |
cmake --install _build
cd ${WORKDIR}/_build
ninja install
cd -
- name: Run integration test
run: |
CMAKE_PREFIX_PATH=${ROOTFOLDER}/_install cmake -B _build_integtest -G Ninja ${ROOTFOLDER}/serial_interface/examples/fortran08
cmake --build _build_integtest
LD_LIBRARY_PATH=${ROOTFOLDER}/_install/lib ./_build_integtest/test_chimescalc ${ROOTFOLDER}/serial_interface/tests/force_fields/test_params.CHON.txt serial_interface/tests/configurations/CHON.testfile.000.xyz | grep "Energy (kcal/mol) -7.83714"
mkdir ${WORKDIR}/_build_integtest
cd ${WORKDIR}/_build_integtest
CMAKE_PREFIX_PATH=${WORKDIR}/_install cmake -G Ninja ${SOURCEDIR}/serial_interface/examples/fortran08
ninja all
LD_LIBRARY_PATH=${WORKDIR}/_install/lib ./test_chimescalc ${SOURCEDIR}/serial_interface/tests/force_fields/test_params.CHON.txt ${SOURCEDIR}/serial_interface/tests/configurations/CHON.testfile.000.xyz | grep "Energy (kcal/mol): -7.83714"
236 changes: 120 additions & 116 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cmake_minimum_required(VERSION 3.13)

############################################################
####################################################################################################
# General settings
############################################################
####################################################################################################

project(ChimesCalc
VERSION 1.0
Expand All @@ -29,9 +29,9 @@ if(NEEDS_LIB_M)
endif()


###############################################################################
# C++/C library
###############################################################################
####################################################################################################
# Static/shared library
####################################################################################################

set(c-sources
"chimesFF/src/chimesFF.cpp"
Expand Down Expand Up @@ -65,102 +65,62 @@ target_compile_features(ChimesCalc PRIVATE cxx_std_11)
install(TARGETS ChimesCalc
EXPORT ${PROJECT_NAME_LOWER}-targets
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${INSTALL_INCLUDEDIR}")
PUBLIC_HEADER DESTINATION "${INSTALL_INCLUDEDIR}")


############################################################
####################################################################################################
# Executables for C/C++
############################################################
####################################################################################################

add_executable(CPP-interface serial_interface/examples/cpp/main.cpp)
target_link_libraries(CPP-interface ChimesCalc)
target_compile_features (CPP-interface PUBLIC cxx_std_11)
target_compile_definitions(CPP-interface PRIVATE "DEBUG=${DEBUG}")
# Main executable installed as chimescalc
add_executable(ChimesCalcExe serial_interface/examples/cpp/main.cpp)
set_target_properties(ChimesCalcExe PROPERTIES OUTPUT_NAME "chimescalc")
target_link_libraries(ChimesCalcExe ChimesCalc)
target_compile_features (ChimesCalcExe PUBLIC cxx_std_11)
target_compile_definitions(ChimesCalcExe PRIVATE "DEBUG=${DEBUG}")

install(TARGETS ChimesCalcExe DESTINATION ${CMAKE_INSTALL_BINDIR})

if(NOT CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
install(TARGETS CPP-interface
DESTINATION ${CMAKE_INSTALL_PREFIX}/serial_interface/examples/cpp/ OPTIONAL)
endif()

add_executable(C_wrapper-direct_interface chimesFF/examples/c/main.c)
target_link_libraries (C_wrapper-direct_interface ChimesCalc ${LIB_M})
target_compile_features (C_wrapper-direct_interface PRIVATE cxx_std_11)
target_compile_definitions(C_wrapper-direct_interface PRIVATE "DEBUG=${DEBUG}")


if(NOT CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
install(TARGETS C_wrapper-direct_interface
DESTINATION ${CMAKE_INSTALL_PREFIX}/chimesFF/examples/c/ OPTIONAL)
endif()


add_executable(C_wrapper-serial_interface serial_interface/examples/c/main.c)
target_link_libraries (C_wrapper-serial_interface ChimesCalc)
target_compile_features (C_wrapper-serial_interface PRIVATE cxx_std_11)
target_compile_definitions(C_wrapper-serial_interface PRIVATE "DEBUG=${DEBUG}")

if(NOT CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
install(TARGETS C_wrapper-serial_interface
DESTINATION ${CMAKE_INSTALL_PREFIX}/serial_interface/examples/c/ OPTIONAL)
endif()
# Test executables
add_executable(chimescalc-test_direct-C chimesFF/examples/c/main.c)
target_link_libraries (chimescalc-test_direct-C ChimesCalc ${LIB_M})
target_compile_features (chimescalc-test_direct-C PRIVATE cxx_std_11)
target_compile_definitions(chimescalc-test_direct-C PRIVATE "DEBUG=${DEBUG}")

add_executable(chimescalc-test_serial-C serial_interface/examples/c/main.c)
target_link_libraries (chimescalc-test_serial-C ChimesCalc)
target_compile_features (chimescalc-test_serial-C PRIVATE cxx_std_11)
target_compile_definitions(chimescalc-test_serial-C PRIVATE "DEBUG=${DEBUG}")

############################################################
# Executables/libraries for Python
############################################################

####################################################################################################
# Dynamically loadable library (e.g for Python)
####################################################################################################

# Shared: .dylib
# Static: .a
# Module: .so
add_library(ChimesCalc_dynamic MODULE "${c-sources}")

add_library(lib-C_wrapper-direct_interface MODULE
${CMAKE_CURRENT_SOURCE_DIR}/chimesFF/api/chimescalc_C.cpp
${CMAKE_CURRENT_SOURCE_DIR}/chimesFF/src/chimesFF.cpp)
set_target_properties(ChimesCalc_dynamic
PROPERTIES OUTPUT_NAME "chimescalc_dl")

# Prevent CMake from prepending "lib" to libwrapper-C.so
set_target_properties (lib-C_wrapper-direct_interface PROPERTIES PREFIX "")
# Tell it which language to use
set_target_properties (lib-C_wrapper-direct_interface PROPERTIES LINKER_LANGUAGE CXX)
target_include_directories(lib-C_wrapper-direct_interface
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/chimesFF/src/)
target_include_directories(lib-C_wrapper-direct_interface
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/chimesFF/api/)
target_compile_features (lib-C_wrapper-direct_interface PUBLIC cxx_std_11)

if(NOT CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
install(TARGETS lib-C_wrapper-direct_interface
DESTINATION ${CMAKE_INSTALL_PREFIX}/chimesFF/examples/python/ OPTIONAL)
endif()
target_include_directories(ChimesCalc_dynamic PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/chimesFF/src>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/chimesFF/api>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/serial_interface/src>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/serial_interface/api>
$<INSTALL_INTERFACE:${INSTALL_INCLUDEDIR}>)

target_compile_definitions(ChimesCalc_dynamic PRIVATE "DEBUG=${DEBUG}")
target_compile_features(ChimesCalc_dynamic PRIVATE cxx_std_11)

add_library(lib-C_wrapper-serial_interface MODULE
${CMAKE_CURRENT_SOURCE_DIR}/serial_interface/api/chimescalc_serial_C.cpp
${CMAKE_CURRENT_SOURCE_DIR}/serial_interface/src/serial_chimes_interface.cpp
${CMAKE_CURRENT_SOURCE_DIR}/chimesFF/src/chimesFF.cpp)

# Prevent CMake from prepending "lib" to libwrapper-C.so
set_target_properties (lib-C_wrapper-serial_interface PROPERTIES PREFIX "")
# Tell it which language to use
set_target_properties (lib-C_wrapper-serial_interface PROPERTIES LINKER_LANGUAGE CXX)
target_include_directories(lib-C_wrapper-serial_interface
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/serial_interface/api/)
target_include_directories(lib-C_wrapper-serial_interface
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/serial_interface/src/)
target_include_directories(lib-C_wrapper-serial_interface
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/chimesFF/src/)
target_compile_features (lib-C_wrapper-serial_interface PUBLIC cxx_std_11)

if(NOT CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
install(TARGETS lib-C_wrapper-serial_interface
DESTINATION ${CMAKE_INSTALL_PREFIX}/serial_interface/examples/python/ OPTIONAL)
endif()
install(TARGETS ChimesCalc_dynamic
EXPORT ${PROJECT_NAME_LOWER}-targets
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
PUBLIC_HEADER DESTINATION "${INSTALL_INCLUDEDIR}")


###############################################################################
# Fortran library (separate library as it needs Fortran runtime to be linked)
###############################################################################
####################################################################################################
# Fortran wrappers (not contained in base library as it requires Fortran runtime library)
####################################################################################################

if(WITH_FORTRAN_API OR WITH_FORTRAN08_API)

Expand Down Expand Up @@ -196,47 +156,26 @@ if(WITH_FORTRAN_API OR WITH_FORTRAN08_API)
install(DIRECTORY "${moddir}/" DESTINATION "${INSTALL_MODULEDIR}")


############################################################
################################################################################################
# Executables for Fortran (90/08)
############################################################

add_executable(fortran_wrapper-direct_interface chimesFF/examples/fortran/main.F90)
target_link_libraries (fortran_wrapper-direct_interface ChimesCalc_Fortran)
target_compile_definitions(fortran_wrapper-direct_interface PRIVATE "DEBUG=${DEBUG}")

if(NOT CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
install(TARGETS fortran_wrapper-direct_interface
DESTINATION ${CMAKE_INSTALL_PREFIX}/chimesFF/examples/fortran/ OPTIONAL)
endif()

################################################################################################

add_executable(fortran_wrapper-serial_interface serial_interface/examples/fortran/main.F90)
target_link_libraries (fortran_wrapper-serial_interface ChimesCalc_Fortran)
target_compile_definitions(fortran_wrapper-serial_interface PRIVATE "DEBUG=${DEBUG}")

if(NOT CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
install(TARGETS fortran_wrapper-direct_interface
DESTINATION ${CMAKE_INSTALL_PREFIX}/serial_interface/examples/fortran/ OPTIONAL)
endif()
add_executable(chimescalc-test_serial-F serial_interface/examples/fortran/main.F90)
target_link_libraries(chimescalc-test_serial-F ChimesCalc_Fortran)
target_compile_definitions(chimescalc-test_serial-F PRIVATE "DEBUG=${DEBUG}")

# Optional, as ancient Fortran compilers may have difficulties with it
if(WITH_FORTRAN08_API)
add_executable(fortran08_wrapper-serial_interface
serial_interface/examples/fortran08/main.F90)
target_link_libraries (fortran08_wrapper-serial_interface ChimesCalc_Fortran)
target_compile_definitions(fortran08_wrapper-serial_interface PRIVATE "DEBUG=${DEBUG}")

if(NOT CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
install(TARGETS fortran08_wrapper-serial_interface
DESTINATION ${CMAKE_INSTALL_PREFIX}/serial_interface/examples/fortran08/ OPTIONAL)
endif()
add_executable(chimescalc-test_serial-F08 serial_interface/examples/fortran08/main.F90)
target_link_libraries(chimescalc-test_serial-F08 ChimesCalc_Fortran)
target_compile_definitions(chimescalc-test_serial-F08 PRIVATE "DEBUG=${DEBUG}")
endif()

endif()

###############################################################################
####################################################################################################
# Create CMake export file
###############################################################################
####################################################################################################

include(CMakePackageConfigHelpers)

Expand All @@ -260,3 +199,68 @@ install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME_LOWER}-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME_LOWER}-config-version.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME_LOWER}")


####################################################################################################
# Add regression tests for the various APIs
####################################################################################################

enable_testing()

set(apis
"cpp;${CMAKE_CURRENT_BINARY_DIR}/chimescalc"
"c;${CMAKE_CURRENT_BINARY_DIR}/chimescalc-test_serial-C"
"fortran;${CMAKE_CURRENT_BINARY_DIR}/chimescalc-test_serial-F"
"fortran08;${CMAKE_CURRENT_BINARY_DIR}/chimescalc-test_serial-F08")

set(_testdir "${CMAKE_CURRENT_SOURCE_DIR}/serial_interface/tests")
file(STRINGS ${_testdir}/test_list.dat _testcases)
foreach(_testcase IN LISTS _testcases)
if("${_testcase}" STREQUAL "")
continue()
endif()
list(GET _testcase 0 _paramfile)
string(STRIP "${_paramfile}" _paramfile)
list(GET _testcase 1 _geometry)
string(STRIP "${_geometry}" _geometry)
string(REPLACE "#" "" _geometry_escaped "${_geometry}")
list(GET _testcase 2 _configopt)
string(STRIP "${_configopt}" _configopt)
list(GET _testcase 3 _testlabels)
string(STRIP "${_testlabels}" _testlabels)

set(_add_test False)
foreach(_label IN LISTS TEST_LABELS)
if("${_testlabels}" MATCHES "${_label}")
set(_add_test True)
break()
endif()
endforeach()
if(NOT _add_test)
continue()
endif()

set(_apis "${apis}")
list(LENGTH _apis _apis_length )
while(_apis_length GREATER 0)
list(POP_FRONT _apis _api_abbrev)
list(POP_FRONT _apis _api_executable)
#message(STATUS "Test added: ${_api_abbrev}:${_paramfile}:${_geometry_escaped}")
list(LENGTH _apis _apis_length)

add_test(
NAME "${_api_abbrev}/${_paramfile}:${_geometry_escaped}"
COMMAND
${_testdir}/run_single_test.sh
${_api_executable}
${_paramfile}
${_geometry}
${_configopt}
${CMAKE_CURRENT_BINARY_DIR}/_test/${_api_abbrev}/${_paramfile}:${_geometry_escaped})
if("${_api_abbrev}" STREQUAL "py")
set_tests_properties("${_api_abbrev}/${_paramfile}:${_geometry_escaped}"
PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}"
ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}")
endif()
endwhile()
endforeach()
5 changes: 1 addition & 4 deletions chimesFF/api/chimescalc_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
A simple python interface for chimesFF access.
Expects "libwrapper-C.so" in the same directory as this script
The following must be included in any python script calling this wrapper:
import chimescalc_py
chimescalc_py.chimes_wrapper = chimescalc_py.init_chimes_wrapper("/path/to/lib-C_wrapper-direct_interface.so")
chimescalc_py.chimes_wrapper = chimescalc_py.init_chimes_wrapper("libchimescalc-direct_dl.so")
chimescalc_py.set_chimes()
chimescalc_py.init_chimes()
chimescalc_py.read_params("some_parameter_file.txt")
Expand Down
4 changes: 2 additions & 2 deletions chimesFF/examples/c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ test_wrapper-C.o : main.c $(WRAPPER_SRC) $(WRAPPER_HDR)
LINKS = chimesFF.o test_wrapper-C.o chimescalc_C.o

test_wrapper-C : $(LINKS)
$(CXX) $(LINKS) -o C_wrapper-direct_interface
$(CXX) $(LINKS) -o chimescalc-test_direct-C

clean:
rm -f *.o

clean-all:
rm -f *.o
rm -f C_wrapper-direct_interface
rm -f chimescalc-test_direct-C

all:
make chimesFF.o
Expand Down
4 changes: 2 additions & 2 deletions chimesFF/examples/cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ CXX_SRC = main.cpp $(CXX_LOC)/../../../serial_interface/src/serial_chimes_interf
CXX_HDR = $(CXX_LOC)/../../../serial_interface/src/serial_chimes_interface.h $(CXX_LOC)/../../src/chimesFF.h

all: $(CXX_SRC) $(CXX_HDR)
$(CXX) $(CXX_SRC) -o CPP-interface -I $(CXX_LOC)/../../src -I $(CXX_LOC)/../../../serial_interface/src/
$(CXX) $(CXX_SRC) -o chimescalc -I $(CXX_LOC)/../../src -I $(CXX_LOC)/../../../serial_interface/src/
clean:
rm -f CPP-interface
rm -f chimescalc
Loading

0 comments on commit 7ca7d39

Please sign in to comment.