Skip to content

Commit

Permalink
Merge de7f698 into fc03a45
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrnz committed Oct 17, 2019
2 parents fc03a45 + de7f698 commit 6a39859
Show file tree
Hide file tree
Showing 157 changed files with 10,645 additions and 450 deletions.
139 changes: 139 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ option(USE_PREBUILT_LLVMCLANG_PACKAGE "Use the pre-built version of the LLVMClan
option(USE_PREBUILT_OAUTH_PACKAGE "Use the pre-built version of the OAuth package" ON)
option(USE_PREBUILT_OPENSSL_PACKAGE "Use the pre-built version of the OpenSSL package" ON)
option(USE_PREBUILT_PYTHON_PACKAGES_PACKAGE "Use the pre-built version of various Python packages" ON)
option(USE_PREBUILT_PYTHONQT_PACKAGE "Use the pre-built version of the PythonQt package" ON)
option(USE_PREBUILT_QSCINTILLA_PACKAGE "Use the pre-built version of the QScintilla package" ON)
option(USE_PREBUILT_QWT_PACKAGE "Use the pre-built version of the Qwt package" ON)
option(USE_PREBUILT_SUNDIALS_PACKAGE "Use the pre-built version of the SUNDIALS package" ON)
Expand Down Expand Up @@ -625,6 +626,13 @@ configure_file(${CMAKE_SOURCE_DIR}/res/common.qrc.in
configure_file(${CMAKE_SOURCE_DIR}/res/i18n.qrc.in
${I18N_QRC_FILENAME})

# The Python interface depends on Python headers, so we only include it if we
# are using the prebuilt version of our Python and QtWebKit packages

if(USE_PREBUILT_PYTHON_AND_QTWEBKIT_PACKAGES)
set(PYTHON_INTERFACE_FILENAME src/plugins/pythoninterface.cpp)
endif()

# Files that make up the GUI version of OpenCOR

set(SOURCES
Expand Down Expand Up @@ -653,6 +661,7 @@ set(SOURCES
src/plugins/plugininterface.cpp
src/plugins/pluginmanager.cpp
src/plugins/preferencesinterface.cpp
${PYTHON_INTERFACE_FILENAME}
src/plugins/solverinterface.cpp
src/plugins/viewinterface.cpp
src/plugins/windowinterface.cpp
Expand Down Expand Up @@ -690,6 +699,7 @@ if(WIN32)
src/plugins/plugininfo.cpp
src/plugins/plugininterface.cpp
src/plugins/pluginmanager.cpp
${PYTHON_INTERFACE_FILENAME}
src/plugins/solverinterface.cpp

src/windows/main.cpp
Expand Down Expand Up @@ -870,6 +880,7 @@ if(USE_PREBUILT_QTWEBKIT_PACKAGE)
list(APPEND PLUGINS
thirdParty/libSBML
thirdParty/PythonPackages
thirdParty/PythonQtAPI

dataStore/BioSignalMLDataStore
dataStore/CSVDataStore
Expand All @@ -887,6 +898,9 @@ if(USE_PREBUILT_QTWEBKIT_PACKAGE)
miscellaneous/Compiler
miscellaneous/Core
miscellaneous/HelpWindow
miscellaneous/JupyterKernel
miscellaneous/PythonConsoleWindow
miscellaneous/PythonShell
miscellaneous/WebBrowserWindow

organisation/FileBrowserWindow
Expand All @@ -906,6 +920,8 @@ if(USE_PREBUILT_QTWEBKIT_PACKAGE)
support/CellMLSupport
support/COMBINESupport
support/PMRSupport
support/PythonSupport
support/PythonQtSupport
support/SEDMLSupport
support/SimulationSupport
support/StandardSupport
Expand Down Expand Up @@ -963,6 +979,10 @@ if(USE_PREBUILT_QTWEBKIT_PACKAGE)
add_definitions(-DENABLE_TEST_PLUGINS)
endif()

# Let OpenCOR know that we want Python support

add_definitions(-DPYTHON_SUPPORT)

# Let OpenCOR know about the prebuilt version of our QtWebKit package
# being used

Expand Down Expand Up @@ -1028,6 +1048,7 @@ configure_clang_and_clang_tidy(${CMAKE_PROJECT_NAME})
if(WIN32)
target_link_libraries(${CMAKE_PROJECT_NAME}
${Qt5Core_QTMAIN_LIBRARIES}
${PYTHON_LIBRARY}
)
endif()

Expand All @@ -1037,6 +1058,29 @@ foreach(REQUIRED_QT_MODULE ${REQUIRED_QT_MODULES})
)
endforeach()

# We can't compile Python interface code until after the Python headers are in
# place

if(NOT "${PYTHON_DEPENDENCIES}" STREQUAL "")
add_dependencies(${CMAKE_PROJECT_NAME} ${PYTHON_DEPENDENCIES})
endif()

# On Linux, our Python package needs to be directly linked to OpenCOR otherwise
# Python extension DSOs can't find symbols
# Note: this is because the lookup scope changes for DSOs that are loaded
# using dlopen()...
# (See https://www.akkadia.org/drepper/dsohowto.pdf)

if(NOT WIN32 AND NOT APPLE)
include_directories(${PYTHON_INCLUDE_DIR})

target_link_libraries(${CMAKE_PROJECT_NAME}
${PYTHON_LIBRARY}
)

add_dependencies(${CMAKE_PROJECT_NAME} PythonPlugin)
endif()

# Build the CLI version of OpenCOR (Windows specific)
# Note: when it comes to WINDOWS_CLI_PROJECT_NAME, we used to have it set to
# ${CMAKE_PROJECT_NAME}.com, but Ninja found a duplicate rule (from a copy
Expand All @@ -1059,7 +1103,12 @@ if(WIN32)
target_link_libraries(${WINDOWS_CLI_PROJECT_NAME}
Qt5::Core
Qt5::Network
${PYTHON_LIBRARY}
)

if(NOT "${PYTHON_DEPENDENCIES}" STREQUAL "")
add_dependencies(${WINDOWS_CLI_PROJECT_NAME} ${PYTHON_DEPENDENCIES})
endif()
endif()

# Some post-processing specific stuff
Expand Down Expand Up @@ -1285,6 +1334,40 @@ if(WIN32)
install(FILES ${VBS_FILENAME}
DESTINATION .)

# Python runtime libraries and utilities

install(DIRECTORY ${PROJECT_BUILD_DIR}/Python
DESTINATION .)

# Batch files to setup and run Python and Jupyter

set(JUPYTER_CONSOLE_FILENAME "${PROJECT_BUILD_DIR}/jupyterconsole.bat")
set(RUN_PYTHON_FILENAME "${PROJECT_BUILD_DIR}/runpython.bat")

configure_file(${PLATFORM_DISTRIB_DIR}/jupyterconsole.bat.in ${JUPYTER_CONSOLE_FILENAME})
copy_file_to_build_dir(DIRECT ${PLATFORM_DISTRIB_DIR} . jupyterlab.bat)
copy_file_to_build_dir(DIRECT ${PLATFORM_DISTRIB_DIR} . jupyterlab.vbs)
copy_file_to_build_dir(DIRECT ${PLATFORM_DISTRIB_DIR} . jupyternotebook.bat)
copy_file_to_build_dir(DIRECT ${PLATFORM_DISTRIB_DIR} . jupyternotebook.vbs)
copy_file_to_build_dir(DIRECT ${PLATFORM_DISTRIB_DIR} . runjupyter.bat)
configure_file(${PLATFORM_DISTRIB_DIR}/runpython.bat.in ${RUN_PYTHON_FILENAME})
copy_file_to_build_dir(DIRECT ${PLATFORM_DISTRIB_DIR} . setpythonpath.bat)

install(FILES ${JUPYTER_CONSOLE_FILENAME}
${PLATFORM_DISTRIB_DIR}/jupyterlab.bat
${PLATFORM_DISTRIB_DIR}/jupyterlab.vbs
${PLATFORM_DISTRIB_DIR}/jupyternotebook.bat
${PLATFORM_DISTRIB_DIR}/jupyternotebook.vbs
${PLATFORM_DISTRIB_DIR}/runjupyter.bat
${RUN_PYTHON_FILENAME}
${PLATFORM_DISTRIB_DIR}/setpythonpath.bat
DESTINATION .)

copy_file_to_build_dir(DIRECT ${PLATFORM_DISTRIB_DIR} ./Python/Scripts start_jupyter.py)

install(FILES ${PLATFORM_DISTRIB_DIR}/start_jupyter.py
DESTINATION ./Python/Scripts)

# File type association
# Note: the calls to SHChangeNotify are to ensure that Windows refreshes
# file icons (so that it is clear to the user that an extension has
Expand All @@ -1301,6 +1384,12 @@ if(WIN32)
\\\${UnregisterExtension} \\\".cellml\\\" \\\"CellML File\\\"
System::Call \\\"Shell32::SHChangeNotify(i 0x08000000, i 0, i 0, i 0)\\\"
")

# Update Python scripts to refer to our installed Python

set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS
"${CPACK_NSIS_EXTRA_INSTALL_COMMANDS} Exec '\\\"\\\$INSTDIR\\\\Python\\\\bin\\\\python.exe\\\" \\\"\\\$INSTDIR\\\\Python\\\\Scripts\\\\setpythonpath.py\\\" \\\"\\\$INSTDIR\\\\Python\\\" -s'
")
endif()
elseif(APPLE)
# Select PackageMaker and ZIP as the packagers on macOS
Expand Down Expand Up @@ -1330,6 +1419,29 @@ elseif(APPLE)
DESTINATION .
RENAME ${CMAKE_PROJECT_NAME}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)

# Shell scripts to setup and run Python and Jupyter

set(JUPYTER_CONSOLE_FILENAME ${PROJECT_BUILD_DIR}/jupyterconsole)
set(RUN_JUPYTER_FILENAME ${PROJECT_BUILD_DIR}/runjupyter)
set(RUN_PYTHON_FILENAME ${PROJECT_BUILD_DIR}/runpython)
set(SET_PYTHON_PATH_FILENAME ${PROJECT_BUILD_DIR}/setpythonpath)

configure_file(${PLATFORM_DISTRIB_DIR}/jupyterconsole.in ${JUPYTER_CONSOLE_FILENAME} @ONLY)
copy_file_to_build_dir(DIRECT ${PLATFORM_DISTRIB_DIR} . jupyterlab)
copy_file_to_build_dir(DIRECT ${PLATFORM_DISTRIB_DIR} . jupyternotebook)
configure_file(${PLATFORM_DISTRIB_DIR}/runjupyter.in ${RUN_JUPYTER_FILENAME} @ONLY)
configure_file(${PLATFORM_DISTRIB_DIR}/runpython.in ${RUN_PYTHON_FILENAME} @ONLY)
configure_file(${PLATFORM_DISTRIB_DIR}/setpythonpath.in ${SET_PYTHON_PATH_FILENAME} @ONLY)

install(FILES ${JUPYTER_CONSOLE_FILENAME}
${PLATFORM_DISTRIB_DIR}/jupyterlab
${PLATFORM_DISTRIB_DIR}/jupyternotebook
${RUN_JUPYTER_FILENAME}
${RUN_PYTHON_FILENAME}
${SET_PYTHON_PATH_FILENAME}
DESTINATION .
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
else()
# Select TGZ as the packager on Linux

Expand Down Expand Up @@ -1395,6 +1507,33 @@ else()
DESTINATION .
RENAME ${CMAKE_PROJECT_NAME}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)

# Python runtime libraries and utilities

install(DIRECTORY ${PROJECT_BUILD_DIR}/python
DESTINATION .
USE_SOURCE_PERMISSIONS)

# Shell scripts to setup and run Python and Jupyter

set(JUPYTER_CONSOLE_FILENAME ${PROJECT_BUILD_DIR}/jupyterconsole)
set(RUN_PYTHON_FILENAME ${PROJECT_BUILD_DIR}/runpython)

configure_file(${PLATFORM_DISTRIB_DIR}/jupyterconsole.in ${JUPYTER_CONSOLE_FILENAME} @ONLY)
copy_file_to_build_dir(DIRECT ${PLATFORM_DISTRIB_DIR} . jupyterlab)
copy_file_to_build_dir(DIRECT ${PLATFORM_DISTRIB_DIR} . jupyternotebook)
copy_file_to_build_dir(DIRECT ${PLATFORM_DISTRIB_DIR} . runjupyter)
configure_file(${PLATFORM_DISTRIB_DIR}/runpython.in ${RUN_PYTHON_FILENAME} @ONLY)
copy_file_to_build_dir(DIRECT ${PLATFORM_DISTRIB_DIR} . setpythonpath)

install(FILES ${JUPYTER_CONSOLE_FILENAME}
${PLATFORM_DISTRIB_DIR}/jupyterlab
${PLATFORM_DISTRIB_DIR}/jupyternotebook
${PLATFORM_DISTRIB_DIR}/runjupyter
${RUN_PYTHON_FILENAME}
${PLATFORM_DISTRIB_DIR}/setpythonpath
DESTINATION .
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
endif()

# Specify the package file name, depending on whether we are generating a
Expand Down
14 changes: 11 additions & 3 deletions cmake/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ macro(build_documentation DOCUMENTATION_NAME)
${PROJECT_BUILD_DIR}/doc/${DOCUMENTATION_NAME}
)

# Make our local target depend on having Python fully installed

add_dependencies(${DOCUMENTATION_BUILD} ${PYTHON_DEPENDENCIES})

# Make our local target depend on our project build target and make our
# documentation build target depend on our local target

Expand Down Expand Up @@ -187,6 +191,7 @@ macro(add_plugin PLUGIN_NAME)
EXTERNAL_BINARIES
SYSTEM_BINARIES
DEPENDS_ON
BYPRODUCTS
TESTS
)

Expand Down Expand Up @@ -277,8 +282,10 @@ macro(add_plugin PLUGIN_NAME)
endforeach()

# Create a custom target for copying external binaries
# Note: this is to prevent Ninja from getting confused with circular
# references...
# Note #1: this is to prevent Ninja from getting confused with circular
# references...
# Note #2: we use this target in the PythonQtAPI build script when setting
# the PYTHON_DEPENDENCIES list...

if( NOT "${ARG_EXTERNAL_BINARIES_DIR}" STREQUAL ""
OR ( NOT "${ARG_EXTERNAL_SOURCE_DIR}" STREQUAL ""
Expand Down Expand Up @@ -381,7 +388,8 @@ macro(add_plugin PLUGIN_NAME)

add_custom_command(TARGET ${COPY_EXTERNAL_BINARIES_TARGET}
COMMAND ${CMAKE_COMMAND} -E copy_directory ${ARG_EXTERNAL_SOURCE_DIR}
${ARG_EXTERNAL_DESTINATION_DIR})
${ARG_EXTERNAL_DESTINATION_DIR}
BYPRODUCTS ${ARG_BYPRODUCTS})
endif()

# System binaries
Expand Down
Empty file modified distrib/linux/application.in
100644 → 100755
Empty file.
5 changes: 5 additions & 0 deletions distrib/linux/jupyterconsole.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

appDir="$(cd "$(dirname "$0")"; pwd)"

${appDir}/runjupyter console --kernel @CMAKE_PROJECT_NAME@ $*
5 changes: 5 additions & 0 deletions distrib/linux/jupyterlab
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

appDir="$(cd "$(dirname "$0")"; pwd)"

${appDir}/runjupyter lab --ip 127.0.0.1 $*
5 changes: 5 additions & 0 deletions distrib/linux/jupyternotebook
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

appDir="$(cd "$(dirname "$0")"; pwd)"

${appDir}/runjupyter notebook --ip 127.0.0.1 $*
9 changes: 9 additions & 0 deletions distrib/linux/runjupyter
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

appDir="$(cd "$(dirname "$0")"; pwd)"

${appDir}/setpythonpath

export PATH=${appDir}:$PATH

${appDir}/python/bin/jupyter $*
7 changes: 7 additions & 0 deletions distrib/linux/runpython.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

appDir="$(cd "$(dirname "$0")"; pwd)"

${appDir}/setpythonpath

${appDir}/bin/@CMAKE_PROJECT_NAME@ -c Python $*
5 changes: 5 additions & 0 deletions distrib/linux/setpythonpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

appDir="$(cd "$(dirname "$0")"; pwd)"

${appDir}/python/bin/python ${appDir}/python/bin/setpythonpath.py ${appDir}/python -s
Empty file modified distrib/macos/application.in
100644 → 100755
Empty file.
5 changes: 5 additions & 0 deletions distrib/macos/jupyterconsole.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

appDir="$(cd "$(dirname "$0")"; pwd)"

${appDir}/runjupyter console --kernel @CMAKE_PROJECT_NAME@ $*
5 changes: 5 additions & 0 deletions distrib/macos/jupyterlab
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

appDir="$(cd "$(dirname "$0")"; pwd)"

${appDir}/runjupyter lab --ip 127.0.0.1 $*
5 changes: 5 additions & 0 deletions distrib/macos/jupyternotebook
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

appDir="$(cd "$(dirname "$0")"; pwd)"

${appDir}/runjupyter notebook --ip 127.0.0.1 $*
9 changes: 9 additions & 0 deletions distrib/macos/runjupyter.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

appDir="$(cd "$(dirname "$0")"; pwd)"

${appDir}/setpythonpath

export PATH=${appDir}:$PATH

${appDir}/@CMAKE_PROJECT_NAME@.app/Contents/Frameworks/Python/bin/jupyter $*
7 changes: 7 additions & 0 deletions distrib/macos/runpython.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

appDir="$(cd "$(dirname "$0")"; pwd)"

${appDir}/setpythonpath

${appDir}/@CMAKE_PROJECT_NAME@.app/Contents/MacOS/@CMAKE_PROJECT_NAME@ -c Python $*
8 changes: 8 additions & 0 deletions distrib/macos/setpythonpath.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

appDir="$(cd "$(dirname "$0")"; pwd)"

${appDir}/@CMAKE_PROJECT_NAME@.app/Contents/Frameworks/Python/bin/python \
${appDir}/@CMAKE_PROJECT_NAME@.app/Contents/Frameworks/Python/bin/setpythonpath.py \
${appDir}/@CMAKE_PROJECT_NAME@.app/Contents/Frameworks/Python \
-s
7 changes: 7 additions & 0 deletions distrib/windows/jupyterconsole.bat.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@ECHO OFF

TITLE Running the Jupyter Lab environment...

SET appDir=%~dp0

CALL "%appDir%runjupyter.bat" console --kernel ${CMAKE_PROJECT_NAME} %*
7 changes: 7 additions & 0 deletions distrib/windows/jupyterlab.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@ECHO OFF

TITLE Running the Jupyter Lab environment...

SET appDir=%~dp0

CALL "%appDir%runjupyter.bat" lab --ip 127.0.0.1 %*

0 comments on commit 6a39859

Please sign in to comment.