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

add static building option #20

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
45 changes: 38 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ function(cat IN_FILE OUT_FILE)
file(APPEND ${OUT_FILE} "${CONTENTS}")
endfunction()

option(BUILD_SHARED_LIB "build as shared library" ON)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
find_package(pcre2 REQUIRED)

set(FILE_VERSION 5.44)

set(WIN_COMPAT_SOURCES
Expand Down Expand Up @@ -75,19 +80,23 @@ FILE(WRITE file/tests/test.c "${TEST_C_CONTENT_NEW}")


add_definitions(-DHAVE_CONFIG_H -DVERSION="${FILE_VERSION}" -DWIN32_LEAN_AND_MEAN -DWIN32 -DPCRE2_STATIC )
add_library(libmagic SHARED ${LIBMAGIC_SOURCE_FILES})
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/win-headers pcre2/src file/src dirent/include getopt)
target_link_libraries(libmagic pcre2-posix shlwapi)
if(BUILD_SHARED_LIB)
add_library(libmagic SHARED ${LIBMAGIC_SOURCE_FILES})
else()
add_definitions(-DBUILD_AS_WINDOWS_STATIC_LIBARAY)
add_library(libmagic STATIC ${LIBMAGIC_SOURCE_FILES})
endif()
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/win-headers ${PCRE2_INCLUDE_DIRS} file/src dirent/include getopt)
target_link_libraries(libmagic PRIVATE ${PCRE2_LIBRARIES} ${PCRE2_POSIX_LIBRARIES} shlwapi)

add_subdirectory(pcre2)

# copy /pcre2posix.h to regex.h so it can be used as posix regex libary
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/pcre2/src/pcre2posix.h ${CMAKE_CURRENT_SOURCE_DIR}/pcre2/src/regex.h COPYONLY)
configure_file(${PCRE2_INCLUDE_DIRS}/pcre2posix.h ${PCRE2_INCLUDE_DIRS}/regex.h COPYONLY)

add_executable(file file/src/file.c)
add_executable(file_test file/tests/test.c)
target_link_libraries(file_test libmagic pcre2-posix shlwapi)
target_link_libraries(file libmagic pcre2-posix shlwapi)
target_link_libraries(file_test PRIVATE libmagic shlwapi)
target_link_libraries(file PRIVATE libmagic shlwapi)


# this tests all because of time-zone or crlf errors
Expand Down Expand Up @@ -136,3 +145,25 @@ add_custom_command(OUTPUT magic.mgc
)

add_custom_target(magic_mgc ALL DEPENDS magic.mgc)


install(TARGETS file DESTINATION bin)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/magic.mgc DESTINATION bin)
install(FILES file/src/magic.h DESTINATION include)
install(TARGETS libmagic
EXPORT libmagic-target
RUNTIME DESTINATION lib
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
INCLUDES DESTINATION include
)
install(EXPORT libmagic-target
FILE libmagic-targets.cmake
DESTINATION lib/cmake/libmagic
)
file(WRITE
${CMAKE_BINARY_DIR}/libmagic-config.cmake
"include(\${CMAKE_CURRENT_LIST_DIR}/libmagic-targets.cmake)\n")
install(FILES
${CMAKE_BINARY_DIR}/libmagic-config.cmake
DESTINATION lib/cmake/libmagic)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This aims to have everything one needs to build file on windows with visual stud
## Checkout with submodules

```sh
git submodule update --init --recursiv
git submodule update --init --recursive
```

## External Dependencies
Expand Down
107 changes: 102 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,127 @@ matrix:
fast_finish: false # set this flag to immediately finish build once one of the jobs fails.

environment:
BUILD_DIR: "%APPVEYOR_BUILD_FOLDER%\\build"
INSTALL_DIR: "%APPVEYOR_BUILD_FOLDER%\\install"
PCRE2_ROOT: "%APPVEYOR_BUILD_FOLDER%\\pcre2"
PCRE2_BUILD_DIR: "%PCRE2_ROOT%\\build"
PCRE2_INSTALL_DIR: "%PCRE2_ROOT%\\install_dir"
matrix:
- PLATFORM: x86
BUILDER: CMake
GENERATOR: "NMake Makefiles"
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022
MSVC_NAME: vs2022
LIB_TYPE: shared
CMAKE_OPTIONS: -DBUILD_SHARED_LIB=ON
- PLATFORM: x86
BUILDER: CMake
GENERATOR: "NMake Makefiles"
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022
MSVC_NAME: vs2022
LIB_TYPE: static
CMAKE_OPTIONS: -DBUILD_SHARED_LIB=OFF

