[CMake] On Windows, require manual specification of python libs.
authorZachary Turner <zturner@google.com>
Mon, 23 Feb 2015 21:20:59 +0000 (21:20 +0000)
committerZachary Turner <zturner@google.com>
Mon, 23 Feb 2015 21:20:59 +0000 (21:20 +0000)
Embedding python with MSVC is very finicky, for reasons having
to do with the operating system's CRT, the implementation of
python itself on Windows, and even bugs in CMake.

One side effect of this is that we cannot rely on FindPythonLibs
and FindPythonInterp CMake functions to locate the correct
version of Python.  We must instead manually specify the location
of PYTHON_LIBRARY and PYTHON_INCLUDE_DIR.

As a side effect, this fixes building LLDB in release mode by
specifying -DCMAKE_BUILD_TYPE=Release, which was previously
broken.

llvm-svn: 230262

lldb/CMakeLists.txt
lldb/source/CMakeLists.txt

index efc866d..a37147c 100644 (file)
@@ -72,15 +72,17 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
   include(HandleLLVMOptions)
 
   # Verify that we can find a Python 2 interpreter.  Python 3 is unsupported.
-  set(Python_ADDITIONAL_VERSIONS 2.7 2.6 2.5)
-  include(FindPythonInterp)
-  if( NOT PYTHONINTERP_FOUND )
-    message(FATAL_ERROR
-  "Unable to find Python interpreter, required for builds and testing.
-
-  Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")
+  if (PYTHON_EXECUTABLE STREQUAL "")
+    set(Python_ADDITIONAL_VERSIONS 2.7 2.6 2.5)
+    include(FindPythonInterp)
+    if( NOT PYTHONINTERP_FOUND )
+      message(FATAL_ERROR
+              "Unable to find Python interpreter, required for builds and testing.
+               Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")
+    endif()
+  else()
+    message("-- Found PythonInterp: ${PYTHON_EXECUTABLE}")
   endif()
-
   # Import CMake library targets from LLVM and Clang.
   include("${LLDB_PATH_TO_LLVM_BUILD}/share/llvm/cmake/LLVMConfig.cmake")
   include("${LLDB_PATH_TO_CLANG_BUILD}/share/clang/cmake/ClangConfig.cmake")
@@ -136,8 +138,18 @@ if (NOT LLDB_DISABLE_PYTHON)
       set(CMAKE_LIBRARY_ARCHITECTURE "x86_64-linux-gnu")
     endif()
   endif()
-  find_package(PythonLibs REQUIRED)
-  include_directories(${PYTHON_INCLUDE_DIRS})
+  if (MSVC)
+    if (PYTHON_INCLUDE_DIR STREQUAL "" OR PYTHON_LIBRARY STREQUAL "")
+      message(FATAL_ERROR "Building on MSVC requires manual specification of "
+                          "PYTHON_INCLUDE_DIR and PYTHON_LIBRARY")
+    else()
+      message("-- Found PythonLibs: ${PYTHON_LIBRARY}")
+      include_directories(${PYTHON_INCLUDE_DIR})
+    endif()
+  else()
+    find_package(PythonLibs REQUIRED)
+    include_directories(${PYTHON_INCLUDE_DIRS})
+  endif()
 endif()
 
 include_directories(../clang/include)
index 0259176..cd5730f 100644 (file)
@@ -47,20 +47,26 @@ add_lldb_library(liblldb SHARED
   ${LLDB_VERS_GENERATED_FILE}
   )
 
+
 if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
-target_link_libraries(liblldb PRIVATE lldbAPI)
+  target_link_libraries(liblldb PRIVATE lldbAPI)
+  # Only MSVC has the ABI compatibility and avoids using FindPythonLibs,
+  # so only it needs to explicitly link against ${PYTHON_LIBRARY}
+  if (MSVC)
+    target_link_libraries(liblldb PRIVATE ${PYTHON_LIBRARY})
+  endif()
 
-set_target_properties(liblldb
-  PROPERTIES
-  OUTPUT_NAME liblldb
-  VERSION ${LLDB_VERSION}
-  )
+  set_target_properties(liblldb
+    PROPERTIES
+    OUTPUT_NAME liblldb
+    VERSION ${LLDB_VERSION}
+    )
 else()
-set_target_properties(liblldb
-  PROPERTIES
-  OUTPUT_NAME lldb
-  VERSION ${LLDB_VERSION}
-  )
+  set_target_properties(liblldb
+    PROPERTIES
+    OUTPUT_NAME lldb
+    VERSION ${LLDB_VERSION}
+    )
 endif()
 
 if (LLDB_WRAP_PYTHON OR LLDB_VERS_GENERATED_FILE)