From a016625c58fe6629fd8a79c934f2569f9f1adf62 Mon Sep 17 00:00:00 2001 From: Hugh Sorby Date: Thu, 7 Nov 2024 13:31:59 +1300 Subject: [PATCH 1/4] Fix static build and test on Linux. --- src/CMakeLists.txt | 4 ++++ src/bindings/CMakeLists.txt | 3 +++ src/bindings/python/CMakeLists.txt | 2 +- tests/gtest/cmake/internal_utils.cmake | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) 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..7da52952ad 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 "The Python bindings are not intended to work 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} From b0b0952778c904a8fb706c87265984f7240c7886 Mon Sep 17 00:00:00 2001 From: Hugh Sorby Date: Thu, 7 Nov 2024 13:40:53 +1300 Subject: [PATCH 2/4] Enable static build and test of Linux environment. --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b7abf4e9f6..4c4b2977a4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,11 +33,11 @@ jobs: 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 + unit_tests: ON - name: 'Linux shared - C++/Python' os: ubuntu-latest bindings_python: ON From 12b53b1e7bafd94b5bf7e47a50af4e2e38f265c4 Mon Sep 17 00:00:00 2001 From: Hugh Sorby Date: Thu, 7 Nov 2024 13:54:20 +1300 Subject: [PATCH 3/4] Remove unit_tests from CI.yml test matrix as they are now always on. --- .github/workflows/ci.yml | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4c4b2977a4..85d02379e4 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++' os: ubuntu-latest bindings_python: OFF build_shared: OFF - unit_tests: ON - 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 From e0aa82e21e3e47d5df618e75d9824621c7c7dabb Mon Sep 17 00:00:00 2001 From: Hugh Sorby Date: Mon, 11 Nov 2024 10:35:03 +1300 Subject: [PATCH 4/4] Update CMakeLists.txt adjust warning message. --- src/bindings/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings/CMakeLists.txt b/src/bindings/CMakeLists.txt index 7da52952ad..ded2e1d548 100644 --- a/src/bindings/CMakeLists.txt +++ b/src/bindings/CMakeLists.txt @@ -18,7 +18,7 @@ endif() if(LIBCELLML_BINDINGS_PYTHON) if(NOT LIBCELLML_BUILD_SHARED) - message(WARNING "The Python bindings are not intended to work with static libraries.") + message(WARNING "It is **not** recommended to build the Python bindings with static libraries.") endif() add_subdirectory(python) endif()