File: GetDefineString.cmake

package info (click to toggle)
freespace2 24.0.2%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: trixie
  • size: 43,188 kB
  • sloc: cpp: 583,107; ansic: 21,729; python: 1,174; sh: 464; makefile: 248; xml: 181
file content (58 lines) | stat: -rw-r--r-- 2,421 bytes parent folder | download | duplicates (8)
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
# - Script to get the value of a preprocessor definition that is a string,
# after including the given files
# Requires that the associated source file be present: GetDefineString.cpp.in.
#
#   get_define_string(NAME <define_name> [INCLUDES <files>] RESULT <variable>
#                     [FLAGS <compile-flags>]
#                     [INCLUDE_DIRS <include-dirs>]
#                     [DEFINES] <-Ddefinitions>)
# Original Author:
# 2014 Ryan Pavlik <ryan@sensics.com> <abiryan@ryand.net>
#
# Copyright Sensics, Inc. 2014.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)


get_filename_component(_getdefinestring_moddir "${CMAKE_CURRENT_LIST_FILE}" PATH)

function(get_define_string)
	include(CMakeParseArguments)
	cmake_parse_arguments(_gds "" "NAME;RESULT" "INCLUDES;FLAGS;INCLUDE_DIRS;DEFINES" ${ARGN})
	if(NOT _gds_NAME)
		message(FATAL_ERROR "Must pass NAME to get_define_string!")
	endif()
	if(NOT _gds_RESULT)
		message(FATAL_ERROR "Must pass RESULT to get_define_string!")
	endif()
	if(NOT DEFINED "${_gds_RESULT}_CHECKED" OR (NOT "${${_gds_RESULT}_CHECKED}" STREQUAL "${ARGN}"))
		set(${_gds_RESULT}_CHECKED "${ARGN}" CACHE INTERNAL "" FORCE)
		set(GET_DEFINE_STRING_NAME ${_gds_NAME})
		set(_INCLUDES)
		if(_gds_INCLUDE_DIRS)
			set(_INCLUDES "-DINCLUDE_DIRECTORIES:STRING=${_gds_INCLUDE_DIRS}")
		endif()
		set(GET_DEFINE_STRING_INCLUDES)
		foreach(_file ${_gds_INCLUDES})
			set(GET_DEFINE_STRING_INCLUDES "${GET_DEFINE_STRING_INCLUDES}#include <${_file}>\n")
		endforeach()
		set(_src "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/GetDefineString${_gds_RESULT}.cpp")
		set(_out "${CMAKE_CURRENT_BINARY_DIR}/GetDefineString${_gds_RESULT}.out")
		configure_file("${_getdefinestring_moddir}/GetDefineString.cpp.in" "${_src}")
		try_compile(_result "${CMAKE_CURRENT_BINARY_DIR}" SOURCES "${_src}"
			CMAKE_FLAGS ${_INCLUDES}
			COMPILE_DEFINITIONS ${_gds_DEFINES}
			OUTPUT_VARIABLE OUTPUT
			COPY_FILE "${_out}")
		if(_result)
			file(STRINGS "${_out}" _result_string REGEX "INFO:[A-Za-z0-9_]+\\[[^]]*\\]")
			if("${_result_string}" MATCHES "INFO:define\\[([^]\"]*)\\]")
				set(${_gds_RESULT}_CACHED "${CMAKE_MATCH_1}" CACHE INTERNAL "" FORCE)
			endif()
		else()
			set(${_gds_RESULT}_CACHED NOTFOUND)
		endif()
	endif()
	set(${_gds_RESULT} ${${_gds_RESULT}_CACHED} PARENT_SCOPE)
endfunction()