1 # CMake script for finding HOOMD and setting up all needed compile options to create and link a plugin library
3 # Variables taken as input to this module:
4 # HOOMD_ROOT : location to look for HOOMD, if it is not in the system path
6 # Variables defined by this module:
7 # FOUND_HOOMD : set to true if HOOMD is found
8 # HOOMD_LIBRARIES : a list of all libraries needed to link to to access hoomd (uncached)
9 # HOOMD_INCLUDE_DIR : a list of all include directories that need to be set to include HOOMD
10 # HOOMD_BIN_DIR : the directory containing the hoomd runner executable
11 # HOOMD_LIB : a cached var locating the hoomd library to link to
13 # various ENABLE_ flags translated from hoomd_config.h so this plugin build can match the ABI of the installed hoomd
15 # as a convenience (for the intended purpose of this find script), all include directories and definitions needed
16 # to compile with all the various libs (boost, python, winsoc, etc...) are set within this script
18 # see if we can find the HOOMD bin/ directory first. This usually works well if "hoomd" is in the path
19 find_path(HOOMD_BIN_DIR
23 set(_hoomd_root_guess "HOOMD_ROOT-NOTFOUND")
25 message(STATUS "Found HOOMD bin directory: ${HOOMD_BIN_DIR}")
26 mark_as_advanced(HOOMD_BIN_DIR)
27 # guess the root dir location from the bin
28 string(REGEX REPLACE "[/\\\\]?bin*[/\\\\]?$" "" _hoomd_root_guess ${HOOMD_BIN_DIR})
31 # root directory where HOOMD was found
32 set(HOOMD_ROOT ${_hoomd_root_guess} CACHE PATH "Root directory where HOOMD is installed")
34 # try again to find HOOMD_BIN_DIR
35 if (NOT HOOMD_BIN_DIR)
36 find_path(HOOMD_BIN_DIR
38 HINTS ${HOOMD_ROOT}/bin
40 endif (NOT HOOMD_BIN_DIR)
43 message(STATUS "Found HOOMD bin directory: ${HOOMD_BIN_DIR}")
46 # search for the hoomd include directory
47 find_path(HOOMD_INCLUDE_DIR
48 NAMES hoomd/hoomd_config.h
49 HINTS ${HOOMD_ROOT}/include
52 if (HOOMD_INCLUDE_DIR)
53 message(STATUS "Found HOOMD include directory: ${HOOMD_INCLUDE_DIR}")
54 mark_as_advanced(HOOMD_INCLUDE_DIR)
55 endif (HOOMD_INCLUDE_DIR)
57 # find the hoomd library
58 # we need to add a blank prefix to find the python module library
59 set(_old_prefixes ${CMAKE_FIND_LIBRARY_PREFIXES})
60 set(CMAKE_FIND_LIBRARY_PREFIXES "" "lib")
61 find_library(HOOMD_LIB
63 HINTS ${HOOMD_ROOT}/lib/hoomd/python-module ${HOOMD_ROOT}/lib
64 ${HOOMD_ROOT}/lib64/hoomd/python-module ${HOOMD_ROOT}/lib64
65 ${HOOMD_ROOT}/lib64/python/site-packages
66 ${HOOMD_ROOT}/lib64/python2.4/site-packages
67 ${HOOMD_ROOT}/lib64/python2.5/site-packages
68 ${HOOMD_ROOT}/lib64/python2.6/site-packages
69 ${HOOMD_ROOT}/lib64/python2.7/site-packages
70 ${HOOMD_ROOT}/lib/python/site-packages
71 ${HOOMD_ROOT}/lib/python2.4/site-packages
72 ${HOOMD_ROOT}/lib/python2.5/site-packages
73 ${HOOMD_ROOT}/lib/python2.6/site-packages
74 ${HOOMD_ROOT}/lib/python2.7/site-packages
76 set(CMAKE_FIND_LIBRARY_PREFIXES ${_old_prefixes})
79 message(STATUS "Found HOOMD library: ${HOOMD_LIB}")
80 mark_as_advanced(HOOMD_LIB)
83 set(HOOMD_FOUND FALSE)
84 if (HOOMD_INCLUDE_DIR AND HOOMD_BIN_DIR AND HOOMD_ROOT AND HOOMD_LIB)
86 mark_as_advanced(HOOMD_ROOT)
87 endif (HOOMD_INCLUDE_DIR AND HOOMD_BIN_DIR AND HOOMD_ROOT AND HOOMD_LIB)
90 message(SEND_ERROR "HOOMD Not found. Please specify the location of your hoomd installation in HOOMD_ROOT")
91 endif (NOT HOOMD_FOUND)
93 #############################################################
94 ## Now that we've found hoomd, lets do some setup
97 # read in hoomd_config.h
98 file(STRINGS ${HOOMD_INCLUDE_DIR}/hoomd/hoomd_config.h _hoomd_config_h_lines)
99 # go through all the lines in the file
100 foreach(_line ${_hoomd_config_h_lines})
101 # if this line is #define VARIABLE
102 if (${_line} MATCHES "^#define .*$")
103 string(REGEX REPLACE "#define (.*)$" "\\1" _var ${_line})
104 # and if it is not HOOMD_CONFIG_H
105 if (NOT ${_var} MATCHES "HOOMD_CONFIG_H")
106 message(STATUS "found define: ${_var}")
107 # translate it to a CMake cache variable
108 set(${_var} ON CACHE BOOL "Imported setting from hoomd_config.h, it matches the setting used to build HOOMD" FORCE)
109 endif (NOT ${_var} MATCHES "HOOMD_CONFIG_H")
110 endif (${_line} MATCHES "^#define .*$")
112 # if this line is an #undef VARIABLE
113 if (${_line} MATCHES "#undef .*")
114 string(REGEX REPLACE "/. #undef (.*) ./" "\\1" _var ${_line})
115 message(STATUS "found undef: ${_var}")
116 # translate it to a CMake cache variable
117 set(${_var} OFF CACHE BOOL "Imported setting from hoomd_config.h, it matches the setting used to build HOOMD" FORCE)
118 endif (${_line} MATCHES "#undef .*")
121 include_directories(${HOOMD_INCLUDE_DIR})
122 include_directories(${HOOMD_INCLUDE_DIR}/hoomd)
124 # run all of HOOMD's generic lib setup scripts
125 set(CMAKE_MODULE_PATH ${HOOMD_ROOT}/share/hoomd/CMake/cuda
126 ${HOOMD_ROOT}/share/hoomd/CMake/hoomd
127 ${HOOMD_ROOT}/share/hoomd/CMake/python
131 # Find the python executable and libraries
132 include (HOOMDPythonSetup)
133 # Find the boost libraries and set them up
134 include (HOOMDBoostSetup)
135 # Find CUDA and set it up
136 include (HOOMDCUDASetup)
138 include (HOOMDCFlagsSetup)
139 # include some os specific options
140 include (HOOMDOSSpecificSetup)
141 # setup common libraries used by all targets in this project
142 include (HOOMDCommonLibsSetup)
144 include (HOOMDMacros)
146 include (HOOMDMPISetup)
148 set(HOOMD_LIBRARIES ${HOOMD_LIB} ${HOOMD_COMMON_LIBS})