Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CMake to work with FetchContent #196

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

awild82
Copy link

@awild82 awild82 commented Nov 5, 2021

Description

This pull request makes some trivial changes to the CMake structure in order to enable inclusion of PCMSolver in other projects via FetchContent. In particular, it adds the api directory as an interface include directory on both the shared and static targets, and it makes the external/Catch directory relative to the PCMSolver root, not the total build root.

Motivation and Context

This PR enables inclusion of PCMSolver through FetchContent.

How Has This Been Tested?

This PR was primarily tested through:

  1. Ensuring that changes did not affect the build process of PCMSolver on its own (and ensuring that the tests still pass)
  2. Including the PCMSolver build through FetchContent in a dummy CMake build. This was tested with the standard build, SHARED_LIBRARY_ONLY=ON, and STATIC_LIBRARY_ONLY=ON. I only tested this on a CentOS 7 server, but none of the code I changed should affect builds on Windows or Mac, so I don't expect issues from those installations either.

FetchContent CMake build details

The structure of the dummy CMake project is a single CMakeLists.txt and a single source file, test.cxx.

The CMakeLists.txt file had the following content:

cmake_minimum_required(VERSION 3.14)
project(Testing LANGUAGES C CXX Fortran)

include(FetchContent)

FetchContent_Declare(pcmsolver
  GIT_REPOSITORY https://github.com/awild82/pcmsolver.git
  GIT_TAG c0fe869a6245f28186af0329f6308f47e8ca75ea
)
FetchContent_MakeAvailable(pcmsolver)


add_executable(test_fetchcontent test.cxx)
target_link_libraries(test_fetchcontent PCMSolver)

The only non-standard thing here is that this project must be declared having a Fortran language dependency when linking against the PCMSolver static library in order for the Fortran symbols from pedra to be resolved.

The test.cxx file can be pretty much whatever you like to test inclusion and linking. I used some code from the C host example:

#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <pcmsolver.h>

#define NR_NUCLEI 6

void host_writer(const char * message) { printf("%s\n", message); }

struct PCMInput pcmsolver_input() {
  struct PCMInput host_input;

  strcpy(host_input.cavity_type, "gepol");
  host_input.patch_level = 2;
  host_input.coarsity = 0.5;
  host_input.area = 0.2;
  host_input.min_distance = 0.1;
  host_input.der_order = 4;
  host_input.scaling = true;
  strcpy(host_input.radii_set, "bondi");
  strcpy(host_input.restart_name, "cavity.npz");
  host_input.min_radius = 100.0;

  strcpy(host_input.solver_type, "iefpcm");
  strcpy(host_input.solvent, "water");
  strcpy(host_input.equation_type, "secondkind");
  host_input.correction = 0.0;
  host_input.probe_radius = 1.0;

  strcpy(host_input.inside_type, "vacuum");
  host_input.outside_epsilon = 1.0;
  strcpy(host_input.outside_type, "uniformdielectric");

  return host_input;
}

int main() {
  // Setup stolen from C-Host example
  double charges[NR_NUCLEI] = {6.0, 1.0, 1.0, 6.0, 1.0, 1.0};
  double coordinates[3 * NR_NUCLEI] = {0.0,
                                       0.000000,
                                       1.257892,
                                       0.0,
                                       1.745462,
                                       2.342716,
                                       0.0,
                                       -1.745462,
                                       2.342716,
                                       0.0,
                                       0.000000,
                                       -1.257892,
                                       0.0,
                                       1.745462,
                                       -2.342716,
                                       0.0,
                                       -1.745462,
                                       -2.342716};
  int symmetry_info[4] = {3, 4, 2, 1};
  struct PCMInput host_input = pcmsolver_input();

  pcmsolver_context_t * pcm_context = pcmsolver_new(PCMSOLVER_READER_HOST,
                                                    NR_NUCLEI,
                                                    charges,
                                                    coordinates,
                                                    symmetry_info,
                                                    &host_input,
                                                    host_writer);

  pcmsolver_print(pcm_context);

  return 0;
}

The final executable was executed and gave the expected print to stdout.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Status

  • Ready to go
  • Cherry-pick to latest release branch

@robertodr robertodr mentioned this pull request Feb 1, 2023
5 tasks
@loriab loriab mentioned this pull request Apr 6, 2023
67 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant