@@ -33,7 +33,7 @@ if(NOT CMAKE_VERSION VERSION_LESS 3.1)
3333 endif ()
3434endif ()
3535
36- # Fall back to heuristics
36+ # Fall back to heuristics
3737if (NOT PYBIND11_CPP_STANDARD AND NOT CMAKE_CXX_STANDARD)
3838 if (MSVC )
3939 set (PYBIND11_CPP_STANDARD /std:c++14)
@@ -142,17 +142,32 @@ function(pybind11_add_module target_name)
142142
143143 if (ARG_EXCLUDE_FROM_ALL)
144144 set (exclude_from_all EXCLUDE_FROM_ALL )
145+ else ()
146+ set (exclude_from_all "" )
145147 endif ()
146148
147149 add_library (${target_name} ${lib_type} ${exclude_from_all} ${ARG_UNPARSED_ARGUMENTS} )
148150
149151 if (ARG_SYSTEM)
150152 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." )
151167 endif ()
152168
153169 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}
156171 PRIVATE ${PYTHON_INCLUDE_DIRS} )
157172
158173 # Python debug libraries expose slightly different objects
@@ -201,10 +216,12 @@ function(pybind11_add_module target_name)
201216 endif ()
202217
203218 # 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 ()
208225 endif ()
209226
210227 if (ARG_NO_EXTRAS)
0 commit comments