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

Update build process #3

Merged
merged 14 commits into from
Oct 26, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
python -m cibuildwheel --output-dir dist
env:
CIBW_BUILD: ${{ matrix.cibw_build }}
CIBW_BUILD_VERBOSITY: 3
CIBW_SKIP: "*musllinux*"
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014
CIBW_BEFORE_ALL_MACOS: brew install llvm &&
Expand All @@ -53,7 +54,6 @@ jobs:
CIBW_ENVIRONMENT_LINUX: LD_LIBRARY_PATH="/tmp/filepattern_bld/local_install/lib:/tmp/filepattern_bld/local_install/lib64:$LD_LIBRARY_PATH" ON_GITHUB="TRUE" FILEPATTERN_DEP_DIR="/tmp/filepattern_bld/local_install"
CIBW_ENVIRONMENT_WINDOWS: PATH="$TEMP\\filepattern\\bin;$PATH" ON_GITHUB="TRUE" FILEPATTERN_DEP_DIR="C:\\TEMP\\filepattern_bld\\local_install"
CIBW_REPAIR_WHEEL_COMMAND_MACOS: DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-listdeps {wheel} && DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-wheel --require-archs {delocate_archs} -w {dest_dir} {wheel}
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: "delvewheel repair -w {dest_dir} {wheel}"
CIBW_ARCHS: ${{ matrix.cibw_archs }}
CIBW_TEST_REQUIRES: pytest pydantic
CIBW_TEST_COMMAND: pytest {project}/tests/
Expand Down
79 changes: 11 additions & 68 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,82 +10,25 @@ endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)


file(READ src/filepattern/cpp/version.h VER_FILE )
string(REGEX MATCH "#define PROJECT_VER \"([0-9]+)\.([0-9]+)\.([0-9+])\"" _ "${VER_FILE}")
set (filepattern_VERSION_MAJOR ${CMAKE_MATCH_1})
set (filepattern_VERSION_MINOR ${CMAKE_MATCH_2})
set (filepattern_VERSION_PATCH ${CMAKE_MATCH_3})
set(filepattern_VERSION "${filepattern_VERSION_MAJOR}.${filepattern_VERSION_MINOR}.${filepattern_VERSION_PATCH}")
message(STATUS "Building filepattern ${filepattern_VERSION}" )

option(RUN_GTEST "Downloads google unit test API and runs google test scripts to test Filepattern" OFF)

if(JAVA_BINDING)
add_compile_definitions(JAVA_BINDING)
endif()

#==== Source files
set(SOURCE src/filepattern/cpp/pattern.cpp
src/filepattern/cpp/interface/filepattern.cpp
src/filepattern/cpp/internal/internal_pattern.cpp
src/filepattern/cpp/internal/filepattern.cpp
src/filepattern/cpp/internal/stringpattern.cpp
src/filepattern/cpp/internal/vectorpattern.cpp
src/filepattern/cpp/external/external_pattern.cpp
src/filepattern/cpp/external/external_filepattern.cpp
src/filepattern/cpp/external/external_stringpattern.cpp
src/filepattern/cpp/external/external_vectorpattern.cpp
src/filepattern/cpp/util/fs_stream.cpp
src/filepattern/cpp/util/sort.cpp
src/filepattern/cpp/util/vector_parser.cpp
)
if (NOT BUILD_PYTHON_LIB) # Not taking the setup.py route, just building libs
if (NOT MSVC)
if (NOT DEFINED CMAKE_CXX_VISIBILITY_PRESET AND
NOT DEFINED CMAKE_VISIBILITY_INLINES_HIDDEN)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)
endif ()
endif()


