Skip to content

Commit 852cb7f

Browse files
Use the correct Python lib for each build configuration generated by the Visual Studio CMake generator
Summary: Previously `CMAKE_BUILD_TYPE` was used to determine whether to link in `python27.lib` or `python27_d.lib`, unfortunately this only works reliably when using a CMake generator that generates a single build configuration (e.g. Ninja). The Visual Studio CMake generator generates four build configurations at once (`Debug`, `Release`, `RelWithDebInfo`, `MinSizeRel`), so if `CMAKE_BUILD_TYPE` is set to `Debug` all four build configurations end up linking in `python27_d.lib`, this is clearly undesirable. To ensure that the correct Python lib is used for each build configuration the value of `PYTHON_LIBRARY` is now determined using generator expressions that evaluate to either the debug or release Python lib. The values of `PYTHON_EXECUTABLE` and `PYTHON_DLL` are now likewise determined using generator expressions. Note that these changes only apply to the Windows build. Patch by Vadim Macagon. Thanks! Reviewers: zturner, brucem Subscribers: zturner, lldb-commits Differential Revision: http://reviews.llvm.org/D13234 llvm-svn: 248991
1 parent c32c277 commit 852cb7f

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

lldb/cmake/modules/LLDBConfig.cmake

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,39 @@ if (NOT LLDB_DISABLE_PYTHON)
4848
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
4949
if (NOT "${PYTHON_HOME}" STREQUAL "")
5050
file(TO_CMAKE_PATH "${PYTHON_HOME}" PYTHON_HOME)
51-
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
52-
file(TO_CMAKE_PATH "${PYTHON_HOME}/python_d.exe" PYTHON_EXECUTABLE)
53-
file(TO_CMAKE_PATH "${PYTHON_HOME}/libs/python27_d.lib" PYTHON_LIBRARY)
54-
file(TO_CMAKE_PATH "${PYTHON_HOME}/python27_d.dll" PYTHON_DLL)
55-
else()
56-
file(TO_CMAKE_PATH "${PYTHON_HOME}/python.exe" PYTHON_EXECUTABLE)
57-
file(TO_CMAKE_PATH "${PYTHON_HOME}/libs/python27.lib" PYTHON_LIBRARY)
58-
file(TO_CMAKE_PATH "${PYTHON_HOME}/python27.dll" PYTHON_DLL)
59-
endif()
51+
file(TO_CMAKE_PATH "${PYTHON_HOME}/python_d.exe" PYTHON_DEBUG_EXE)
52+
file(TO_CMAKE_PATH "${PYTHON_HOME}/libs/python27_d.lib" PYTHON_DEBUG_LIB)
53+
file(TO_CMAKE_PATH "${PYTHON_HOME}/python27_d.dll" PYTHON_DEBUG_DLL)
54+
55+
file(TO_CMAKE_PATH "${PYTHON_HOME}/python.exe" PYTHON_RELEASE_EXE)
56+
file(TO_CMAKE_PATH "${PYTHON_HOME}/libs/python27.lib" PYTHON_RELEASE_LIB)
57+
file(TO_CMAKE_PATH "${PYTHON_HOME}/python27.dll" PYTHON_RELEASE_DLL)
58+
59+
# Generator expressions are evaluated in the context of each build configuration generated
60+
# by CMake. Here we use the $<CONFIG:Debug>:VALUE logical generator expression to ensure
61+
# that the debug Python library, DLL, and executable are used in the Debug build configuration.
62+
#
63+
# Generator expressions can be difficult to grok at first so here's a breakdown of the one
64+
# used for PYTHON_LIBRARY:
65+
#
66+
# 1. $<CONFIG:Debug> evaluates to 1 when the Debug configuration is being generated,
67+
# or 0 in all other cases.
68+
# 2. $<$<CONFIG:Debug>:${PYTHON_DEBUG_LIB}> expands to ${PYTHON_DEBUG_LIB} when the Debug
69+
# configuration is being generated, or nothing (literally) in all other cases.
70+
# 3. $<$<NOT:$<CONFIG:Debug>>:${PYTHON_RELEASE_LIB}> expands to ${PYTHON_RELEASE_LIB} when
71+
# any configuration other than Debug is being generated, or nothing in all other cases.
72+
# 4. The conditionals in 2 & 3 are mutually exclusive.
73+
# 5. A logical expression with a conditional that evaluates to 0 yields no value at all.
74+
#
75+
# Due to 4 & 5 it's possible to concatenate 2 & 3 to obtain a single value specific to each
76+
# build configuration. In this example the value will be ${PYTHON_DEBUG_LIB} when generating the
77+
# Debug configuration, or ${PYTHON_RELEASE_LIB} when generating any other configuration.
78+
# Note that it's imperative that there is no whitespace between the two expressions, otherwise
79+
# CMake will insert a semicolon between the two.
80+
81+
set (PYTHON_EXECUTABLE $<$<CONFIG:Debug>:${PYTHON_DEBUG_EXE}>$<$<NOT:$<CONFIG:Debug>>:${PYTHON_RELEASE_EXE}>)
82+
set (PYTHON_LIBRARY $<$<CONFIG:Debug>:${PYTHON_DEBUG_LIB}>$<$<NOT:$<CONFIG:Debug>>:${PYTHON_RELEASE_LIB}>)
83+
set (PYTHON_DLL $<$<CONFIG:Debug>:${PYTHON_DEBUG_DLL}>$<$<NOT:$<CONFIG:Debug>>:${PYTHON_RELEASE_DLL}>)
6084

6185
file(TO_CMAKE_PATH "${PYTHON_HOME}/Include" PYTHON_INCLUDE_DIR)
6286
if (NOT LLDB_RELOCATABLE_PYTHON)

0 commit comments

Comments
 (0)