Skip to content

Commit

Permalink
Squashed 'thirdParty/cmake-modules/' changes from af5d9d4..ad799c9
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Third Party authored and ax3l committed Jul 29, 2015
1 parent ac7454a commit 740e446
Showing 1 changed file with 74 additions and 25 deletions.
99 changes: 74 additions & 25 deletions FindmallocMC.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# To provide a hint to this module where to find the mallocMC installation,
# set the MALLOCMC_ROOT environment variable. You can also set the
# MALLOCMC_ROOT CMake variable, which will take precedence over the environment
# variable.
# variable. Boths hints are preferred over the DEFAULT_PATHS.
#
# This module requires CUDA and Boost. When calling it, make sure to call
# find_package(CUDA) and find_package(Boost) first.
Expand All @@ -22,6 +22,8 @@
# mallocMC_INCLUDE_DIRS - Include directories for the mallocMC headers.
# mallocMC_FOUND - TRUE if FindmallocMC found a working install
# mallocMC_VERSION - Version in format Major.Minor.Patch
# and for individual COMPONENTS:
# mallocMC_<COMPONENT>_FOUND - TRUE if FindmallocMC found that component
#
# The following variables are optional and only defined if the selected
# components require them:
Expand Down Expand Up @@ -52,12 +54,7 @@

# Required cmake version ######################################################
#
cmake_minimum_required(VERSION 2.8.5)


# mallocMC ####################################################################
#
set(mallocMC_FOUND TRUE)
cmake_minimum_required(VERSION 2.8.12.2)


# dependencies ################################################################
Expand All @@ -73,14 +70,22 @@ find_path(mallocMC_ROOT_DIR
PATHS ${MALLOCMC_ROOT} ENV MALLOCMC_ROOT
PATH_SUFFIXES "src"
DOC "mallocMC ROOT location"
)
NO_DEFAULT_PATH
)
find_path(mallocMC_ROOT_DIR
NAMES include/mallocMC/mallocMC.hpp
PATH_SUFFIXES "src"
DOC "mallocMC ROOT location"
)

set(mallocMC_REQUIRED_VARS_LIST mallocMC_ROOT_DIR mallocMC_INCLUDE_DIRS)
mark_as_advanced(mallocMC_ROOT_DIR)

if(mallocMC_ROOT_DIR)

# find version ##############################################################
#
# to do: regex me
file(STRINGS "${mallocMC_ROOT_DIR}/include/mallocMC/version.hpp"
mallocMC_VERSION_MAJOR_HPP REGEX "#define MALLOCMC_VERSION_MAJOR ")
file(STRINGS "${mallocMC_ROOT_DIR}/include/mallocMC/version.hpp"
Expand All @@ -93,10 +98,17 @@ if(mallocMC_ROOT_DIR)
${mallocMC_VERSION_MINOR_HPP})
string(REGEX MATCH "([0-9]+)" mallocMC_VERSION_PATCH
${mallocMC_VERSION_PATCH_HPP})
unset(mallocMC_VERSION_MAJOR_HPP)
unset(mallocMC_VERSION_MINOR_HPP)
unset(mallocMC_VERSION_PATCH_HPP)

# mallocMC variables ########################################################
#
set(mallocMC_VERSION "${mallocMC_VERSION_MAJOR}.${mallocMC_VERSION_MINOR}.${mallocMC_VERSION_PATCH}")
unset(mallocMC_VERSION_MAJOR)
unset(mallocMC_VERSION_MINOR)
unset(mallocMC_VERSION_PATCH)

set(mallocMC_INCLUDE_DIRS ${mallocMC_ROOT_DIR}/include)