if(DEFINED filepattern_SHARED_LIB)
set(BUILD_SHARED_LIBS ${filepattern_SHARED_LIB})
endif()
add_library(filepattern ${SOURCE})
add_library(filepattern::filepattern ALIAS filepattern)
set_target_properties(filepattern PROPERTIES
VERSION ${filepattern_VERSION}
SOVERSION ${filepattern_VERSION_MAJOR})
target_include_directories(
filepattern PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>")
include(GenerateExportHeader)
generate_export_header(filepattern EXPORT_FILE_NAME include/filepattern_export.h)
target_compile_definitions(
filepattern PUBLIC "$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:FILEPATTERN_STATIC_DEFINE>")
target_compile_definitions(filepattern PUBLIC FP_CPP_LIB_EXPORT)
target_include_directories(
filepattern PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>")
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_link_libraries(filepattern PRIVATE stdc++fs)
endif()
string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}" is_top_level)
option(filepattern_INCLUDE_PACKAGING "Include packaging rules for FilePattern" "${is_top_level}")
if (filepattern_INCLUDE_PACKAGING)
add_subdirectory(packaging)
endif ()
endif()

if(BUILD_PYTHON_LIB)

find_package(pybind11 CONFIG REQUIRED)

pybind11_add_module(backend
${SOURCE}
src/filepattern/cpp/bindings.cpp
)
target_compile_definitions(backend PRIVATE WITH_PYTHON_H)
find_package(filepattern QUIET)
if (NOT filepattern_FOUND)
message(STATUS "libfilepattern not found. It will be build from source.")
set(filepattern_SHARED_LIB ON)
add_subdirectory(src/filepattern/cpp ${CMAKE_BINARY_DIR}/third-party)
add_dependencies(backend filepattern)
target_include_directories(backend PRIVATE ${CMAKE_BINARY_DIR}/third-party/include)
else()
target_compile_definitions(backend PRIVATE WITH_LIBFILEPATTERN)
endif()
target_link_libraries(backend PRIVATE filepattern::filepattern)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_link_libraries(backend PRIVATE stdc++fs)
endif()
Expand Down
22 changes: 15 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# -*- coding: utf-8 -*-
from distutils.version import LooseVersion
from pathlib import Path
from setuptools import find_packages, Extension
from setuptools.command.build_ext import build_ext
import os
import platform
import re
import setuptools
import shutil
import subprocess
import sys
import versioneer
import platform
import subprocess
import setuptools

from distutils.version import LooseVersion
from setuptools import find_packages, Extension
from setuptools.command.build_ext import build_ext

with open("README.md", "r") as fh:
long_description = fh.read()
Expand Down Expand Up @@ -70,6 +71,13 @@ def build_extension(self, ext):
cwd=self.build_temp, env=env)
subprocess.check_call(['cmake', '--build', '.'] + build_args,
cwd=self.build_temp)
if platform.system() == "Windows":
dll_files = list(Path(os.path.abspath(self.build_temp)).rglob("filepattern.dll"))
if len(dll_files) > 0:
for file in dll_files:
print(f"Copying ${file.as_posix()} -> {extdir}")
shutil.copy(file.as_posix(), extdir)

print() # Add an empty line for cleaner output\


Expand Down
78 changes: 78 additions & 0 deletions src/filepattern/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
cmake_minimum_required(VERSION 3.20)
project(libfilepattern)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(DEFINED ENV{FILEPATTERN_DEP_DIR})
set(CMAKE_PREFIX_PATH $ENV{FILEPATTERN_DEP_DIR})
link_directories($ENV{FILEPATTERN_DEP_DIR}/lib)
endif()

file(READ version.h VER_FILE )
string(REGEX MATCH "#define PROJECT_VER \"([0-9]+)\.([0-9]+)\.([0-9+])\"" _ "${VER_FILE}")
set (filepattern_VERSION_MAJOR ${CMAKE_MATCH_1})
set (filepattern_VERSION_MINOR ${CMAKE_MATCH_2})
set (filepattern_VERSION_PATCH ${CMAKE_MATCH_3})
set(filepattern_VERSION "${filepattern_VERSION_MAJOR}.${filepattern_VERSION_MINOR}.${filepattern_VERSION_PATCH}")
message(STATUS "Building libfilepattern ${filepattern_VERSION}" )

if(JAVA_BINDING)
add_compile_definitions(JAVA_BINDING)
endif()

#==== Source files
set(SOURCE pattern.cpp
interface/filepattern.cpp
internal/internal_pattern.cpp
internal/filepattern.cpp
internal/stringpattern.cpp
internal/vectorpattern.cpp
external/external_pattern.cpp
external/external_filepattern.cpp
external/external_stringpattern.cpp
external/external_vectorpattern.cpp
util/fs_stream.cpp
util/sort.cpp
util/vector_parser.cpp
)

