Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 1 | # |
| 2 | # Licensed to the Apache Software Foundation (ASF) under one |
| 3 | # or more contributor license agreements. See the NOTICE file |
| 4 | # distributed with this work for additional information |
| 5 | # regarding copyright ownership. The ASF licenses this file |
| 6 | # to you under the Apache License, Version 2.0 (the |
| 7 | # "License"); you may not use this file except in compliance |
| 8 | # with the License. You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, |
| 13 | # software distributed under the License is distributed on an |
| 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | # KIND, either express or implied. See the License for the |
| 16 | # specific language governing permissions and limitations |
| 17 | # under the License. |
| 18 | # |
| 19 | |
| 20 | |
| 21 | # Always include srcdir and builddir in include path |
| 22 | # This saves typing ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY} in |
| 23 | # about every subdir |
| 24 | # since cmake 2.4.0 |
| 25 | set(CMAKE_INCLUDE_CURRENT_DIR ON) |
| 26 | |
| 27 | # Put the include dirs which are in the source or build tree |
| 28 | # before all other include dirs, so the headers in the sources |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 29 | # are preferred over the already installed ones |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 30 | # since cmake 2.4.1 |
| 31 | set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON) |
| 32 | |
| 33 | # Use colored output |
| 34 | # since cmake 2.4.0 |
| 35 | set(CMAKE_COLOR_MAKEFILE ON) |
| 36 | |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 37 | # Create the compile command database for clang by default |
| 38 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
| 39 | |
James E. King III | ef32bc1 | 2019-01-17 14:08:44 -0500 | [diff] [blame] | 40 | # Set the CMAKE_BUILD_TYPE if it is not already defined |
| 41 | include(BuildType) |
| 42 | |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 43 | # Put the libraries and binaries that get built into directories at the |
| 44 | # top of the build tree rather than in hard-to-find leaf |
| 45 | # directories. This simplifies manual testing and the use of the build |
| 46 | # tree rather than installed thrift libraries. |
| 47 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
| 48 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
| 49 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) |
Marco Molteni | aeb89aa | 2015-04-17 13:48:36 +0200 | [diff] [blame] | 50 | |
| 51 | # |
| 52 | # "rpath" support. |
| 53 | # See http://www.itk.org/Wiki/index.php?title=CMake_RPATH_handling |
| 54 | # |
| 55 | # On MacOSX, for shared libraries, enable rpath support. |
| 56 | set(CMAKE_MACOSX_RPATH TRUE) |
| 57 | # |
| 58 | # On any OS, for executables, allow linking with shared libraries in non-system |
| 59 | # locations and running the executables without LD_PRELOAD or similar. |
| 60 | # This requires the library to be built with rpath support. |
| 61 | set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) |
James E. King, III | 43e959b | 2017-04-04 13:04:29 -0400 | [diff] [blame] | 62 | |
| 63 | # |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 64 | # C++ Language Level Defaults - this depends on the compiler capabilities |
James E. King, III | 43e959b | 2017-04-04 13:04:29 -0400 | [diff] [blame] | 65 | # |
| 66 | if (NOT DEFINED CMAKE_CXX_STANDARD) |
cyy | 5e16f8b | 2019-01-06 10:49:20 +0800 | [diff] [blame] | 67 | set(CMAKE_CXX_STANDARD 11) # C++11 |
| 68 | message(STATUS "Setting C++11 as the default language level.") |
James E. King, III | 43e959b | 2017-04-04 13:04:29 -0400 | [diff] [blame] | 69 | message(STATUS "To specify a different C++ language level, set CMAKE_CXX_STANDARD") |
| 70 | endif() |
| 71 | |
cyy | 5e16f8b | 2019-01-06 10:49:20 +0800 | [diff] [blame] | 72 | if (CMAKE_CXX_STANDARD EQUAL 98) |
| 73 | message(FATAL_ERROR "only C++11 or above C++ standard is supported") |
| 74 | elseif (CMAKE_CXX_STANDARD EQUAL 11) |
| 75 | # should not fallback to C++98 |
| 76 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
James E. King, III | 43e959b | 2017-04-04 13:04:29 -0400 | [diff] [blame] | 77 | endif() |
| 78 | |
| 79 | if (NOT DEFINED CMAKE_CXX_EXTENSIONS) |
| 80 | set(CMAKE_CXX_EXTENSIONS OFF) # use standards compliant language level for portability |
| 81 | endif() |
cyy | 8cd3f92 | 2019-01-22 16:28:15 +0800 | [diff] [blame] | 82 | |
| 83 | if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") |
| 84 | include(CheckCXXCompilerFlag) |
| 85 | set(CMAKE_REQUIRED_QUIET ON) |
| 86 | check_cxx_compiler_flag("/Zc:__cplusplus" res_var) |
| 87 | if (res_var) |
| 88 | # Make MSVC reporting correct value for __cplusplus |
| 89 | # See https://blogs.msdn.microsoft.com/vcblog/2018/04/09/msvc-now-correctly-reports-__cplusplus/ |
| 90 | add_compile_options("/Zc:__cplusplus") |
| 91 | endif() |
| 92 | endif() |