Skip to content

Commit d326372

Browse files
committed
Adjust add_cpp2py_module function to also take a DIRECTORY keyword
1 parent 660051b commit d326372

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

cmake/Cpp2PyConfig.cmake.in

+9-8
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,21 @@ include(@CMAKE_INSTALL_PREFIX@/lib/cmake/cpp2py/cpp2py-targets.cmake)
6666
# * Compiles the wrapper-code into the module ${module_name}.so
6767
#
6868
###################################################################################
69-
macro(add_cpp2py_module)
69+
function(add_cpp2py_module)
7070

7171
if(${ARGC} EQUAL 1)
7272
set(module_name ${ARGV0})
7373
else()
74-
cmake_parse_arguments(add_cpp2py_module "" "NAME" "DEPENDS" ${ARGN})
75-
set(module_name ${add_cpp2py_module_NAME})
76-
set(header_dependencies ${add_cpp2py_module_DEPENDS})
74+
cmake_parse_arguments(ARG "" "NAME;DIRECTORY" "DEPENDS" ${ARGN})
75+
set(module_name ${ARG_NAME})
76+
set(module_dir ${ARG_DIRECTORY})
77+
set(header_dependencies ${ARG_DEPENDS})
7778
endif()
7879

7980
message(STATUS "Adding cpp2py Python module ${module_name}")
8081

81-
set(desc_name ${CMAKE_CURRENT_SOURCE_DIR}/${module_name}_desc.py) # the desc file
82-
set(wrap_name ${CMAKE_CURRENT_BINARY_DIR}/${module_name}_wrap.cxx) # path to the wrapping code
82+
set(desc_name ${CMAKE_CURRENT_SOURCE_DIR}/${module_dir}/${module_name}_desc.py) # the desc file
83+
set(wrap_name ${CMAKE_CURRENT_BINARY_DIR}/${module_dir}/${module_name}_wrap.cxx) # path to the wrapping code
8384

8485
add_custom_command(OUTPUT ${wrap_name} DEPENDS ${desc_name} ${header_dependencies}
8586
COMMAND PYTHONPATH=${PROJECT_BINARY_DIR}:${PROJECT_BINARY_DIR}/python:${CPP2PY_ADD_MODULE_ADDITIONAL_PYTHONPATH}:$ENV{PYTHONPATH} ${CPP2PY_PYTHON_EXECUTABLE} ${desc_name} ${wrap_name})
@@ -93,13 +94,13 @@ macro(add_cpp2py_module)
9394
set_target_properties(${module_name}
9495
PROPERTIES
9596
PREFIX "" #eliminate the lib in front of the module name
96-
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
97+
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${module_dir}
9798
)
9899

99100
# Keep a list of every module target.
100101
# Usage : e.g. Documentation top target depends on them being built first
101102
set_property(GLOBAL APPEND PROPERTY CPP2PY_MODULES_LIST ${module_name})
102103

103-
endmacro(add_cpp2py_module)
104+
endfunction(add_cpp2py_module)
104105

105106
endif(NOT CPP2PY_FOUND)

cpp2py/CMakeLists.txt

+9-8
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,21 @@ execute_process(COMMAND ${PROJECT_BINARY_DIR}/bin/cp_rs ${CMAKE_CURRENT_SOURCE_D
2929
# * Compiles the wrapper-code into the module ${module_name}.so
3030
#
3131
###################################################################################
32-
macro(add_cpp2py_module)
32+
function(add_cpp2py_module)
3333

3434
if(${ARGC} EQUAL 1)
3535
set(module_name ${ARGV0})
3636
else()
37-
cmake_parse_arguments(add_cpp2py_module "" "NAME" "DEPENDS" ${ARGN})
38-
set(module_name ${add_cpp2py_module_NAME})
39-
set(header_dependencies ${add_cpp2py_module_DEPENDS})
37+
cmake_parse_arguments(ARG "" "NAME;DIRECTORY" "DEPENDS" ${ARGN})
38+
set(module_name ${ARG_NAME})
39+
set(module_dir ${ARG_DIRECTORY})
40+
set(header_dependencies ${ARG_DEPENDS})
4041
endif()
4142

4243
message(STATUS "Adding cpp2py Python module ${module_name}")
4344

44-
set(desc_name ${CMAKE_CURRENT_SOURCE_DIR}/${module_name}_desc.py) # the desc file
45-
set(wrap_name ${CMAKE_CURRENT_BINARY_DIR}/${module_name}_wrap.cxx) # path to the wrapping code
45+
set(desc_name ${CMAKE_CURRENT_SOURCE_DIR}/${module_dir}/${module_name}_desc.py) # the desc file
46+
set(wrap_name ${CMAKE_CURRENT_BINARY_DIR}/${module_dir}/${module_name}_wrap.cxx) # path to the wrapping code
4647

4748
add_custom_command(OUTPUT ${wrap_name} DEPENDS ${desc_name} ${header_dependencies}
4849
COMMAND PYTHONPATH=${PROJECT_BINARY_DIR}:${PROJECT_BINARY_DIR}/python:${CPP2PY_BINARY_DIR}:${CPP2PY_ADD_MODULE_ADDITIONAL_PYTHONPATH}:$ENV{PYTHONPATH} ${PYTHON_EXECUTABLE} ${desc_name} ${wrap_name})
@@ -56,11 +57,11 @@ macro(add_cpp2py_module)
5657
set_target_properties(${module_name}
5758
PROPERTIES
5859
PREFIX "" #eliminate the lib in front of the module name
59-
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
60+
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${module_dir}
6061
)
6162

6263
# Keep a list of every module target.
6364
# Usage : e.g. Documentation top target depends on them being built first
6465
set_property(GLOBAL APPEND PROPERTY CPP2PY_MODULES_LIST ${module_name})
6566

66-
endmacro(add_cpp2py_module)
67+
endfunction(add_cpp2py_module)

0 commit comments

Comments
 (0)