Skip to content

Commit

Permalink
[cmake] Change directory structure for cpp2py library to match app4triqs
Browse files Browse the repository at this point in the history
  • Loading branch information
Wentzell committed May 26, 2020
1 parent 9a6e011 commit 06304b4
Show file tree
Hide file tree
Showing 28 changed files with 42 additions and 19 deletions.
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ MESSAGE(STATUS "LibClang additional flags: ${LIBCLANG_CXX_FLAGS}")
set(LIBCLANG_CXX_FLAGS "${LIBCLANG_CXX_FLAGS}" CACHE STRING "Additional flags to be passed to libclang when parsing with clang")
set(LIBCLANG_LOCATION "${LIBCLANG_LOCATION}" CACHE STRING "Location of the libclang library")

# Detect Python
# --- Python ---

find_package(Python)
add_library(cpp2py::python_and_numpy ALIAS python_and_numpy)
install(TARGETS python_and_numpy EXPORT cpp2py-targets)

# find_package(Python3 COMPONENTS Development Interpreter)
Expand All @@ -74,8 +76,7 @@ install(TARGETS python_and_numpy EXPORT cpp2py-targets)
# subdirs
add_subdirectory(bin) # Executables
add_subdirectory(cmake) # Exported Cpp2Py-Config
add_subdirectory(include)
add_subdirectory(lib)
add_subdirectory(c++/cpp2py)

# The python modules
add_subdirectory(cpp2py)
Expand Down
22 changes: 22 additions & 0 deletions c++/cpp2py/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
add_library(cpp2py signal_handler.cpp exceptions.cpp)
add_library(cpp2py::cpp2py ALIAS cpp2py)

target_compile_options(cpp2py PRIVATE -std=c++14 -fPIC)
target_include_directories(cpp2py
PUBLIC
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/c++>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/c++>
)

# Install the library in lib and export the cpp2py target
install(TARGETS cpp2py EXPORT cpp2py-targets DESTINATION lib)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION include FILES_MATCHING PATTERN "*.hpp" PATTERN "*.h" PATTERN "*.hxx")

# --- Python ---

target_link_libraries(cpp2py PUBLIC python_and_numpy)

# ---------------

# Install the exported targets
install(EXPORT cpp2py-targets NAMESPACE cpp2py:: DESTINATION lib/cmake/cpp2py)
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.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ namespace cpp2py {
}
};

template <> struct py_converter<unsigned char> {

static PyObject *c2py(unsigned char c) { return PyBytes_FromStringAndSize(reinterpret_cast<char *>(&c), 1); }

static unsigned char py2c(PyObject *ob) { return static_cast<unsigned char>(PyBytes_AsString(ob)[0]); }

static bool is_convertible(PyObject *ob, bool raise_exception) {
if (PyBytes_Check(ob) and PyBytes_Size(ob) == 1) return true;
if (raise_exception) { PyErr_SetString(PyExc_TypeError, "Cannot convert to unsigned char"); }
return false;
}
};

template <> struct py_converter<const char *> {

static PyObject *c2py(const char *x) { return PyUnicode_FromString(x); }
Expand Down
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.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion cmake/Cpp2PyConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ macro(add_cpp2py_module)
COMMAND PYTHONPATH=${PROJECT_BINARY_DIR}:${PROJECT_BINARY_DIR}/python:${CPP2PY_ADD_MODULE_ADDITIONAL_PYTHONPATH}:$ENV{PYTHONPATH} ${CPP2PY_PYTHON_EXECUTABLE} ${desc_name} ${wrap_name})

add_library(${module_name} MODULE ${wrap_name})
target_link_libraries(${module_name} cpp2py)
target_link_libraries(${module_name} cpp2py::cpp2py)

set_target_properties(${module_name}
PROPERTIES
Expand Down
4 changes: 2 additions & 2 deletions cpp2py/mako/wrap.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using dcomplex = std::complex<double>;

// first the basic stuff
#include <cpp2py.hpp>
#include <cpp2py/cpp2py.hpp>
#include <cpp2py/converters/string.hpp>

// for converters
Expand Down Expand Up @@ -111,7 +111,7 @@ template <> struct py_converter<${c_name_absolute}> {
if (raise_exception) {
auto err = "Convertion of C++ enum ${c_name_absolute} : \nThe string \"" + s +"\" is not in [${','.join([str(x) for x in values])}]";
PyErr_SetString(PyExc_ValueError, err.c_str());
#include <cpp2py.hpp>
#include <cpp2py/cpp2py.hpp>
}
return false;
}
Expand Down
1 change: 0 additions & 1 deletion include/CMakeLists.txt

This file was deleted.

12 changes: 0 additions & 12 deletions lib/CMakeLists.txt

This file was deleted.

0 comments on commit 06304b4

Please sign in to comment.