forked from Mirrors/openclonk
cmake: Use C++ compiler to check for X11/extensions/Xrandr.h and keysym.h
To do this, port the CHECK_INCLUDE_FILES macro from the CMake source to C++. While at it, actually check for both headers instead of XLib.h alone.issue1247
parent
b1292a3421
commit
f6b7001d0b
|
@ -57,6 +57,12 @@ endif()
|
|||
option(USE_OPEN_AL "Use OpenAL to play sounds" ${INITIAL_USE_OPEN_AL})
|
||||
option(WITH_AUTOMATIC_UPDATE "Automatic updates are downloaded from the project website." OFF)
|
||||
|
||||
# We link Boost statically because that makes it easier for us to distribute
|
||||
# the resulting binary. Distributions have the ability to guarantee a certain
|
||||
# version of the library exists on the system though, so they may prefer
|
||||
# dynamic linking.
|
||||
option(USE_STATIC_BOOST "Link Boost libraries statically" ON)
|
||||
|
||||
# Remove obsolete options
|
||||
unset(OC_BUILD_MULTIPROCESSOR CACHE)
|
||||
|
||||
|
@ -77,7 +83,6 @@ foreach(FLAG ${OC_CXX_FLAGS})
|
|||
set(OC_REQUIRED_FLAGS "${OC_REQUIRED_FLAGS} ${FLAG}")
|
||||
endforeach()
|
||||
|
||||
set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
|
||||
set(CMAKE_REQUIRED_FLAGS ${OC_REQUIRED_FLAGS})
|
||||
|
||||
REQUIRE_CXX_SOURCE_COMPILES("#include <memory>\nint main() { std::unique_ptr<int> a; std::shared_ptr<int> b; }" HAVE_C11_SMART_PTRS)
|
||||
|
@ -93,17 +98,6 @@ CHECK_CXX_SOURCE_COMPILES("int main() { static_assert(true, \"\"); }" HAVE_STATI
|
|||
CHECK_CXX_SOURCE_COMPILES("#include <regex>\nint main() { std::cregex_iterator ri; }" HAVE_WORKING_REGEX)
|
||||
CMAKE_DEPENDENT_OPTION(USE_BOOST_REGEX "Use Boost.Regex even if the C++ runtime has a working implementation of <regex>" OFF "HAVE_WORKING_REGEX" ON)
|
||||
|
||||
# Reset CMAKE_REQUIRED_FLAGS after having done the C++0x checks
|
||||
# otherwise they are used for C library checks as well and the C compiler bails
|
||||
# out because it does not understand -std=gnu++0x
|
||||
set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
|
||||
|
||||
# We link Boost statically because that makes it easier for us to distribute
|
||||
# the resulting binary. Distributions have the ability to guarantee a certain
|
||||
# version of the library exists on the system though, so they may prefer
|
||||
# dynamic linking.
|
||||
option(USE_STATIC_BOOST "Link Boost libraries statically" ON)
|
||||
|
||||
if(MSVC_VERSION GREATER 1499)
|
||||
list(APPEND OC_CXX_FLAGS /MP)
|
||||
list(REMOVE_ITEM OC_CXX_FLAGS_DEBUG /Gm)
|
||||
|
@ -731,6 +725,7 @@ include_directories(
|
|||
# Check for required system headers
|
||||
############################################################################
|
||||
include(CheckIncludeFileCXX)
|
||||
include(CheckIncludeFilesCXX)
|
||||
CHECK_INCLUDE_FILE_CXX(direct.h HAVE_DIRECT_H)
|
||||
CHECK_INCLUDE_FILE_CXX(io.h HAVE_IO_H)
|
||||
CHECK_INCLUDE_FILE_CXX(locale.h HAVE_LOCALE_H)
|
||||
|
@ -753,13 +748,8 @@ if(USE_CONSOLE)
|
|||
CHECK_INCLUDE_FILE_CXX(readline/readline.h HAVE_READLINE_READLINE_H)
|
||||
endif()
|
||||
CHECK_INCLUDE_FILE_CXX(natupnp.h HAVE_NATUPNP_H)
|
||||
|
||||
# ck 09-09-20: The following headers require Xlib.h for things such as
|
||||
# 'Bool' and 'Window' to be defined. Unfortunately, this doesn't exist
|
||||
# as a CXX version (yet?).
|
||||
include(CheckIncludeFiles)
|
||||
CHECK_INCLUDE_FILES(X11/Xlib.h X11/extensions/Xrandr.h HAVE_X11_EXTENSIONS_XRANDR_H)
|
||||
CHECK_INCLUDE_FILES(X11/Xlib.h X11/keysym.h HAVE_X11_KEYSYM_H)
|
||||
CHECK_INCLUDE_FILES_CXX("X11/Xlib.h;X11/extensions/Xrandr.h" HAVE_X11_EXTENSIONS_XRANDR_H)
|
||||
CHECK_INCLUDE_FILES_CXX("X11/Xlib.h;X11/keysym.h" HAVE_X11_KEYSYM_H)
|
||||
CHECK_INCLUDE_FILE_CXX(iconv.h HAVE_ICONV)
|
||||
|
||||
if(HAVE_ICONV)
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
# - Check if the files can be included
|
||||
#
|
||||
# CHECK_INCLUDE_FILES_CXX(INCLUDE VARIABLE)
|
||||
#
|
||||
# INCLUDE - list of files to include
|
||||
# VARIABLE - variable to return result
|
||||
#
|
||||
# The following variables may be set before calling this macro to
|
||||
# modify the way the check is run:
|
||||
#
|
||||
# CMAKE_REQUIRED_FLAGS = string of compile command line flags
|
||||
# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
|
||||
# CMAKE_REQUIRED_INCLUDES = list of include directories
|
||||
|
||||
#=============================================================================
|
||||
# Copyright 2003-2012 Kitware, Inc.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
#
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
#
|
||||
# * Neither the names of Kitware, Inc., the Insight Software Consortium,
|
||||
# nor the names of their contributors may be used to endorse or promote
|
||||
# products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#=============================================================================
|
||||
|
||||
macro(CHECK_INCLUDE_FILES_CXX INCLUDE VARIABLE)
|
||||
if("${VARIABLE}" MATCHES "^${VARIABLE}$")
|
||||
set(CMAKE_CONFIGURABLE_FILE_CONTENT "/* */\n")
|
||||
if(CMAKE_REQUIRED_INCLUDES)
|
||||
set(CHECK_INCLUDE_FILES_INCLUDE_DIRS "-DINCLUDE_DIRECTORIES=${CMAKE_REQUIRED_INCLUDES}")
|
||||
else()
|
||||
set(CHECK_INCLUDE_FILES_INCLUDE_DIRS)
|
||||
endif()
|
||||
set(CHECK_INCLUDE_FILES_CONTENT "/* */\n")
|
||||
set(MACRO_CHECK_INCLUDE_FILES_FLAGS ${CMAKE_REQUIRED_FLAGS})
|
||||
foreach(FILE ${INCLUDE})
|
||||
set(CMAKE_CONFIGURABLE_FILE_CONTENT
|
||||
"${CMAKE_CONFIGURABLE_FILE_CONTENT}#include <${FILE}>\n")
|
||||
endforeach()
|
||||
set(CMAKE_CONFIGURABLE_FILE_CONTENT
|
||||
"${CMAKE_CONFIGURABLE_FILE_CONTENT}\n\nint main(){return 0;}\n")
|
||||
configure_file("${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in"
|
||||
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFiles.cxx" @ONLY IMMEDIATE)
|
||||
|
||||
set(_INCLUDE ${INCLUDE}) # remove empty elements
|
||||
if("${_INCLUDE}" MATCHES "^([^;]+);.+;([^;]+)$")
|
||||
list(LENGTH _INCLUDE _INCLUDE_LEN)
|
||||
set(_description "${_INCLUDE_LEN} C++ include files ${CMAKE_MATCH_1}, ..., ${CMAKE_MATCH_2}")
|
||||
elseif("${_INCLUDE}" MATCHES "^([^;]+);([^;]+)$")
|
||||
set(_description "C++ include files ${CMAKE_MATCH_1}, ${CMAKE_MATCH_2}")
|
||||
else()
|
||||
set(_description "C++ include file ${_INCLUDE}")
|
||||
endif()
|
||||
|
||||
message(STATUS "Looking for ${_description}")
|
||||
try_compile(${VARIABLE}
|
||||
${CMAKE_BINARY_DIR}
|
||||
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFiles.cxx
|
||||
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
|
||||
CMAKE_FLAGS
|
||||
-DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILES_FLAGS}
|
||||
"${CHECK_INCLUDE_FILES_INCLUDE_DIRS}"
|
||||
OUTPUT_VARIABLE OUTPUT)
|
||||
if(${VARIABLE})
|
||||
message(STATUS "Looking for ${_description} - found")
|
||||
set(${VARIABLE} 1 CACHE INTERNAL "Have include ${INCLUDE}")
|
||||
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
|
||||
"Determining if C++ files ${INCLUDE} "
|
||||
"exist passed with the following output:\n"
|
||||
"${OUTPUT}\n\n")
|
||||
else()
|
||||
message(STATUS "Looking for ${_description} - not found")
|
||||
set(${VARIABLE} "" CACHE INTERNAL "Have includes ${INCLUDE}")
|
||||
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
|
||||
"Determining if C++ files ${INCLUDE} "
|
||||
"exist failed with the following output:\n"
|
||||
"${OUTPUT}\nSource:\n${CMAKE_CONFIGURABLE_FILE_CONTENT}\n")
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
Loading…
Reference in New Issue