Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions cmake/nanobind-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ endfunction()
# ---------------------------------------------------------------------------

function (nanobind_build_library TARGET_NAME)
cmake_parse_arguments(PARSE_ARGV 1 ARG
"AS_SYSINCLUDE" "" "")

if (TARGET ${TARGET_NAME})
return()
endif()
Expand All @@ -114,6 +117,10 @@ function (nanobind_build_library TARGET_NAME)
set (TARGET_TYPE SHARED)
endif()

if (${ARG_AS_SYSINCLUDE})
set (AS_SYSINCLUDE SYSTEM)
endif()

add_library(${TARGET_NAME} ${TARGET_TYPE}
EXCLUDE_FROM_ALL
${NB_DIR}/include/nanobind/make_iterator.h
Expand Down Expand Up @@ -238,7 +245,7 @@ function (nanobind_build_library TARGET_NAME)
${NB_DIR}/ext/robin_map/include)
endif()

target_include_directories(${TARGET_NAME} PUBLIC
target_include_directories(${TARGET_NAME} ${AS_SYSINCLUDE} PUBLIC
${Python_INCLUDE_DIRS}
${NB_DIR}/include)

Expand Down Expand Up @@ -312,7 +319,7 @@ endfunction()

function(nanobind_add_module name)
cmake_parse_arguments(PARSE_ARGV 1 ARG
"STABLE_ABI;FREE_THREADED;NB_STATIC;NB_SHARED;PROTECT_STACK;LTO;NOMINSIZE;NOSTRIP;MUSL_DYNAMIC_LIBCPP"
"STABLE_ABI;FREE_THREADED;NB_STATIC;NB_SHARED;PROTECT_STACK;LTO;NOMINSIZE;NOSTRIP;MUSL_DYNAMIC_LIBCPP;NB_SUPPRESS_WARNINGS"
"NB_DOMAIN" "")

add_library(${name} MODULE ${ARG_UNPARSED_ARGUMENTS})
Expand Down Expand Up @@ -357,7 +364,11 @@ function(nanobind_add_module name)
set(libname ${libname}-${ARG_NB_DOMAIN})
endif()

nanobind_build_library(${libname})
if (ARG_NB_SUPPRESS_WARNINGS)
set(EXTRA_LIBRARY_PARAMS AS_SYSINCLUDE)
endif()

nanobind_build_library(${libname} ${EXTRA_LIBRARY_PARAMS})

if (ARG_NB_DOMAIN)
target_compile_definitions(${name} PRIVATE NB_DOMAIN=${ARG_NB_DOMAIN})
Expand Down
7 changes: 7 additions & 0 deletions docs/api_cmake.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ The high-level interface consists of just one CMake command:
- The opposite of ``NB_STATIC``: compile the core nanobind library
as a shared library for use in projects that consist of multiple
extensions.
* - ``NB_SUPPRESS_WARNINGS``
- Mark the include directories of nanobind and Python as
[SYSTEM](https://cmake.org/cmake/help/latest/command/include_directories.html)
include directories, which suppresses any potential warning messages
originating there. This is mainly of relevance if your project artificially
raises the warning level via flags like `-pedantic`, ``-Wcast-qual``,
``-Wsign-conversion``.
* - ``PROTECT_STACK``
- Don't remove stack smashing-related protections.
* - ``LTO``
Expand Down
Loading