Skip to content

Commit 740e446

Browse files
Third Partyax3l
authored andcommitted
Squashed 'thirdParty/cmake-modules/' changes from af5d9d4..ad799c9
ad799c9 Merge pull request #9 from ComputationalRadiationPhysics/topic-mallocVersionCleanup 9299042 mallocMC: Unset Temp Vars (Version) 3a65fa4 Merge pull request #8 from ComputationalRadiationPhysics/topic-mallocPreferHints b481ca0 CMake: FOUND_VAR & CUDA_SEPARABLE_COMPILATION 70b94e6 Fix Cache Weirdness (Last Commit) e4f0d5b Fix CACHE Scopes and Clean Ups a118419 Find mallocMC: Prefer Hints over Default Paths git-subtree-dir: thirdParty/cmake-modules git-subtree-split: ad799c9b3e5c1146ef005afb69c5a88216476a83
1 parent ac7454a commit 740e446

File tree

1 file changed

+74
-25
lines changed

1 file changed

+74
-25
lines changed

FindmallocMC.cmake

Lines changed: 74 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# To provide a hint to this module where to find the mallocMC installation,
1414
# set the MALLOCMC_ROOT environment variable. You can also set the
1515
# MALLOCMC_ROOT CMake variable, which will take precedence over the environment
16-
# variable.
16+
# variable. Boths hints are preferred over the DEFAULT_PATHS.
1717
#
1818
# This module requires CUDA and Boost. When calling it, make sure to call
1919
# find_package(CUDA) and find_package(Boost) first.
@@ -22,6 +22,8 @@
2222
# mallocMC_INCLUDE_DIRS - Include directories for the mallocMC headers.
2323
# mallocMC_FOUND - TRUE if FindmallocMC found a working install
2424
# mallocMC_VERSION - Version in format Major.Minor.Patch
25+
# and for individual COMPONENTS:
26+
# mallocMC_<COMPONENT>_FOUND - TRUE if FindmallocMC found that component
2527
#
2628
# The following variables are optional and only defined if the selected
2729
# components require them:
@@ -52,12 +54,7 @@
5254

5355
# Required cmake version ######################################################
5456
#
55-
cmake_minimum_required(VERSION 2.8.5)
56-
57-
58-
# mallocMC ####################################################################
59-
#
60-
set(mallocMC_FOUND TRUE)
57+
cmake_minimum_required(VERSION 2.8.12.2)
6158

6259

6360
# dependencies ################################################################
@@ -73,14 +70,22 @@ find_path(mallocMC_ROOT_DIR
7370
PATHS ${MALLOCMC_ROOT} ENV MALLOCMC_ROOT
7471
PATH_SUFFIXES "src"
7572
DOC "mallocMC ROOT location"
76-
)
73+
NO_DEFAULT_PATH
74+
)
75+
find_path(mallocMC_ROOT_DIR
76+
NAMES include/mallocMC/mallocMC.hpp
77+
PATH_SUFFIXES "src"
78+
DOC "mallocMC ROOT location"
79+
)
7780

7881
set(mallocMC_REQUIRED_VARS_LIST mallocMC_ROOT_DIR mallocMC_INCLUDE_DIRS)
82+
mark_as_advanced(mallocMC_ROOT_DIR)
7983

8084
if(mallocMC_ROOT_DIR)
8185

8286
# find version ##############################################################
8387
#
88+
# to do: regex me
8489
file(STRINGS "${mallocMC_ROOT_DIR}/include/mallocMC/version.hpp"
8590
mallocMC_VERSION_MAJOR_HPP REGEX "#define MALLOCMC_VERSION_MAJOR ")
8691
file(STRINGS "${mallocMC_ROOT_DIR}/include/mallocMC/version.hpp"
@@ -93,10 +98,17 @@ if(mallocMC_ROOT_DIR)
9398
${mallocMC_VERSION_MINOR_HPP})
9499
string(REGEX MATCH "([0-9]+)" mallocMC_VERSION_PATCH
95100
${mallocMC_VERSION_PATCH_HPP})
101+
unset(mallocMC_VERSION_MAJOR_HPP)
102+
unset(mallocMC_VERSION_MINOR_HPP)
103+
unset(mallocMC_VERSION_PATCH_HPP)
96104

97105
# mallocMC variables ########################################################
98106
#
99107
set(mallocMC_VERSION "${mallocMC_VERSION_MAJOR}.${mallocMC_VERSION_MINOR}.${mallocMC_VERSION_PATCH}")
108+
unset(mallocMC_VERSION_MAJOR)
109+
unset(mallocMC_VERSION_MINOR)
110+
unset(mallocMC_VERSION_PATCH)
111+
100112
set(mallocMC_INCLUDE_DIRS ${mallocMC_ROOT_DIR}/include)
101113

