diff --git a/CMakeLists.txt b/CMakeLists.txt index 04b2e65ac..ef8dce960 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,8 @@ SOURCE_GROUP("Builtins" REGULAR_EXPRESSION "builtin_.*") # Support folders. SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON) +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") + # All objects that the system needs to build fish, except fish.cpp SET(FISH_SRCS src/autoload.cpp src/builtin.cpp src/builtin_bg.cpp src/builtin_bind.cpp diff --git a/cmake/CheckIncludeFiles.cmake b/cmake/CheckIncludeFiles.cmake new file mode 100644 index 000000000..998cd18a4 --- /dev/null +++ b/cmake/CheckIncludeFiles.cmake @@ -0,0 +1,123 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See full license information in +# doc_src/license.hdr or https://cmake.org/licensing for details. + +#.rst: +# CheckIncludeFiles +# ----------------- +# +# Provides a macro to check if a list of one or more header files can +# be included together in ``C``. +# +# .. command:: CHECK_INCLUDE_FILES +# +# :: +# +# CHECK_INCLUDE_FILES("" [LANGUAGE ]) +# +# Check if the given ```` list may be included together +# in a ``C`` source file and store the result in an internal cache +# entry named ````. Specify the ```` argument +# as a :ref:`;-list ` of header file names. +# +# If LANGUAGE is set, the specified compiler will be used to perform the +# check. Acceptable values are C and CXX. +# +# 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 +# ``CMAKE_REQUIRED_QUIET`` +# execute quietly without messages +# +# See modules :module:`CheckIncludeFile` and :module:`CheckIncludeFileCXX` +# to check for a single header file in ``C`` or ``CXX`` languages. + +macro(CHECK_INCLUDE_FILES INCLUDE VARIABLE) + if(NOT DEFINED "${VARIABLE}") + set(CMAKE_CONFIGURABLE_FILE_CONTENT "/* */\n") + + if("x${ARGN}" STREQUAL "x") + if(CMAKE_C_COMPILER_LOADED) + set(_lang C) + elseif(CMAKE_CXX_COMPILER_LOADED) + set(_lang CXX) + else() + message(FATAL_ERROR "CHECK_INCLUDE_FILES needs either C or CXX language enabled") + endif() + elseif("x${ARGN}" MATCHES "^xLANGUAGE;([a-zA-Z]+)$") + set(_lang "${CMAKE_MATCH_1}") + else() + message(FATAL_ERROR "Unknown arguments:\n ${ARGN}\n") + endif() + + if(_lang STREQUAL "C") + set(src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckIncludeFiles/${var}.c) + elseif(_lang STREQUAL "CXX") + set(src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckIncludeFiles/${var}.cpp) + else() + message(FATAL_ERROR "Unknown language:\n ${_lang}\nSupported languages: C, CXX.\n") + endif() + + 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}) + string(APPEND CMAKE_CONFIGURABLE_FILE_CONTENT + "#include <${FILE}>\n") + endforeach() + string(APPEND CMAKE_CONFIGURABLE_FILE_CONTENT + "\n\nint main(void){return 0;}\n") + configure_file("${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in" + "${src}" @ONLY) + + set(_INCLUDE ${INCLUDE}) # remove empty elements + if("${_INCLUDE}" MATCHES "^([^;]+);.+;([^;]+)$") + list(LENGTH _INCLUDE _INCLUDE_LEN) + set(_description "${_INCLUDE_LEN} include files ${CMAKE_MATCH_1}, ..., ${CMAKE_MATCH_2}") + elseif("${_INCLUDE}" MATCHES "^([^;]+);([^;]+)$") + set(_description "include files ${CMAKE_MATCH_1}, ${CMAKE_MATCH_2}") + else() + set(_description "include file ${_INCLUDE}") + endif() + + if(NOT CMAKE_REQUIRED_QUIET) + message(STATUS "Looking for ${_description}") + endif() + try_compile(${VARIABLE} + ${CMAKE_BINARY_DIR} + ${src} + 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}) + if(NOT CMAKE_REQUIRED_QUIET) + message(STATUS "Looking for ${_description} - found") + endif() + set(${VARIABLE} 1 CACHE INTERNAL "Have include ${INCLUDE}") + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Determining if files ${INCLUDE} " + "exist passed with the following output:\n" + "${OUTPUT}\n\n") + else() + if(NOT CMAKE_REQUIRED_QUIET) + message(STATUS "Looking for ${_description} - not found") + endif() + set(${VARIABLE} "" CACHE INTERNAL "Have includes ${INCLUDE}") + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining if files ${INCLUDE} " + "exist failed with the following output:\n" + "${OUTPUT}\nSource:\n${CMAKE_CONFIGURABLE_FILE_CONTENT}\n") + endif() + endif() +endmacro() diff --git a/cmake/ConfigureChecks.cmake b/cmake/ConfigureChecks.cmake index 6508d6640..cbf9aedb3 100644 --- a/cmake/ConfigureChecks.cmake +++ b/cmake/ConfigureChecks.cmake @@ -20,6 +20,7 @@ SET(PACKAGE_TARNAME "fish") INCLUDE(CheckFunctionExists) INCLUDE(CheckCXXSymbolExists) INCLUDE(CheckIncludeFileCXX) +INCLUDE(CheckIncludeFiles) INCLUDE(CheckStructHasMember) INCLUDE(CheckCXXSourceCompiles) INCLUDE(CheckTypeSize) diff --git a/doc_src/license.hdr b/doc_src/license.hdr index 9ad8ed8de..fae1fee59 100644 --- a/doc_src/license.hdr +++ b/doc_src/license.hdr @@ -129,6 +129,47 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ---- +## License for CMake + +The `fish` source code contains files from [CMake](https://cmake.org) to support the build system. +This code is distributed under the terms of a BSD-style license. Copyright 2000-2017 Kitware, Inc. +and Contributors. + +The BSD license for CMake follows. + +CMake - Cross Platform Makefile Generator +Copyright 2000-2017 Kitware, Inc. and Contributors +All rights reserved. + +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 name of Kitware, Inc. nor the names of 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. + +---- + ## License for wcslcpy and code derived from tmux `fish` also contains small amounts of code under the OpenBSD license, namely a version of the function strlcpy, modified for use with wide character strings. This code is copyrighted by Todd C. Miller (1998). It also contains code from [tmux](http://tmux.sourceforge.net), copyrighted by Nicholas Marriott (2007), and made available under an identical license.