Skip to content

Conversation

@ahoarau
Copy link

@ahoarau ahoarau commented Dec 10, 2025

In this PR we introduce the JRL CMake Modules v2, extracted from the repo: https://github.com/ahoarau/jrl-cmakemodules-v2

The integration on the user-side can be done as follows:

set(JRL_CMAKEMODULES_USE_V2 ON CACHE BOOL "Use jrl-cmakemodules v2")
if(JRL_CMAKEMODULES_SOURCE_DIR)
  message(STATUS "Using jrl-cmakemodules from source directory: ${JRL_CMAKEMODULES_SOURCE_DIR}")
  add_subdirectory(${JRL_CMAKEMODULES_SOURCE_DIR} jrl-cmakemodules)
else()
  find_package(jrl-cmakemodules 0.2.0 CONFIG REQUIRED)
endif()

We can still use the repo jrl-cmakemodules as usual, i.e. with pixi or manually installing it.
Either set an env variable JRL_CMAKEMODULES_SOURCE_DIR pointing to the jrl repo source location or use the installed version (find_package(...)).
Then define JRL_CMAKEMODULES_USE_V2 ON to bypass the v1 and use exclusively the v2.
We do not intend to use both v1 and v2 in projects.

TODO:

  • Port the main modules
  • Test the integration in client repo (proxsuite, eigenpy, nanoeigenpy, coal)
  • Figure out why gersemi still needs to re-format the new modules
  • Add COMPATIBLITY_OPTION for jrl_cmake_dependent_option()
  • Port tests from original repo
  • Port CI from original repo
  • Rewrite release.cmake in python (help wanted)

Copy link
Contributor

Choose a reason for hiding this comment

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

We must add copyright on all new files:

# Copyright 2025 INRIA

Copy link
Author

Choose a reason for hiding this comment

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

Done ✅

@@ -0,0 +1,58 @@
# jrl_boostpy_add_module(name [sources...])
function(jrl_boostpy_add_module name)
python_add_library(${name} MODULE WITH_SOABI ${ARGN})
Copy link
Contributor

Choose a reason for hiding this comment

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

This function depend of find_package(Python) call. We need to add guards to print a nice error if python_add_library is not defined.

Copy link
Author

Choose a reason for hiding this comment

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

Done for the Boost::python target as well

Comment on lines 28 to 33
mgr = DllDirectoryManager()
module_path = os.path.dirname(__file__)
mgr.safe_add_dll_directory(os.path.join(module_path, '..', '..', '..', 'bin'))
dll_dirs = @__DLL_DIRS__@
for dll_dir in dll_dirs:
mgr.safe_add_dll_directory(os.path.join(module_path, dll_dir))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think DllDirectoryManager.__del__ will never be called here.

mgr will never be delete when we import @__MODULE_NAME__@.

You can check it with toto.py:

class Toto:
    def __init__(self):
        print("toto.__init__")

    def __del__(self):
        print("toto.__del__")


t = Toto()

If you import toto Only enter will be called.

You need to use contextlib to handle it well.

Copy link
Author

Choose a reason for hiding this comment

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

fixed, thank for the insights. ✅


include(${CMAKE_CURRENT_SOURCE_DIR}/modules/jrl.cmake)

if(CMAKE_UTILS_BUILD_TESTS)
Copy link
Contributor

Choose a reason for hiding this comment

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

JRL_CMAKEMODULES_BUILD_TESTS is more appropriate.

Also, this should be an option.

Copy link
Author

Choose a reason for hiding this comment

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

oops I forgot that one, done ✅

@@ -1,5 +1,10 @@
cmake_minimum_required(VERSION 3.22)

if(JRL_CMAKEMODULES_USE_V2)
Copy link
Contributor

Choose a reason for hiding this comment

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

JRL_CMAKEMODULES_USE_V2 should be an option

Copy link
Author

Choose a reason for hiding this comment

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

done ✅

endif()
endfunction()

function(jrl_python_generate_init_py name)
Copy link
Contributor

Choose a reason for hiding this comment

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

Add some documentation

Comment on lines +1700 to +1739
if(NOT Python_EXECUTABLE)
message(
FATAL_ERROR
"Python_EXECUTABLE not defined.
Please use jrl_find_package(Python REQUIRED COMPONENT Interpreter)"
)
endif()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use jrl_check_var_defined ?

Also, in BoostPython.cmake you use $<TARGET_FILE:Python::Interpreter>. Which one is the best ?

Comment on lines 1738 to 1777
if(NOT Python_EXECUTABLE)
message(
FATAL_ERROR
"Python_EXECUTABLE not defined.
Please use jrl_find_package(Python REQUIRED COMPONENT Interpreter)"
)
endif()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use jrl_check_var_defined ?

Also, in BoostPython.cmake you use $<TARGET_FILE:Python::Interpreter>. Which one is the best ?

endif()
endfunction()

function(jrl_python_compute_install_dir output)
Copy link
Contributor

Choose a reason for hiding this comment

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

Add some documentation

Comment on lines 11 to 14
if(NOT PROJECT_IS_TOP_LEVEL)
return()
endif()

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't get it. We will return if included from the main CMakeLists.txt. Then we will not generate the configuration file.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's maybe clearer to directly include v2/modules/jrl.cmake in the PACKAGE_TOP_MACROS.

@nim65s nim65s self-requested a review December 15, 2025 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants