|
11 | 11 | # )
|
12 | 12 | #
|
13 | 13 | # To provide a hint to this module where to find the mallocMC installation,
|
14 |
| -# set the MALLOCMC_ROOT environment variable. |
| 14 | +# set the MALLOCMC_ROOT environment variable. You can also set the |
| 15 | +# MALLOCMC_ROOT CMake variable, which will take precedence over the environment |
| 16 | +# variable. |
15 | 17 | #
|
16 | 18 | # This module requires CUDA and Boost. When calling it, make sure to call
|
17 | 19 | # find_package(CUDA) and find_package(Boost) first.
|
18 | 20 | #
|
19 | 21 | # This module will define the following variables:
|
20 | 22 | # mallocMC_INCLUDE_DIRS - Include directories for the mallocMC headers.
|
21 |
| -# mallocMC_FOUND - TRUE if FindMallocMC found a working install |
| 23 | +# mallocMC_FOUND - TRUE if FindmallocMC found a working install |
22 | 24 | # mallocMC_VERSION - Version in format Major.Minor.Patch
|
23 | 25 | #
|
| 26 | +# The following variables are optional and only defined if the selected |
| 27 | +# components require them: |
| 28 | +# mallocMC_LIBRARIES - mallocMC libraries for dynamic linking using |
| 29 | +# target_link_libraries(${mallocMC_LIBRARIES}) |
| 30 | +# mallocMC_DEFINITIONS - Compiler definitions you should add with |
| 31 | +# add_definitions(${mallocMC_DEFINITIONS}) |
| 32 | +# |
24 | 33 |
|
25 | 34 |
|
26 | 35 | ###############################################################################
|
27 |
| -# Copyright 2014 Axel Huebl, Felix Schmitt, Rene Widera, Carlchristian Eckert |
28 |
| -# |
29 |
| -# This file is part of PIConGPU. |
| 36 | +# Copyright 2014-2015 Axel Huebl, Felix Schmitt, Rene Widera, |
| 37 | +# Carlchristian Eckert |
30 | 38 | #
|
31 |
| -# PIConGPU is free software: you can redistribute it and/or modify |
32 |
| -# it under the terms of the GNU General Public License as published by |
33 |
| -# the Free Software Foundation, either version 3 of the License, or |
34 |
| -# (at your option) any later version. |
| 39 | +# Permission to use, copy, modify, and/or distribute this software for any |
| 40 | +# purpose with or without fee is hereby granted, provided that the above |
| 41 | +# copyright notice and this permission notice appear in all copies. |
35 | 42 | #
|
36 |
| -# PIConGPU is distributed in the hope that it will be useful, |
37 |
| -# but WITHOUT ANY WARRANTY; without even the implied warranty of |
38 |
| -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
39 |
| -# GNU General Public License for more details. |
40 |
| -# |
41 |
| -# You should have received a copy of the GNU General Public License |
42 |
| -# along with PIConGPU. |
43 |
| -# If not, see <http://www.gnu.org/licenses/>. |
| 43 | +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 44 | +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 45 | +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 46 | +# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 47 | +# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, |
| 48 | +# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE |
| 49 | +# USE OR PERFORMANCE OF THIS SOFTWARE. |
44 | 50 | ###############################################################################
|
45 | 51 |
|
46 | 52 |
|
47 |
| -############################################################################### |
48 |
| -# Required cmake version |
49 |
| -############################################################################### |
50 |
| - |
| 53 | +# Required cmake version ###################################################### |
| 54 | +# |
51 | 55 | cmake_minimum_required(VERSION 2.8.5)
|
52 | 56 |
|
53 | 57 |
|
54 |
| -############################################################################### |
55 |
| -# mallocMC |
56 |
| -############################################################################### |
57 |
| - |
58 |
| -# we start by assuming we found mallocMC and falsify it if some |
59 |
| -# dependencies are missing (or if we did not find mallocMC at all) |
| 58 | +# mallocMC #################################################################### |
| 59 | +# |
60 | 60 | set(mallocMC_FOUND TRUE)
|
61 | 61 |
|
62 | 62 |
|
63 |
| -############################################################################### |
64 |
| -# preconditions |
65 |
| -############################################################################### |
66 |
| - |
67 |
| -if(NOT CUDA_FOUND) |
68 |
| - set(mallocMC_FOUND FALSE) |
69 |
| - message(STATUS "could not find CUDA, try something like find_package(CUDA REQUIRED)") |
70 |
| -elseif(CUDA_VERSION VERSION_LESS "5.0") |
71 |
| - set(mallocMC_FOUND FALSE) |
72 |
| - message(STATUS "CUDA found, but version too low (needs 5.0 or higher)") |
73 |
| -endif(NOT CUDA_FOUND) |
74 |
| - |
75 |
| -if(NOT Boost_FOUND) |
76 |
| - set(mallocMC_FOUND FALSE) |
77 |
| - message(STATUS "could not find Boost, try something like find_package(Boost REQUIRED)") |
78 |
| -elseif(Boost_VERSION LESS 104800) |
79 |
| - set(mallocMC_FOUND FALSE) |
80 |
| - message(STATUS "Boost found, but version too low (needs 1.48 or higher)") |
81 |
| -endif(NOT Boost_FOUND) |
| 63 | +# dependencies ################################################################ |
| 64 | +# |
| 65 | +find_package(CUDA 5.0 REQUIRED) |
| 66 | +find_package(Boost 1.48.0 REQUIRED) |
82 | 67 |
|
83 | 68 |
|
84 |
| -# find mallocMC installation ################################################# |
| 69 | +# find mallocMC installation ################################################## |
85 | 70 | #
|
86 | 71 | find_path(mallocMC_ROOT_DIR
|
87 |
| - NAMES include/mallocMC/mallocMC.hpp |
88 |
| - PATHS ENV MALLOCMC_ROOT |
89 |
| - DOC "mallocMC ROOT location" |
90 |
| -) |
| 72 | + NAMES include/mallocMC/mallocMC.hpp |
| 73 | + PATHS ${MALLOCMC_ROOT} ENV MALLOCMC_ROOT |
| 74 | + PATH_SUFFIXES "src" |
| 75 | + DOC "mallocMC ROOT location" |
| 76 | + ) |
91 | 77 |
|
| 78 | +set(mallocMC_REQUIRED_VARS_LIST mallocMC_ROOT_DIR mallocMC_INCLUDE_DIRS) |
92 | 79 |
|
93 | 80 | if(mallocMC_ROOT_DIR)
|
94 |
| - # mallocMC headers ########################################################## |
95 |
| - # |
96 |
| - list(APPEND mallocMC_INCLUDE_DIRS ${mallocMC_ROOT_DIR}/include) |
97 | 81 |
|
98 |
| - |
99 |
| - # find version ############################################################ |
| 82 | + # find version ############################################################## |
100 | 83 | #
|
101 | 84 | file(STRINGS "${mallocMC_ROOT_DIR}/include/mallocMC/version.hpp"
|
102 |
| - mallocMC_VERSION_MAJOR_HPP REGEX "#define MALLOCMC_VERSION_MAJOR ") |
| 85 | + mallocMC_VERSION_MAJOR_HPP REGEX "#define MALLOCMC_VERSION_MAJOR ") |
103 | 86 | file(STRINGS "${mallocMC_ROOT_DIR}/include/mallocMC/version.hpp"
|
104 |
| - mallocMC_VERSION_MINOR_HPP REGEX "#define MALLOCMC_VERSION_MINOR ") |
| 87 | + mallocMC_VERSION_MINOR_HPP REGEX "#define MALLOCMC_VERSION_MINOR ") |
105 | 88 | file(STRINGS "${mallocMC_ROOT_DIR}/include/mallocMC/version.hpp"
|
106 |
| - mallocMC_VERSION_PATCH_HPP REGEX "#define MALLOCMC_VERSION_PATCH ") |
| 89 | + mallocMC_VERSION_PATCH_HPP REGEX "#define MALLOCMC_VERSION_PATCH ") |
107 | 90 | string(REGEX MATCH "([0-9]+)" mallocMC_VERSION_MAJOR
|
108 | 91 | ${mallocMC_VERSION_MAJOR_HPP})
|
109 | 92 | string(REGEX MATCH "([0-9]+)" mallocMC_VERSION_MINOR
|
110 | 93 | ${mallocMC_VERSION_MINOR_HPP})
|
111 | 94 | string(REGEX MATCH "([0-9]+)" mallocMC_VERSION_PATCH
|
112 | 95 | ${mallocMC_VERSION_PATCH_HPP})
|
113 | 96 |
|
| 97 | + # mallocMC variables ######################################################## |
| 98 | + # |
114 | 99 | set(mallocMC_VERSION "${mallocMC_VERSION_MAJOR}.${mallocMC_VERSION_MINOR}.${mallocMC_VERSION_PATCH}")
|
| 100 | + set(mallocMC_INCLUDE_DIRS ${mallocMC_ROOT_DIR}/include) |
| 101 | + |
| 102 | + # check additional components ############################################### |
| 103 | + # |
| 104 | + foreach(COMPONENT ${mallocMC_FIND_COMPONENTS}) |
| 105 | + set(mallocMC_${COMPONENT}_FOUND TRUE) |
| 106 | + |
| 107 | + if(${COMPONENT} STREQUAL "halloc") |
| 108 | + |
| 109 | + # halloc linked library ################################################# |
| 110 | + # |
| 111 | + list(APPEND mallocMC_REQUIRED_VARS_LIST mallocMC_LIBRARIES) |
| 112 | + find_library(${COMPONENT}_LIBRARY |
| 113 | + NAMES libhalloc.a |
| 114 | + PATHS "${mallocMC_ROOT_DIR}/../halloc/" ENV HALLOC_ROOT |
| 115 | + PATH_SUFFIXES "lib" "bin" |
| 116 | + ) |
| 117 | + if(${COMPONENT}_LIBRARY) |
| 118 | + list(APPEND mallocMC_LIBRARIES ${${COMPONENT}_LIBRARY}) |
| 119 | + else(${COMPONENT}_LIBRARY) |
| 120 | + if(mallocMC_FIND_REQUIRED OR NOT mallocMC_FIND_QUIETLY) |
| 121 | + message(WARNING "libhalloc.a not found. Ensure it is compiled correctly and set HALLOC_ROOT") |
| 122 | + endif() |
| 123 | + set(mallocMC_${COMPONENT}_FOUND FALSE) |
| 124 | + endif(${COMPONENT}_LIBRARY) |
| 125 | + |
| 126 | + # halloc headers ######################################################## |
| 127 | + # |
| 128 | + find_path(${COMPONENT}_INCLUDE_DIR |
| 129 | + NAMES halloc.h |
| 130 | + PATHS "${mallocMC_ROOT_DIR}/../halloc/" ENV HALLOC_ROOT |
| 131 | + PATH_SUFFIXES "include" "src" |
| 132 | + ) |
| 133 | + if(${COMPONENT}_INCLUDE_DIR) |
| 134 | + list(APPEND mallocMC_INCLUDE_DIRS ${${COMPONENT}_INCLUDE_DIR}) |
| 135 | + else(${COMPONENT}_INCLUDE_DIR) |
| 136 | + set(mallocMC_${COMPONENT}_FOUND FALSE) |
| 137 | + endif(${COMPONENT}_INCLUDE_DIR) |
| 138 | + |
| 139 | + # set separable compilation ############################################# |
| 140 | + # |
| 141 | + if(mallocMC_${COMPONENT}_FOUND) |
| 142 | + set(CUDA_SEPARABLE_COMPILATION ON PARENT_SCOPE) |
| 143 | + endif(mallocMC_${COMPONENT}_FOUND) |
| 144 | + |
| 145 | + endif(${COMPONENT} STREQUAL "halloc") |
| 146 | + |
| 147 | + endforeach(COMPONENT ${mallocMC_FIND_COMPONENTS}) |
115 | 148 |
|
116 |
| -else(mallocMC_ROOT_DIR) |
117 |
| - set(mallocMC_FOUND FALSE) |
118 |
| - message(STATUS "Can NOT find mallocMC - set MALLOCMC_ROOT") |
119 | 149 | endif(mallocMC_ROOT_DIR)
|
120 | 150 |
|
121 | 151 |
|
122 |
| -# unset checked variables if not found ######################################## |
| 152 | +# handles the REQUIRED, QUIET and version-related arguments for find_package ## |
123 | 153 | #
|
124 |
| -if(NOT mallocMC_FOUND) |
125 |
| - unset(mallocMC_INCLUDE_DIRS) |
126 |
| -endif(NOT mallocMC_FOUND) |
127 |
| - |
128 |
| - |
129 |
| -############################################################################### |
130 |
| -# FindPackage Options |
131 |
| -############################################################################### |
132 |
| - |
133 |
| -# handles the REQUIRED, QUIET and version-related arguments for find_package |
| 154 | +list(REMOVE_DUPLICATES mallocMC_REQUIRED_VARS_LIST) |
134 | 155 | include(FindPackageHandleStandardArgs)
|
135 | 156 | find_package_handle_standard_args(mallocMC
|
136 |
| - REQUIRED_VARS mallocMC_INCLUDE_DIRS |
| 157 | + FOUND_VAR mallocMC_FOUND |
| 158 | + REQUIRED_VARS ${mallocMC_REQUIRED_VARS_LIST} |
137 | 159 | VERSION_VAR mallocMC_VERSION
|
138 |
| -) |
| 160 | + HANDLE_COMPONENTS |
| 161 | + ) |
| 162 | +unset(mallocMC_REQUIRED_VARS_LIST) |
0 commit comments