mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-24 22:25:10 +00:00
style: avoid using unintialized variables (#2806)
* style: avoid using unintialized variables Tested with cmake --warn-unintialized -S . -B build * refactor: use function for possibly uninit vars
This commit is contained in:
parent
87f5aff4a7
commit
eb83feefff
@ -73,6 +73,8 @@ if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
endif()
|
||||
|
||||
set(pybind11_system "")
|
||||
else()
|
||||
set(PYBIND11_MASTER_PROJECT OFF)
|
||||
set(pybind11_system SYSTEM)
|
||||
|
@ -24,7 +24,7 @@ include(CMakeParseArguments)
|
||||
# Usage:
|
||||
# pybind11_filter_tests(LISTNAME file1.cpp file2.cpp ... MESSAGE "")
|
||||
#
|
||||
macro(PYBIND11_FILTER_TESTS LISTNAME)
|
||||
macro(pybind11_filter_tests LISTNAME)
|
||||
cmake_parse_arguments(ARG "" "MESSAGE" "" ${ARGN})
|
||||
set(PYBIND11_FILTER_TESTS_FOUND OFF)
|
||||
foreach(filename IN LISTS ARG_UNPARSED_ARGUMENTS)
|
||||
@ -39,6 +39,14 @@ macro(PYBIND11_FILTER_TESTS LISTNAME)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
macro(possibly_uninitialized)
|
||||
foreach(VARNAME ${ARGN})
|
||||
if(NOT DEFINED "${VARNAME}")
|
||||
set("${VARNAME}" "")
|
||||
endif()
|
||||
endforeach()
|
||||
endmacro()
|
||||
|
||||
# New Python support
|
||||
if(DEFINED Python_EXECUTABLE)
|
||||
set(PYTHON_EXECUTABLE "${Python_EXECUTABLE}")
|
||||
@ -67,7 +75,7 @@ if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
||||
find_package(pybind11 REQUIRED CONFIG)
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
||||
if(NOT CMAKE_BUILD_TYPE AND NOT DEFINED CMAKE_CONFIGURATION_TYPES)
|
||||
message(STATUS "Setting tests build type to MinSizeRel as none was specified")
|
||||
set(CMAKE_BUILD_TYPE
|
||||
MinSizeRel
|
||||
@ -345,12 +353,15 @@ foreach(target ${test_targets})
|
||||
if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
|
||||
set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY
|
||||
"${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
||||
if(DEFINED CMAKE_CONFIGURATION_TYPES)
|
||||
foreach(config ${CMAKE_CONFIGURATION_TYPES})
|
||||
string(TOUPPER ${config} config)
|
||||
set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${config}
|
||||
"${CMAKE_CURRENT_BINARY_DIR}")
|
||||
endforeach()
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# Make sure pytest is found or produce a warning
|
||||
|
@ -55,6 +55,8 @@ function(pybind11_add_build_test name)
|
||||
add_dependencies(test_cmake_build test_build_${name})
|
||||
endfunction()
|
||||
|
||||
possibly_uninitialized(PYTHON_MODULE_EXTENSION Python_INTERPRETER_ID)
|
||||
|
||||
pybind11_add_build_test(subdirectory_function)
|
||||
pybind11_add_build_test(subdirectory_target)
|
||||
if("${PYTHON_MODULE_EXTENSION}" MATCHES "pypy" OR "${Python_INTERPRETER_ID}" STREQUAL "PyPy")
|
||||
|
@ -1,4 +1,7 @@
|
||||
possibly_uninitialized(PYTHON_MODULE_EXTENSION Python_INTERPRETER_ID)
|
||||
|
||||
if("${PYTHON_MODULE_EXTENSION}" MATCHES "pypy" OR "${Python_INTERPRETER_ID}" STREQUAL "PyPy")
|
||||
message(STATUS "Skipping embed test on PyPy")
|
||||
add_custom_target(cpptest) # Dummy target on PyPy. Embedding is not supported.
|
||||
set(_suppress_unused_variable_warning "${DOWNLOAD_CATCH}")
|
||||
return()
|
||||
|
@ -64,6 +64,9 @@ if(EIGEN3_INCLUDE_DIR)
|
||||
set(EIGEN3_FOUND ${EIGEN3_VERSION_OK})
|
||||
|
||||
else(EIGEN3_INCLUDE_DIR)
|
||||
if(NOT DEFINED KDE4_INCLUDE_DIR)
|
||||
set(KDE4_INCLUDE_DIR "")
|
||||
endif()
|
||||
|
||||
find_path(
|
||||
EIGEN3_INCLUDE_DIR
|
||||
|
@ -57,6 +57,8 @@ endif()
|
||||
|
||||
if(PythonLibsNew_FIND_QUIETLY)
|
||||
set(_pythonlibs_quiet QUIET)
|
||||
else()
|
||||
set(_pythonlibs_quiet "")
|
||||
endif()
|
||||
|
||||
if(PythonLibsNew_FIND_REQUIRED)
|
||||
|
@ -12,6 +12,8 @@ get_property(
|
||||
|
||||
if(pybind11_FIND_QUIETLY)
|
||||
set(_pybind11_quiet QUIET)
|
||||
else()
|
||||
set(_pybind11_quiet "")
|
||||
endif()
|
||||
|
||||
if(CMAKE_VERSION VERSION_LESS 3.12)
|
||||
|
@ -10,6 +10,8 @@ include(CMakeParseArguments)
|
||||
|
||||
if(pybind11_FIND_QUIETLY)
|
||||
set(_pybind11_quiet QUIET)
|
||||
else()
|
||||
set(_pybind11_quiet "")
|
||||
endif()
|
||||
|
||||
# If this is the first run, PYTHON_VERSION can stand in for PYBIND11_PYTHON_VERSION
|
||||
@ -22,11 +24,16 @@ if(NOT DEFINED PYBIND11_PYTHON_VERSION AND DEFINED PYTHON_VERSION)
|
||||
CACHE STRING "Python version to use for compiling modules")
|
||||
unset(PYTHON_VERSION)
|
||||
unset(PYTHON_VERSION CACHE)
|
||||
else()
|
||||
# If this is set as a normal variable, promote it, otherwise, make an empty cache variable.
|
||||
elseif(DEFINED PYBIND11_PYTHON_VERSION)
|
||||
# If this is set as a normal variable, promote it
|
||||
set(PYBIND11_PYTHON_VERSION
|
||||
"${PYBIND11_PYTHON_VERSION}"
|
||||
CACHE STRING "Python version to use for compiling modules")
|
||||
else()
|
||||
# Make an empty cache variable.
|
||||
set(PYBIND11_PYTHON_VERSION
|
||||
""
|
||||
CACHE STRING "Python version to use for compiling modules")
|
||||
endif()
|
||||
|
||||
# A user can set versions manually too
|
||||
|
Loading…
Reference in New Issue
Block a user