Skip to content
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 Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ authors = ["James Swent"]
AbstractAlgebra = "c3fe647b-3220-5bb0-a1ea-a7954cac585d"
CxxWrap = "1f15a43c-97ca-5a2a-ae31-89f07a497df4"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
libsemigroups_jll = "99c76e05-e2a6-5e47-b69a-d74ec2f0d12c"

[compat]
AbstractAlgebra = "0.43, 0.48"
Expand Down
12 changes: 12 additions & 0 deletions deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
build.jl - Build script for semigroups_julia C++ library

This script builds the C++ wrapper library during package installation.
Uses libsemigroups_jll for the pre-built libsemigroups headers and library.
"""

using CxxWrap
using libsemigroups_jll

# Get the source and build directories
const src_dir = joinpath(@__DIR__, "src")
Expand All @@ -22,6 +24,11 @@ mkpath(build_dir)
# Get JlCxx directory
const jlcxx_dir = CxxWrap.prefix_path()

# Get libsemigroups paths from JLL
const libsemigroups_artifact = libsemigroups_jll.artifact_dir
const libsemigroups_incdir = joinpath(libsemigroups_artifact, "include")
const libsemigroups_libdir = joinpath(libsemigroups_artifact, "lib")

# Get Julia paths to work around FindJulia.cmake issues
julia_bindir = dirname(Sys.BINDIR)
julia_includedir = joinpath(julia_bindir, "include", "julia")
Expand All @@ -31,6 +38,9 @@ println("Building semigroups_julia library...")
println("Source directory: $src_dir")
println("Build directory: $build_dir")
println("JlCxx directory: $jlcxx_dir")
println("libsemigroups artifact: $libsemigroups_artifact")
println("libsemigroups include: $libsemigroups_incdir")
println("libsemigroups lib: $libsemigroups_libdir")
println("Julia include dir: $julia_includedir")
println("Julia lib dir: $julia_libdir")

Expand All @@ -41,6 +51,8 @@ cmake_args = [
"-DJulia_EXECUTABLE=$(joinpath(Sys.BINDIR, "julia"))",
"-DJulia_INCLUDE_DIRS=$julia_includedir",
"-DJulia_LIBRARY_DIR=$julia_libdir",
"-DLIBSEMIGROUPS_INCLUDE_DIR=$libsemigroups_incdir",
"-DLIBSEMIGROUPS_LIBRARY_DIR=$libsemigroups_libdir",
]

# Add macOS-specific flags if needed
Expand Down
33 changes: 26 additions & 7 deletions deps/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,23 @@ endif()
# Find JlCxx (CxxWrap C++ library)
find_package(JlCxx REQUIRED)

# Find libsemigroups via pkg-config
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBSEMIGROUPS REQUIRED libsemigroups)

pkg_get_variable(LIBSEMIGROUPS_INCLUDEDIR libsemigroups includedir)
# Find libsemigroups - prefer JLL paths if provided, fall back to pkg-config
if(DEFINED LIBSEMIGROUPS_INCLUDE_DIR AND DEFINED LIBSEMIGROUPS_LIBRARY_DIR)
message(STATUS "Using libsemigroups from JLL:")
message(STATUS " include dir: ${LIBSEMIGROUPS_INCLUDE_DIR}")
message(STATUS " library dir: ${LIBSEMIGROUPS_LIBRARY_DIR}")
# JLL bundles fmt/rx/etc headers under include/libsemigroups/, so we need both paths
set(LIBSEMIGROUPS_INCLUDE_DIRS "${LIBSEMIGROUPS_INCLUDE_DIR};${LIBSEMIGROUPS_INCLUDE_DIR}/libsemigroups")
set(LIBSEMIGROUPS_LIBRARY_DIRS "${LIBSEMIGROUPS_LIBRARY_DIR}")
set(LIBSEMIGROUPS_LIBRARIES "semigroups")
set(LIBSEMIGROUPS_INCLUDEDIR "${LIBSEMIGROUPS_INCLUDE_DIR}")
else()
# Fall back to system-installed libsemigroups via pkg-config
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBSEMIGROUPS REQUIRED libsemigroups)
pkg_get_variable(LIBSEMIGROUPS_INCLUDEDIR libsemigroups includedir)
message(STATUS "Using system libsemigroups via pkg-config")
endif()

message(STATUS "JlCxx found at: ${JlCxx_DIR}")
message(STATUS "libsemigroups include dirs: ${LIBSEMIGROUPS_INCLUDE_DIRS}")
Expand Down Expand Up @@ -58,13 +70,20 @@ target_link_libraries(libsemigroups_julia
julia
)

# Compiler flags from pkg-config
# Compiler flags
target_compile_options(libsemigroups_julia PRIVATE
${LIBSEMIGROUPS_CFLAGS_OTHER}
"-I${LIBSEMIGROUPS_INCLUDEDIR}"
-fno-char8_t # Work around C++20 char8_t issues with fmt in libsemigroups
)

# Set RPATH to find libsemigroups at runtime
if(DEFINED LIBSEMIGROUPS_LIBRARY_DIR)
set_target_properties(libsemigroups_julia PROPERTIES
INSTALL_RPATH "${LIBSEMIGROUPS_LIBRARY_DIR}"
BUILD_RPATH "${LIBSEMIGROUPS_LIBRARY_DIR}"
)
endif()

# Set output name - removes the extra "lib" prefix CMake would add
set_target_properties(libsemigroups_julia PROPERTIES
PREFIX ""
Expand Down
1 change: 1 addition & 0 deletions src/Semigroups.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Semigroups
using CxxWrap
using AbstractAlgebra
using Dates: TimePeriod, Nanosecond
using libsemigroups_jll

# ============================================================================
# Debug mode
Expand Down
10 changes: 9 additions & 1 deletion src/setup.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ setup.jl - Library location and build logic for Semigroups.jl

This module handles locating the compiled C++ wrapper library,
either from a pre-built location or by building it from source.
Uses libsemigroups_jll for the pre-built libsemigroups headers and library.
"""

module Setup

using CxxWrap
using libsemigroups_jll

# Get the path to the deps directory
function deps_dir()
Expand Down Expand Up @@ -51,15 +53,21 @@ function build_library()
# Get JlCxx (CxxWrap C++ library) directory
jlcxx_dir = CxxWrap.prefix_path()

# Get libsemigroups paths from JLL
libsemigroups_incdir = joinpath(libsemigroups_jll.artifact_dir, "include")
libsemigroups_libdir = joinpath(libsemigroups_jll.artifact_dir, "lib")

# Configure with CMake
cmake_args = [
"-DCMAKE_BUILD_TYPE=Release",
"-DJlCxx_DIR=$(joinpath(jlcxx_dir, "lib", "cmake", "JlCxx"))",
"-DLIBSEMIGROUPS_INCLUDE_DIR=$libsemigroups_incdir",
"-DLIBSEMIGROUPS_LIBRARY_DIR=$libsemigroups_libdir",
]

# Add macOS-specific flags if needed
if Sys.isapple()
push!(cmake_args, "-DCMAKE_OSX_DEPLOYMENT_TARGET=10.15")
push!(cmake_args, "-DCMAKE_OSX_DEPLOYMENT_TARGET=11.0")
end

# Run CMake configure
Expand Down
Loading