@@ -9,23 +9,9 @@ include("../cmake/CompilerWarnings.cmake")
99
1010project (libmambapy)
1111
12- # Link to aggregated libmamba target (includes all components) For solver-only usage (e.g.,
13- # conda-libmamba-solver), could link to: mamba::libmamba-common-dyn (or -static) and
14- # mamba::libmamba-solver-dyn (or -static) instead of the full libmamba target
15- if (NOT TARGET mamba::libmamba)
12+ # Find libmamba components
13+ if (NOT TARGET mamba::libmamba-common-dyn AND NOT TARGET mamba::libmamba-common-static)
1614 find_package (libmamba CONFIG REQUIRED )
17- # Try to find component targets first, fall back to aggregated
18- if (TARGET mamba::libmamba-common-dyn AND TARGET mamba::libmamba-solver-dyn)
19- # For now, still use aggregated target for full functionality TODO: Create solver-only
20- # bindings target for conda-libmamba-solver
21- set (libmamba_target mamba::libmamba-dyn)
22- elseif (TARGET mamba::libmamba-dyn)
23- set (libmamba_target mamba::libmamba-dyn)
24- else ()
25- set (libmamba_target mamba::libmamba)
26- endif ()
27- else ()
28- set (libmamba_target mamba::libmamba)
2915endif ()
3016
3117if (NOT TARGET mamba::libmamba-dyn-spdlog)
@@ -36,19 +22,90 @@ find_package(Python COMPONENTS Interpreter Development.Module)
3622find_package (pybind11 REQUIRED )
3723find_package (msgpack-c REQUIRED )
3824
25+ # Set variables for component CMakeLists.txt files
26+ set (LIBMAMBAPY_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} /bindings)
27+ set (LIBMAMBAPY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} )
28+
29+ # Build component bindings
30+ # ========================
31+ # Build order: common → solver (mirrors libmamba component order)
32+
33+ # Include component CMakeLists.txt files
34+ add_subdirectory (common )
35+ add_subdirectory (solver )
36+
37+ # Determine linkage type from libmamba components
38+ if (TARGET mamba::libmamba-common-dyn)
39+ set (BUILD_SHARED_BINDINGS ON )
40+ set (BUILD_STATIC_BINDINGS OFF )
41+ elseif (TARGET mamba::libmamba-common-static)
42+ set (BUILD_SHARED_BINDINGS OFF )
43+ set (BUILD_STATIC_BINDINGS ON )
44+ else ()
45+ message (FATAL_ERROR "Neither libmamba-common-dyn nor libmamba-common-static found" )
46+ endif ()
47+
48+ # Create component binding targets
49+ if (BUILD_SHARED_BINDINGS)
50+ libmambapy_common_create_target (libmambapy-common SHARED )
51+ libmambapy_solver_create_target (libmambapy-solver SHARED )
52+ endif ()
53+
54+ if (BUILD_STATIC_BINDINGS)
55+ libmambapy_common_create_target (libmambapy-common-static STATIC )
56+ libmambapy_solver_create_target (libmambapy-solver-static STATIC )
57+ endif ()
58+
59+ # Create aggregated bindings module for backward compatibility
60+ # ============================================================
61+ # This module includes legacy.cpp and re-exports component modules
62+
63+ # Determine which libmamba target to use for aggregated module
64+ if (BUILD_SHARED_BINDINGS)
65+ if (TARGET mamba::libmamba-dyn)
66+ set (libmamba_target mamba::libmamba-dyn)
67+ else ()
68+ # Fall back to component targets
69+ set (
70+ libmamba_target
71+ mamba::libmamba-common-dyn
72+ mamba::libmamba-solver-dyn
73+ mamba::libmamba-network-dyn
74+ mamba::libmamba-archive-dyn
75+ )
76+ endif ()
77+ else ()
78+ if (TARGET mamba::libmamba-static)
79+ set (libmamba_target mamba::libmamba-static)
80+ else ()
81+ # Fall back to component targets
82+ set (
83+ libmamba_target
84+ mamba::libmamba-common-static
85+ mamba::libmamba-solver-static
86+ mamba::libmamba-network-static
87+ mamba::libmamba-archive-static
88+ )
89+ endif ()
90+ endif ()
91+
92+ # Create aggregated bindings module for backward compatibility This module includes all bindings and
93+ # maintains the same API as before
3994pybind11_add_module (
4095 bindings
4196 bindings/longpath.manifest
4297 # Entry point to all submodules
4398 bindings/bindings.cpp
4499 # All bindings used to live in a global module
45100 bindings/legacy.cpp
46- # Submodules
101+ # Component bindings (included for backward compatibility) Note: Component modules are separate
102+ # optional modules
47103 bindings/utils.cpp
48104 bindings/specs.cpp
49105 bindings/solver.cpp
50106 bindings/solver_libsolv.cpp
51107)
108+
52109# TODO: remove when `SubdirData::cache_path()` is removed
53110if (
54111 CMAKE_CXX_COMPILER_ID STREQUAL "Clang"
@@ -68,6 +125,11 @@ mamba_target_add_compile_warnings(bindings WARNING_AS_ERROR ${MAMBA_WARNING_AS_E
68125target_link_libraries (
69126 bindings PRIVATE pybind11::pybind11 ${libmamba_target} mamba::libmamba-dyn-spdlog msgpack-c
70127)
128+ # Note: Component modules (libmambapy-common, libmambapy-solver) are separate Python extension
129+ # modules and cannot be linked to the aggregated bindings module. They are optional and can be
130+ # imported independently. The aggregated bindings module includes all source files for backward
131+ # compatibility.
132+
71133target_compile_features (bindings PUBLIC cxx_std_20 )
72134set_target_properties (
73135 bindings
@@ -78,15 +140,32 @@ set_target_properties(
78140)
79141
80142# Installation
143+ # ============
81144
82145if (SKBUILD)
146+ # Install all component modules and aggregated module
83147 install (TARGETS bindings DESTINATION libmambapy)
148+ if (BUILD_SHARED_BINDINGS)
149+ if (TARGET libmambapy-common)
150+ install (TARGETS libmambapy-common DESTINATION libmambapy)
151+ endif ()
152+ if (TARGET libmambapy-solver)
153+ install (TARGETS libmambapy-solver DESTINATION libmambapy)
154+ endif ()
155+ else ()
156+ if (TARGET libmambapy-common-static)
157+ install (TARGETS libmambapy-common-static DESTINATION libmambapy)
158+ endif ()
159+ if (TARGET libmambapy-solver-static)
160+ install (TARGETS libmambapy-solver-static DESTINATION libmambapy)
161+ endif ()
162+ endif ()
84163else ()
85164 # WARNING: this default should probably not be used for installation but only for local
86165 # development and testing. Proper installation should be controlled externally by a Python
87166 # packager tool
88167
89- # Build bindings in a self-contain libmambapy/ folder inside the build tree
168+ # Build bindings in a self-contained libmambapy/ folder inside the build tree
90169 set_target_properties (
91170 bindings PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR} /libmambapy"
92171 )
@@ -107,16 +186,89 @@ else()
107186 )
108187 add_dependencies (bindings libmambapy_copy_files )
109188
189+ # Also copy component module directories (if they exist) These are included in the main
190+ # copy_directory command above, so no separate commands needed
191+
192+ # Set output directories for component modules to be in the same location as bindings
193+ if (BUILD_SHARED_BINDINGS)
194+ if (TARGET libmambapy-common)
195+ set_target_properties (
196+ libmambapy-common
197+ PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR} /libmambapy"
198+ )
199+ add_dependencies (libmambapy-common libmambapy_copy_files )
200+ endif ()
201+ if (TARGET libmambapy-solver)
202+ set_target_properties (
203+ libmambapy-solver
204+ PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR} /libmambapy"
205+ )
206+ add_dependencies (libmambapy-solver libmambapy_copy_files )
207+ endif ()
208+ else ()
209+ if (TARGET libmambapy-common-static)
210+ set_target_properties (
211+ libmambapy-common-static
212+ PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR} /libmambapy"
213+ )
214+ add_dependencies (libmambapy-common-static libmambapy_copy_files )
215+ endif ()
216+ if (TARGET libmambapy-solver-static)
217+ set_target_properties (
218+ libmambapy-solver-static
219+ PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR} /libmambapy"
220+ )
221+ add_dependencies (libmambapy-solver-static libmambapy_copy_files )
222+ endif ()
223+ endif ()
224+
110225 set (
111226 MAMBA_INSTALL_PYTHON_EXT_LIBDIR
112227 "lib"
113228 CACHE PATH "Installation directory for Python extension"
114229 )
115230
231+ # Install all targets
116232 install (
117233 TARGETS bindings
118234 EXCLUDE_FROM_ALL
119235 COMPONENT Mamba_Python_Extension
120236 DESTINATION ${MAMBA_INSTALL_PYTHON_EXT_LIBDIR}
121237 )
238+
239+ if (BUILD_SHARED_BINDINGS)
240+ if (TARGET libmambapy-common)
241+ install (
242+ TARGETS libmambapy-common
243+ EXCLUDE_FROM_ALL
244+ COMPONENT Mamba_Python_Extension
245+ DESTINATION ${MAMBA_INSTALL_PYTHON_EXT_LIBDIR}
246+ )
247+ endif ()
248+ if (TARGET libmambapy-solver)
249+ install (
250+ TARGETS libmambapy-solver
251+ EXCLUDE_FROM_ALL
252+ COMPONENT Mamba_Python_Extension
253+ DESTINATION ${MAMBA_INSTALL_PYTHON_EXT_LIBDIR}
254+ )
255+ endif ()
256+ else ()
257+ if (TARGET libmambapy-common-static)
258+ install (
259+ TARGETS libmambapy-common-static
260+ EXCLUDE_FROM_ALL
261+ COMPONENT Mamba_Python_Extension
262+ DESTINATION ${MAMBA_INSTALL_PYTHON_EXT_LIBDIR}
263+ )
264+ endif ()
265+ if (TARGET libmambapy-solver-static)
266+ install (
267+ TARGETS libmambapy-solver-static
268+ EXCLUDE_FROM_ALL
269+ COMPONENT Mamba_Python_Extension
270+ DESTINATION ${MAMBA_INSTALL_PYTHON_EXT_LIBDIR}
271+ )
272+ endif ()
273+ endif ()
122274endif ()
0 commit comments