- PLATFORM: x64
BUILDER: CMake
GENERATOR: "NMake Makefiles"
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022
MSVC_NAME: vs2022
LIB_TYPE: shared
CMAKE_OPTIONS: -DBUILD_SHARED_LIB=ON
- PLATFORM: x64
BUILDER: CMake
GENERATOR: "NMake Makefiles"
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022
MSVC_NAME: vs2022
LIB_TYPE: static
CMAKE_OPTIONS: -DBUILD_SHARED_LIB=OFF

- PLATFORM: x86
BUILDER: CMake
GENERATOR: "NMake Makefiles"
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
MSVC_NAME: vs2019
LIB_TYPE: shared
CMAKE_OPTIONS: -DBUILD_SHARED_LIB=ON
- PLATFORM: x86
BUILDER: CMake
GENERATOR: "NMake Makefiles"
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
MSVC_NAME: vs2019
LIB_TYPE: static
CMAKE_OPTIONS: -DBUILD_SHARED_LIB=OFF

- PLATFORM: x64
BUILDER: CMake
GENERATOR: "NMake Makefiles"
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
MSVC_NAME: vs2019
LIB_TYPE: shared
CMAKE_OPTIONS: -DBUILD_SHARED_LIB=ON
- PLATFORM: x64
BUILDER: CMake
GENERATOR: "NMake Makefiles"
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
MSVC_NAME: vs2019
LIB_TYPE: static
CMAKE_OPTIONS: -DBUILD_SHARED_LIB=OFF

- PLATFORM: x86
BUILDER: CMake
GENERATOR: "NMake Makefiles"
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
MSVC_NAME: vs2017
LIB_TYPE: shared
CMAKE_OPTIONS: -DBUILD_SHARED_LIB=ON
- PLATFORM: x86
BUILDER: CMake
GENERATOR: "NMake Makefiles"
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
MSVC_NAME: vs2017
LIB_TYPE: static
CMAKE_OPTIONS: -DBUILD_SHARED_LIB=OFF

- PLATFORM: x64
BUILDER: CMake
GENERATOR: "NMake Makefiles"
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
MSVC_NAME: vs2017
LIB_TYPE: shared
CMAKE_OPTIONS: -DBUILD_SHARED_LIB=ON
- PLATFORM: x64
BUILDER: CMake
GENERATOR: "NMake Makefiles"
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
MSVC_NAME: vs2017
LIB_TYPE: static
CMAKE_OPTIONS: -DBUILD_SHARED_LIB=OFF

- PLATFORM: x64
GENERATOR: "NMake Makefiles"
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
MSVC_NAME: vs2015
LIB_TYPE: shared
CMAKE_OPTIONS: -DBUILD_SHARED_LIB=ON
- PLATFORM: x64
GENERATOR: "NMake Makefiles"
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
MSVC_NAME: vs2015
LIB_TYPE: static
CMAKE_OPTIONS: -DBUILD_SHARED_LIB=OFF

- PLATFORM: x86
GENERATOR: "NMake Makefiles"
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
MSVC_NAME: vs2015
LIB_TYPE: shared
CMAKE_OPTIONS: -DBUILD_SHARED_LIB=ON
- PLATFORM: x86
GENERATOR: "NMake Makefiles"
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
MSVC_NAME: vs2015
LIB_TYPE: static
CMAKE_OPTIONS: -DBUILD_SHARED_LIB=OFF

init:
- ps: 'Write-Host "Building GEOS branch: $env:APPVEYOR_REPO_BRANCH" -ForegroundColor Magenta'
Expand All @@ -75,24 +157,39 @@ init:
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2015" if "%GENERATOR%"=="NMake Makefiles" if "%PLATFORM%"=="x64" call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64

