@@ -33,7 +33,7 @@ if(NOT CMAKE_VERSION VERSION_LESS 3.1)
33
33
endif ()
34
34
endif ()
35
35
36
- # Fall back to heuristics
36
+ # Fall back to heuristics
37
37
if (NOT PYBIND11_CPP_STANDARD AND NOT CMAKE_CXX_STANDARD )
38
38
if (MSVC )
39
39
set (PYBIND11_CPP_STANDARD /std:c++14 )
@@ -142,17 +142,32 @@ function(pybind11_add_module target_name)
142
142
143
143
if (ARG_EXCLUDE_FROM_ALL )
144
144
set (exclude_from_all EXCLUDE_FROM_ALL )
145
+ else ()
146
+ set (exclude_from_all "" )
145
147
endif ()
146
148
147
149
add_library (${target_name} ${lib_type} ${exclude_from_all} ${ARG_UNPARSED_ARGUMENTS} )
148
150
149
151
if (ARG_SYSTEM )
150
152
set (inc_isystem SYSTEM )
153
+ else ()
154
+ set (inc_isystem "" )
155
+ endif ()
156
+
157
+ set (PYBIND11_INCLUDE_DIR_SELECTED "" )
158
+ if (PYBIND11_INCLUDE_DIR )
159
+ # from project CMakeLists.txt
160
+ set (PYBIND11_INCLUDE_DIR_SELECTED ${PYBIND11_INCLUDE_DIR} )
161
+ elseif (pybind11_INCLUDE_DIR )
162
+ # from pybind11Config
163
+ set (PYBIND11_INCLUDE_DIR_SELECTED ${pybind11_INCLUDE_DIR} )
164
+ else ()
165
+ message (FATAL "No pybind11_INCLUDE_DIR available. Use "
166
+ "find_package(pybind11) before calling pybind11_add_module." )
151
167
endif ()
152
168
153
169
target_include_directories (${target_name} ${inc_isystem}
154
- PRIVATE ${PYBIND11_INCLUDE_DIR} # from project CMakeLists.txt
155
- PRIVATE ${pybind11_INCLUDE_DIR} # from pybind11Config
170
+ PRIVATE ${PYBIND11_INCLUDE_DIR_SELECTED}
156
171
PRIVATE ${PYTHON_INCLUDE_DIRS} )
157
172
158
173
# Python debug libraries expose slightly different objects
@@ -201,10 +216,12 @@ function(pybind11_add_module target_name)
201
216
endif ()
202
217
203
218
# Make sure C++11/14 are enabled
204
- if (CMAKE_VERSION VERSION_LESS 3.3 )
205
- target_compile_options (${target_name} PUBLIC ${PYBIND11_CPP_STANDARD} )
206
- else ()
207
- target_compile_options (${target_name} PUBLIC $< $< COMPILE_LANGUAGE:CXX> :${PYBIND11_CPP_STANDARD} > )
219
+ if (PYBIND11_CPP_STANDARD )
220
+ if (CMAKE_VERSION VERSION_LESS 3.3 )
221
+ target_compile_options (${target_name} PUBLIC ${PYBIND11_CPP_STANDARD} )
222
+ else ()
223
+ target_compile_options (${target_name} PUBLIC $< $< COMPILE_LANGUAGE:CXX> :${PYBIND11_CPP_STANDARD} > )
224
+ endif ()
208
225
endif ()
209
226
210
227
if (ARG_NO_EXTRAS )
0 commit comments