|
| 1 | +# Copyright (c) 2016, Technische Universität Dresden, Germany |
| 2 | +# All rights reserved. |
| 3 | +# |
| 4 | +# Redistribution and use in source and binary forms, with or without modification, are permitted |
| 5 | +# provided that the following conditions are met: |
| 6 | +# |
| 7 | +# 1. Redistributions of source code must retain the above copyright notice, this list of conditions |
| 8 | +# and the following disclaimer. |
| 9 | +# |
| 10 | +# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions |
| 11 | +# and the following disclaimer in the documentation and/or other materials provided with the |
| 12 | +# distribution. |
| 13 | +# |
| 14 | +# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse |
| 15 | +# or promote products derived from this software without specific prior written permission. |
| 16 | +# |
| 17 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR |
| 18 | +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 19 | +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
| 20 | +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 21 | +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 22 | +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER |
| 23 | +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF |
| 24 | +# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | + |
| 26 | +IF(SCOREP_CONFIG_PATH) |
| 27 | + FIND_PROGRAM(SCOREP_CONFIG NAMES scorep-config |
| 28 | + PATHS |
| 29 | + ${SCOREP_CONFIG_PATH} |
| 30 | + /opt/scorep/bin |
| 31 | + ) |
| 32 | +ELSE(SCOREP_CONFIG_PATH) |
| 33 | + FIND_PROGRAM(SCOREP_CONFIG NAMES scorep-config |
| 34 | + PATHS |
| 35 | + /opt/scorep/bin |
| 36 | + ) |
| 37 | +ENDIF(SCOREP_CONFIG_PATH) |
| 38 | + |
| 39 | +IF(NOT SCOREP_CONFIG) |
| 40 | + MESSAGE(STATUS "no scorep-config found") |
| 41 | + set(SCOREP_FOUND false) |
| 42 | +ELSE(NOT SCOREP_CONFIG) |
| 43 | + |
| 44 | + message(STATUS "SCOREP library found. (using ${SCOREP_CONFIG})") |
| 45 | + |
| 46 | + execute_process(COMMAND ${SCOREP_CONFIG} "--user" "--cppflags" OUTPUT_VARIABLE SCOREP_CONFIG_FLAGS) |
| 47 | + |
| 48 | + string(REGEX MATCHALL "-I[^ ]*" SCOREP_CONFIG_INCLUDES "${SCOREP_CONFIG_FLAGS}") |
| 49 | + foreach(inc ${SCOREP_CONFIG_INCLUDES}) |
| 50 | + string(SUBSTRING ${inc} 2 -1 inc) |
| 51 | + list(APPEND SCOREP_INCLUDE_DIRS ${inc}) |
| 52 | + endforeach() |
| 53 | + |
| 54 | + string(REGEX MATCHALL "(^| +)-[^I][^ ]*" SCOREP_CONFIG_CXXFLAGS "${SCOREP_CONFIG_FLAGS}") |
| 55 | + foreach(flag ${SCOREP_CONFIG_CXXFLAGS}) |
| 56 | + string(STRIP ${flag} flag) |
| 57 | + list(APPEND SCOREP_CXX_FLAGS ${flag}) |
| 58 | + endforeach() |
| 59 | + |
| 60 | + unset(SCOREP_CONFIG_FLAGS) |
| 61 | + unset(SCOREP_CONFIG_INCLUDES) |
| 62 | + unset(SCOREP_CONFIG_CXXFLAGS) |
| 63 | + |
| 64 | + execute_process(COMMAND ${SCOREP_CONFIG} "--user" "--ldflags" OUTPUT_VARIABLE _LINK_LD_ARGS) |
| 65 | + STRING( REPLACE " " ";" _LINK_LD_ARGS ${_LINK_LD_ARGS} ) |
| 66 | + FOREACH( _ARG ${_LINK_LD_ARGS} ) |
| 67 | + IF(${_ARG} MATCHES "^-L") |
| 68 | + STRING(REGEX REPLACE "^-L" "" _ARG ${_ARG}) |
| 69 | + SET(SCOREP_LINK_DIRS ${SCOREP_LINK_DIRS} ${_ARG}) |
| 70 | + ENDIF(${_ARG} MATCHES "^-L") |
| 71 | + ENDFOREACH(_ARG) |
| 72 | + |
| 73 | + execute_process(COMMAND ${SCOREP_CONFIG} "--user" "--libs" OUTPUT_VARIABLE _LINK_LD_ARGS) |
| 74 | + STRING( REPLACE " " ";" _LINK_LD_ARGS ${_LINK_LD_ARGS} ) |
| 75 | + FOREACH( _ARG ${_LINK_LD_ARGS} ) |
| 76 | + IF(${_ARG} MATCHES "^-l") |
| 77 | + STRING(REGEX REPLACE "^-l" "" _ARG ${_ARG}) |
| 78 | + FIND_LIBRARY(_SCOREP_LIB_FROM_ARG NAMES ${_ARG} |
| 79 | + PATHS |
| 80 | + ${SCOREP_LINK_DIRS} |
| 81 | + ) |
| 82 | + IF(_SCOREP_LIB_FROM_ARG) |
| 83 | + SET(SCOREP_LIBRARIES ${SCOREP_LIBRARIES} ${_SCOREP_LIB_FROM_ARG}) |
| 84 | + ENDIF(_SCOREP_LIB_FROM_ARG) |
| 85 | + UNSET(_SCOREP_LIB_FROM_ARG CACHE) |
| 86 | + ENDIF(${_ARG} MATCHES "^-l") |
| 87 | + ENDFOREACH(_ARG) |
| 88 | + |
| 89 | + set(SCOREP_FOUND true) |
| 90 | +ENDIF(NOT SCOREP_CONFIG) |
| 91 | + |
| 92 | +include (FindPackageHandleStandardArgs) |
| 93 | +FIND_PACKAGE_HANDLE_STANDARD_ARGS( |
| 94 | + Scorep DEFAULT_MSG |
| 95 | + SCOREP_CONFIG |
| 96 | + SCOREP_LIBRARIES |
| 97 | + SCOREP_INCLUDE_DIRS |
| 98 | +) |
| 99 | + |
| 100 | +add_library(Scorep::Scorep INTERFACE IMPORTED) |
| 101 | +set_target_properties(Scorep::Scorep PROPERTIES |
| 102 | + INTERFACE_INCLUDE_DIRECTORIES "${SCOREP_INCLUDE_DIRS}" |
| 103 | + INTERFACE_LINK_LIBRARIES "${SCOREP_LIBRARIES}" |
| 104 | +) |
| 105 | + |
| 106 | +add_library(Scorep::Plugin INTERFACE IMPORTED) |
| 107 | +set_target_properties(Scorep::Plugin PROPERTIES |
| 108 | + INTERFACE_INCLUDE_DIRECTORIES "${SCOREP_INCLUDE_DIRS}" |
| 109 | +) |
| 110 | + |
| 111 | +mark_as_advanced(SCOREP_CONFIG) |
0 commit comments