Skip to content

Commit

Permalink
Merge branch 'master' into documentation/howto_build_the_maven_artifa…
Browse files Browse the repository at this point in the history
…ct_yourself
  • Loading branch information
ralfkonrad committed Oct 11, 2024
2 parents ee2da10 + 5596df1 commit 74c8f3d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 47 deletions.
4 changes: 2 additions & 2 deletions .github/actions/build_native_library/env_variables/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ runs:
echo "CXXFLAGS=-stdlib=libc++" >> $GITHUB_ENV
echo "HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1" >> $GITHUB_ENV
- name: Setup BOOST_ROOT and directories on Windows
- name: Setup installation directories on Windows
if: runner.os == 'Windows'
shell: pwsh
run: |
Write "BOOST_DOWNLOAD_URI=https://downloads.sourceforge.net/project/boost/boost-binaries/1.86.0/boost_1_86_0-msvc-14.3-64.exe" >> $env:GITHUB_ENV
Write "BOOST_INSTALLER_PATH=$env:RUNNER_TEMP\boost.exe" >> $env:GITHUB_ENV
Write "BOOST_ROOT=$env:RUNNER_TEMP\boost" >> $env:GITHUB_ENV
Write "BOOST_INSTALL_DIR=$env:RUNNER_TEMP\boost" >> $env:GITHUB_ENV
Write "Boost_DIR=$env:RUNNER_TEMP\boost\lib64-msvc-14.3\cmake\Boost-1.86.0" >> $env:GITHUB_ENV
Write "SWIG_DOWNLOAD_URI=https://sourceforge.net/projects/swig/files/swigwin/swigwin-4.2.1/swigwin-4.2.1.zip/download" >> $env:GITHUB_ENV
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/build_native_library/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ runs:
shell: pwsh
run: |
Start-BitsTransfer -Source $env:BOOST_DOWNLOAD_URI -Destination $env:BOOST_INSTALLER_PATH
Start-Process -Wait -FilePath "$env:BOOST_INSTALLER_PATH" "/SILENT","/SP-","/SUPPRESSMSGBOXES","/DIR=$env:BOOST_ROOT"
Start-Process -Wait -FilePath "$env:BOOST_INSTALLER_PATH" "/SILENT","/SP-","/SUPPRESSMSGBOXES","/DIR=$env:BOOST_INSTALL_DIR"
Start-BitsTransfer -Source $env:SWIG_DOWNLOAD_URI -Destination $env:SWIG_ZIP_FILE_PATH
Expand-Archive $env:SWIG_ZIP_FILE_PATH $env:RUNNER_TEMP
Expand Down
45 changes: 21 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
cmake_minimum_required(VERSION 3.25.0)

# For MSVC RUNTIME LIBRARY, need CMP0091=NEW and cmake 3.15+
cmake_policy(SET CMP0091 NEW)

# Target specific architectures for macOS and iOS, enable dual builds both for arm64 and amd64 architectures
# According to the documentation:
# The value of this variable should be set prior to the first project() or enable_language() command
# invocation because it may influence configuration of the toolchain and flags
set(CMAKE_OSX_ARCHITECTURES arm64 x86_64)

# The FindBoost module is removed in cmake 3.30, finding the upstream BoostConfig.cmake
if (POLICY CMP0167)
cmake_policy(SET CMP0167 NEW)
endif ()

project(quantlib_for_maven VERSION 1.35.0 LANGUAGES CXX)

