|
1 |
| -# CMake script for finding HOOMD and setting up all needed compile options to create and link a plugin library |
| 1 | +# FindHOOMD |
| 2 | +# --------- |
| 3 | +# |
| 4 | +# CMake script for finding HOOMD and setting up all needed compile options |
| 5 | +# to create and link a plugin library |
2 | 6 | #
|
3 | 7 | # Variables taken as input to this module:
|
4 |
| -# HOOMD_ROOT : location to look for HOOMD, if it is not in the python path |
| 8 | +# HOOMD_ROOT -- Location to look for HOOMD, if it is not in the python path |
5 | 9 | #
|
6 | 10 | # 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_LIB : a cached var locating the hoomd library to link to |
| 11 | +# HOOMD_INCLUDE_DIR -- Include directories that need to be set to include HOOMD |
| 12 | +# HOOMD_LIB -- Cached var locating the hoomd library to link to |
| 13 | +# HOOMD_LIBRARIES -- Libraries needed to link to to access hoomd (uncached) |
| 14 | +# HOOMD_FOUND |
11 | 15 | #
|
12 |
| -# various ENABLE_ flags translated from hoomd_config.h so this plugin build can match the ABI of the installed hoomd |
| 16 | +# Various ENABLE_ flags are translated from hoomd_config.h |
| 17 | +# so this plugin build can match the ABI of the installed hoomd |
13 | 18 | #
|
14 |
| -# as a convenience (for the intended purpose of this find script), all include directories and definitions needed |
15 |
| -# to compile with all the various libs (boost, python, winsoc, etc...) are set within this script |
16 |
| - |
17 |
| -set(HOOMD_ROOT "" CACHE FILEPATH "Directory containing a hoomd installation (i.e. _hoomd.so)") |
| 19 | +# As a convenience (for the intended purpose of this find script), |
| 20 | +# all include directories and definitions needed to compile with all the various libs |
| 21 | +# (boost, python, winsoc, etc...) are set within this script |
18 | 22 |
|
19 |
| -# Let HOOMD_ROOT take precedence, but if unset, try letting Python find a hoomd package in its default paths. |
20 |
| -if(HOOMD_ROOT) |
21 |
| - set(hoomd_installation_guess ${HOOMD_ROOT}) |
22 |
| -else(HOOMD_ROOT) |
23 |
| - find_package(PythonInterp) |
24 |
| - |
25 |
| - set(find_hoomd_script " |
| 23 | +function(find_hoomd_with_python) |
| 24 | + find_package(Python QUIET COMPONENTS Interpreter) |
| 25 | + set(FIND_HOOMD_SCRIPT " |
26 | 26 | from __future__ import print_function;
|
27 |
| -import sys, os; sys.stdout = open(os.devnull, 'w') |
28 |
| -import hoomd |
29 |
| -print(os.path.dirname(hoomd.__file__), file=sys.stderr, end='')") |
30 |
| - |
31 |
| - execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "${find_hoomd_script}" |
32 |
| - ERROR_VARIABLE hoomd_installation_guess) |
33 |
| - message(STATUS "Python output: " ${hoomd_installation_guess}) |
34 |
| -endif(HOOMD_ROOT) |
| 27 | +import os |
| 28 | +try: |
| 29 | + import hoomd |
| 30 | + print(os.path.dirname(hoomd.__file__), end='') |
| 31 | +except: |
| 32 | + print('', end='')" |
| 33 | + ) |
| 34 | + execute_process( |
| 35 | + COMMAND ${Python_EXECUTABLE} -c "${FIND_HOOMD_SCRIPT}" |
| 36 | + OUTPUT_VARIABLE HOOMD_ROOT |
| 37 | + ) |
| 38 | + set(HOOMD_DIR ${HOOMD_ROOT} PARENT_SCOPE) |
| 39 | +endfunction() |
35 | 40 |
|
36 |
| -message(STATUS "Looking for a HOOMD installation at " ${hoomd_installation_guess}) |
37 |
| -find_path(FOUND_HOOMD_ROOT |
38 |
| - NAMES _hoomd.so __init__.py |
39 |
| - HINTS ${hoomd_installation_guess} |
40 |
| - ) |
41 |
| - |
42 |
| -if(FOUND_HOOMD_ROOT) |
43 |
| - set(HOOMD_ROOT ${FOUND_HOOMD_ROOT} CACHE FILEPATH "Directory containing a hoomd installation (i.e. _hoomd.so)" FORCE) |
44 |
| - message(STATUS "Found hoomd installation at " ${HOOMD_ROOT}) |
45 |
| -else(FOUND_HOOMD_ROOT) |
46 |
| - message(FATAL_ERROR "Could not find hoomd installation, either set HOOMD_ROOT or set PYTHON_EXECUTABLE to a python which can find hoomd") |
47 |
| -endif(FOUND_HOOMD_ROOT) |
| 41 | +if(HOOMD_ROOT) |
| 42 | + set(HOOMD_DIR ${HOOMD_ROOT}) |
| 43 | +elseif(DEFINED ENV{HOOMD_ROOT}) |
| 44 | + set(HOOMD_DIR $ENV{HOOMD_ROOT}) |
| 45 | +else() |
| 46 | + find_hoomd_with_python() |
| 47 | +endif() |
48 | 48 |
|
49 |
| -# search for the hoomd include directory |
50 | 49 | find_path(HOOMD_INCLUDE_DIR
|
51 |
| - NAMES HOOMDVersion.h |
52 |
| - HINTS ${HOOMD_ROOT}/include |
53 |
| - ) |
54 |
| - |
55 |
| -if (HOOMD_INCLUDE_DIR) |
56 |
| - message(STATUS "Found HOOMD include directory: ${HOOMD_INCLUDE_DIR}") |
57 |
| - mark_as_advanced(HOOMD_INCLUDE_DIR) |
58 |
| -endif (HOOMD_INCLUDE_DIR) |
59 |
| - |
60 |
| -set(HOOMD_FOUND FALSE) |
61 |
| -if (HOOMD_INCLUDE_DIR AND HOOMD_ROOT) |
62 |
| - set(HOOMD_FOUND TRUE) |
63 |
| - mark_as_advanced(HOOMD_ROOT) |
64 |
| -endif (HOOMD_INCLUDE_DIR AND HOOMD_ROOT) |
65 |
| - |
66 |
| -if (NOT HOOMD_FOUND) |
67 |
| - message(SEND_ERROR "HOOMD Not found. Please specify the location of your hoomd installation in HOOMD_ROOT") |
68 |
| -endif (NOT HOOMD_FOUND) |
69 |
| - |
70 |
| -############################################################# |
71 |
| -## Now that we've found hoomd, lets do some setup |
72 |
| -if (HOOMD_FOUND) |
73 |
| - |
74 |
| -include_directories(${HOOMD_INCLUDE_DIR}) |
75 |
| - |
76 |
| -# run all of HOOMD's generic lib setup scripts |
77 |
| -set(CMAKE_MODULE_PATH ${HOOMD_ROOT} |
78 |
| - ${HOOMD_ROOT}/CMake/hoomd |
79 |
| - ${HOOMD_ROOT}/CMake/thrust |
80 |
| - ${CMAKE_MODULE_PATH} |
81 |
| - ) |
82 |
| - |
83 |
| -# grab previously-set hoomd configuration |
84 |
| -include (hoomd_cache) |
85 |
| - |
86 |
| -# Handle user build options |
87 |
| -include (CMake_build_options) |
88 |
| -include (CMake_preprocessor_flags) |
89 |
| -# setup the install directories |
90 |
| -include (CMake_install_options) |
91 |
| - |
92 |
| -# Find the python executable and libraries |
93 |
| -include (HOOMDPythonSetup) |
94 |
| -# Find CUDA and set it up |
95 |
| -include (HOOMDCUDASetup) |
96 |
| -# Set default CFlags |
97 |
| -include (HOOMDCFlagsSetup) |
98 |
| -# include some os specific options |
99 |
| -include (HOOMDOSSpecificSetup) |
100 |
| -# setup common libraries used by all targets in this project |
101 |
| -include (HOOMDCommonLibsSetup) |
102 |
| -# setup macros |
103 |
| -include (HOOMDMacros) |
104 |
| -# setup MPI support |
105 |
| -include (HOOMDMPISetup) |
106 |
| - |
107 |
| -set(HOOMD_LIB ${HOOMD_ROOT}/_hoomd${PYTHON_MODULE_EXTENSION}) |
108 |
| -set(HOOMD_MD_LIB ${HOOMD_ROOT}/md/_md${PYTHON_MODULE_EXTENSION}) |
109 |
| -set(HOOMD_DEM_LIB ${HOOMD_ROOT}/dem/_dem${PYTHON_MODULE_EXTENSION}) |
110 |
| -set(HOOMD_HPMC_LIB ${HOOMD_ROOT}/hpmc/_hpmc${PYTHON_MODULE_EXTENSION}) |
111 |
| -set(HOOMD_CGCMM_LIB ${HOOMD_ROOT}/cgcmm/_cgcmm${PYTHON_MODULE_EXTENSION}) |
112 |
| -set(HOOMD_METAL_LIB ${HOOMD_ROOT}/metal/_metal${PYTHON_MODULE_EXTENSION}) |
113 |
| -set(HOOMD_DEPRECATED_LIB ${HOOMD_ROOT}/deprecated/_deprecated${PYTHON_MODULE_EXTENSION}) |
114 |
| - |
115 |
| -set(HOOMD_LIBRARIES ${HOOMD_LIB} ${HOOMD_COMMON_LIBS}) |
116 |
| -set(HOOMD_LIBRARIES ${HOOMD_LIB} ${HOOMD_COMMON_LIBS}) |
117 |
| - |
118 |
| -endif (HOOMD_FOUND) |
| 50 | + NAMES HOOMDVersion.h |
| 51 | + HINTS ${HOOMD_DIR}/include |
| 52 | +) |
| 53 | +if(HOOMD_INCLUDE_DIR) |
| 54 | + file(READ "${HOOMD_INCLUDE_DIR}/HOOMDVersion.h" HOOMD_VERSION_HEADER) |
| 55 | + string(REGEX |
| 56 | + MATCH "([0-9]+)\\.([0-9]+)\\.([0-9]+)" HOOMD_VERSION ${HOOMD_VERSION_HEADER} |
| 57 | + ) |
| 58 | +endif() |
| 59 | +mark_as_advanced(HOOMD_FOUND HOOMD_DIR HOOMD_INCLUDE_DIR HOOMD_VERSION) |
| 60 | + |
| 61 | +include(FindPackageHandleStandardArgs) |
| 62 | +find_package_handle_standard_args(HOOMD |
| 63 | + REQUIRED_VARS HOOMD_DIR HOOMD_INCLUDE_DIR HOOMD_VERSION |
| 64 | +) |
| 65 | + |
| 66 | +if(HOOMD_FOUND) |
| 67 | + include_directories(${HOOMD_INCLUDE_DIR}) |
| 68 | + # Run all of HOOMD's generic lib setup scripts |
| 69 | + set(CMAKE_MODULE_PATH |
| 70 | + ${HOOMD_DIR} |
| 71 | + ${HOOMD_DIR}/CMake/hoomd |
| 72 | + ${HOOMD_DIR}/CMake/thrust |
| 73 | + ${CMAKE_MODULE_PATH} |
| 74 | + ) |
| 75 | + # Grab previously-set hoomd configuration |
| 76 | + include(hoomd_cache) |
| 77 | + # Handle user build options |
| 78 | + include(CMake_build_options) |
| 79 | + include(CMake_preprocessor_flags) |
| 80 | + # setup the install directories |
| 81 | + include(CMake_install_options) |
| 82 | + # Find the python executable and libraries |
| 83 | + include(HOOMDPythonSetup) |
| 84 | + # Find CUDA and set it up |
| 85 | + include(HOOMDCUDASetup) |
| 86 | + # Set default CFlags |
| 87 | + include(HOOMDCFlagsSetup) |
| 88 | + # Include some os specific options |
| 89 | + include(HOOMDOSSpecificSetup) |
| 90 | + # Setup common libraries used by all targets in this project |
| 91 | + include(HOOMDCommonLibsSetup) |
| 92 | + # Setup macros |
| 93 | + include(HOOMDMacros) |
| 94 | + # Setup MPI support |
| 95 | + include(HOOMDMPISetup) |
| 96 | + |
| 97 | + set(HOOMD_LIB ${HOOMD_DIR}/_hoomd${PYTHON_MODULE_EXTENSION}) |
| 98 | + set(HOOMD_MD_LIB ${HOOMD_DIR}/md/_md${PYTHON_MODULE_EXTENSION}) |
| 99 | + set(HOOMD_DEM_LIB ${HOOMD_DIR}/dem/_dem${PYTHON_MODULE_EXTENSION}) |
| 100 | + set(HOOMD_HPMC_LIB ${HOOMD_DIR}/hpmc/_hpmc${PYTHON_MODULE_EXTENSION}) |
| 101 | + set(HOOMD_CGCMM_LIB ${HOOMD_DIR}/cgcmm/_cgcmm${PYTHON_MODULE_EXTENSION}) |
| 102 | + set(HOOMD_METAL_LIB ${HOOMD_DIR}/metal/_metal${PYTHON_MODULE_EXTENSION}) |
| 103 | + set(HOOMD_DEPRECATED_LIB ${HOOMD_DIR}/deprecated/_deprecated${PYTHON_MODULE_EXTENSION}) |
| 104 | + |
| 105 | + set(HOOMD_LIBRARIES ${HOOMD_LIB} ${HOOMD_COMMON_LIBS}) |
| 106 | + set(HOOMD_LIBRARIES ${HOOMD_LIB} ${HOOMD_COMMON_LIBS}) |
| 107 | +endif(HOOMD_FOUND) |
0 commit comments