@@ -22,10 +22,41 @@ endif()
2222set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR } /cmake"
2323 "${CMAKE_MODULE_PATH } " )
2424
25+ # ##############################################################################
26+ # Resolve the project version
27+ # ##############################################################################
28+ # Must run before project(), which needs the numeric version up front. See
29+ # cmake/PyinterpVersion.cmake for the list of sources and their precedence.
30+ include (PyinterpVersion )
31+ pyinterp_resolve_version ("${CMAKE_CURRENT_SOURCE_DIR } " )
32+
2533# ##############################################################################
2634# Project settings
2735# ##############################################################################
28- project (pyinterp LANGUAGES CXX )
36+ project (
37+ pyinterp
38+ VERSION ${PYINTERP_VERSION_STRING}
39+ LANGUAGES CXX )
40+
41+ # Export the version to a parent project (add_subdirectory, FetchContent).
42+ pyinterp_publish_version ()
43+
44+ # ##############################################################################
45+ # Sub-project detection
46+ # ##############################################################################
47+ # When pyinterp is consumed as a CMake sub-project, the caller wants the C++
48+ # library, not the Python extension: building the bindings would drag in Python,
49+ # nanobind and the stub generation for nothing. PROJECT_IS_TOP_LEVEL needs CMake
50+ # 3.21, so derive it by hand to keep the 3.19 requirement.
51+ if ("${CMAKE_SOURCE_DIR } " STREQUAL "${CMAKE_CURRENT_SOURCE_DIR } " )
52+ set (PYINTERP_IS_TOP_LEVEL ON )
53+ else ()
54+ set (PYINTERP_IS_TOP_LEVEL OFF )
55+ endif ()
56+
57+ option (PYINTERP_BUILD_PYTHON_BINDINGS
58+ "Build the pyinterp.core Python extension" ${PYINTERP_IS_TOP_LEVEL} )
59+ option (PYINTERP_BUILD_TESTS "Build the C++ unit tests" ${PYINTERP_IS_TOP_LEVEL} )
2960
3061# ##############################################################################
3162# CMake policies
@@ -277,7 +308,9 @@ if(NOT WIN32)
277308endif ()
278309
279310# Python
280- if (CMAKE_CROSSCOMPILING OR DEFINED ENV{CONDA_BUILD_CROSS_COMPILATION})
311+ if (NOT PYINTERP_BUILD_PYTHON_BINDINGS)
312+ # Nothing to do: the Python extension is not being built.
313+ elseif (CMAKE_CROSSCOMPILING OR DEFINED ENV{CONDA_BUILD_CROSS_COMPILATION})
281314 if (NOT DEFINED PYTHON_ROOT_DIR AND DEFINED ENV{PREFIX})
282315 set (PYTHON_ROOT_DIR "$ENV{PREFIX} " )
283316 endif ()
@@ -342,7 +375,9 @@ else()
342375 OPTIONAL_COMPONENTS Development.SABIModule
343376 REQUIRED )
344377endif ()
345- include_directories (SYSTEM PRIVATE ${Python_INCLUDE_DIRS} )
378+ if (PYINTERP_BUILD_PYTHON_BINDINGS)
379+ include_directories (SYSTEM ${Python_INCLUDE_DIRS} )
380+ endif ()
346381
347382# BLAS
348383#
@@ -372,7 +407,7 @@ if(BLAS_FOUND)
372407 if (MKL_INCLUDE_DIR)
373408 add_definitions (-DEIGEN_USE_MKL_ALL )
374409 add_definitions (-DMKL_LP64 )
375- include_directories (SYSTEM PRIVATE ${MKL_INCLUDE_DIR} )
410+ include_directories (SYSTEM ${MKL_INCLUDE_DIR} )
376411 endif ()
377412 endif ()
378413else ()
@@ -398,12 +433,13 @@ else()
398433endif ()
399434
400435# Eigen3
401- include_directories (SYSTEM PRIVATE
402- ${CMAKE_CURRENT_SOURCE_DIR } /third_party/eigen )
436+ include_directories (SYSTEM ${CMAKE_CURRENT_SOURCE_DIR } /third_party/eigen )
403437
404438# GoogleTest
405- include (CTest )
406- find_package (GTest )
439+ if (PYINTERP_BUILD_TESTS)
440+ include (CTest )
441+ find_package (GTest )
442+ endif ()
407443
408444# ##############################################################################
409445# Parse FFT implementation configuration
@@ -431,8 +467,7 @@ endif()
431467
432468# MKL does not provide a Discrete Cosine Transform (DCT). Always use pocketfft
433469# for DCTs even when MKL is chosen as the FFT backend.
434- include_directories (SYSTEM PRIVATE
435- ${CMAKE_CURRENT_SOURCE_DIR } /third_party/pocketfft )
470+ include_directories (SYSTEM ${CMAKE_CURRENT_SOURCE_DIR } /third_party/pocketfft )
436471if (FFT_IMPLEMENTATION STREQUAL "pocketfft" )
437472 set (FFT_LIBRARIES)
438473endif ()
@@ -475,9 +510,11 @@ endif()
475510# ##############################################################################
476511# Add subdirectories
477512# ##############################################################################
478- add_subdirectory (${CMAKE_CURRENT_SOURCE_DIR } /third_party/nanobind )
479- include_directories (SYSTEM
480- ${CMAKE_CURRENT_SOURCE_DIR } /third_party/nanobind/include )
513+ if (PYINTERP_BUILD_PYTHON_BINDINGS)
514+ add_subdirectory (${CMAKE_CURRENT_SOURCE_DIR } /third_party/nanobind )
515+ include_directories (SYSTEM
516+ ${CMAKE_CURRENT_SOURCE_DIR } /third_party/nanobind/include )
517+ endif ()
481518
482519# ##############################################################################
483520# External dependencies
@@ -545,14 +582,14 @@ if(NOT Boost_FOUND)
545582 check_boost_version ("${Boost_INCLUDE_DIRS} " "1.90.0" )
546583endif ()
547584
548- include_directories (SYSTEM PRIVATE ${Boost_INCLUDE_DIRS} )
585+ include_directories (SYSTEM ${Boost_INCLUDE_DIRS} )
549586
550587add_subdirectory (cxx )
551588
552589# ##############################################################################
553590# Disable clang-tidy for third-party targets (after add_subdirectory)
554591# ##############################################################################
555- if (ENABLE_CLANG_TIDY)
592+ if (ENABLE_CLANG_TIDY AND TARGET nanobind-static )
556593 set_target_properties (nanobind-static PROPERTIES CXX_CLANG_TIDY "" )
557594endif ()
558595
@@ -587,6 +624,8 @@ format_enabled(ENABLE_CLANG_TIDY CLANG_TIDY_LINE)
587624
588625set (CONFIG_LINES
589626 "==================[ PyInterp Configuration Summary ]=================="
627+ "Version: ${PYINTERP_VERSION_FULL} "
628+ "Version source: ${PYINTERP_VERSION_SOURCE} "
590629 "Platform: ${CMAKE_SYSTEM_NAME } ${CMAKE_SYSTEM_PROCESSOR } "
591630 "Build type: ${CMAKE_BUILD_TYPE } "
592631 "CMake Version: ${CMAKE_VERSION } "
0 commit comments