]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
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 | |
29 | # are preferred over the already installed ones | |
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 | ||
37 | # Create the compile command database for clang by default | |
38 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | |
39 | ||
40 | # Set the CMAKE_BUILD_TYPE if it is not already defined | |
41 | include(BuildType) | |
42 | ||
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) | |
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) | |
62 | ||
63 | # | |
64 | # C++ Language Level Defaults - this depends on the compiler capabilities | |
65 | # | |
66 | if (NOT DEFINED CMAKE_CXX_STANDARD) | |
67 | set(CMAKE_CXX_STANDARD 11) # C++11 | |
68 | message(STATUS "Setting C++11 as the default language level.") | |
69 | message(STATUS "To specify a different C++ language level, set CMAKE_CXX_STANDARD") | |
70 | endif() | |
71 | ||
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) | |
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() | |
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() |