102114
# check additional components ###############################################
@@ -109,39 +121,54 @@ if(mallocMC_ROOT_DIR)
109121
# halloc linked library #################################################
110122
#
111123
list(APPEND mallocMC_REQUIRED_VARS_LIST mallocMC_LIBRARIES)
112-
find_library(${COMPONENT}_LIBRARY
124+
find_library(mallocMC_${COMPONENT}_LIBRARY
113125
NAMES libhalloc.a
114-
PATHS "${mallocMC_ROOT_DIR}/../halloc/" ENV HALLOC_ROOT
126+
PATHS ${HALLOC_ROOT} "${mallocMC_ROOT_DIR}/../halloc/" ENV HALLOC_ROOT
115127
PATH_SUFFIXES "lib" "bin"
116-
)
117-
if(${COMPONENT}_LIBRARY)
118-
list(APPEND mallocMC_LIBRARIES ${${COMPONENT}_LIBRARY})
119-
else(${COMPONENT}_LIBRARY)
128+
DOC "Libraries for the mallocMC component ${COMPONENT}."
129+
NO_DEFAULT_PATH
130+
)
131+
find_library(mallocMC_${COMPONENT}_LIBRARY
132+
NAMES libhalloc.a
133+
PATH_SUFFIXES "lib" "bin"
134+
DOC "Libraries for the mallocMC component ${COMPONENT}."
135+
)
136+
if(mallocMC_${COMPONENT}_LIBRARY)
137+
list(APPEND mallocMC_LIBRARIES ${mallocMC_${COMPONENT}_LIBRARY})
138+
else(mallocMC_${COMPONENT}_LIBRARY)
120139
if(mallocMC_FIND_REQUIRED OR NOT mallocMC_FIND_QUIETLY)
121140
message(WARNING "libhalloc.a not found. Ensure it is compiled correctly and set HALLOC_ROOT")
122141
endif()
123-
set(mallocMC_${COMPONENT}_FOUND FALSE)
124-
endif(${COMPONENT}_LIBRARY)
142+
unset(mallocMC_${COMPONENT}_FOUND)
143+
endif(mallocMC_${COMPONENT}_LIBRARY)
125144

126145
# halloc headers ########################################################
127146
#
128-
find_path(${COMPONENT}_INCLUDE_DIR
147+
find_path(mallocMC_${COMPONENT}_INCLUDE_DIR
148+
NAMES halloc.h
149+
PATHS ${HALLOC_ROOT} "${mallocMC_ROOT_DIR}/../halloc/" ENV HALLOC_ROOT
150+
PATH_SUFFIXES "include" "src"
151+
DOC "Includes for the mallocMC component ${COMPONENT}."
152+
NO_DEFAULT_PATH
153+
)
154+
find_path(mallocMC_${COMPONENT}_INCLUDE_DIR
129155
NAMES halloc.h
130-
PATHS "${mallocMC_ROOT_DIR}/../halloc/" ENV HALLOC_ROOT
131156
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)
157+
DOC "Includes for the mallocMC component ${COMPONENT}."
158+
)
159+
if(mallocMC_${COMPONENT}_INCLUDE_DIR)
160+
list(APPEND mallocMC_INCLUDE_DIRS ${mallocMC_${COMPONENT}_INCLUDE_DIR})
161+
else(mallocMC_${COMPONENT}_INCLUDE_DIR)
162+
unset(mallocMC_${COMPONENT}_FOUND)
163+
endif(mallocMC_${COMPONENT}_INCLUDE_DIR)
138164

139165
# set separable compilation #############################################
140166
#
141167
if(mallocMC_${COMPONENT}_FOUND)
142168
set(CUDA_SEPARABLE_COMPILATION ON PARENT_SCOPE)
143169
endif(mallocMC_${COMPONENT}_FOUND)
144170

171+
mark_as_advanced(mallocMC_${COMPONENT}_INCLUDE_DIR mallocMC_${COMPONENT}_LIBRARY)
145172
endif(${COMPONENT} STREQUAL "halloc")
146173

147174
endforeach(COMPONENT ${mallocMC_FIND_COMPONENTS})
@@ -158,5 +185,27 @@ find_package_handle_standard_args(mallocMC
158185
REQUIRED_VARS ${mallocMC_REQUIRED_VARS_LIST}
159186
VERSION_VAR mallocMC_VERSION
160187
HANDLE_COMPONENTS
161-
)
188+
)
189+
190+
# clean up
191+
#
192+
# unset cached variables in case we did not find a valid install
193+
# (e.g., we only found an outdated version)
194+
if(NOT mallocMC_FOUND)
195+
# default vars
196+
unset(mallocMC_VERSION)
197+
foreach(REQ_VAR ${mallocMC_REQUIRED_VARS_LIST})
198+
unset(${REQ_VAR})
199+
unset(${REQ_VAR} CACHE)
200+
endforeach()
201+
202+
# user-level component vars
203+
foreach(COMPONENT ${mallocMC_FIND_COMPONENTS})
204+
unset(mallocMC_${COMPONENT}_FOUND)
205+
unset(mallocMC_${COMPONENT}_LIBRARY CACHE)
206+
unset(mallocMC_${COMPONENT}_INCLUDE_DIR CACHE)
207+
endforeach()
208+
endif()
209+
210+
# always clean internal required vars list
162211
unset(mallocMC_REQUIRED_VARS_LIST)

0 commit comments

Comments
 (0)