dgasmith / gau2grid

Fast computation of a gaussian and its derivative on a grid.
https://gau2grid.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
29 stars 15 forks source link

Allow for inclusion as a CMake Subproject #63

Closed wavefunction91 closed 3 years ago

wavefunction91 commented 4 years ago

Ideally, gau2grid could be included in a downstream CMake project as

FetchContent_Declare( gau2grid GIT_REPOSITORY https://github.com/dgasmith/gau2grid.git )
FetchContent_MakeAvailable( gau2grid )

target_link_libraries( my_target PUBLIC gg )

This populates directories ${CMAKE_BINARY_DIR}/_deps/gau2grid-src, etc. The generator on line 58 assumes that CMAKE_SOURCE_DIR and PROJECT_SOURCE_DIR are the same, which is not the case through FetchContent. Making this generator point explicitly to PROJECT_SOURCE_DIR fixes the problem.

A (albeit hacky) workaround of this is the following

  FetchContent_Declare(                                                               
    gau2grid
    GIT_REPOSITORY https://github.com/dgasmith/gau2grid.git                           
  )                                                                                   

  FetchContent_GetProperties( gau2grid )                                              
  if( NOT gau2grid_POPULATED )
    FetchContent_Populate( gau2grid )
    file( READ ${gau2grid_SOURCE_DIR}/CMakeLists.txt GAU2GRID_CMAKE_LISTS )
    string( REPLACE "CMAKE_SOURCE_DIR" "PROJECT_SOURCE_DIR" GAU2GRID_CORRECT "${GAU2GRID_CMAKE_LISTS}" )
    file( WRITE ${gau2grid_SOURCE_DIR}/CMakeLists.txt "${GAU2GRID_CORRECT}" )         
    add_subdirectory( ${gau2grid_SOURCE_DIR} ${gau2grid_BINARY_DIR} )                 
  endif() 
wavefunction91 commented 3 years ago

Closed via #68