77# debugging but will never allow jemalloc in a release build if not on Linux.
88#
99# Usage: include(cmake/duckdb_loader.cmake) # Optionally load extensions
10- # set(CORE_EXTENSIONS "json;parquet;icu")
10+ # set(BUILD_EXTENSIONS "json;parquet;icu")
1111#
1212# # set sensible defaults for a debug build: duckdb_configure_for_debug()
1313#
@@ -35,7 +35,7 @@ _duckdb_set_default(DUCKDB_SOURCE_PATH
3535 "${CMAKE_CURRENT_SOURCE_DIR} /external/duckdb" )
3636
3737# Extension list - commonly used extensions for Python
38- _duckdb_set_default (CORE_EXTENSIONS "core_functions;parquet;icu;json" )
38+ _duckdb_set_default (BUILD_EXTENSIONS "core_functions;parquet;icu;json" )
3939
4040# Core build options - disable unnecessary components for Python builds
4141_duckdb_set_default (BUILD_SHELL OFF )
@@ -64,8 +64,8 @@ _duckdb_set_default(DEBUG_STACKTRACE OFF)
6464set (DUCKDB_SOURCE_PATH
6565 "${DUCKDB_SOURCE_PATH} "
6666 CACHE PATH "Path to DuckDB source directory" )
67- set (CORE_EXTENSIONS
68- "${CORE_EXTENSIONS } "
67+ set (BUILD_EXTENSIONS
68+ "${BUILD_EXTENSIONS } "
6969 CACHE STRING "Semicolon-separated list of extensions to enable" )
7070set (BUILD_SHELL
7171 "${BUILD_SHELL} "
@@ -110,40 +110,32 @@ set(DEBUG_STACKTRACE
110110
111111function (_duckdb_validate_jemalloc_config )
112112 # Check if jemalloc is in the extension list
113- if (NOT CORE_EXTENSIONS MATCHES "jemalloc" )
113+ if (NOT BUILD_EXTENSIONS MATCHES "jemalloc" )
114114 return ()
115115 endif ()
116116
117- # If we're on Linux then using jemalloc is fine, otherwise we only allow it in
118- # debug builds
119- if (NOT CMAKE_SYSTEM_NAME STREQUAL "Linux" )
120- set (is_debug_build FALSE )
121- if (CMAKE_BUILD_TYPE STREQUAL "Debug" )
122- set (is_debug_build TRUE )
123- endif ()
124- if (is_debug_build)
125- message (
126- WARNING
127- "jemalloc extension enabled on ${CMAKE_SYSTEM_NAME} in Debug build.\n "
128- "This is only recommended for debugging purposes.\n "
129- "jemalloc is officially supported only on Linux." )
130- else ()
131- message (
132- WARNING
133- "jemalloc extension is only supported on ${CMAKE_SYSTEM_NAME} in Debug builds.\n "
134- "Removing jemalloc from extension list.\n "
135- "In non-debug builds, jemalloc is only supported on Linux." )
136- # Remove jemalloc from the extension list
137- string (REPLACE "jemalloc" "" CORE_EXTENSIONS_FILTERED
138- "${CORE_EXTENSIONS} " )
139- string (REGEX REPLACE ";+" ";" CORE_EXTENSIONS_FILTERED
140- "${CORE_EXTENSIONS_FILTERED} " )
141- string (REGEX REPLACE "^;|;$" "" CORE_EXTENSIONS_FILTERED
142- "${CORE_EXTENSIONS_FILTERED} " )
143- set (CORE_EXTENSIONS
144- "${CORE_EXTENSIONS_FILTERED} "
145- PARENT_SCOPE )
146- endif ()
117+ # jemalloc is only enabled on 64bit x86 linux builds
118+ if (CMAKE_SIZEOF_VOID_P EQUAL 8
119+ AND CMAKE_SYSTEM_NAME STREQUAL "Linux"
120+ AND NOT BSD)
121+ set (jemalloc_allowed TRUE )
122+ else ()
123+ set (jemalloc_allowed FALSE )
124+ endif ()
125+
126+ if (NOT jemalloc_allowed)
127+ message (WARNING "jemalloc extension is only supported on Linux.\n "
128+ "Removing jemalloc from extension list." )
129+ # Remove jemalloc from the extension list
130+ string (REPLACE "jemalloc" "" BUILD_EXTENSIONS_FILTERED
131+ "${BUILD_EXTENSIONS} " )
132+ string (REGEX REPLACE ";+" ";" BUILD_EXTENSIONS_FILTERED
133+ "${BUILD_EXTENSIONS_FILTERED} " )
134+ string (REGEX REPLACE "^;|;$" "" BUILD_EXTENSIONS_FILTERED
135+ "${BUILD_EXTENSIONS_FILTERED} " )
136+ set (BUILD_EXTENSIONS
137+ "${BUILD_EXTENSIONS_FILTERED} "
138+ PARENT_SCOPE )
147139 endif ()
148140endfunction ()
149141
@@ -188,19 +180,17 @@ function(_duckdb_create_interface_target target_name)
188180 if (CMAKE_SYSTEM_NAME STREQUAL "Windows" )
189181 target_compile_options (
190182 ${target_name}
191- INTERFACE
192- /wd4244 # suppress Conversion from 'type1' to 'type2', possible loss of
193- # data
194- /wd4267 # suppress Conversion from ‘size_t’ to ‘type’, possible loss of
195- # data
196- /wd4200 # suppress Nonstandard extension used: zero-sized array in
197- # struct/union
198- /wd26451
199- /wd26495 # suppress Code Analysis
200- /D_CRT_SECURE_NO_WARNINGS # suppress warnings about unsafe functions
201- /D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR # see
202- # https://github.com/duckdblabs/duckdb-internal/issues/5151
203- /utf-8 # treat source files as UTF-8 encoded
183+ INTERFACE /wd4244 # suppress Conversion from 'type1' to 'type2', possible
184+ # loss of data
185+ /wd4267 # suppress Conversion from ‘size_t’ to ‘type’, possible
186+ # loss of data
187+ /wd4200 # suppress Nonstandard extension used: zero-sized array
188+ # in struct/union
189+ /wd26451
190+ /wd26495 # suppress Code Analysis
191+ /D_CRT_SECURE_NO_WARNINGS # suppress warnings about unsafe
192+ # functions
193+ /utf-8 # treat source files as UTF-8 encoded
204194 )
205195 elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin" )
206196 target_compile_options (
@@ -225,10 +215,6 @@ function(_duckdb_print_summary)
225215 message (STATUS " Native Arch: ${NATIVE_ARCH} " )
226216 message (STATUS " Unity Build Disabled: ${DISABLE_UNITY} " )
227217
228- if (CORE_EXTENSIONS)
229- message (STATUS " Extensions: ${CORE_EXTENSIONS} " )
230- endif ()
231-
232218 set (debug_opts)
233219 if (FORCE_ASSERT)
234220 list (APPEND debug_opts "FORCE_ASSERT" )
@@ -256,6 +242,26 @@ function(duckdb_add_library target_name)
256242
257243 # Create clean interface target
258244 _duckdb_create_interface_target (${target_name} )
245+
246+ # Propagate BUILD_EXTENSIONS back to caller scope in case it was modified
247+ set (BUILD_EXTENSIONS
248+ "${BUILD_EXTENSIONS} "
249+ PARENT_SCOPE )
250+ endfunction ()
251+
252+ function (duckdb_link_extensions target_name )
253+ # Link to the DuckDB static library and extensions
254+ target_link_libraries (${target_name}
255+ PRIVATE duckdb_generated_extension_loader )
256+ if (BUILD_EXTENSIONS)
257+ message (STATUS "Linking DuckDB extensions:" )
258+ foreach (ext IN LISTS BUILD_EXTENSIONS)
259+ message (STATUS "- ${ext} " )
260+ target_link_libraries (${target_name} PRIVATE ${ext} _extension )
261+ endforeach ()
262+ else ()
263+ message (STATUS "No DuckDB extensions linked in" )
264+ endif ()
259265endfunction ()
260266
261267# ════════════════════════════════════════════════════════════════════════════════
0 commit comments