1 # This file is executed by cmake when invoked with --find-package.
2 # It expects that the following variables are set using -D:
3 # NAME = name of the package
4 # COMPILER_ID = the CMake compiler ID for which the result is, i.e. GNU/Intel/Clang/MSVC, etc.
5 # LANGUAGE = language for which the result will be used, i.e. C/CXX/Fortan/ASM
6 # MODE = EXIST : only check for existance of the given package
7 # COMPILE : print the flags needed for compiling an object file which uses the given package
8 # LINK : print the flags needed for linking when using the given package
9 # QUIET = if TRUE, don't print anything
11 #=============================================================================
12 # Copyright 2006-2011 Alexander Neundorf, <neundorf@kde.org>
14 # Distributed under the OSI-approved BSD License (the "License");
15 # see accompanying file Copyright.txt for details.
17 # This software is distributed WITHOUT ANY WARRANTY; without even the
18 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 # See the License for more information.
20 #=============================================================================
21 # (To distribute this file outside of CMake, substitute the full
22 # License text for the above reference.)
25 message(FATAL_ERROR "Name of the package to be searched not specified. Set the CMake variable NAME, e.g. -DNAME=JPEG .")
29 message(FATAL_ERROR "COMPILER_ID argument not specified. In doubt, use GNU.")
33 message(FATAL_ERROR "LANGUAGE argument not specified. Use C, CXX or Fortran.")
37 message(FATAL_ERROR "MODE argument not specified. Use either EXIST, COMPILE or LINK.")
40 # require the current version. If we don't do this, Platforms/CYGWIN.cmake complains because
41 # it doesn't know whether it should set WIN32 or not:
42 cmake_minimum_required(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION} )
44 macro(ENABLE_LANGUAGE)
45 # disable the enable_language() command, otherwise --find-package breaks on Windows.
46 # On Windows, enable_language(RC) is called in the platform files unconditionally.
47 # But in --find-package mode, we don't want (and can't) enable any language.
50 set(CMAKE_PLATFORM_INFO_DIR ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY})
52 include(CMakeDetermineSystem)
54 # short-cut some tests on Darwin, see Darwin-GNU.cmake:
55 if("${CMAKE_SYSTEM_NAME}" MATCHES Darwin AND "${COMPILER_ID}" MATCHES GNU)
56 set(CMAKE_${LANGUAGE}_SYSROOT_FLAG "")
57 set(CMAKE_${LANGUAGE}_OSX_DEPLOYMENT_TARGET_FLAG "")
60 # Also load the system specific file, which sets up e.g. the search paths.
61 # This makes the FIND_XXX() calls work much better
62 include(CMakeSystemSpecificInformation)
66 # try to guess whether we have a 64bit system, if it has not been set
68 if(NOT CMAKE_SIZEOF_VOID_P)
69 set(CMAKE_SIZEOF_VOID_P 4)
71 set(CMAKE_SIZEOF_VOID_P 8)
73 # use the file utility to check whether itself is 64 bit:
74 find_program(FILE_EXECUTABLE file)
76 get_filename_component(FILE_ABSPATH "${FILE_EXECUTABLE}" ABSOLUTE)
77 execute_process(COMMAND "${FILE_ABSPATH}" "${FILE_ABSPATH}" OUTPUT_VARIABLE fileOutput ERROR_QUIET)
78 if("${fileOutput}" MATCHES "64-bit")
79 set(CMAKE_SIZEOF_VOID_P 8)
85 # guess Debian multiarch if it has not been set:
86 if(EXISTS /etc/debian_version)
87 if(NOT CMAKE_${LANGUAGE}_LANGUAGE_ARCHITECTURE )
88 file(GLOB filesInLib RELATIVE /lib /lib/*-linux-gnu* )
89 foreach(file ${filesInLib})
90 if("${file}" MATCHES "${CMAKE_LIBRARY_ARCHITECTURE_REGEX}")
91 set(CMAKE_${LANGUAGE}_LANGUAGE_ARCHITECTURE ${file})
100 set(CMAKE_${LANGUAGE}_COMPILER "dummy")
101 set(CMAKE_${LANGUAGE}_COMPILER_ID "${COMPILER_ID}")
102 include(CMake${LANGUAGE}Information)
105 function(set_compile_flags_var _packageName)
106 string(TOUPPER "${_packageName}" PACKAGE_NAME)
107 # Check the following variables:
115 if(DEFINED ${_packageName}_INCLUDE_DIRS)
116 set(includes ${_packageName}_INCLUDE_DIRS)
117 elseif(DEFINED ${PACKAGE_NAME}_INCLUDE_DIRS)
118 set(includes ${PACKAGE_NAME}_INCLUDE_DIRS)
119 elseif(DEFINED ${_packageName}_INCLUDES)
120 set(includes ${_packageName}_INCLUDES)
121 elseif(DEFINED ${PACKAGE_NAME}_INCLUDES)
122 set(includes ${PACKAGE_NAME}_INCLUDES)
123 elseif(DEFINED ${_packageName}_INCLUDE_DIR)
124 set(includes ${_packageName}_INCLUDE_DIR)
125 elseif(DEFINED ${PACKAGE_NAME}_INCLUDE_DIR)
126 set(includes ${PACKAGE_NAME}_INCLUDE_DIR)
129 set(PACKAGE_INCLUDE_DIRS "${${includes}}" PARENT_SCOPE)
131 # Check the following variables:
135 if(DEFINED ${_packageName}_DEFINITIONS)
136 set(definitions ${_packageName}_DEFINITIONS)
137 elseif(DEFINED ${PACKAGE_NAME}_DEFINITIONS)
138 set(definitions ${PACKAGE_NAME}_DEFINITIONS)
141 set(PACKAGE_DEFINITIONS "${${definitions}}" )
146 function(set_link_flags_var _packageName)
147 string(TOUPPER "${_packageName}" PACKAGE_NAME)
148 # Check the following variables:
154 if(DEFINED ${_packageName}_LIBRARIES)
155 set(libs ${_packageName}_LIBRARIES)
156 elseif(DEFINED ${PACKAGE_NAME}_LIBRARIES)
157 set(libs ${PACKAGE_NAME}_LIBRARIES)
158 elseif(DEFINED ${_packageName}_LIBS)
159 set(libs ${_packageName}_LIBS)
160 elseif(DEFINED ${PACKAGE_NAME}_LIBS)
161 set(libs ${PACKAGE_NAME}_LIBS)
164 set(PACKAGE_LIBRARIES "${${libs}}" PARENT_SCOPE )
169 find_package("${NAME}" QUIET)
171 set(PACKAGE_FOUND FALSE)
173 string(TOUPPER "${NAME}" UPPERCASE_NAME)
175 if(${NAME}_FOUND OR ${UPPERCASE_NAME}_FOUND)
176 set(PACKAGE_FOUND TRUE)
178 if("${MODE}" STREQUAL "EXIST")
180 elseif("${MODE}" STREQUAL "COMPILE")
181 set_compile_flags_var(${NAME})
182 elseif("${MODE}" STREQUAL "LINK")
183 set_link_flags_var(${NAME})
185 message(FATAL_ERROR "Invalid mode argument ${MODE} given.")
190 set(PACKAGE_QUIET ${SILENT} )