# set the Boost and Swig versions we want to use
Expand All @@ -28,27 +20,27 @@ set(QL_THROW_IN_CYCLES ON CACHE BOOL "Throw an exception when a notification loo
set(QL_FASTER_LAZY_OBJECTS OFF CACHE BOOL "Cause lazy objects to forward just the first notification instead of every one")

# paths needed throughout the build
cmake_path(SET QUANTLIB_ROOT external/QuantLib)
cmake_path(SET QL_MVN_QUANTLIB_ROOT external/QuantLib)

cmake_path(SET QUANTLIB_ROOT_DIR ${CMAKE_SOURCE_DIR}/${QUANTLIB_ROOT})
cmake_path(SET QUANTLIB_GENERATED_HEADERS_DIR ${CMAKE_BINARY_DIR}/${QUANTLIB_ROOT})
cmake_path(SET QL_MVN_QUANTLIB_ROOT_DIR ${CMAKE_SOURCE_DIR}/${QL_MVN_QUANTLIB_ROOT})
cmake_path(SET QL_MVN_QUANTLIB_GENERATED_HEADERS_DIR ${CMAKE_BINARY_DIR}/${QL_MVN_QUANTLIB_ROOT})

cmake_path(SET QUANTLIB_SWIG_ROOT_DIR ${CMAKE_SOURCE_DIR}/external/QuantLib-SWIG/SWIG)
cmake_path(SET QL_MVN_QUANTLIB_SWIG_ROOT_DIR ${CMAKE_SOURCE_DIR}/external/QuantLib-SWIG/SWIG)

cmake_path(SET SWIG_ROOT swig)
cmake_path(SET QL_ENTRYPOINT_I_FILE ${CMAKE_SOURCE_DIR}/${SWIG_ROOT}/QuantLibEntrypoint.i)
cmake_path(SET QL_MVN_SWIG_ROOT swig)
cmake_path(SET QL_MVN_ENTRYPOINT_I_FILE ${CMAKE_SOURCE_DIR}/${QL_MVN_SWIG_ROOT}/QuantLibEntrypoint.i)

cmake_path(SET SWIG_CPP_DIR ${CMAKE_BINARY_DIR}/cpp)
cmake_path(SET QL_MVN_SWIG_CPP_DIR ${CMAKE_BINARY_DIR}/cpp)

cmake_path(SET SWIG_JAVA_DIR ${CMAKE_SOURCE_DIR}/java)
cmake_path(SET SWIG_JAVA_SRC_DIR ${SWIG_JAVA_DIR}/src/main)
cmake_path(SET SWIG_JAVA_PACKAGE_DIR ${SWIG_JAVA_SRC_DIR}/java/org/quantlib)
cmake_path(SET SWIG_JAVA_RESOURCES_DIR ${SWIG_JAVA_SRC_DIR}/resources)
cmake_path(SET SWIG_JAVA_TARGET_DIR ${SWIG_JAVA_DIR}/target)
cmake_path(SET QL_MVN_SWIG_JAVA_DIR ${CMAKE_SOURCE_DIR}/java)
cmake_path(SET QL_MVN_SWIG_JAVA_SRC_DIR ${QL_MVN_SWIG_JAVA_DIR}/src/main)
cmake_path(SET QL_MVN_SWIG_JAVA_PACKAGE_DIR ${QL_MVN_SWIG_JAVA_SRC_DIR}/java/org/quantlib)
cmake_path(SET QL_MVN_SWIG_JAVA_RESOURCES_DIR ${QL_MVN_SWIG_JAVA_SRC_DIR}/resources)
cmake_path(SET QL_MVN_SWIG_JAVA_TARGET_DIR ${QL_MVN_SWIG_JAVA_DIR}/target)

# Path for package-local cmake modules
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
list(APPEND CMAKE_MODULE_PATH ${QUANTLIB_ROOT_DIR}/cmake)
list(APPEND CMAKE_MODULE_PATH ${QL_MVN_QUANTLIB_ROOT_DIR}/cmake)

set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
Expand All @@ -63,7 +55,12 @@ if (${MSVC})
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif ()

find_package(Boost ${QL_MVN_BOOST_VERSION} EXACT CONFIG REQUIRED)
# The FindBoost module is removed in cmake 3.30, finding the upstream BoostConfig.cmake
if (POLICY CMP0167)
find_package(Boost ${QL_MVN_BOOST_VERSION} EXACT CONFIG REQUIRED)
else ()
find_package(Boost ${QL_MVN_BOOST_VERSION} EXACT REQUIRED)
endif ()

add_subdirectory(${QUANTLIB_ROOT})
add_subdirectory(${SWIG_ROOT})
add_subdirectory(${QL_MVN_QUANTLIB_ROOT})
add_subdirectory(${QL_MVN_SWIG_ROOT})
14 changes: 7 additions & 7 deletions cmake/CreateJavaLibraryDirectory.cmake
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
cmake_path(SET SWIG_JAVA_RESOURCES_NATIVE_DIR ${SWIG_JAVA_RESOURCES_DIR}/native)
cmake_path(SET QL_MVN_SWIG_JAVA_RESOURCES_NATIVE_DIR ${QL_MVN_SWIG_JAVA_RESOURCES_DIR}/native)
if (${WIN32})
cmake_path(APPEND SWIG_JAVA_RESOURCES_NATIVE_DIR windows)
cmake_path(APPEND QL_MVN_SWIG_JAVA_RESOURCES_NATIVE_DIR windows)
if (${CMAKE_SIZEOF_VOID_P} EQUAL 4)
cmake_path(APPEND SWIG_JAVA_RESOURCES_NATIVE_DIR x86)
cmake_path(APPEND QL_MVN_SWIG_JAVA_RESOURCES_NATIVE_DIR x86)
else ()
cmake_path(APPEND SWIG_JAVA_RESOURCES_NATIVE_DIR amd64)
cmake_path(APPEND QL_MVN_SWIG_JAVA_RESOURCES_NATIVE_DIR amd64)
endif ()
elseif (${LINUX})
cmake_path(APPEND SWIG_JAVA_RESOURCES_NATIVE_DIR linux)
cmake_path(APPEND QL_MVN_SWIG_JAVA_RESOURCES_NATIVE_DIR linux)
elseif (${APPLE})
cmake_path(APPEND SWIG_JAVA_RESOURCES_NATIVE_DIR macos)
cmake_path(APPEND QL_MVN_SWIG_JAVA_RESOURCES_NATIVE_DIR macos)
else ()
message(FATAL_ERROR "Unsupported platform ${CMAKE_SYSTEM}...")
endif ()

file(MAKE_DIRECTORY ${SWIG_JAVA_RESOURCES_NATIVE_DIR})
file(MAKE_DIRECTORY ${QL_MVN_SWIG_JAVA_RESOURCES_NATIVE_DIR})
26 changes: 13 additions & 13 deletions swig/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,34 @@ find_package(JNI REQUIRED)
find_package(SWIG ${QL_MVN_SWIG_VERSION} EXACT REQUIRED COMPONENTS java)
include(UseSWIG)

set_property(SOURCE ${QL_ENTRYPOINT_I_FILE} PROPERTY CPLUSPLUS ON)
set_property(SOURCE ${QL_ENTRYPOINT_I_FILE} PROPERTY SWIG_MODULE_NAME QuantLib)
set_property(SOURCE ${QL_ENTRYPOINT_I_FILE} PROPERTY COMPILE_DEFINITIONS JAVA_FINALIZER)
set_property(SOURCE ${QL_ENTRYPOINT_I_FILE} PROPERTY INCLUDE_DIRECTORIES ${QUANTLIB_SWIG_ROOT_DIR})
set_property(SOURCE ${QL_ENTRYPOINT_I_FILE} PROPERTY USE_TARGET_INCLUDE_DIRECTORIES OFF)
set_property(SOURCE ${QL_MVN_ENTRYPOINT_I_FILE} PROPERTY CPLUSPLUS ON)
set_property(SOURCE ${QL_MVN_ENTRYPOINT_I_FILE} PROPERTY SWIG_MODULE_NAME QuantLib)
set_property(SOURCE ${QL_MVN_ENTRYPOINT_I_FILE} PROPERTY COMPILE_DEFINITIONS JAVA_FINALIZER)
set_property(SOURCE ${QL_MVN_ENTRYPOINT_I_FILE} PROPERTY INCLUDE_DIRECTORIES ${QL_MVN_QUANTLIB_SWIG_ROOT_DIR})
set_property(SOURCE ${QL_MVN_ENTRYPOINT_I_FILE} PROPERTY USE_TARGET_INCLUDE_DIRECTORIES OFF)

swig_add_library(
QuantLibJNI
TYPE SHARED
LANGUAGE java
OUTFILE_DIR ${SWIG_CPP_DIR}
OUTPUT_DIR ${SWIG_JAVA_PACKAGE_DIR}
SOURCES ${QL_ENTRYPOINT_I_FILE})
OUTFILE_DIR ${QL_MVN_SWIG_CPP_DIR}
OUTPUT_DIR ${QL_MVN_SWIG_JAVA_PACKAGE_DIR}
SOURCES ${QL_MVN_ENTRYPOINT_I_FILE})

