Skip to content

Commit

Permalink
Merge d2bd511 into 1251c86
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrnz committed Nov 28, 2019
2 parents 1251c86 + d2bd511 commit 5507137
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 50 deletions.
181 changes: 131 additions & 50 deletions src/plugins/thirdParty/Python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ set(NUMERIC_LIBRARY_VERSION 37)

# Git tag of our Python sources

set(GIT_TAG "opencor-3.7.5")
set(GIT_TAG "opencor")

# Specify where our local package will be installed

Expand Down Expand Up @@ -130,6 +130,23 @@ if(NOT APPLE)
set(BZIP2_LIBRARY ${BZIP2_SHARED_LIBRARY}.${BZIP2_VERSION})
endif()

# Bundle liblzma with Python
# Note: it is statically linked on macOS...

if(WIN32)
set(LZMA_SHARED_LIBRARY liblzma${CMAKE_SHARED_LIBRARY_SUFFIX})
else()
set(LZMA_SHARED_LIBRARY ${CMAKE_SHARED_LIBRARY_PREFIX}lzma${CMAKE_SHARED_LIBRARY_SUFFIX})
endif()

list(APPEND EXTERNAL_BINARIES
${LZMA_SHARED_LIBRARY}
)

list(APPEND SHA1_FILES
${LIBRARY_DIR}/${LZMA_SHARED_LIBRARY}
)

# Bundle SQLite3 with Python
# Note: it is statically linked on macOS...

Expand All @@ -144,7 +161,17 @@ if(NOT APPLE)
)

if(WIN32)
# On Windows, we also need the import library
# On Windows, we also need import libraries

set(LZMA_IMPORT_LIBRARY liblzma${CMAKE_IMPORT_LIBRARY_SUFFIX})

list(APPEND EXTERNAL_BINARIES
${LZMA_IMPORT_LIBRARY}
)

list(APPEND SHA1_FILES
${LIBRARY_DIR}/${LZMA_IMPORT_LIBRARY}
)

set(SQLITE3_IMPORT_LIBRARY ${CMAKE_IMPORT_LIBRARY_PREFIX}sqlite3${CMAKE_IMPORT_LIBRARY_SUFFIX})

Expand Down Expand Up @@ -232,12 +259,10 @@ else()
set(PYTHON_READLINE_OPTION -DUSE_SYSTEM_READLINE=ON)
endif()

if(APPLE)
# macOS provides bzip2
# Find or build the bzip2 library

find_package(BZip2 REQUIRED)
else()
# Build bzip2 for Windows and Linux
if(WIN32)
# Build bzip2 for Windows

set(BZIP2_LIBRARY_DIR ${PROJECT_BINARY_DIR}/bzip2-opencor-${BZIP2_VERSION})

Expand All @@ -255,34 +280,74 @@ else()

message("Building '${BZIP2_LIBRARY}'...")

if(WIN32)
execute_process(COMMAND nmake -f makefile.msc lib
WORKING_DIRECTORY ${BZIP2_LIBRARY_DIR}
OUTPUT_QUIET)
else()
execute_process(COMMAND make -f Makefile-libbz2_so
WORKING_DIRECTORY ${BZIP2_LIBRARY_DIR}
OUTPUT_QUIET)

# Rename bzip2's library and copy it to the plugin's external
# binaries directory

file(RENAME ${BZIP2_LIBRARY_DIR}/${BZIP2_LIBRARY}
${BZIP2_LIBRARY_DIR}/${BZIP2_SHARED_LIBRARY})

