]> git.lyx.org Git - lyx.git/blob - development/cmake/modules/FindCXX11Compiler.cmake
Cmake tests: macro setmarkedtestlabel() worked only by chance
[lyx.git] / development / cmake / modules / FindCXX11Compiler.cmake
1 # This file is part of lyx.
2 #
3 # The module comes from the enblend project, slightly modified.
4 #
5 # Check if compiler supports C++11 features
6 # and which compiler switches are necessary
7 # CXX11_FLAG : contains the necessary compiler flag
8
9 #
10 # Copyright (c) 2013 Thomas Modes <tmodes@@users.sourceforge.net>
11 #
12 #  Redistribution and use in source and binary forms, with or without
13 #  modification, are permitted provided that the following conditions
14 #  are met:
15 #
16 #  1. Redistributions of source code must retain the copyright
17 #         notice, this list of conditions and the following disclaimer.
18 #  2. Redistributions in binary form must reproduce the copyright
19 #         notice, this list of conditions and the following disclaimer in the
20 #         documentation and/or other materials provided with the distribution.
21 #  3. The name of the author may not be used to endorse or promote products
22 #         derived from this software without specific prior written permission.
23 #
24 # This file is distributed in the hope that it will be useful,
25 # but WITHOUT ANY WARRANTY; without even the implied warranty of
26 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27 # GNU General Public License for more details.
28 #
29 # You should have received a copy of the GNU General Public License
30 # along with lyx; if not, write to the Free Software
31 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
32 #
33
34 INCLUDE(CheckCXXSourceCompiles)
35 INCLUDE(FindPackageHandleStandardArgs)
36
37 if (CMAKE_CXX_COMPILER_ID MATCHES "^[cC]lang$")
38   set(CXX11_FLAG_CANDIDATES "--std=c++11 -Wno-deprecated-register")
39 else()
40   if (CYGWIN)
41     set(CXX11_FLAG_CANDIDATES "--std=gnu++11")
42   else()
43     set(CXX11_FLAG_CANDIDATES
44       "--std=c++11"
45       "--std=gnu++11"
46       "--std=gnu++0x"
47     )
48   endif()
49 endif()
50
51 # sample openmp source code to test
52 SET(CXX11_TEST_SOURCE 
53 "
54 template <typename T>
55 struct check
56 {
57     static_assert(sizeof(int) <= sizeof(T), \"not big enough\");
58 };
59
60 typedef check<check<bool>> right_angle_brackets;
61
62 class TestDeleted
63 {
64 public:
65     TestDeleted() = delete;
66 };
67
68
69 int a;
70 decltype(a) b;
71
72 typedef check<int> check_type;
73 check_type c;
74 check_type&& cr = static_cast<check_type&&>(c);
75
76 auto d = a;
77
78 int main() {
79   return 0;
80 };
81 ")
82
83 # check c compiler
84 set(SAFE_CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET})
85 set(CMAKE_REQUIRED_QUIET ON)
86 FOREACH(FLAG ${CXX11_FLAG_CANDIDATES})
87   SET(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
88   SET(CMAKE_REQUIRED_FLAGS "${FLAG}")
89   UNSET(CXX11_FLAG_DETECTED CACHE)
90   CHECK_CXX_SOURCE_COMPILES("${CXX11_TEST_SOURCE}" CXX11_FLAG_DETECTED)
91   SET(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
92   IF(CXX11_FLAG_DETECTED)
93     SET(CXX11_FLAG "${FLAG}")
94     message(STATUS "CXX11_FLAG_DETECTED = \"${FLAG}\"")
95     set(LYX_USE_CXX11 1)
96     BREAK()
97   ENDIF()
98 ENDFOREACH()
99 set(CMAKE_REQUIRED_QUIET ${SAFE_CMAKE_REQUIRED_QUIET})
100
101 # handle the standard arguments for find_package
102 FIND_PACKAGE_HANDLE_STANDARD_ARGS(CXX11Compiler DEFAULT_MSG CXX11_FLAG)
103
104 MARK_AS_ADVANCED(CXX11_FLAG)