Skip to content

Commit

Permalink
Updated linking against XAD to avoid linker problems
Browse files Browse the repository at this point in the history
  • Loading branch information
auto-differentiation-dev committed Apr 4, 2024
1 parent 110f31b commit d3eb89b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [1.5.1.1] - 2024-03-29

Minor fixes to allow linking against QuantLib-Risks without duplicate symbols.

## [1.5.1] - 2024-03-28

Initial release of Python bindings for XAD.


[1.5.1.1]: https://github.com/auto-differentiation/xad-py/compare/v1.5.1...v1.5.1.1

[1.5.1]: https://github.com/auto-differentiation/xad-py/releases/tag/v1.5.1
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

[tool.poetry]
name = "xad"
version = "1.5.1"
version = "1.5.1.1"
description = "High-Performance Automatic Differentiation for Python"
authors = ["Auto Differentiation Dev Team <[email protected]>"]
readme = "README.md"
Expand Down Expand Up @@ -102,6 +102,10 @@ requires = [
]
build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
minversion = "6.0"
testpaths = ["tests"]

[tool.black]
line-length = 100
target-version = ["py38", "py39", "py310", "py311", "py312"]
Expand Down
41 changes: 36 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,47 @@ if(MSVC)
option(XAD_STATIC_MSVC_RUNTIME "Use static runtime" ON)
endif()

find_package(Threads REQUIRED)

add_subdirectory(pybind11)
add_subdirectory(xad)

pybind11_add_module(_xad module.cpp math.hpp tape.hpp real.hpp exceptions.hpp)
target_link_libraries(_xad PRIVATE XAD::xad)
target_compile_definitions(_xad PRIVATE VERSION_INFO=${PROJECT_VERSION})
# Note: We bake XAD directly into this module, rather than linking, since
# otherwise we get conflicting definitions of the types when used in
# QuantLib-Risks-Py which causes a segfault We assume a platform that at least
# supports the AVX instructions set

pybind11_add_module(
_xad
module.cpp
math.hpp
tape.hpp
real.hpp
exceptions.hpp
xad/src/Tape.cpp)

target_include_directories(_xad PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/xad/src
xad/src)
set_target_properties(_xad PROPERTIES CXX_STANDARD 17)
if(MSVC)
# to allow using M_PI and the like
target_compile_definitions(_xad PRIVATE _USE_MATH_DEFINES)
target_compile_options(_xad PRIVATE -nologo -utf-8 "/arch:AVX")
target_compile_definitions(
_xad
PRIVATE VERSION_INFO=${PROJECT_VERSION}
_UNICODE
UNICODE
WIN32_LEAN_AND_MEAN
WIN32
_WIN32
_USE_MATH_DEFINES)
# static MSVC runtime to avoid linking issues in Python and QuantLib-Risks
set_target_properties(_xad PROPERTIES MSVC_RUNTIME_LIBRARY
"MultiThreaded$<$<CONFIG:Debug>:Debug>")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
target_compile_options(_xad PRIVATE -mavx -stdlib=libc++
-mmacosx-version-min=10.9)
target_compile_definitions(_xad PRIVATE VERSION_INFO=${PROJECT_VERSION})
else()
target_compile_options(_xad PRIVATE -mavx)
target_compile_definitions(_xad PRIVATE VERSION_INFO=${PROJECT_VERSION})
endif()

0 comments on commit d3eb89b

Please sign in to comment.