If you are writing a C++ application that uses a cheminformatics toolkit, a key step during the configuration process is to tell the build system the location of the toolkit libraries and include files. However, in an ideal world, the build system would find these automatically based on standard install locations or hints such as the value of RDBASE for RDKit.
We have incorporated some of these ideas into CMake modules to find Open Babel, OEChem or RDKit. As a service to the community, we are placing these into the public domain (E&OE). Enjoy.
# FindOpenBabel.cmake # Placed in the public domain by NextMove Software in 2013 # Try to find Open Babel headers and libraries # Defines: # # OPENBABEL_FOUND - system has Open Babel # OPENBABEL_INCLUDE_DIRS - the Open Babel include directories # OPENBABEL_LIBRARIES - Link these to use Open Babel if(OPENBABEL_INCLUDE_DIRS AND OPENBABEL_LIBRARIES) # in cache already or user-specified set(OPENBABEL_FOUND TRUE) else() if(NOT OPENBABEL_INCLUDE_DIRS) if(WIN32) find_path(OPENBABEL_INCLUDE_DIR openbabel/obconversion.h PATHS ${OPENBABEL_DIR}\\include $ENV{OPENBABEL_INCLUDE_DIR} $ENV{OPENBABEL_INCLUDE_DIR}\\openbabel-2.0 $ENV{OPENBABEL_INCLUDE_PATH} $ENV{OPENBABEL_INCLUDE_PATH}\\openbabel-2.0 $ENV{OPENBABEL_DIR}\\include $ENV{OPENBABEL_PATH}\\include $ENV{OPENBABEL_BASE}\\include C:\\OpenBabel\\include ) find_path(OPENBABEL_INCLUDE_DIR2 openbabel/babelconfig.h PATHS ${OPENBABEL_DIR}/windows-vc2008/build/include $ENV{OPENBABEL_DIR}/windows-vc2008/build/include ) set(OPENBABEL_INCLUDE_DIRS ${OPENBABEL_INCLUDE_DIR} ${OPENBABEL_INCLUDE_DIR2}) else() find_path(OPENBABEL_INCLUDE_DIRS openbabel/obconversion.h PATHS ${OPENBABEL_DIR}/include $ENV{OPENBABEL_INCLUDE_DIR}/openbabel-2.0 $ENV{OPENBABEL_INCLUDE_DIR} $ENV{OPENBABEL_INCLUDE_PATH}/openbabel-2.0 $ENV{OPENBABEL_INCLUDE_PATH} $ENV{OPENBABEL_DIR}/include/openbabel-2.0 $ENV{OPENBABEL_DIR}/include $ENV{OPENBABEL_PATH}/include/openbabel-2.0 $ENV{OPENBABEL_PATH}/include $ENV{OPENBABEL_BASE}/include/openbabel-2.0 $ENV{OPENBABEL_BASE}/include /usr/include/openbabel-2.0 /usr/include /usr/local/include/openbabel-2.0 /usr/local/include /usr/local/openbabel/include/openbabel-2.0 /usr/local/openbabel/include /usr/local/openbabel-2.0/include/openbabel-2.0 /usr/local/openbabel-2.0/include ~/include/openbabel-2.0 ~/include ) endif() if(OPENBABEL_INCLUDE_DIRS) message(STATUS "Found Open Babel include files at ${OPENBABEL_INCLUDE_DIRS}") endif() endif() if(NOT OPENBABEL_LIBRARY_DIR) find_library(OPENBABEL_LIBRARIES NAMES openbabel openbabel-2 PATHS ${OPENBABEL_DIR}/lib ${OPENBABEL_DIR}/windows-vc2008/build/src/Release $ENV{OPENBABEL_LIBRARIES} $ENV{OPENBABEL_DIR}/lib $ENV{OPENBABEL_DIR}/windows-vc2008/build/src/Release $ENV{OPENBABEL_PATH}/lib $ENV{OPENBABEL_BASE}/lib /usr/lib /usr/local/lib ~/lib $ENV{LD_LIBRARY_PATH} ) if(OPENBABEL_LIBRARIES) message(STATUS "Found Open Babel library at ${OPENBABEL_LIBRARIES}") endif() endif() if(OPENBABEL_INCLUDE_DIRS AND OPENBABEL_LIBRARIES) set(OPENBABEL_FOUND TRUE) endif() mark_as_advanced(OPENBABEL_INCLUDE_DIRS OPENBABEL_LIBRARIES) endif()
# FindOEChem.cmake # Placed in the public domain by NextMove Software in 2013 # Try to find OEChem headers and libraries # Defines: # # OECHEM_FOUND - system has OEChem # OECHEM_INCLUDE_DIR - the OEChem include directory # OECHEM_LIBRARIES - Link these to use OEChem if(OECHEM_INCLUDE_DIR AND OECHEM_LIBRARIES) # in cache already or user-specified set(OECHEM_FOUND TRUE) else() if(NOT OECHEM_INCLUDE_DIR) if(WIN32) find_path(OECHEM_INCLUDE_DIR oechem.h PATHS $ENV{OECHEM_INCLUDE_DIR} $ENV{OECHEM_INCLUDE_PATH} $ENV{OECHEM_BASE}\\toolkits\\include $ENV{OECHEM_BASE}\\include C:\\OpenEye\\toolkits\\include C:\\OpenEye\\include ) else() find_path(OECHEM_INCLUDE_DIR oechem.h PATHS $ENV{OECHEM_INCLUDE_DIR} $ENV{OECHEM_INCLUDE_PATH} $ENV{OECHEM_BASE}/toolkits/include $ENV{OECHEM_BASE}/include /usr/local/openeye/toolkits/include /usr/local/openeye/include /usr/include /usr/local/include ~/include ) if(OECHEM_INCLUDE_DIR) message(STATUS "Found OEChem include files at ${OECHEM_INCLUDE_DIR}") endif() endif() endif() if(NOT OECHEM_LIBRARIES) find_library(OECHEM_LIB NAMES oechem HINTS ${OECHEM_INCLUDE_DIR}/../lib PATHS $ENV{OECHEM_LIB_DIR} $ENV{OECHEM_LIB_PATH} $ENV{OECHEM_LIBRARIES} $ENV{OECHEM_BASE}/toolkits/lib $ENV{OECHEM_BASE}/lib /usr/openeye/toolkits/lib /usr/openeye/lib /usr/local/openeye/toolkits/lib /usr/local/openeye/lib ~/openeye/toolkits/lib ~/openeye/lib $ENV{LD_LIBRARY_PATH} ) if(OECHEM_LIB) GET_FILENAME_COMPONENT(OECHEM_LIBRARY_DIR ${OECHEM_LIB} PATH) message(STATUS "Found OEChem libraries at ${OECHEM_LIBRARY_DIR}") # Note that the order of the following libraries is significant!! find_library(OESYSTEM_LIB NAMES oesystem HINTS ${OECHEM_LIBRARY_DIR}) find_library(OEPLATFORM_LIB NAMES oeplatform HINTS ${OECHEM_LIBRARY_DIR}) set (OECHEM_LIBRARIES ${OECHEM_LIB} ${OESYSTEM_LIB} ${OEPLATFORM_LIB}) endif() endif() if(OECHEM_INCLUDE_DIR AND OECHEM_LIBRARIES) set(OECHEM_FOUND TRUE) endif() mark_as_advanced(OECHEM_INCLUDE_DIR OECHEM_LIBRARIES) endif()
# FindRDKit.cmake # Placed in the public domain by NextMove Software in 2013 # Try to find RDKit headers and libraries # Defines: # # RDKIT_FOUND - system has RDKit # RDKIT_INCLUDE_DIR - the RDKit include directory # RDKIT_LIBRARIES - Link these to use RDKit if(RDKIT_INCLUDE_DIR AND RDKIT_LIBRARIES) # in cache already or user-specified set(RDKIT_FOUND TRUE) else() if(NOT RDKIT_INCLUDE_DIR) if(WIN32) find_path(RDKIT_INCLUDE_DIR GraphMol/RDKitBase.h PATHS ${RDKIT_DIR}\\Code $ENV{RDKIT_INCLUDE_DIR} $ENV{RDKIT_INCLUDE_PATH} $ENV{RDKIT_BASE}\\Code $ENV{RDBASE}\\Code C:\\RDKit\\include C:\\RDKit\\Code ) else() find_path(RDKIT_INCLUDE_DIR GraphMol/RDKitBase.h PATHS ${RDKIT_DIR}/Code $ENV{RDKIT_INCLUDE_DIR} $ENV{RDKIT_INCLUDE_PATH} $ENV{RDKIT_BASE}/Code $ENV{RDBASE}/Code /usr/local/rdkit/include/Code /usr/local/rdkit/include /usr/local/rdkit/Code ~/rdkit/Code ) endif() if(RDKIT_INCLUDE_DIR) message(STATUS "Found RDKit include files at ${RDKIT_INCLUDE_DIR}") endif() endif() if(NOT RDKIT_LIBRARIES) find_library(FILEPARSERS_LIB NAMES FileParsers PATHS ${RDKIT_DIR}/lib $ENV{RDKIT_LIB_DIR} $ENV{RDKIT_LIB_PATH} $ENV{RDKIT_LIBRARIES} $ENV{RDKIT_BASE}/lib $ENV{RDBASE}/lib /usr/local/rdkit/lib ~/rdkit/lib $ENV{LD_LIBRARY_PATH} ) if(FILEPARSERS_LIB) GET_FILENAME_COMPONENT(RDKIT_LIBRARY_DIR ${FILEPARSERS_LIB} PATH) message(STATUS "Found RDKit libraries at ${RDKIT_LIBRARY_DIR}") # Note that the order of the following libraries is significant!! find_library(SMILESPARSE_LIB NAMES SmilesParse HINTS ${RDKIT_LIBRARY_DIR}) find_library(DEPICTOR_LIB NAMES Depictor HINTS ${RDKIT_LIBRARY_DIR}) find_library(GRAPHMOL_LIB NAMES GraphMol HINTS ${RDKIT_LIBRARY_DIR}) find_library(RDGEOMETRYLIB_LIB NAMES RDGeometryLib HINTS ${RDKIT_LIBRARY_DIR}) find_library(RDGENERAL_LIB NAMES RDGeneral HINTS ${RDKIT_LIBRARY_DIR}) set (RDKIT_LIBRARIES ${FILEPARSERS_LIB} ${SMILESPARSE_LIB} ${DEPICTOR_LIB} ${GRAPHMOL_LIB} ${RDGEOMETRYLIB_LIB} ${RDGENERAL_LIB}) endif() if(RDKIT_LIBRARIES) message(STATUS "Found RDKit library files at ${RDKIT_LIBRARIES}") endif() endif() if(RDKIT_INCLUDE_DIR AND RDKIT_LIBRARIES) set(RDKIT_FOUND TRUE) endif() mark_as_advanced(RDKIT_INCLUDE_DIR RDKIT_LIBRARIES) endif()