before_build:
- ps: 'Write-Host "Running $env:BUILDER with $env:GENERATOR" -ForegroundColor Magenta'
- git submodule update --init --recursive
- cmake.exe -G "%GENERATOR%" -DCMAKE_BUILD_TYPE=%CONFIGURATION% %APPVEYOR_BUILD_FOLDER%
- mkdir %BUILD_DIR%
- mkdir %PCRE2_BUILD_DIR%

- ps: 'Write-Host "Building pcre2" -ForegroundColor Magenta'
- cd %PCRE2_BUILD_DIR%
- cmake -G "%GENERATOR%" -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DCMAKE_INSTALL_PREFIX="%PCRE2_INSTALL_DIR%" "%PCRE2_ROOT%"
- cmake --build . --config %CONFIGURATION%
- ps: 'Write-Host "Installing pcre2" -ForegroundColor Magenta'
- cmake --install . --config %CONFIGURATION%

- ps: 'Write-Host "Running $env:BUILDER with $env:GENERATOR" -ForegroundColor Magenta'
- cd %BUILD_DIR%
- cmake -G "%GENERATOR%" -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% "%CMAKE_OPTIONS%" %APPVEYOR_BUILD_FOLDER%


build_script:
- ps: 'Write-Host "Running $env:BUILDER:" -ForegroundColor Magenta'
- cd %BUILD_DIR%
- cmake --build . --config %CONFIGURATION%
- cmake --install . --config %CONFIGURATION%


test_script:
- ctest --output-on-failure

after_build:
# file_5.32-vs2015-x64.zip
- 7z a file_%APPVEYOR_BUILD_VERSION%-%MSVC_NAME%-%PLATFORM%.zip libmagic.dll file.exe magic.mgc
# file_5.32-vs2015-x64-shared.zip
- cd %APPVEYOR_BUILD_FOLDER%
- 7z a file_%APPVEYOR_BUILD_VERSION%-%MSVC_NAME%-%PLATFORM%-%LIB_TYPE%.zip %INSTALL_DIR%/*

artifacts:
- path: file_%APPVEYOR_BUILD_VERSION%-%MSVC_NAME%-%PLATFORM%.zip
- path: file_%APPVEYOR_BUILD_VERSION%-%MSVC_NAME%-%PLATFORM%-%LIB_TYPE%.zip


# If you need to debug AppVeyor session (https://www.appveyor.com/docs/how-to/rdp-to-build-worker), then:
Expand Down
19 changes: 19 additions & 0 deletions cmake/Findpcre2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
if(DEFINED ENV{PCRE2_INSTALL_DIR})
set(PCRE2_INSTALL_DIR $ENV{PCRE2_INSTALL_DIR})
else()
set(PCRE2_INSTALL_DIR pcre2/install_dir)
endif()

MESSAGE("PCRE2_INSTALL_DIR: " ${PCRE2_INSTALL_DIR})
find_library(PCRE2_LIBRARIES NAMES pcre2 pcre2-8 pcre2d pcre2-8d PATHS "${PCRE2_INSTALL_DIR}/lib")
find_library(PCRE2_POSIX_LIBRARIES NAMES pcre2-posix pcre2-posix-8 pcre2-posixd pcre2-posix-8d PATHS "${PCRE2_INSTALL_DIR}/lib")
find_path(PCRE2_INCLUDE_DIRS pcre2.h PATHS "${PCRE2_INSTALL_DIR}/include")
if(PCRE2_LIBRARIES AND PCRE2_INCLUDE_DIRS)
message(STATUS "PCRE2 libs: ${PCRE2_LIBRARIES}")
message(STATUS "PCRE2 include directory: ${PCRE2_INCLUDE_DIRS}")
set(PCRE2_FOUND TRUE CACHE BOOL "Found PCRE2 libraries" FORCE)
add_custom_target(pcre2)
else()
set(PCRE2_FOUND FALSE CACHE BOOL "Found PCRE2 libraries" FORCE)
message(STATUS "PCRE2 library not found.")
endif()