diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 348a982135..9b0b6920c9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,46 +23,38 @@ jobs: os: windows-latest bindings_python: ON build_shared: OFF - unit_tests: ON set_path: $env:Path="C:\libxml2\bin;C:\zlib\bin;"+$env:Path additional_cmake_options: -DLIBXML2_INCLUDE_DIR="C:\libxml2\include\libxml2" -DLIBXML2_LIBRARY="C:\libxml2\lib\libxml2.lib" -DZLIB_INCLUDE_DIR="C:\zlib\include" -DZLIB_LIBRARY="C:\zlib\lib\z_dll.lib" - name: 'Windows shared - C++/Python' os: windows-latest bindings_python: ON build_shared: ON - unit_tests: ON set_path: $env:Path="C:\libxml2\bin;C:\zlib\bin;"+$env:Path additional_cmake_options: -DLIBXML2_INCLUDE_DIR="C:\libxml2\include\libxml2" -DLIBXML2_LIBRARY="C:\libxml2\lib\libxml2.lib" -DZLIB_INCLUDE_DIR="C:\zlib\include" -DZLIB_LIBRARY="C:\zlib\lib\z_dll.lib" - - name: 'Linux static - C++ (build only)' + - name: 'Linux static - C++' os: ubuntu-latest bindings_python: OFF build_shared: OFF - unit_tests: OFF - name: 'Linux shared - C++/Python' os: ubuntu-latest bindings_python: ON build_shared: ON - unit_tests: ON - name: 'macOS static - C++ (Intel)' os: macos-13 bindings_python: OFF build_shared: OFF - unit_tests: ON - name: 'macOS shared - C++/Python (Intel)' os: macos-13 bindings_python: ON build_shared: ON - unit_tests: ON - name: 'macOS static - C++ (ARM)' os: macos-latest bindings_python: OFF build_shared: OFF - unit_tests: ON - name: 'macOS shared - C++/Python (ARM)' os: macos-latest bindings_python: ON build_shared: ON - unit_tests: ON steps: - name: Check out libCellML uses: actions/checkout@v4 @@ -99,13 +91,12 @@ jobs: mkdir build cd build ${{ matrix.set_path }} - cmake -G Ninja -DBINDINGS_PYTHON=${{ matrix.bindings_python }} -DBUILD_SHARED=${{ matrix.build_shared }} -DCOVERAGE=OFF -DLLVM_COVERAGE=OFF -DMEMCHECK=OFF -DUNIT_TESTS=${{ matrix.unit_tests }} ${{ matrix.additional_cmake_options }} .. + cmake -G Ninja -DBINDINGS_PYTHON=${{ matrix.bindings_python }} -DBUILD_SHARED=${{ matrix.build_shared }} -DCOVERAGE=OFF -DLLVM_COVERAGE=OFF -DMEMCHECK=OFF -DUNIT_TESTS=ON ${{ matrix.additional_cmake_options }} .. - name: Build libCellML run: | cd build ninja - name: Unit testing - if: ${{ matrix.unit_tests == 'ON' }} run: | cd build ninja test diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b790b2198f..e89a672648 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -216,6 +216,10 @@ set_target_properties(cellml PROPERTIES COMPATIBLE_INTERFACE_STRING ${PROJECT_VERSION_MAJOR} ) +if(NOT LIBCELLML_BUILD_SHARED AND CMAKE_SYSTEM_NAME STREQUAL "Linux") + set_target_properties(cellml PROPERTIES POSITION_INDEPENDENT_CODE 1) +endif() + set(DEBUG_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/debug.cpp ) diff --git a/src/bindings/CMakeLists.txt b/src/bindings/CMakeLists.txt index e981babe02..ded2e1d548 100644 --- a/src/bindings/CMakeLists.txt +++ b/src/bindings/CMakeLists.txt @@ -17,6 +17,9 @@ if(LIBCELLML_BINDINGS_PYTHON) # Or any other bindings that use SWIG. endif() if(LIBCELLML_BINDINGS_PYTHON) + if(NOT LIBCELLML_BUILD_SHARED) + message(WARNING "It is **not** recommended to build the Python bindings with static libraries.") + endif() add_subdirectory(python) endif() diff --git a/src/bindings/python/CMakeLists.txt b/src/bindings/python/CMakeLists.txt index c98abd754f..966dc02647 100644 --- a/src/bindings/python/CMakeLists.txt +++ b/src/bindings/python/CMakeLists.txt @@ -67,7 +67,7 @@ set_source_files_properties(${SWIG_INTERFACE_SRCS} PROPERTIES set(SETUP_PY_PACKAGE_FILES "'\${TARGET_FILE_NAME_cellml}'") list(APPEND FINALISE_PYTHON_BINDINGS_ARGUMENTS -DTARGET_FILE_NAME_cellml=$) -if (UNIX AND NOT APPLE) +if (UNIX AND NOT APPLE AND LIBCELLML_BUILD_SHARED) list(APPEND SETUP_PY_PACKAGE_FILES "'\${TARGET_SONAME_FILE_NAME_cellml}'") list(APPEND FINALISE_PYTHON_BINDINGS_ARGUMENTS -DTARGET_SONAME_FILE_NAME_cellml=$) set(_GENERATOR_EXPRESSION_LIBCELLML_SONAME $) diff --git a/tests/gtest/cmake/internal_utils.cmake b/tests/gtest/cmake/internal_utils.cmake index 78ab035dff..d73dc4a995 100644 --- a/tests/gtest/cmake/internal_utils.cmake +++ b/tests/gtest/cmake/internal_utils.cmake @@ -134,6 +134,7 @@ function(cxx_library_with_type name type cxx_flags) add_library(${name} ${type} ${ARGN}) set_target_properties(${name} PROPERTIES + POSITION_INDEPENDENT_CODE 1 COMPILE_FLAGS "${cxx_flags}") if (BUILD_SHARED_LIBS OR type STREQUAL "SHARED") set_target_properties(${name}