Skip to content

Commit

Permalink
add config file for vcpkg (intel#10)
Browse files Browse the repository at this point in the history
* add config file for vcpkg

* added examples, update example readme

* update CI pipeline

* add build type

* update comments

* test

* test

* test

* update test

* add sequential jobs

* update PKG_CONFIG_PATH

* update PKG_CONFIG_PATH

* set env variable for vcpkg

* remove dependency

* add pkg-config to Shared Build
  • Loading branch information
GelilaSeifu authored Jul 16, 2021
1 parent e0dc9b0 commit f591537
Show file tree
Hide file tree
Showing 10 changed files with 226 additions and 49 deletions.
59 changes: 46 additions & 13 deletions .github/workflows/github-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ on:
env:
HEXL_VER: 1.1.1
HEXL_DIR: ${GITHUB_WORKSPACE}/lib/cmake/hexl-${HEXL_VER}
ICELAKE_CMAKE_TOOLCHAIN_FILE: >
-DCMAKE_TOOLCHAIN_FILE=/home/github-ci/vcpkg/scripts/buildsystems/vcpkg.cmake
DEFAULT_EXAMPLE_FLAGS: >
-DHEXL_HINT_DIR=${GITHUB_WORKSPACE}/lib/cmake/hexl-${HEXL_VER}
DEFAULT_COMPILER_FLAGS: >
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_CXX_COMPILER=clang++-10
-DCMAKE_C_COMPILER=clang-10
-DHEXL_BENCHMARK=ON
Expand Down Expand Up @@ -98,15 +101,16 @@ jobs:
cmake --install build
# Build example
cd example;
cd example/cmake;
cmake -S . -B build ${{ env.DEFAULT_EXAMPLE_FLAGS }}
cmake --build build -j4
cd ..
# Run tests and example
# Run example
build/example
cd ../..
# Run tests
build/test/unit-test
example/build/example
set +x
shared-build:
Expand Down Expand Up @@ -139,7 +143,7 @@ jobs:
cmake --install build
# Build and run example
cd example;
cd example/cmake;
cmake -S . -B build -DHEXL_SHARED_LIB=ON -DCMAKE_INSTALL_PREFIX=./ ${{ env.DEFAULT_EXAMPLE_FLAGS }}
cmake --build build -j4
build/example
Expand Down Expand Up @@ -179,7 +183,7 @@ jobs:
build/test/unit-test
# Build and run example
cd example;
cd example/cmake;
cmake -S . -B build -DCMAKE_CXX_COMPILER=g++-9 -DCMAKE_C_COMPILER=gcc-9 -DCMAKE_INSTALL_PREFIX=./ ${{ env.DEFAULT_EXAMPLE_FLAGS }}
cmake --build build -j4
build/example
Expand Down Expand Up @@ -288,6 +292,8 @@ jobs:
cmake --version
pwd
ls
# export PKG_CONFIG_PATH=$GITHUB_WORKSPACE/lib/pkgconfig
# echo $PKG_CONFIG_PATH
- name: Default Build
run: |
Expand All @@ -298,15 +304,35 @@ jobs:
cmake --install build
# Build example
cd example;
cd example/cmake;
cmake -S . -B build ${{ env.DEFAULT_EXAMPLE_FLAGS }}
cmake --build build -j4
# Run example
build/example
# Build example using pkg-config
cd ../pkg-config;
# Set PKG_CONFIG_PATH to locate hexl.pc
export PKG_CONFIG_PATH=$GITHUB_WORKSPACE/lib/pkgconfig
cmake -S . -B build
cmake --build build -j4
cd ..
# Run tests and example
# Run example
build/example
# Build example using vcpkg
cd ../vcpkg;
cmake -S . -B build ${{env.ICELAKE_CMAKE_TOOLCHAIN_FILE}}
cmake --build build -j4
# Run example
build/example
cd ../..
# Run tests
build/test/unit-test
example/build/example
set +x
shared-build-icelake:
Expand Down Expand Up @@ -339,10 +365,17 @@ jobs:
cmake --install build
# Build and run example
cd example;
cd example/cmake;
cmake -S . -B build -DHEXL_SHARED_LIB=ON -DCMAKE_INSTALL_PREFIX=./ ${{ env.DEFAULT_EXAMPLE_FLAGS }}
cmake --build build -j4
build/example
# Build example using pkg-config
cd ../pkg-config;
# Set PKG_CONFIG_PATH to locate hexl.pc
export PKG_CONFIG_PATH=$GITHUB_WORKSPACE/lib/pkgconfig
cmake -S . -B build
cmake --build build -j4
set +x
debug-build-icelake:
Expand Down Expand Up @@ -376,7 +409,7 @@ jobs:
build/test/unit-test
# Build and run example
cd example;
cd example/cmake;
cmake -S . -B build -DCMAKE_CXX_COMPILER=g++-9 -DCMAKE_C_COMPILER=gcc-9 -DCMAKE_INSTALL_PREFIX=./ ${{ env.DEFAULT_EXAMPLE_FLAGS }}
cmake --build build -j4
build/example
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ docs/doxygen/
Doxyfile
hexl/include/hexl/util/defines.hpp
cmake/hexl-*.*.*/HEXLConfig.cmake
pkgconfig/hexl.pc
22 changes: 21 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,30 @@ message(STATUS "CMAKE_INSTALL_LIBDIR: ${CMAKE_INSTALL_LIBDIR}")
message(STATUS "CMAKE_INSTALL_INCLUDEDIR: ${CMAKE_INSTALL_INCLUDEDIR}")
message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/hexl.pc.in ${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/hexl.pc @ONLY)

if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/hexl.pc)
install(
FILES ${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/hexl.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
endif()

#------------------------------------------------------------------------------
# Third-party code...
#------------------------------------------------------------------------------
add_subdirectory(cmake/third-party/cpu-features)
find_package(CpuFeatures CONFIG)
if (NOT CpuFeatures_FOUND)
message(STATUS "CpuFeatures: not found")
add_subdirectory(cmake/third-party/cpu-features)
else()
message(STATUS "CpuFeatures: found")
add_library(cpu_features ALIAS CpuFeatures::cpu_features)
get_target_property(
CpuFeatures_INCLUDE_DIR
CpuFeatures::cpu_features
INTERFACE_INCLUDE_DIRECTORIES)
endif()


if (HEXL_TESTING OR HEXL_BENCHMARK OR HEXL_DEBUG)
if(NOT TARGET Threads::Threads)
Expand Down
6 changes: 6 additions & 0 deletions cmake/hexl/HEXLConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@

@PACKAGE_INIT@

include(CMakeFindDependencyMacro)
find_package(CpuFeatures CONFIG)
if(NOT CpuFeatures_FOUND)
message(WARNING "Could not find dependency `CpuFeatures` required by this configuration")
endif()

include(${CMAKE_CURRENT_LIST_DIR}/HEXLTargets.cmake)

# Defines HEXL_FOUND: If Intel HEXL library was found
Expand Down
22 changes: 19 additions & 3 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
# Example using Intel HEXL in an external application

To use Intel HEXL in an external application, first install Intel HEXL. Then, in your external application, add the following lines to your `CMakeLists.txt`:
To use Intel HEXL in an external application, you can use one of the three provided ways.

* Install Intel HEXL. Then, in your external application, add the following lines to your `CMakeLists.txt`:

```bash
find_package(HEXL 1.1.1
HINTS ${HEXL_HINT_DIR}
REQUIRED)
target_link_libraries(<your target> hexl)
target_link_libraries(<your target> HEXL::hexl)
```
If Intel HEXL is installed globally, `HEXL_HINT_DIR` is not needed. Otherwise, `HEXL_HINT_DIR` should be the directory containing `HEXLConfig.cmake`, e.g. `${CMAKE_INSTALL_PREFIX}/lib/cmake/hexl-1.1.1/`

* Install Intel HEXL. Then, in your external application, add the following lines to your `CMakeLists.txt`:

```bash
include(FindPkgConfig)
pkg_check_modules(HEXL REQUIRED IMPORTED_TARGET hexl)
target_link_libraries(<your target> PkgConfig::HEXL)
```

If Intel HEXL is installed globally, `HEXL_HINT_DIR` is not needed. Otherwise, `HEXL_HINT_DIR` should be the directory containing `HEXLConfig.cmake`, e.g. `${CMAKE_INSTALL_PREFIX}/lib/cmake/hexl-1.1.0/`
* Install Intel HEXL from vcpkg. Then, in your external application, add the following lines to your `CMakeLists.txt`:

```bash
find_package(HEXL CONFIG REQUIRED)
target_link_libraries(<your target> HEXL::hexl)
```
3 changes: 2 additions & 1 deletion example/CMakeLists.txt → example/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ project(hexl_example LANGUAGES C CXX)
cmake_minimum_required(VERSION 3.5.1)
set(CMAKE_CXX_STANDARD 11)

# Example using source
find_package(HEXL 1.1.1
HINTS ${HEXL_HINT_DIR}
REQUIRED)
if (NOT TARGET HEXL::hexl)
message(FATAL_ERROR "TARGET HEXL::hexl not found")
endif()

add_executable(example example.cpp)
add_executable(example ../example.cpp)
target_link_libraries(example PRIVATE HEXL::hexl)
17 changes: 17 additions & 0 deletions example/pkg-config/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright (C) 2020-2021 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

project(hexl_example LANGUAGES C CXX)
cmake_minimum_required(VERSION 3.5.1)
set(CMAKE_CXX_STANDARD 11)

# Example using pkg_check_modules
include(FindPkgConfig)
if(NOT PKG_CONFIG_FOUND)
message(FATAL_ERROR "pkg-config not found!" )
endif()

pkg_check_modules(HEXL REQUIRED IMPORTED_TARGET hexl)

add_executable(example ../example.cpp)
target_link_libraries(example PkgConfig::HEXL)
17 changes: 17 additions & 0 deletions example/vcpkg/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright (C) 2020-2021 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

project(hexl_example LANGUAGES C CXX)
cmake_minimum_required(VERSION 3.5.1)
set(CMAKE_CXX_STANDARD 11)

# Example using vcpkg
find_package(HEXL CONFIG REQUIRED)
if(NOT HEXL_FOUND)
message(FATAL_ERROR "HEXL: not found")
else()
message(STATUS "HEXL: found")
endif()

add_executable(example ../example.cpp)
target_link_libraries(example PRIVATE HEXL::hexl)
Loading

0 comments on commit f591537

Please sign in to comment.