Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split C++ code in 2 separate shared libraries #32

Merged
merged 2 commits into from
Jan 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ script:
--warn-uninitialized \
-DUSE_CLANG_TIDY:BOOL=ON \
-DBasalt_CXX_OPTIMIZE:BOOL=$CXX_OPTIMIZE \
-DPYTHON_EXECUTABLE:FILEPATH=`which python3` \
-DCMAKE_CXX_STANDARD=$CPP \
- make VERBOSE=1 -j2
- ctest -j2 --output-on-failure
Expand Down
9 changes: 6 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ include(cmake/bob.cmake)
bob_begin_package()

bob_option(Basalt_USE_pybind11 "Build Python bindings" OFF)
bob_option(Basalt_BUILD_PYTHON_PACKAGE "Build Python package" OFF)
bob_option(USE_CLANG_TIDY "Perform C++ static analysis while compiling" OFF)

set(Basalt_SERIALIZATION_METHODS CEREAL SSTREAM)
Expand Down Expand Up @@ -81,9 +80,13 @@ set(spdlog_include_directory
if(USE_CLANG_TIDY)
cmake_minimum_required(VERSION 3.8)
find_package(ClangTidy REQUIRED)
set(CLANG_TIDY_ARGS "-extra-arg=-Wno-unknown-warning-option"
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CLANG_TIDY_ARGS -extra-arg=-Wno-unknown-warning-option
CACHE STRING "clang-tidy command options")
set(CMAKE_CXX_CLANG_TIDY "${ClangTidy_EXECUTABLE}" ${CLANG_TIDY_ARGS})
set(CMAKE_CXX_CLANG_TIDY
"${ClangTidy_EXECUTABLE}"
-p "${CMAKE_BINARY_DIR}/compile_commands.json"
${CLANG_TIDY_ARGS})
endif()
add_subdirectory(src)
if(NOT Basalt_BUILD_PYTHON_PACKAGE)
Expand Down
1 change: 1 addition & 0 deletions basalt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from enum import Enum

from _basalt import *
from _basalt import __version__, __rocksdb_version__

Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ def build_extension(self, ext):
'-DPYTHON_EXECUTABLE=' + sys.executable,
'-DBasalt_USE_pybind11:BOOL=True',
'-DCMAKE_BUILD_TYPE=',
'-DBasalt_BUILD_PYTHON_PACKAGE:BOOL=TRUE',
]

optimize = 'ON' if self.debug else 'OFF'
build_args = ['--config', optimize]
build_args = ['--config', optimize, '--target', '_basalt']

if platform.system() == "Windows":
cmake_args += [
Expand Down
42 changes: 18 additions & 24 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pure C++ shared library
set(basalt_SOURCES
basalt/connections.cpp
basalt/graph.hpp
Expand Down Expand Up @@ -28,33 +29,26 @@ include_directories(${cereal_include_directory}
${CMAKE_CURRENT_SOURCE_DIR}/basalt
${CMAKE_CURRENT_BINARY_DIR})

add_library(basalt_obj OBJECT ${basalt_SOURCES} ${basalt_HEADERS})
set_property(TARGET basalt_obj PROPERTY POSITION_INDEPENDENT_CODE ON)

# Shared library
add_library(basalt SHARED $<TARGET_OBJECTS:basalt_obj>)
target_link_libraries(basalt ${RocksDB_LIBRARIES})
bob_library_includes(basalt)
bob_export_target(basalt)
install(FILES ${basalt_HEADERS} DESTINATION include)

# Shared library with Python bindings
set(PYBIND11_SOURCES
basalt/circuit_payloads.hpp
basalt/circuit_payloads.cpp
basalt/py_basalt.cpp
basalt/py_helpers.hpp)
set(PYBIND11_CPP_STANDARD -std=c++11)

if(Basalt_BUILD_PYTHON_PACKAGE)
add_subdirectory(${pybind11_project_directory})
pybind11_add_module(_basalt
${PYBIND11_SOURCES}
${basalt_SOURCES}
${basalt_HEADERS})
target_link_libraries(_basalt PRIVATE ${RocksDB_LIBRARIES})
else()
add_library(basalt ${basalt_SOURCES} ${basalt_HEADERS})
bob_library_includes(basalt)
bob_export_target(basalt)
target_link_libraries(basalt ${RocksDB_LIBRARIES})
install(FILES ${basalt_HEADERS} DESTINATION include)

if(Basalt_USE_pybind11)
add_subdirectory(third_party/pybind11)
pybind11_add_module(pybasalt
${PYBIND11_SOURCES}
${basalt_SOURCES}
${basalt_HEADERS})
target_link_libraries(pybasalt PRIVATE ${RocksDB_LIBRARIES})
endif()
endif()
add_subdirectory(${pybind11_project_directory})
pybind11_add_module(_basalt
SHARED
${PYBIND11_SOURCES}
$<TARGET_OBJECTS:basalt_obj>)
target_link_libraries(_basalt PRIVATE ${RocksDB_LIBRARIES})
2 changes: 1 addition & 1 deletion tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include_directories(${catch2_include_directory} ${cereal_include_directory})

add_executable(unit-tests 101.cpp)
target_link_libraries(unit-tests PRIVATE basalt)
target_link_libraries(unit-tests PRIVATE _basalt ${PYTHON_LIBRARIES})

add_test(NAME unit-tests COMMAND $<TARGET_FILE:unit-tests>)