From 141e8cc0afad1e06904fab36ff4ca5f8b64f44e7 Mon Sep 17 00:00:00 2001 From: Nils Leif Fischer Date: Fri, 26 Jun 2020 12:15:10 +0200 Subject: [PATCH] Fix uninitialized-variables cmake warnings --- tools/FindPythonLibsNew.cmake | 12 +++++++++++- tools/pybind11Tools.cmake | 31 ++++++++++++++++++++++++------- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/tools/FindPythonLibsNew.cmake b/tools/FindPythonLibsNew.cmake index 31d1ddb73..d0c8fa260 100644 --- a/tools/FindPythonLibsNew.cmake +++ b/tools/FindPythonLibsNew.cmake @@ -56,6 +56,9 @@ if(PYTHONLIBS_FOUND AND PYTHON_MODULE_EXTENSION) endif() # Use the Python interpreter to find the libs. +if(NOT PythonLibsNew_FIND_VERSION) + set(PythonLibsNew_FIND_VERSION "") +endif() if(PythonLibsNew_FIND_REQUIRED) find_package(PythonInterp ${PythonLibsNew_FIND_VERSION} REQUIRED) else() @@ -192,11 +195,18 @@ MARK_AS_ADVANCED( # module. SET(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}") SET(PYTHON_LIBRARIES "${PYTHON_LIBRARY}") +if(NOT PYTHON_DEBUG_LIBRARY) + SET(PYTHON_DEBUG_LIBRARY "") +endif() SET(PYTHON_DEBUG_LIBRARIES "${PYTHON_DEBUG_LIBRARY}") find_package_message(PYTHON "Found PythonLibs: ${PYTHON_LIBRARY}" - "${PYTHON_EXECUTABLE}${PYTHON_VERSION}") + "${PYTHON_EXECUTABLE}${PYTHON_VERSION_STRING}") set(PYTHONLIBS_FOUND TRUE) set(PythonLibsNew_FOUND TRUE) + +if(NOT PYTHON_MODULE_PREFIX) + SET(PYTHON_MODULE_PREFIX "") +endif() diff --git a/tools/pybind11Tools.cmake b/tools/pybind11Tools.cmake index 8d85dd4eb..a3603abe9 100644 --- a/tools/pybind11Tools.cmake +++ b/tools/pybind11Tools.cmake @@ -33,7 +33,7 @@ if(NOT CMAKE_VERSION VERSION_LESS 3.1) endif() endif() -# Fall back to heuristics +# Fall back to heuristics if(NOT PYBIND11_CPP_STANDARD AND NOT CMAKE_CXX_STANDARD) if(MSVC) set(PYBIND11_CPP_STANDARD /std:c++14) @@ -142,17 +142,32 @@ function(pybind11_add_module target_name) if(ARG_EXCLUDE_FROM_ALL) set(exclude_from_all EXCLUDE_FROM_ALL) + else() + set(exclude_from_all "") endif() add_library(${target_name} ${lib_type} ${exclude_from_all} ${ARG_UNPARSED_ARGUMENTS}) if(ARG_SYSTEM) set(inc_isystem SYSTEM) + else() + set(inc_isystem "") + endif() + + set(PYBIND11_INCLUDE_DIR_SELECTED "") + if(PYBIND11_INCLUDE_DIR) + # from project CMakeLists.txt + set(PYBIND11_INCLUDE_DIR_SELECTED ${PYBIND11_INCLUDE_DIR}) + elseif(pybind11_INCLUDE_DIR) + # from pybind11Config + set(PYBIND11_INCLUDE_DIR_SELECTED ${pybind11_INCLUDE_DIR}) + else() + message(FATAL "No pybind11_INCLUDE_DIR available. Use " + "find_package(pybind11) before calling pybind11_add_module.") endif() target_include_directories(${target_name} ${inc_isystem} - PRIVATE ${PYBIND11_INCLUDE_DIR} # from project CMakeLists.txt - PRIVATE ${pybind11_INCLUDE_DIR} # from pybind11Config + PRIVATE ${PYBIND11_INCLUDE_DIR_SELECTED} PRIVATE ${PYTHON_INCLUDE_DIRS}) # Python debug libraries expose slightly different objects @@ -201,10 +216,12 @@ function(pybind11_add_module target_name) endif() # Make sure C++11/14 are enabled - if(CMAKE_VERSION VERSION_LESS 3.3) - target_compile_options(${target_name} PUBLIC ${PYBIND11_CPP_STANDARD}) - else() - target_compile_options(${target_name} PUBLIC $<$:${PYBIND11_CPP_STANDARD}>) + if(PYBIND11_CPP_STANDARD) + if(CMAKE_VERSION VERSION_LESS 3.3) + target_compile_options(${target_name} PUBLIC ${PYBIND11_CPP_STANDARD}) + else() + target_compile_options(${target_name} PUBLIC $<$:${PYBIND11_CPP_STANDARD}>) + endif() endif() if(ARG_NO_EXTRAS)