set_property(TARGET QuantLibJNI PROPERTY
SWIG_COMPILE_OPTIONS -package org.quantlib)

if (${MSVC})
set_property(TARGET QuantLibJNI PROPERTY
RUNTIME_OUTPUT_DIRECTORY ${SWIG_JAVA_RESOURCES_NATIVE_DIR})
RUNTIME_OUTPUT_DIRECTORY ${QL_MVN_SWIG_JAVA_RESOURCES_NATIVE_DIR})
else ()
set_property(TARGET QuantLibJNI PROPERTY
LIBRARY_OUTPUT_DIRECTORY ${SWIG_JAVA_RESOURCES_NATIVE_DIR})
LIBRARY_OUTPUT_DIRECTORY ${QL_MVN_SWIG_JAVA_RESOURCES_NATIVE_DIR})
endif ()

target_include_directories(QuantLibJNI SYSTEM PRIVATE
${QUANTLIB_GENERATED_HEADERS_DIR}
${QUANTLIB_ROOT_DIR}
${QL_MVN_QUANTLIB_GENERATED_HEADERS_DIR}
${QL_MVN_QUANTLIB_ROOT_DIR}
${Boost_INCLUDE_DIRS}
${JNI_INCLUDE_DIRS})

Expand All @@ -66,6 +66,6 @@ target_link_libraries(QuantLibJNI
add_custom_command(
TARGET QuantLibJNI POST_BUILD
COMMAND ./mvnw --batch-mode --show-version clean verify
WORKING_DIRECTORY ${SWIG_JAVA_DIR}
WORKING_DIRECTORY ${QL_MVN_SWIG_JAVA_DIR}
COMMENT "Running './mvnw --batch-mode --show-version clean verify'."
VERBATIM)

0 comments on commit 74c8f3d

Please sign in to comment.