Skip to content

Commit 06304b4

Browse files
committed
[cmake] Change directory structure for cpp2py library to match app4triqs
1 parent 9a6e011 commit 06304b4

28 files changed

+42
-19
lines changed

CMakeLists.txt

+4-3
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ MESSAGE(STATUS "LibClang additional flags: ${LIBCLANG_CXX_FLAGS}")
5151
set(LIBCLANG_CXX_FLAGS "${LIBCLANG_CXX_FLAGS}" CACHE STRING "Additional flags to be passed to libclang when parsing with clang")
5252
set(LIBCLANG_LOCATION "${LIBCLANG_LOCATION}" CACHE STRING "Location of the libclang library")
5353

54-
# Detect Python
54+
# --- Python ---
55+
5556
find_package(Python)
57+
add_library(cpp2py::python_and_numpy ALIAS python_and_numpy)
5658
install(TARGETS python_and_numpy EXPORT cpp2py-targets)
5759

5860
# find_package(Python3 COMPONENTS Development Interpreter)
@@ -74,8 +76,7 @@ install(TARGETS python_and_numpy EXPORT cpp2py-targets)
7476
# subdirs
7577
add_subdirectory(bin) # Executables
7678
add_subdirectory(cmake) # Exported Cpp2Py-Config
77-
add_subdirectory(include)
78-
add_subdirectory(lib)
79+
add_subdirectory(c++/cpp2py)
7980

8081
# The python modules
8182
add_subdirectory(cpp2py)

c++/cpp2py/CMakeLists.txt

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
add_library(cpp2py signal_handler.cpp exceptions.cpp)
2+
add_library(cpp2py::cpp2py ALIAS cpp2py)
3+
4+
target_compile_options(cpp2py PRIVATE -std=c++14 -fPIC)
5+
target_include_directories(cpp2py
6+
PUBLIC
7+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/c++>
8+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/c++>
9+
)
10+
11+
# Install the library in lib and export the cpp2py target
12+
install(TARGETS cpp2py EXPORT cpp2py-targets DESTINATION lib)
13+
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION include FILES_MATCHING PATTERN "*.hpp" PATTERN "*.h" PATTERN "*.hxx")
14+
15+
# --- Python ---
16+
17+
target_link_libraries(cpp2py PUBLIC python_and_numpy)
18+
19+
# ---------------
20+
21+
# Install the exported targets
22+
install(EXPORT cpp2py-targets NAMESPACE cpp2py:: DESTINATION lib/cmake/cpp2py)
File renamed without changes.
File renamed without changes.
File renamed without changes.

include/cpp2py/converters/string.hpp renamed to c++/cpp2py/converters/string.hpp

+13
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ namespace cpp2py {
2929
}
3030
};
3131

32+
template <> struct py_converter<unsigned char> {
33+
34+
static PyObject *c2py(unsigned char c) { return PyBytes_FromStringAndSize(reinterpret_cast<char *>(&c), 1); }
35+
36+
static unsigned char py2c(PyObject *ob) { return static_cast<unsigned char>(PyBytes_AsString(ob)[0]); }
37+
38+
static bool is_convertible(PyObject *ob, bool raise_exception) {
39+
if (PyBytes_Check(ob) and PyBytes_Size(ob) == 1) return true;
40+
if (raise_exception) { PyErr_SetString(PyExc_TypeError, "Cannot convert to unsigned char"); }
41+
return false;
42+
}
43+
};
44+
3245
template <> struct py_converter<const char *> {
3346

3447
static PyObject *c2py(const char *x) { return PyUnicode_FromString(x); }
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

cmake/Cpp2PyConfig.cmake.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ macro(add_cpp2py_module)
8585
COMMAND PYTHONPATH=${PROJECT_BINARY_DIR}:${PROJECT_BINARY_DIR}/python:${CPP2PY_ADD_MODULE_ADDITIONAL_PYTHONPATH}:$ENV{PYTHONPATH} ${CPP2PY_PYTHON_EXECUTABLE} ${desc_name} ${wrap_name})
8686

8787
add_library(${module_name} MODULE ${wrap_name})
88-
target_link_libraries(${module_name} cpp2py)
88+
target_link_libraries(${module_name} cpp2py::cpp2py)
8989

9090
set_target_properties(${module_name}
9191
PROPERTIES

cpp2py/mako/wrap.cxx

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using dcomplex = std::complex<double>;
66

77
// first the basic stuff
8-
#include <cpp2py.hpp>
8+
#include <cpp2py/cpp2py.hpp>
99
#include <cpp2py/converters/string.hpp>
1010

1111
// for converters
@@ -111,7 +111,7 @@ template <> struct py_converter<${c_name_absolute}> {
111111
if (raise_exception) {
112112
auto err = "Convertion of C++ enum ${c_name_absolute} : \nThe string \"" + s +"\" is not in [${','.join([str(x) for x in values])}]";
113113
PyErr_SetString(PyExc_ValueError, err.c_str());
114-
#include <cpp2py.hpp>
114+
#include <cpp2py/cpp2py.hpp>
115115
}
116116
return false;
117117
}

include/CMakeLists.txt

-1
This file was deleted.

lib/CMakeLists.txt

-12
This file was deleted.

0 commit comments

Comments
 (0)