File: Utilities.cmake

package info (click to toggle)
nexus 4.4.3-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,876 kB
  • sloc: cpp: 34,928; ansic: 17,317; f90: 2,326; xml: 2,071; java: 1,953; fortran: 1,529; python: 766; makefile: 532; sh: 460; tcl: 173; lisp: 169
file content (223 lines) | stat: -rw-r--r-- 9,233 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
## Process this file with cmake
#=============================================================================
#  NeXus - Neutron & X-ray Common Data Format
#
#  CMakeLists for building the NeXus library and applications.
#
#  Copyright (C) 2011 Freddie Akeroyd
#
#  This library is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by the
#  Free Software Foundation; either version 2 of the License, or (at your
#  option) any later version.
#
#  This library is distributed in the hope that it will be useful, but WITHOUT
#  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
#  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
#  for more details.
#
#  You should have received a copy of the GNU Lesser General Public License
#  along with this library; if not, write to the Free Software Foundation,
#  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#  For further information, see <http://www.nexusformat.org>
#
#
#=============================================================================
include(CMakeParseArguments)

#-----------------------------------------------------------------------------
# This module provides some utility functions that are used throughout the
# project for configuration
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# checks a list of possible compiler flags and adds allowed ones 
# to the current list
#
function(check_add_c_compiler_flags)
    foreach(FLAG ${ARGV})
        check_c_compiler_flag(${FLAG} RES)
	    if (RES)
            set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAG}" PARENT_SCOPE)
	    endif()
	endforeach()
endfunction()

#------------------------------------------------------------------------------
# checks a list of possible compiler flags and adds allowed ones to the current
# list
#
function(check_add_cxx_compiler_flags)
    foreach(FLAG ${ARGV})
        check_cxx_compiler_flag(${FLAG} RES)
	    if (RES)
            set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}" PARENT_SCOPE)
	    endif()
	endforeach()
endfunction()

#------------------------------------------------------------------------------
# define a HAVE_  if both  BUILD_  and  _FOUND  are defined e.g. creates
# HAVE_HDF5 if both BUILD_HDF5 and HDF5_FOUND are ture
#
function(create_have_vars)
    foreach(NAME ${ARGV})
        if(${BUILD_${NAME}} AND ${${NAME}_FOUND})
	        set(HAVE_${NAME} ON PARENT_SCOPE)
	    else()
	        set(HAVE_${NAME} OFF PARENT_SCOPE)
	    endif()
	endforeach()
endfunction()

#-----------------------------------------------------------------------------
# Still need to check whether or not this function is required. 
#
function(install_pdb target)
#	set (OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR})
	set (OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/Release)
	get_target_property (OUT_NAME ${target} OUTPUT_NAME)
	get_filename_component (OUT_BASE_NAME ${OUT_NAME} NAME_WE)
#	set(PDB_FILE ${OUT_DIR}/${OUT_BASE_NAME}${CMAKE_DEBUG_POSTFIX}.pdb)
	set(PDB_FILE ${OUT_DIR}/${OUT_BASE_NAME}.pdb)
	install (FILES ${PDB_FILE} DESTINATION bin COMPONENT Runtime)  
endfunction()

#-----------------------------------------------------------------------------
function(search_module_library VAR)
    set(multiValueArgs SEARCH_PATH)
    set(oneValueArgs)
    cmake_parse_arguments(find_module_library "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

    if(${VAR}_LIBRARY_DIRS)
        #if the user has provided a path we use this one 
        find_library(LIBFILES NAME ${LIB_NAMES} PATHS ${${VAR}_LIBRARY_DIRS} NO_DEFAULT_PATH)
    else()
        #if the user has not provided a path we look in the 
        #system defaults
        find_library(LIBFILES NAME ${LIB_NAMES} PATHS)
        get_filename_component(${VAR}_LIBRARY_DIRS ${LIBFILES} PATH)
    endif()

    if(${LIBFILES} MATCHES "LIBFILES-NOTFOUND")
        message(STATUS "Could not find ${VAR} runtime binaries")
        set(HAVE_${VAR} FALSE PARENT_SCOPE)
    endif()
endfunction()

#-----------------------------------------------------------------------------
function(search_module_header VAR)

endfunction()

#-----------------------------------------------------------------------------
#
# Looks for a particular module 
#
# The function has three strategies to look for header and library files
# 1.) Check for user provided ${VAR}_INCLUDE_DIRS and ${VAR}_LIBRARY_DIRS
#     If the use has provided a location we look there for the libraries. 
#     The search is exclusive. Only the user provided directories are 
#     searched. This is to avoid conflicts with other version of a 
#     particular library which might be installed in the default locations.
# 2.) If the user has not provided any location we firs try pkg-config 
#     to look for the module. The name of the module is passed via the 
#     MOD_NAME keywoard argument.
# 3.) If no  pkg-config module is available, the function looks in the 
#     default search paths. It can use the environment variable 
#     ${MOD_NAME}_ROOT as a path hint.
#
# Arguments:
#   Positional arguments: 
#   VAR ................. prefix used for all output variables
# Results:
#   HAVE_{VAR} .......... true if the module was found (false otherwise)
#   ${VAR}_INCLUDE_DIRS . holding the header directory
#   ${VAR}_LIBRARY_DIRS . directory with runtime libraries
#   
# 
# 
function(find_module VAR )
    set(oneValueArgs MOD_NAME)
    set(multiValueArgs LIB_NAMES HEADER_NAMES)
    cmake_parse_arguments(find_module "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
    set(LIB_NAMES  ${find_module_LIB_NAMES})
    set(HEADER_NAMES ${find_module_HEADER_NAMES})
    set(MOD_NAME ${find_module_MOD_NAME})
    
    set(HAVE_${VAR} TRUE PARENT_SCOPE)

    if(${VAR}_INCLUDE_DIRS OR ${VAR}_LIBRARY_DIRS)
        #if the user has provided the search path we have to do nothing but check 
        #wether or not the library files exist 
        if(${VAR}_LIBRARY_DIRS)
            #if the user has provided a path we use this one 
            find_library(${VAR}_LIBFILES NAME ${LIB_NAMES} 
                         PATHS ${${VAR}_LIBRARY_DIRS} NO_DEFAULT_PATH)
        else()
            #if the user has not provided a path we look in the 
            #system defaults
            find_library(${VAR}_LIBFILES NAME ${LIB_NAMES} PATHS)
            get_filename_component(${VAR}_LIBRARY_DIRS ${${VAR}_LIBFILES} PATH)
        endif()

        if(${${VAR}_LIBFILES} MATCHES "${VAR}_LIBFILES-NOTFOUND")
            message(STATUS "Could not find ${VAR} runtime binaries")
            set(HAVE_${VAR} FALSE PARENT_SCOPE)
        endif()

        #-------------------------------------------------------------------------
        # search for the header file
        #-------------------------------------------------------------------------
        if(${VAR}_INCLUDE_DIRS)
            #just check if the user provided path contains the header file
            find_file(${VAR}_HDRFILES NAME ${HEADER_NAMES} 
                      PATHS ${${VAR}_INCLUDE_DIRS} NO_DEFAULT_PATH)
        else()
            find_file(${VAR}_HDRFILES NAME ${HEADER_NAMES} PATHS)
            get_filename_component(${VAR}_INCLUDE_DIRS ${${VAR}_HDRFILES} PATH)
        endif()
        
        if(${${VAR}_HDRFILES} MATCHES "${VAR}_HDRFILES-NOTFOUND")
            message(STATUS "Could not find ${VAR} header files!")
            set(HAVE_${VAR} FALSE PARENT_SCOPE)
        endif()

    else()
        #if the user has not provided any configuration we have to do this manually
        if(PKG_CONFIG_FOUND AND MOD_NAME)
            #the easy way  - we use package config
            message(STATUS "pkg-config is searching for : ${MOD_NAME}")
            pkg_search_module(${VAR} ${MOD_NAME})
        endif()

        #if pkg-config was not successful we have to do this the hard way
        if(NOT ${VAR}_FOUND)
            find_library(${VAR}_LIBFILES NAME ${LIB_NAMES} PATHS ENV ${MOD_NAME}_ROOT)
            if(${${VAR}_LIBFILES} MATCHES "${VAR}_LIBFILES-NOTFOUND")
                set(STATUS "Could not find ${VAR} runtime binaries!")
                set(HAVE_${VAR} FALSE PARENT_SCOPE)
            else()
                get_filename_component(${VAR}_LIBRARY_DIRS 
                    ${${VAR}_LIBFILES} PATH) 
                message(STATUS "${VAR} libraries: ${${VAR}_LIBFILES}")
            endif()

            find_file(${VAR}_HDRFILES NAME ${HEADER_NAMES} PATHS ENV ${MOD_NAME}_ROOT)
            if(${${VAR}_HDRFILES} MATCHES "${VAR}_HDRFILES-NOTFOUND")
                message(STATUS "Could not find ${VAR} header files!")
                set(HAVE_${VAR} FALSE PARENT_SCOPE)
            else()
                get_filename_component(${VAR}_INCLUDE_DIRS ${${VAR}_HDRFILES} PATH)
                message(STATUS "${VAR} headers: ${${VAR}_HDRFILES}")
            endif()
            
        endif()

    endif()
    set(${VAR}_INCLUDE_DIRS ${${VAR}_INCLUDE_DIRS} PARENT_SCOPE)
    set(${VAR}_LIBRARY_DIRS ${${VAR}_LIBRARY_DIRS} PARENT_SCOPE)
	set(${VAR}_LIBFILES ${${VAR}_LIBFILES} PARENT_SCOPE)

endfunction()