file(COPY ${BZIP2_LIBRARY_DIR}/${BZIP2_SHARED_LIBRARY}
DESTINATION ${EXTERNAL_BINARIES_DIR}
FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
endif()
execute_process(COMMAND nmake -f makefile.msc lib
WORKING_DIRECTORY ${BZIP2_LIBRARY_DIR}
OUTPUT_QUIET)
endif()

set(BZIP2_INCLUDE_DIR ${BZIP2_LIBRARY_DIR})
set(BZIP2_LIBRARIES ${BZIP2_LIBRARY_DIR}/${BZIP2_LIBRARY})
else()
# Find bzip2 under macOS and Linux

if(WIN32)
set(BZIP2_LIBRARIES ${BZIP2_LIBRARY_DIR}/${BZIP2_LIBRARY})
else()
set(BZIP2_LIBRARIES ${EXTERNAL_BINARIES_DIR}/${BZIP2_SHARED_LIBRARY})
# Note: macOS provides bzip2

# Note: We assume `libbz2-dev` has been installed for Ubuntu

find_package(BZip2 REQUIRED)

if(NOT APPLE)
get_filename_component(BZIP2_LIBRARY_DIR ${BZIP2_LIBRARIES} DIRECTORY)
endif()
endif()

# Find or build the lzma library

if(WIN32)
# Download `xz` for Windows, which includes `lzma`

set(XZ_VERSION 5.2.4)

set(XZ_PACKAGE_DIR ${PROJECT_BINARY_DIR}/xz-${XZ_VERSION})

set(LZMA_IMPORT_LIBRARY_DIR ${XZ_PACKAGE_DIR}/doc)
set(LZMA_LIBRARY_DIR ${XZ_PACKAGE_DIR}/bin_x86-64)

if(NOT EXISTS ${XZ_PACKAGE_DIR}/include/lzma.h)
set(XZ_ARCHIVE xz-${XZ_VERSION}-windows.7z)

message("Downloading '${XZ_ARCHIVE}'...")

file(DOWNLOAD https://tukaani.org/xz/${XZ_ARCHIVE} ${PROJECT_BINARY_DIR}/downloads/${XZ_ARCHIVE}
SHOW_PROGRESS)

file(MAKE_DIRECTORY ${XZ_PACKAGE_DIR})

execute_process(COMMAND ${CMAKE_COMMAND} -E tar -xJf ${PROJECT_BINARY_DIR}/downloads/${XZ_ARCHIVE}
WORKING_DIRECTORY ${XZ_PACKAGE_DIR}
OUTPUT_QUIET)

message("Building LZMA import library...")

execute_process(COMMAND lib /verbose /def:liblzma.def /out:${LZMA_IMPORT_LIBRARY} /machine:x64
WORKING_DIRECTORY ${LZMA_IMPORT_LIBRARY_DIR}
OUTPUT_QUIET)
endif()

set(LIBLZMA_INCLUDE_DIRS ${XZ_PACKAGE_DIR}/include)
set(LIBLZMA_LIBRARIES ${LZMA_IMPORT_LIBRARY_DIR}/${LZMA_IMPORT_LIBRARY})

elseif(APPLE)
# Use Homebrew's LZMA and link with static library so we don't have to bundle it

set(LIBLZMA_INCLUDE_DIRS /usr/local/include)
set(LIBLZMA_LIBRARIES /usr/local/lib/liblzma.a)
else()
# Note: We assume `liblzma-dev` has been installed for Ubuntu

find_package(LibLZMA REQUIRED)

get_filename_component(LZMA_LIBRARY_DIR ${LIBLZMA_LIBRARIES} DIRECTORY)
endif()

# Jupyter and IPython require SQLite3
Expand All @@ -306,7 +371,7 @@ else()
OUTPUT_QUIET)
endif()

if(NOT EXISTS ${SQLITE3_LIBRARY_DIR}/sqlite3.lib)
if(NOT EXISTS ${SQLITE3_LIBRARY_DIR}/${SQLITE3_IMPORT_LIBRARY})
set(SQLITE3_DLL_ZIP sqlite-dll-win64-x64-${SQLITE3_VERSION}.zip)

message("Downloading '${SQLITE3_DLL_ZIP}'...")
Expand All @@ -317,37 +382,46 @@ else()
execute_process(COMMAND ${CMAKE_COMMAND} -E tar -xf zips/${SQLITE3_DLL_ZIP} --format=zip
WORKING_DIRECTORY ${SQLITE3_LIBRARY_DIR}
OUTPUT_QUIET)
execute_process(COMMAND lib /verbose /def:sqlite3.def /out:sqlite3.lib /machine:x64
execute_process(COMMAND lib /verbose /def:sqlite3.def /out:${SQLITE3_IMPORT_LIBRARY} /machine:x64
WORKING_DIRECTORY ${SQLITE3_LIBRARY_DIR}
OUTPUT_QUIET)
endif()

set(SQLITE3_INCLUDE_DIR ${SQLITE3_LIBRARY_DIR}/sqlite-amalgamation-${SQLITE3_VERSION})
set(SQLite3_INCLUDE_DIRS ${SQLITE3_LIBRARY_DIR}/sqlite-amalgamation-${SQLITE3_VERSION})
set(SQLite3_LIBRARIES ${SQLITE3_LIBRARY_DIR}/${SQLITE3_IMPORT_LIBRARY})
elseif(APPLE)
# Use Homebrew's SQLite3

set(SQLITE3_INCLUDE_DIR /usr/local/opt/sqlite3/include)
set(SQLITE3_LIBRARY_DIR /usr/local/opt/sqlite3/lib)

# Link to SQLite3's static library so we don't have to bundle it

set(SQLITE3_IMPORT_LIBRARY libsqlite3.a)
set(SQLite3_INCLUDE_DIRS /usr/local/opt/sqlite3/include)
set(SQLite3_LIBRARIES /usr/local/opt/sqlite3/lib/libsqlite3.a)
else()
find_package(SQLite3 REQUIRED)
# Note: We assume `libsqlite3-dev` has been installed for Ubuntu

set(SQLITE3_INCLUDE_DIR ${SQLite3_INCLUDE_DIRS})
find_package(SQLite3 REQUIRED)

get_filename_component(SQLITE3_LIBRARY_DIR ${SQLite3_LIBRARIES} DIRECTORY)
get_filename_component(SQLITE3_IMPORT_LIBRARY ${SQLite3_LIBRARIES} NAME)
endif()

if(NOT APPLE)
# Copy SQLite3's library to the plugin's external binaries directory
# Copy shared libraries to the plugin's external binaries directory

execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${LZMA_LIBRARY_DIR}/${LZMA_SHARED_LIBRARY}
${EXTERNAL_BINARIES_DIR})

execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${SQLITE3_LIBRARY_DIR}/${SQLITE3_SHARED_LIBRARY}
${EXTERNAL_BINARIES_DIR})

if(WIN32)
if(UNIX)
# We also need to copy bzip2 library for Unix

execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${BZIP2_LIBRARY_DIR}/${BZIP2_SHARED_LIBRARY}
${EXTERNAL_BINARIES_DIR})
else()
# We also need import libraries for Windows

execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${LZMA_IMPORT_LIBRARY_DIR}/${LZMA_IMPORT_LIBRARY}
${EXTERNAL_BINARIES_DIR})

execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${SQLITE3_LIBRARY_DIR}/${SQLITE3_IMPORT_LIBRARY}
${EXTERNAL_BINARIES_DIR})
endif()
Expand Down Expand Up @@ -406,12 +480,6 @@ else()

-DINSTALL_DEVELOPMENT=ON

# Jupyter needs SQLite3

-DENABLE_SQLITE3=ON
-DSQLITE3_INCLUDE_PATH=${SQLITE3_INCLUDE_DIR}
-DSQLITE3_LIBRARY=${SQLITE3_LIBRARY_DIR}/${SQLITE3_IMPORT_LIBRARY}

# Turn off things we don't want

-DINSTALL_MANUAL=OFF
Expand Down Expand Up @@ -445,12 +513,24 @@ else()
-DBZIP2_INCLUDE_DIR=${BZIP2_INCLUDE_DIR}
-DBZIP2_LIBRARIES=${BZIP2_LIBRARIES}

# Link to the LZMA library

-DUSE_SYSTEM_LZMA=OFF
-DLIBLZMA_INCLUDE_DIRS=${LIBLZMA_INCLUDE_DIRS}
-DLIBLZMA_LIBRARIES=${LIBLZMA_LIBRARIES}

# Use our OpenSSL

-DUSE_SYSTEM_OpenSSL=OFF
-DOPENSSL_INCLUDE_DIR=${OPENSSL_INCLUDE_DIR}
-DOPENSSL_LIBRARIES=${PYTHON_OPENSSL_LIBRARIES}

# Jupyter needs SQLite3

-DENABLE_SQLITE3=ON
-DSQLITE3_INCLUDE_PATH=${SQLite3_INCLUDE_DIRS}
-DSQLITE3_LIBRARY=${SQLite3_LIBRARIES}

# Use our zlib

-DUSE_SYSTEM_ZLIB=OFF
Expand Down Expand Up @@ -501,6 +581,7 @@ else()
COMMAND ${CMAKE_COMMAND} -E copy ${ZLIB_DLL} bin
COMMAND ${CMAKE_COMMAND} -E copy ${OPENSSL_CRYPTO_DLL} bin
COMMAND ${CMAKE_COMMAND} -E copy ${OPENSSL_SSL_DLL} bin
COMMAND ${CMAKE_COMMAND} -E copy ${LZMA_LIBRARY_DIR}/${LZMA_SHARED_LIBRARY} bin
COMMAND ${CMAKE_COMMAND} -E copy ${SQLITE3_LIBRARY_DIR}/${SQLITE3_SHARED_LIBRARY} bin
WORKING_DIRECTORY ${FULL_LOCAL_EXTERNAL_PACKAGE_DIR}
DEPENDEES install)
Expand Down
24 changes: 24 additions & 0 deletions src/plugins/thirdParty/Python/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Dependencies
============

macOS
-----

* SQLite: ``brew install sqlite3``
* lzma: ``brew install xz``


Ubuntu
------

* bzip2: ``sudo apt-get install libbz2-dev``
* libffi: ``sudo apt install libffi-dev``
* lzma: ``sudo apt-get install liblzma-dev``
* readline: ``sudo apt-get install libreadline-dev``
* SQLite: ``sudo apt install libsqlite3-dev``


Windows
-------

* We download and build bzip2, xz (lzma) and SQLite3 as part of the Python build.

0 comments on commit 5507137

Please sign in to comment.