Skip to content
Open
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
54 changes: 29 additions & 25 deletions cpp/cmake/modules/FindCSP.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,39 @@ if(EXISTS "${CMAKE_SOURCE_DIR}/csp/__init__.py")
set(__csp_base_path "${CMAKE_SOURCE_DIR}/csp")
set(__csp_include_path "${CMAKE_SOURCE_DIR}/cpp")
set(__csp_lib_path "${CMAKE_SOURCE_DIR}/")
set(__csp_base_path "${CMAKE_SOURCE_DIR}/csp")
set(__csp_base_path "${CMAKE_SOURCE_DIR}/csp")
set(__csp_version "0.0.0")
else()
set(CSP_IN_SOURCE_BUILD OFF)
# Find out the base path by interrogating the installed csp
find_package(Python ${CSP_PYTHON_VERSION} EXACT REQUIRED COMPONENTS Interpreter)
execute_process(
COMMAND "${Python_EXECUTABLE}" -c
"from __future__ import print_function;import os.path;import csp;print(os.path.dirname(csp.__file__), end='')"
OUTPUT_VARIABLE __csp_base_path)

# Find out the include path
execute_process(
COMMAND "${Python_EXECUTABLE}" -c
"from __future__ import print_function;import csp;print(csp.get_include_path(), end='')"
OUTPUT_VARIABLE __csp_include_path)

# Find out the lib path
execute_process(
COMMAND "${Python_EXECUTABLE}" -c
"from __future__ import print_function;import csp;print(csp.get_lib_path(), end='')"
OUTPUT_VARIABLE __csp_lib_path)

# And the version
execute_process(
COMMAND "${Python_EXECUTABLE}" -c
"from __future__ import print_function;import csp;print(csp.__version__, end='')"
OUTPUT_VARIABLE __csp_version)

# find_package(CSP) is invoked once per csp_autogen() call (see Findcsp_autogen.cmake),
# and MODULE-mode find scripts re-run their whole body every time. The find_* calls below
# are cache variables so they no-op after the first run, but execute_process is not cached.
# Query all the csp paths/version in a single python subprocess and cache the results so the
# python interpreter is only spawned once for the entire configure step.
if(NOT DEFINED __csp_base_path)
execute_process(
COMMAND "${Python_EXECUTABLE}" -c
"import os.path;import csp;print('\\n'.join([os.path.dirname(csp.__file__), csp.get_include_path(), csp.get_lib_path(), csp.__version__]))"
OUTPUT_VARIABLE __csp_query_output
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE __csp_query_result)

if(NOT __csp_query_result EQUAL 0)
message(FATAL_ERROR "Failed to query csp package paths via ${Python_EXECUTABLE}")

@malhotrashivam malhotrashivam Aug 28, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Previously, a failed CSP import let find_package(CSP REQUIRED) fail while find_package(CSP QUIET) returned CSP_FOUND=FALSE. The new FATAL_ERROR aborts both. Can you please once verify if it even matters? Like do we need to support the REQUIRED/QUIET paramaters?

endif()

string(REPLACE "\n" ";" __csp_query_list "${__csp_query_output}")
list(GET __csp_query_list 0 __csp_base_path)
list(GET __csp_query_list 1 __csp_include_path)
list(GET __csp_query_list 2 __csp_lib_path)
list(GET __csp_query_list 3 __csp_version)

set(__csp_base_path "${__csp_base_path}" CACHE INTERNAL "csp package base path")

@malhotrashivam malhotrashivam Aug 28, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: CACHE INTERNAL persists across separate CMake configure runs, so reusing a build directory after changing CSP may retain old paths and versions. Can you please verify if that's okay? Should we use a CMake global property instead?

set(__csp_include_path "${__csp_include_path}" CACHE INTERNAL "csp include path")
set(__csp_lib_path "${__csp_lib_path}" CACHE INTERNAL "csp lib path")
set(__csp_version "${__csp_version}" CACHE INTERNAL "csp version")
endif()
endif()

# Now look for files
Expand Down
Loading