if (NOT MSVC)
if (NOT DEFINED CMAKE_CXX_VISIBILITY_PRESET AND
NOT DEFINED CMAKE_VISIBILITY_INLINES_HIDDEN)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)
endif ()
endif()


if(DEFINED filepattern_SHARED_LIB)
set(BUILD_SHARED_LIBS ${filepattern_SHARED_LIB})
endif()
add_library(filepattern ${SOURCE})
add_library(filepattern::filepattern ALIAS filepattern)
set_target_properties(filepattern PROPERTIES
VERSION ${filepattern_VERSION}
SOVERSION ${filepattern_VERSION_MAJOR})
target_include_directories(
filepattern PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>")
include(GenerateExportHeader)
generate_export_header(filepattern EXPORT_FILE_NAME include/filepattern_export.h)
target_compile_definitions(
filepattern PUBLIC "$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:FILEPATTERN_STATIC_DEFINE>")
target_compile_definitions(filepattern PUBLIC FP_CPP_LIB_EXPORT)
target_include_directories(
filepattern PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>")
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_link_libraries(filepattern PRIVATE stdc++fs)
endif()

string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}" is_top_level)
option(filepattern_INCLUDE_PACKAGING "Include packaging rules for FilePattern" "${is_top_level}")
if (filepattern_INCLUDE_PACKAGING)
add_subdirectory(packaging)
endif ()


set(CMAKE_POSITION_INDEPENDENT_CODE ON)

10 changes: 6 additions & 4 deletions src/filepattern/cpp/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
#include <pybind11/operators.h>
#include <pybind11/complex.h>
#include <pybind11/stl/filesystem.h>
#include <iostream>

#include "include/filepattern.h"
#include "pattern_object.hpp"

namespace py = pybind11;
#ifdef WITH_LIBFILEPATTERN
#include "filepattern/filepattern.h"
#else
#include "include/filepattern.h"
#endif

//PYBIND11_MAKE_OPAQUE(std::vector<std::vector<Tuple>>);
namespace py = pybind11;

PYBIND11_MODULE(backend, m){

Expand Down
1 change: 0 additions & 1 deletion src/filepattern/cpp/interface/filepattern.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "../include/filepattern.h"
#include "filepattern_factory.h"
#include "../pattern_object.hpp"

FilePattern::FilePattern(const std::string& path, const std::string& filePattern, const std::string& block_size, bool recursive, bool suppressWarnings) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ install(TARGETS filepattern EXPORT filepattern_Targets
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)

install(DIRECTORY "${filepattern_SOURCE_DIR}/src/filepattern/cpp/include/" "${filepattern_BINARY_DIR}/include/"
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../include/" "${CMAKE_CURRENT_BINARY_DIR}/../include/"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/filepattern/"
COMPONENT filepattern_Development)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@ else ()
filepattern_load_targets(shared)
endif ()
endif ()

message(STATUS "Found libfilepattern: ${filepattern_VERSION}")
22 changes: 20 additions & 2 deletions src/filepattern/cpp/pattern_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,25 @@
#include<variant>
#include<vector>

#include "util/util.hpp"

#if __has_include(<filesystem>)
#include <filesystem>
namespace fs = std::filesystem;
#elif __has_include(<experimental/filesystem>)
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#else
error "Missing the <filesystem> header."
#endif

using Types = std::variant<int, std::string, double>;
using Map = std::map<std::string, Types>;
#ifdef JAVA_BINDING
using Tuple = std::tuple<Map, std::vector<std::string>>;
#else
using Tuple = std::tuple<Map, std::vector<fs::path>>;
#endif


class PatternObject {
public:
Expand Down Expand Up @@ -83,4 +101,4 @@ class PatternObject {



};
};
6 changes: 3 additions & 3 deletions src/filepattern/cpp/util/fs_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ void FilesystemStream::writeValidFiles(const Tuple& mapping){
}

for(const auto& element: get<1>(mapping)){
#ifdef WITH_PYTHON_H
file << element.string() << "," << '\n';
#else
#ifdef JAVA_BINDING
file << element << "," << '\n';
#else
file << element.string() << "," << '\n';
#endif
}

Expand Down
Loading