Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
pybind11
Commits
c3c27c42
Commit
c3c27c42
authored
May 28, 2016
by
Dean Moldovan
Browse files
Make C++ standard configurable
parent
9fb50c56
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
12 deletions
+19
-12
CMakeLists.txt
CMakeLists.txt
+19
-12
No files found.
CMakeLists.txt
View file @
c3c27c42
...
...
@@ -21,12 +21,28 @@ option(PYBIND11_TEST "Build tests?" ${PYBIND11_MASTER_PROJECT})
# Add a CMake parameter for choosing a desired Python version
set
(
PYBIND11_PYTHON_VERSION
""
CACHE STRING
"Python version to use for compiling the example application"
)
include
(
CheckCXXCompilerFlag
)
list
(
APPEND CMAKE_MODULE_PATH
"
${
CMAKE_CURRENT_LIST_DIR
}
/tools"
)
set
(
Python_ADDITIONAL_VERSIONS 3.4 3.5 3.6 3.7
)
find_package
(
PythonLibsNew
${
PYBIND11_PYTHON_VERSION
}
REQUIRED
)
include
(
CheckCXXCompilerFlag
)
if
(
NOT MSVC AND NOT PYBIND11_CPP_STANDARD
)
check_cxx_compiler_flag
(
"-std=c++14"
HAS_CPP14_FLAG
)
check_cxx_compiler_flag
(
"-std=c++11"
HAS_CPP11_FLAG
)
if
(
HAS_CPP14_FLAG
)
set
(
PYBIND11_CPP_STANDARD -std=c++14
)
elseif
(
HAS_CPP11_FLAG
)
set
(
PYBIND11_CPP_STANDARD -std=c++11
)
else
()
message
(
FATAL_ERROR
"Unsupported compiler -- pybind11 requires C++11 support!"
)
endif
()
set
(
PYBIND11_CPP_STANDARD
${
PYBIND11_CPP_STANDARD
}
CACHE STRING
"C++ standard flag, e.g. -std=c++11 or -std=c++14. Defaults to latest available."
)
endif
()
# Cache variables so pybind11_add_module can be used in parent projects
set
(
PYBIND11_INCLUDE_DIR
"
${
CMAKE_CURRENT_LIST_DIR
}
/include"
CACHE INTERNAL
""
)
set
(
PYTHON_INCLUDE_DIRS
${
PYTHON_INCLUDE_DIRS
}
CACHE INTERNAL
""
)
...
...
@@ -67,16 +83,7 @@ function(pybind11_add_module target_name)
if
(
NOT MSVC
)
# Make sure C++11/14 are enabled
check_cxx_compiler_flag
(
"-std=c++14"
HAS_CPP14_FLAG
)
check_cxx_compiler_flag
(
"-std=c++11"
HAS_CPP11_FLAG
)
if
(
HAS_CPP14_FLAG
)
target_compile_options
(
${
target_name
}
PUBLIC
"-std=c++14"
)
elseif
(
HAS_CPP11_FLAG
)
target_compile_options
(
${
target_name
}
PUBLIC
"-std=c++11"
)
else
()
message
(
FATAL_ERROR
"Unsupported compiler -- pybind11 requires C++11 support!"
)
endif
()
target_compile_options
(
${
target_name
}
PUBLIC
${
PYBIND11_CPP_STANDARD
}
)
# Enable link time optimization and set the default symbol
# visibility to hidden (very important to obtain small binaries)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment