Skip to content

Commit b5e79d9

Browse files
authored
Static libraries: merge in all the object files of our dependencies.
2 parents 8a02cbf + 717ee47 commit b5e79d9

File tree

6 files changed

+114
-26
lines changed

6 files changed

+114
-26
lines changed

.github/workflows/cd.yml

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,51 +15,73 @@ jobs:
1515
fail-fast: false
1616
matrix:
1717
include:
18-
- name: 'Windows static library (Intel)'
18+
- name: 'Windows static library (Intel) (Release)'
1919
os: windows-2022
2020
arch: amd64
21+
build_type: Release
2122
shared_libs: OFF
22-
- name: 'Windows shared library (Intel)'
23+
- name: 'Windows shared library (Intel) (Release)'
2324
os: windows-2022
2425
arch: amd64
26+
build_type: Release
2527
shared_libs: ON
26-
- name: 'Windows static library (ARM)'
28+
- name: 'Windows shared library (Intel) (Debug)'
29+
os: windows-2022
30+
arch: amd64
31+
build_type: Debug
32+
shared_libs: ON
33+
- name: 'Windows static library (ARM) (Release)'
2734
os: windows-2022
2835
arch: amd64_arm64
36+
build_type: Release
2937
shared_libs: OFF
30-
- name: 'Windows shared library (ARM)'
38+
- name: 'Windows shared library (ARM) (Release)'
39+
os: windows-2022
40+
arch: amd64_arm64
41+
build_type: Release
42+
shared_libs: ON
43+
- name: 'Windows shared library (ARM) (Debug)'
3144
os: windows-2022
3245
arch: amd64_arm64
46+
build_type: Debug
3347
shared_libs: ON
3448
- name: 'Linux static library (Intel)'
3549
os: ubuntu-22.04
50+
build_type: Release
3651
shared_libs: OFF
3752
- name: 'Linux shared library (Intel)'
3853
os: ubuntu-22.04
54+
build_type: Release
3955
shared_libs: ON
4056
- name: 'Linux static library (ARM)'
4157
os: ubuntu-22.04-arm
58+
build_type: Release
4259
shared_libs: OFF
4360
- name: 'Linux shared library (ARM)'
4461
os: ubuntu-22.04-arm
62+
build_type: Release
4563
shared_libs: ON
4664
- name: 'macOS static library (Intel)'
4765
os: macos-14
4866
arch: Intel # Only used for buildcache's cache key.
67+
build_type: Release
4968
shared_libs: OFF
5069
target_arch: " -DTARGET_ARCHITECTURE=Intel"
5170
- name: 'macOS shared library (Intel)'
5271
os: macos-14
5372
arch: Intel # Only used for buildcache's cache key.
73+
build_type: Release
5474
shared_libs: ON
5575
target_arch: " -DTARGET_ARCHITECTURE=Intel"
5676
- name: 'macOS static library (ARM)'
5777
os: macos-14
5878
arch: ARM # Only used for buildcache's cache key.
79+
build_type: Release
5980
shared_libs: OFF
6081
- name: 'macOS shared library (ARM)'
6182
os: macos-14
6283
arch: ARM # Only used for buildcache's cache key.
84+
build_type: Release
6385
shared_libs: ON
6486
env:
6587
BUILDCACHE_ACCURACY: STRICT
@@ -74,7 +96,7 @@ jobs:
7496
- name: Install buildcache
7597
uses: opencor/buildcache-action@v1
7698
with:
77-
cache_key: cd-${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.shared_libs }}
99+
cache_key: cd-${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.build_type }}-${{ matrix.shared_libs }}
78100
- name: Configure MSVC
79101
if: ${{ runner.os == 'Windows' }}
80102
uses: ilammy/msvc-dev-cmd@v1
@@ -84,7 +106,7 @@ jobs:
84106
run: |
85107
mkdir build
86108
cd build
87-
cmake -G Ninja ${{ matrix.target_arch }} -DBUILD_TYPE=Release -DCODE_ANALYSIS=OFF -DCODE_COVERAGE=OFF -DDOCUMENTATION=OFF -DJAVASCRIPT_BINDINGS=OFF -DMEMORY_CHECKS=OFF -DPYTHON_BINDINGS=OFF -DPYTHON_UNIT_TESTING=OFF -DSHARED_LIBS=${{ matrix.shared_libs }} -DUNIT_TESTING=OFF ..
109+
cmake -G Ninja ${{ matrix.target_arch }} -DBUILD_TYPE=${{ matrix.build_type }} -DCODE_ANALYSIS=OFF -DCODE_COVERAGE=OFF -DDOCUMENTATION=OFF -DJAVASCRIPT_BINDINGS=OFF -DMEMORY_CHECKS=OFF -DPYTHON_BINDINGS=OFF -DPYTHON_UNIT_TESTING=OFF -DSHARED_LIBS=${{ matrix.shared_libs }} -DUNIT_TESTING=OFF ..
88110
- name: Build libOpenCOR
89111
run: |
90112
cd build

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ jobs:
438438
cd build
439439
${{ matrix.context }} cmake -G Ninja ${{ matrix.target_arch }} -DBUILD_TYPE=${{ matrix.build_type }} -DCODE_ANALYSIS=${{ matrix.code_analysis }} -DCODE_COVERAGE=${{ matrix.code_coverage }} -DDOCUMENTATION=${{ matrix.documentation }} -DINSTALL_PREFIX=${{ github.workspace }}/install -DJAVASCRIPT_BINDINGS=${{ matrix.javascript_bindings }} -DJAVASCRIPT_UNIT_TESTING=${{ matrix.javascript_unit_testing }} -DMEMORY_CHECKS=${{ matrix.memory_checks }} -DPYTHON_BINDINGS=${{ matrix.python_bindings }} -DPYTHON_UNIT_TESTING=${{ matrix.python_unit_testing }} -DSHARED_LIBS=${{ matrix.shared_libs }} -DUNIT_TESTING=${{ matrix.unit_testing }} ..
440440
- name: Build libOpenCOR
441-
if: ${{ (matrix.unit_testing == 'ON') || (matrix.javascript_unit_testing == 'ON') || (matrix.code_analysis == 'ON') || (matrix.code_coverage == 'ON') || (matrix.memory_checks == 'ON') }}
441+
if: ${{ (matrix.install_uninstall_and_package == 'ON') || (matrix.javascript_unit_testing == 'ON') || (matrix.code_analysis == 'ON') || (matrix.code_coverage == 'ON') || (matrix.memory_checks == 'ON') }}
442442
run: |
443443
cd build
444444
ninja

cmake/environmentchecks.cmake

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,16 @@ find_package(Python 3.9
122122
COMPONENTS Interpreter ${NB_PYTHON_DEV_MODULE}
123123
OPTIONAL_COMPONENTS Development.SABIModule)
124124

125-
add_subdirectory(extern/nanobind)
126-
127-
mark_as_advanced(NB_CREATE_INSTALL_RULES
128-
NB_TEST
129-
NB_TEST_SANITZE
130-
NB_TEST_SHARED_BUILD
131-
NB_TEST_STABLE_ABI
132-
nanobind_DIR)
125+
if(Python_EXECUTABLE)
126+
add_subdirectory(extern/nanobind)
127+
128+
mark_as_advanced(NB_CREATE_INSTALL_RULES
129+
NB_TEST
130+
NB_TEST_SANITZE
131+
NB_TEST_SHARED_BUILD
132+
NB_TEST_STABLE_ABI
133+
nanobind_DIR)
134+
endif()
133135

134136
# Look for various programs.
135137

cmake/packaging/CMakeLists.txt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ if(WIN32)
3030
endif()
3131

3232
set(CPACK_GENERATOR ${NSIS_GENERATOR} ZIP)
33-
set(CPACK_SYSTEM_NAME "Windows")
33+
set(CPACK_SYSTEM_NAME "-Windows")
3434
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE.txt")
3535

3636
# Specify the default installation directory.
@@ -44,7 +44,7 @@ elseif(APPLE)
4444
set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME ${CMAKE_PROJECT_NAME})
4545

4646
set(CPACK_GENERATOR productbuild ZIP)
47-
set(CPACK_SYSTEM_NAME "macOS")
47+
set(CPACK_SYSTEM_NAME "-macOS")
4848
set(CPACK_PROJECT_CONFIG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/distrib/package.cmake)
4949

5050
set(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_CURRENT_SOURCE_DIR}/distrib/welcome.txt")
@@ -56,24 +56,32 @@ else()
5656
# Select TGZ as the packager on Linux.
5757

5858
set(CPACK_GENERATOR TGZ)
59-
set(CPACK_SYSTEM_NAME "Linux")
59+
set(CPACK_SYSTEM_NAME "-Linux")
6060
endif()
6161

6262
# Specify the package file name.
6363

6464
if(${LIBOPENCOR_TARGET_ARCHITECTURE} STREQUAL "Intel")
65-
set(LIBRARY_ARCHITECTURE "Intel")
65+
set(LIBRARY_ARCHITECTURE "-Intel")
6666
else()
67-
set(LIBRARY_ARCHITECTURE "ARM")
67+
set(LIBRARY_ARCHITECTURE "-ARM")
6868
endif()
6969

7070
if(LIBOPENCOR_SHARED_LIBS)
71-
set(LIBRARY_TYPE "Shared")
71+
set(LIBRARY_TYPE "-Shared")
7272
else()
73-
set(LIBRARY_TYPE "Static")
73+
set(LIBRARY_TYPE "-Static")
7474
endif()
7575

