Skip to content

Commit 776108e

Browse files
committed
fix CMakeLists.txt bug
1 parent 77fdebe commit 776108e

File tree

6 files changed

+33
-10
lines changed

6 files changed

+33
-10
lines changed

CMakeLists.txt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,21 @@ set_target_properties(${STATIC_LIB} PROPERTIES CLEAN_DIRECT_OUTPUT 1)
3535
set_target_properties(${SHARED_LIB} PROPERTIES CLEAN_DIRECT_OUTPUT 1)
3636

3737
# Some special headers.
38-
include(CheckIncludeFileCXX)
39-
check_include_file_cxx(string_view HAVE_STRING_VIEW)
40-
check_include_file_cxx(optional HAVE_OPTIONAL)
41-
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${PROJECT_SOURCE_DIR}/config.h)
38+
try_compile(HAVE_STRING_VIEW
39+
"${CMAKE_CURRENT_BINARY_DIR}/try_compile"
40+
"${CMAKE_CURRENT_SOURCE_DIR}/try_compile/try_string_view.cpp")
41+
42+
if (HAVE_STRING_VIEW)
43+
add_definitions(-DHAVE_STRING_VIEW)
44+
endif()
45+
46+
try_compile(HAVE_OPTIONAL
47+
"${CMAKE_CURRENT_BINARY_DIR}/try_compile"
48+
"${CMAKE_CURRENT_SOURCE_DIR}/try_compile/try_optional.cpp")
49+
50+
if (HAVE_OPTIONAL)
51+
add_definitions(-DHAVE_OPTIONAL)
52+
endif()
4253

4354
add_subdirectory(test)
4455

config.h.in

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/sw/redis++/utils.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
#include <string>
2222
#include <type_traits>
2323

24-
#include "config.h"
25-
2624
#ifdef HAVE_STRING_VIEW
2725

2826
#include <string_view>

test/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ else()
66
cmake_minimum_required(VERSION 2.8.0)
77
endif()
88

9-
set(CMAKE_CXX_FLAGS "-std=c++11 -Wall -W -Werror -fPIC")
10-
119
set(PROJECT_SOURCE_DIR ${PROJECT_SOURCE_DIR}/src/sw/redis++)
1210

1311
file(GLOB PROJECT_SOURCE_FILES "${PROJECT_SOURCE_DIR}/*.cpp")

try_compile/try_optional.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <optional>
2+
3+
std::optional func() {
4+
return {};
5+
}
6+
7+
int main() {
8+
return 0;
9+
}

try_compile/try_string_view.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <string_view>
2+
3+
std::string_view func() {
4+
return {};
5+
}
6+
7+
int main() {
8+
return 0;
9+
}

0 commit comments

Comments
 (0)