# check additional components ###############################################
Expand All @@ -109,39 +121,54 @@ if(mallocMC_ROOT_DIR)
# halloc linked library #################################################
#
list(APPEND mallocMC_REQUIRED_VARS_LIST mallocMC_LIBRARIES)
find_library(${COMPONENT}_LIBRARY
find_library(mallocMC_${COMPONENT}_LIBRARY
NAMES libhalloc.a
PATHS "${mallocMC_ROOT_DIR}/../halloc/" ENV HALLOC_ROOT
PATHS ${HALLOC_ROOT} "${mallocMC_ROOT_DIR}/../halloc/" ENV HALLOC_ROOT
PATH_SUFFIXES "lib" "bin"
)
if(${COMPONENT}_LIBRARY)
list(APPEND mallocMC_LIBRARIES ${${COMPONENT}_LIBRARY})
else(${COMPONENT}_LIBRARY)
DOC "Libraries for the mallocMC component ${COMPONENT}."
NO_DEFAULT_PATH
)
find_library(mallocMC_${COMPONENT}_LIBRARY
NAMES libhalloc.a
PATH_SUFFIXES "lib" "bin"
DOC "Libraries for the mallocMC component ${COMPONENT}."
)
if(mallocMC_${COMPONENT}_LIBRARY)
list(APPEND mallocMC_LIBRARIES ${mallocMC_${COMPONENT}_LIBRARY})
else(mallocMC_${COMPONENT}_LIBRARY)
if(mallocMC_FIND_REQUIRED OR NOT mallocMC_FIND_QUIETLY)
message(WARNING "libhalloc.a not found. Ensure it is compiled correctly and set HALLOC_ROOT")
endif()
set(mallocMC_${COMPONENT}_FOUND FALSE)
endif(${COMPONENT}_LIBRARY)
unset(mallocMC_${COMPONENT}_FOUND)
endif(mallocMC_${COMPONENT}_LIBRARY)

# halloc headers ########################################################
#
find_path(${COMPONENT}_INCLUDE_DIR
find_path(mallocMC_${COMPONENT}_INCLUDE_DIR
NAMES halloc.h
PATHS ${HALLOC_ROOT} "${mallocMC_ROOT_DIR}/../halloc/" ENV HALLOC_ROOT
PATH_SUFFIXES "include" "src"
DOC "Includes for the mallocMC component ${COMPONENT}."
NO_DEFAULT_PATH
)
find_path(mallocMC_${COMPONENT}_INCLUDE_DIR
NAMES halloc.h
PATHS "${mallocMC_ROOT_DIR}/../halloc/" ENV HALLOC_ROOT
PATH_SUFFIXES "include" "src"
)
if(${COMPONENT}_INCLUDE_DIR)
list(APPEND mallocMC_INCLUDE_DIRS ${${COMPONENT}_INCLUDE_DIR})
else(${COMPONENT}_INCLUDE_DIR)
set(mallocMC_${COMPONENT}_FOUND FALSE)
endif(${COMPONENT}_INCLUDE_DIR)
DOC "Includes for the mallocMC component ${COMPONENT}."
)
if(mallocMC_${COMPONENT}_INCLUDE_DIR)
list(APPEND mallocMC_INCLUDE_DIRS ${mallocMC_${COMPONENT}_INCLUDE_DIR})
else(mallocMC_${COMPONENT}_INCLUDE_DIR)
unset(mallocMC_${COMPONENT}_FOUND)
endif(mallocMC_${COMPONENT}_INCLUDE_DIR)

# set separable compilation #############################################
#
if(mallocMC_${COMPONENT}_FOUND)
set(CUDA_SEPARABLE_COMPILATION ON PARENT_SCOPE)
endif(mallocMC_${COMPONENT}_FOUND)

mark_as_advanced(mallocMC_${COMPONENT}_INCLUDE_DIR mallocMC_${COMPONENT}_LIBRARY)
endif(${COMPONENT} STREQUAL "halloc")

endforeach(COMPONENT ${mallocMC_FIND_COMPONENTS})
Expand All @@ -158,5 +185,27 @@ find_package_handle_standard_args(mallocMC
REQUIRED_VARS ${mallocMC_REQUIRED_VARS_LIST}
VERSION_VAR mallocMC_VERSION
HANDLE_COMPONENTS
)
)

# clean up
#
# unset cached variables in case we did not find a valid install
# (e.g., we only found an outdated version)
if(NOT mallocMC_FOUND)
# default vars
unset(mallocMC_VERSION)
foreach(REQ_VAR ${mallocMC_REQUIRED_VARS_LIST})
unset(${REQ_VAR})
unset(${REQ_VAR} CACHE)
endforeach()

# user-level component vars
foreach(COMPONENT ${mallocMC_FIND_COMPONENTS})
unset(mallocMC_${COMPONENT}_FOUND)
unset(mallocMC_${COMPONENT}_LIBRARY CACHE)
unset(mallocMC_${COMPONENT}_INCLUDE_DIR CACHE)
endforeach()
endif()

# always clean internal required vars list
unset(mallocMC_REQUIRED_VARS_LIST)

0 comments on commit 740e446

Please sign in to comment.