diff --git a/Applications/SlicerApp/Testing/Python/CMakeLists.txt b/Applications/SlicerApp/Testing/Python/CMakeLists.txt index cd81fbb9552..37c99a3ea4e 100644 --- a/Applications/SlicerApp/Testing/Python/CMakeLists.txt +++ b/Applications/SlicerApp/Testing/Python/CMakeLists.txt @@ -302,6 +302,12 @@ slicer_add_python_unittest( TESTNAME_PREFIX nomainwindow_ ) +slicer_add_python_unittest( + SCRIPT ${Slicer_SOURCE_DIR}/Base/Python/slicer/tests/test_slicer_python_sqlite3.py + SLICER_ARGS --no-main-window --disable-modules + TESTNAME_PREFIX nomainwindow_ + ) + slicer_add_python_unittest( SCRIPT ${Slicer_SOURCE_DIR}/Base/Python/slicer/tests/test_slicer_util_VTKObservationMixin.py SLICER_ARGS --no-main-window --disable-modules diff --git a/Base/Python/slicer/tests/test_slicer_python_sqlite3.py b/Base/Python/slicer/tests/test_slicer_python_sqlite3.py new file mode 100644 index 00000000000..de83d22a5a4 --- /dev/null +++ b/Base/Python/slicer/tests/test_slicer_python_sqlite3.py @@ -0,0 +1,36 @@ +import unittest +import slicer +import os +import shutil + +class SlicerPythonSqlite3Tests(unittest.TestCase): + """This test verifies that Python is build with sqlite3 enabled. + """ + + def setUp(self): + self.tempDir = slicer.util.tempDirectory() + + def tearDown(self): + shutil.rmtree(self.tempDir, True) + + def test_sqliteDatabase(self): + import sqlite3 + + database_filename = os.path.join(self.tempDir, 'database.sql') + print("database_filename="+database_filename) + + self.connection = sqlite3.connect(database_filename) + print(sqlite3.version) + self.assertIsNotNone(self.connection) + self.assertTrue(os.path.exists(database_filename)) + + create_table_sql = """ CREATE TABLE IF NOT EXISTS projects ( + id integer PRIMARY KEY, + name text NOT NULL, + begin_date text, + end_date text + ); """ + c = self.connection.cursor() + c.execute(create_table_sql) + + self.connection.close() diff --git a/CMake/SlicerInitializeOSXVariables.cmake b/CMake/SlicerInitializeOSXVariables.cmake index 5b7300fd700..9bb27fc3044 100644 --- a/CMake/SlicerInitializeOSXVariables.cmake +++ b/CMake/SlicerInitializeOSXVariables.cmake @@ -67,7 +67,7 @@ if(APPLE) set(required_deployment_target "10.11") if(CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS ${required_deployment_target}) - message(FATAL_ERROR "CMAKE_OSX_DEPLOYMENT_TARGET must be ${required_deployment_target} or greater.") + message(FATAL_ERROR "CMAKE_OSX_DEPLOYMENT_TARGET ${CMAKE_OSX_DEPLOYMENT_TARGET} must be ${required_deployment_target} or greater.") endif() if(NOT "${CMAKE_OSX_SYSROOT}" STREQUAL "") diff --git a/SuperBuild/External_python.cmake b/SuperBuild/External_python.cmake index 0b8ad8bc448..71b8bcf6751 100644 --- a/SuperBuild/External_python.cmake +++ b/SuperBuild/External_python.cmake @@ -10,6 +10,7 @@ if(NOT Slicer_USE_SYSTEM_python) bzip2 CTKAPPLAUNCHER zlib + sqlite ) endif() if(Slicer_USE_PYTHONQT_WITH_TCL) @@ -165,6 +166,8 @@ if((NOT DEFINED PYTHON_INCLUDE_DIR -DBZIP2_LIBRARIES:FILEPATH=${BZIP2_LIBRARIES} -DZLIB_INCLUDE_DIR:PATH=${ZLIB_INCLUDE_DIR} -DZLIB_LIBRARY:FILEPATH=${ZLIB_LIBRARY} + -DSQLITE3_LIBRARY:FILEPATH=${sqlite_LIBRARY} + -DSQLITE3_INCLUDE_PATH:PATH=${sqlite_INCLUDE_DIR} -DENABLE_TKINTER:BOOL=${Slicer_USE_PYTHONQT_WITH_TCL} -DENABLE_SSL:BOOL=${PYTHON_ENABLE_SSL} -DPatch_EXECUTABLE:FILEPATH=${Patch_EXECUTABLE} diff --git a/SuperBuild/External_sqlite.cmake b/SuperBuild/External_sqlite.cmake new file mode 100644 index 00000000000..e8b69882758 --- /dev/null +++ b/SuperBuild/External_sqlite.cmake @@ -0,0 +1,90 @@ + +set( proj sqlite ) + +# Set dependency list +set(${proj}_DEPENDENCIES "") + +# Include dependent projects if any +ExternalProject_Include_Dependencies(${proj} PROJECT_VAR proj DEPENDS_VAR ${proj}_DEPENDENCIES) + +if(Slicer_USE_SYSTEM_${proj}) + unset(${proj}_DIR CACHE) + unset(${proj} CACHE) + find_package(${proj} REQUIRED) +endif() + +# Sanity checks +if(DEFINED ${proj}_DIR AND NOT EXISTS ${${proj}_DIR}) + message(FATAL_ERROR "${proj}_DIR variable is defined but corresponds to nonexistent directory") +endif() + +if(NOT DEFINED ${proj}_DIR AND NOT Slicer_USE_SYSTEM_${proj}) + + ExternalProject_SetIfNotDefined( + Slicer_${proj}_GIT_REPOSITORY + "${EP_GIT_PROTOCOL}://github.com/azadkuh/sqlite-amalgamation.git" + QUIET + ) + + ExternalProject_SetIfNotDefined( + Slicer_${proj}_GIT_TAG + "3.30.1" + QUIET + ) + + set(EP_SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}) + set(EP_BINARY_DIR ${CMAKE_BINARY_DIR}/${proj}-build) + set(EP_INSTALL_DIR ${CMAKE_BINARY_DIR}/${proj}-install) + + set(${proj}_CMAKE_C_FLAGS ${ep_common_c_flags}) + if(CMAKE_SIZEOF_VOID_P EQUAL 8) # 64-bit + set(${proj}_CMAKE_C_FLAGS "${ep_common_c_flags} -fPIC") + endif() + + ExternalProject_Add(${proj} + ${${proj}_EP_ARGS} + GIT_REPOSITORY "${Slicer_${proj}_GIT_REPOSITORY}" + GIT_TAG "${Slicer_${proj}_GIT_TAG}" + SOURCE_DIR ${EP_SOURCE_DIR} + BINARY_DIR ${EP_BINARY_DIR} + INSTALL_DIR ${EP_INSTALL_DIR} + CMAKE_CACHE_ARGS + -DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER} + -DCMAKE_CXX_FLAGS:STRING=${ep_common_cxx_flags} + -DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER} + -DCMAKE_C_FLAGS:STRING=${${proj}_CMAKE_C_FLAGS} + -DCMAKE_CXX_STANDARD:STRING=${CMAKE_CXX_STANDARD} + -DCMAKE_CXX_STANDARD_REQUIRED:BOOL=${CMAKE_CXX_STANDARD_REQUIRED} + -DCMAKE_CXX_EXTENSIONS:BOOL=${CMAKE_CXX_EXTENSIONS} + -DSQLITE_BUILD_DOC:BOOL=OFF + -DSQLITE_BUILD_EXAMPLES:BOOL=OFF + -DSQLITE_BUILD_TESTS:BOOL=OFF + # recommended options would define SQLITE_OMIT_DEPRECATED and SQLITE_OMIT_DECLTYPE, + # which would cause build errors in Python, so go with deafult options instead + -DBUILD_RECOMMENDED_OPTS:BOOL=OFF + -DCMAKE_INSTALL_PREFIX:PATH=${EP_INSTALL_DIR} + DEPENDS + ${${proj}_DEPENDENCIES} + ) + + ExternalProject_GenerateProjectDescription_Step(${proj}) + + set(${proj}_DIR ${EP_BINARY_DIR}) + set(${proj}_INCLUDE_DIR ${EP_INSTALL_DIR}/include/sqlite3) + if(WIN32) + set(${proj}_LIBRARY ${EP_INSTALL_DIR}/lib/sqlite3.lib) + else() + set(${proj}_LIBRARY ${EP_INSTALL_DIR}/lib/libsqlite3.a) + endif() + +else() + ExternalProject_Add_Empty(${proj} DEPENDS ${${proj}_DEPENDENCIES}) +endif() + +mark_as_superbuild( + VARS + ${proj}_DIR:PATH + ${proj}_LIBRARY:PATH + ${proj}_INCLUDE_DIR:PATH + LABELS "FIND_PACKAGE" + )