76-
set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}-${CPACK_SYSTEM_NAME}-${LIBRARY_ARCHITECTURE}-${LIBRARY_TYPE})
76+
if(WIN32)
77+
if(RELEASE_MODE)
78+
set(LIBRARY_MODE "-Release")
79+
else()
80+
set(LIBRARY_MODE "-Debug")
81+
endif()
82+
endif()
83+
84+
set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}${CPACK_SYSTEM_NAME}${LIBRARY_ARCHITECTURE}${LIBRARY_TYPE}${LIBRARY_MODE})
7785

7886
# Package libOpenCOR.
7987

src/CMakeLists.txt

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,65 @@ if(EMSCRIPTEN)
319319
COMMAND ${CMAKE_COMMAND} -E echo " and can be run using: emrun --browser chrome ${JAVASCRIPT_BINDINGS_DIR}/index.html")
320320
endif()
321321
else()
322+
# If we are building a static version of libOpenCOR then we want to extract the object files from our various
323+
# packages and merge them into libOpenCOR. Indeed, a static library doesn't include its dependencies (it "only"
324+
# references them). So, we need to merge those dependencies into libOpenCOR and, sadly, there is no (easy?) way to
325+
# do this using CMake, so we must do it ourselves. Now, one (big!) downside of this approach is that it blows up the
326+
# size of libOpenCOR since it also merges parts of our dependencies that we don't actually need. So much so that we
327+
# cannot generate a debug version of libOpenCOR on Windows since it would result in a static library that is more
328+
# than 4GB in size (and MSVC's linker cannot create static libraries that big). This is clearly far from ideal, but
329+
# this is the only way to have a static version of libOpenCOR that can be used without having to "manually" link
330+
# against all of its dependencies.
331+
332+
if(NOT LIBOPENCOR_SHARED_LIBS)
333+
# Retrieve the path to our various packages.
334+
335+
set(PACKAGES_DIR ${CMAKE_BINARY_DIR}/packages)
336+
337+
file(GLOB_RECURSE PACKAGES "${PREBUILT_DIR}/*${CMAKE_STATIC_LIBRARY_SUFFIX}")
338+
339+
# Extract the object files from our various packages.
340+
341+
set(PACKAGES_OBJECT_FILES)
342+
343+
foreach(PACKAGE ${PACKAGES})
344+
get_filename_component(PACKAGE_NAME ${PACKAGE} NAME_WE)
345+
346+
set(PACKAGE_DIR ${PACKAGES_DIR}/${PACKAGE_NAME})
347+
348+
file(MAKE_DIRECTORY ${PACKAGE_DIR})
349+
350+
if(WIN32)
351+
execute_process(COMMAND ${CMAKE_AR} /NOLOGO /LIST ${PACKAGE}
352+
OUTPUT_VARIABLE PACKAGE_FILES
353+
OUTPUT_STRIP_TRAILING_WHITESPACE)
354+
355+
string(REPLACE "\n" ";" PACKAGE_FILES ${PACKAGE_FILES})
356+
357+
foreach(PACKAGE_FILE ${PACKAGE_FILES})
358+
string(REGEX MATCH ".*\\${CMAKE_CXX_OUTPUT_EXTENSION}$" IS_OBJECT_FILE ${PACKAGE_FILE})
359+
360+
if(IS_OBJECT_FILE)
361+
execute_process(COMMAND ${CMAKE_AR} /NOLOGO /EXTRACT:${PACKAGE_FILE} ${PACKAGE}
362+
WORKING_DIRECTORY ${PACKAGE_DIR})
363+
endif()
364+
endforeach()
365+
else()
366+
execute_process(COMMAND ${CMAKE_AR} -x ${PACKAGE}
367+
WORKING_DIRECTORY ${PACKAGE_DIR})
368+
endif()
369+
370+
file(GLOB_RECURSE PACKAGE_OBJECT_FILES ${PACKAGE_DIR}/*${CMAKE_CXX_OUTPUT_EXTENSION})
371+
372+
list(APPEND PACKAGES_OBJECT_FILES ${PACKAGE_OBJECT_FILES})
373+
endforeach()
374+
endif()
375+
322376
add_library(${CMAKE_PROJECT_NAME}
323377
${API_HEADER_FILES}
324378
${SOURCE_FILES}
325-
${HEADER_FILES})
379+
${HEADER_FILES}
380+
${PACKAGES_OBJECT_FILES})
326381

327382
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES
328383
CXX_VISIBILITY_PRESET hidden

src/support/combine/combinearchive.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ limitations under the License.
1818

1919
#include "utils.h"
2020

21+
#include "libcombinebegin.h"
2122
#include "combine/combinearchive.h"
23+
#include "omex/CaContent.h"
24+
#include "libcombineend.h"
2225

2326
#include "libopencor/file.h"
2427

25-
#include "omex/CaContent.h"
26-
2728
namespace libOpenCOR {
2829

2930
CombineArchive::Impl::Impl(const FilePtr &pFile, libcombine::CombineArchive *pArchive)

0 commit comments

Comments
 (0)