Skip to content

Commit 410503c

Browse files
authored
Merge pull request #11 from kunaltyagi/cmake-integration
2 parents 555b8f5 + b1bd3a6 commit 410503c

6 files changed

Lines changed: 43 additions & 7 deletions

File tree

bindings/python/scripts/generate.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
from typing import Any, List, Dict
2+
import os
3+
14
from context import scripts
25
import scripts.utils as utils
3-
from typing import Any, List, Dict
46

57

68
class bind:
@@ -427,12 +429,15 @@ def main():
427429
for source in args.files:
428430
source = utils.get_realpath(path=source)
429431
lines_to_write = generate(module_name="pcl", source=source)
432+
output_dir = utils.join_path(args.pybind11_output_path, "pybind11-gen")
430433
output_filepath = utils.get_output_path(
431434
source=source,
432-
output_dir=utils.join_path(args.pybind11_output_path, "pybind11-gen"),
435+
output_dir=output_dir,
433436
split_from="json",
434437
extension=".cpp",
435438
)
439+
out_rel_path = os.path.relpath(output_filepath, args.pybind11_output_path)
440+
print(f"Producing ./{out_rel_path}")
436441
utils.write_to_file(filename=output_filepath, linelist=lines_to_write)
437442

438443

bindings/python/scripts/parse.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import sys
23
import clang.cindex as clang
34

@@ -267,12 +268,15 @@ def main():
267268
parsed_info = parse_file(source, args.compilation_database_path)
268269

269270
# Output path for dumping the parsed info into a json file
271+
output_dir = utils.join_path(args.json_output_path, "json")
270272
output_filepath = utils.get_output_path(
271273
source=source,
272-
output_dir=utils.join_path(args.json_output_path, "json"),
273-
split_from="pcl",
274+
output_dir=output_dir,
275+
split_from=args.project_root,
274276
extension=".json",
275277
)
278+
out_rel_path = os.path.relpath(output_filepath, args.json_output_path)
279+
print(f"Producing ./{out_rel_path}")
276280

277281
# Dump the parsed info at output path
278282
utils.dump_json(filepath=output_filepath, info=parsed_info)

bindings/python/scripts/utils.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ def get_output_path(source, output_dir, split_from, extension):
3535
"""
3636

3737
# split_path: contains the path after splitting. For split_path = pcl, contains the path as seen in the pcl directory
38-
_, split_path = source.split(f"{split_from}{os.sep}", 1)
38+
split_path = source.split(f"{split_from}{os.sep}", 1)
39+
# handle the case where there's nothing to split
40+
split_path = split_path[1] if len(split_path) == 2 else split_path[0]
3941

4042
# relative_dir: contains the relative output path for the json file
4143
# source_filename: contains the source's file name
@@ -93,17 +95,22 @@ def parse_arguments(script):
9395
)
9496
parser.add_argument(
9597
"--json_output_path",
96-
default=get_parent_directory(file=__file__),
98+
default=os.getcwd(),
9799
help="Output path for generated json",
98100
)
101+
parser.add_argument(
102+
"--project-root",
103+
default=os.path.dirname(os.getcwd()),
104+
help="Path to split to make output paths shorter",
105+
)
99106
parser.add_argument("files", nargs="+", help="The source files to parse")
100107

101108
if script == "generate":
102109
parser = argparse.ArgumentParser(description="JSON to pybind11 generation")
103110
parser.add_argument("files", nargs="+", help="JSON input")
104111
parser.add_argument(
105112
"--pybind11_output_path",
106-
default=get_parent_directory(file=__file__),
113+
default=os.getcwd(),
107114
help="Output path for generated cpp",
108115
)
109116

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
project(clang_bind_test VERSION 0.0.1 LANGUAGES CXX)
3+
4+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
5+
6+
add_library(simple src/simple.cpp)
7+
target_include_directories(simple PUBLIC
8+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>
9+
$<INSTALL_INTERFACE:include/>
10+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma once
2+
3+
namespace simple {
4+
int add(int a, int b);
5+
} // namespace simple
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <clang_bind_test/function.hpp>
2+
3+
namespace simple {
4+
int add(int a, int b) { return a + b; }
5+
} // namespace simple

0 commit comments

Comments
 (0)