Skip to content

Commit

Permalink
feature: add handling to install dll too (#19)
Browse files Browse the repository at this point in the history
* add handling to install dll too

modernize cmake files too

* reduce the scope of hidden visibility

* add new arguments to .cmake-format

build dll anly if requested

* fix github yml test config

* fix the mixed build of dll and static libs

tested und debian

* update readme

update used package versions too

* fix wrong option checking

do not use if(DEFINED ...), functions argumanet are always defined!

* revert to orign for one_value_keywords

add notes about the differents

* use option DISABLE_VERSION_SUFFIX YES instead of NO_VERSION_SUFFIX flag

* reformat and yamllint github workflows

support git flow too (with branch develop)

* add new options: DISABLE_CHECK_REQUIRED_COMPONENTS

to calls configure_package_config_file(NO_CHECK_REQUIRED_COMPONENTS_MACRO
...) with this options set

* call check_required_components() only if enabled

* revert my changes

check_required_components() is not longer used

* Update .github/workflows/style.yml

Co-authored-by: Lars Melchior <[email protected]>

* changes according the review comments

build always the shared lib

* do not start CI build on develop branch

requested while review

* Update test/CMakeLists.txt

Co-authored-by: Lars Melchior <[email protected]>

* Update CMakeLists.txt

fix typo

Co-authored-by: Lars Melchior <[email protected]>

Co-authored-by: Lars Melchior <[email protected]>
  • Loading branch information
ClausKlein and TheLartians authored Mar 30, 2021
1 parent 0ef7d94 commit 18beef4
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .cmake-format
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@ parse:
BINARY_DIR: 1
COMPATIBILITY: 1
VERSION_HEADER: 1
EXPORT_HEADER: 1
DISABLE_VERSION_SUFFIX: 1
DEPENDENCIES: +
23 changes: 12 additions & 11 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: Style

on:
Expand All @@ -12,17 +13,17 @@ jobs:
style:

runs-on: macos-latest

steps:
- uses: actions/checkout@v1
- name: Install format dependencies
run: |
brew install clang-format
pip3 install cmake_format==0.6.11 pyyaml
- uses: actions/checkout@v1

- name: Install format dependencies
run: |
brew install clang-format
pip3 install cmake_format==0.6.13 pyyaml
- name: configure
run: cmake -Stest/style -Bbuild/style
- name: configure
run: cmake -S test/style -B build/style

- name: check style
run: cmake --build build/style --target check-format
- name: check style
run: cmake --build build/style --target check-format
9 changes: 5 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: Test

on:
Expand Down Expand Up @@ -27,12 +28,12 @@ jobs:
- name: test and install local build
run: |
cmake -S test -B build/local
cmake --build build/local
./build/local/test
cmake --build build/local
cmake --build build/local --target test
sudo cmake --build build/local --target install
- name: test installed build
run: |
cmake -S test -B build/installed -D TEST_INSTALLED_VERSION=1
cmake --build build/installed
./build/installed/test
cmake --build build/installed
cmake --build build/installed --target test
24 changes: 16 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function(packageProject)
cmake_parse_arguments(
PROJECT
""
"NAME;VERSION;INCLUDE_DIR;INCLUDE_DESTINATION;BINARY_DIR;COMPATIBILITY;VERSION_HEADER;NAMESPACE;DISABLE_VERSION_SUFFIX;ARCH_INDEPENDENT"
"NAME;VERSION;INCLUDE_DIR;INCLUDE_DESTINATION;BINARY_DIR;COMPATIBILITY;EXPORT_HEADER;VERSION_HEADER;NAMESPACE;DISABLE_VERSION_SUFFIX;ARCH_INDEPENDENT"
"DEPENDENCIES"
${ARGN}
)
Expand All @@ -26,7 +26,6 @@ function(packageProject)
set(PROJECT_VERSION_SUFFIX -${PROJECT_VERSION})
endif()

# handle default arguments:
if(NOT DEFINED PROJECT_COMPATIBILITY)
set(PROJECT_COMPATIBILITY AnyNewerVersion)
endif()
Expand All @@ -39,14 +38,23 @@ function(packageProject)
add_library(${PROJECT_NAMESPACE}${PROJECT_NAME} ALIAS ${PROJECT_NAME})
endif()

if(DEFINED PROJECT_VERSION_HEADER)
if(DEFINED PROJECT_VERSION_HEADER OR DEFINED PROJECT_EXPORT_HEADER)
set(PROJECT_VERSION_INCLUDE_DIR ${PROJECT_BINARY_DIR}/PackageProjectInclude)

string(TOUPPER ${PROJECT_NAME} UPPERCASE_PROJECT_NAME)
configure_file(
${PACKAGE_PROJECT_ROOT_PATH}/version.h.in
${PROJECT_VERSION_INCLUDE_DIR}/${PROJECT_VERSION_HEADER} @ONLY
)
if(DEFINED PROJECT_EXPORT_HEADER)
include(GenerateExportHeader)
generate_export_header(
${PROJECT_NAME} EXPORT_FILE_NAME ${PROJECT_VERSION_INCLUDE_DIR}/${PROJECT_EXPORT_HEADER}
)
endif()

if(DEFINED PROJECT_VERSION_HEADER)
string(TOUPPER ${PROJECT_NAME} UPPERCASE_PROJECT_NAME)
configure_file(
${PACKAGE_PROJECT_ROOT_PATH}/version.h.in
${PROJECT_VERSION_INCLUDE_DIR}/${PROJECT_VERSION_HEADER} @ONLY
)
endif()

get_target_property(target_type ${PROJECT_NAME} TYPE)
if(target_type STREQUAL "INTERFACE_LIBRARY")
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ packageProject(
# (optional) create a header containing the version info
# Note: that the path to headers should be lowercase
VERSION_HEADER "${PROJECT_NAME}/version.h"
# (optional) create a export header using GenerateExportHeader module
EXPORT_HEADER "${PROJECT_NAME}/export.h"
# (optional) install your library with a namespace (Note: do NOT add extra '::')
NAMESPACE ${PROJECT_NAMESPACE}
# (optional) define the project's version compatibility, defaults to `AnyNewerVersion`
Expand Down
9 changes: 6 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
cmake_minimum_required(VERSION 3.14)

option(TEST_INSTALLED_VERSION "Test the version found by find_package" OFF)

Expand All @@ -18,8 +18,11 @@ else()
add_subdirectory(transitive_dependency)
endif()

add_executable(test main.cpp)
add_executable(main main.cpp)

target_link_libraries(
test dependency ns::namespaced_dependency transitive_dependency::transitive_dependency
main dependency ns::namespaced_dependency transitive_dependency::transitive_dependency
)

enable_testing()
add_test(NAME test COMMAND main)
6 changes: 3 additions & 3 deletions test/dependency/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
cmake_minimum_required(VERSION 3.14)

project(
dependency
VERSION 1.2.3
LANGUAGES CXX
)

add_library(dependency source/dependency.cpp)
add_library(dependency STATIC source/dependency.cpp)

target_include_directories(
dependency PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
)

add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../.. ${CMAKE_CURRENT_BINARY_DIR}/PackageProject)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../.. PackageProject)

packageProject(
NAME ${PROJECT_NAME}
Expand Down
6 changes: 3 additions & 3 deletions test/namespaced_dependency/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
cmake_minimum_required(VERSION 3.14)

project(
namespaced_dependency
Expand All @@ -7,7 +7,7 @@ project(
)

set(PROJECT_NAMESPACE "ns")
add_library(${PROJECT_NAME} source/namespaced_dependency.cpp)
add_library(${PROJECT_NAME} STATIC source/namespaced_dependency.cpp)
# the alias ${PROJECT_NAMESPACE}::${PROJECT_NAME} is automatically provided by PackageProject.cmake
# if we use the `NAMESPACE` parameter

Expand All @@ -16,7 +16,7 @@ target_include_directories(
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
)

add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../.. ${CMAKE_CURRENT_BINARY_DIR}/PackageProject)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../.. PackageProject)

packageProject(
NAME ${PROJECT_NAME}
Expand Down
2 changes: 1 addition & 1 deletion test/style/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
cmake_minimum_required(VERSION 3.14)

project(StyleCheck)

Expand Down
13 changes: 9 additions & 4 deletions test/transitive_dependency/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
cmake_minimum_required(VERSION 3.14)

project(
transitive_dependency
Expand All @@ -22,16 +22,20 @@ CPMAddPackage(
OPTIONS "CXXOPTS_BUILD_EXAMPLES Off" "CXXOPTS_BUILD_TESTS Off"
)

add_library(${PROJECT_NAME} source/transitive_dependency.cpp)
# Set default visibility to hidden for all targets
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)

add_library(${PROJECT_NAME} SHARED source/transitive_dependency.cpp)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
target_link_libraries(${PROJECT_NAME} fmt cxxopts)
target_link_libraries(${PROJECT_NAME} PUBLIC fmt::fmt-header-only cxxopts)

target_include_directories(
transitive_dependency PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
)

add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../.. ${CMAKE_CURRENT_BINARY_DIR}/PackageProject)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../.. PackageProject)

packageProject(
NAME ${PROJECT_NAME}
Expand All @@ -41,5 +45,6 @@ packageProject(
INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include
INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION}
VERSION_HEADER "transitive_dependency/version.h"
EXPORT_HEADER "transitive_dependency/export.h"
DEPENDENCIES "fmt 7.1.3;cxxopts 2.2.0"
)
2 changes: 1 addition & 1 deletion test/transitive_dependency/cmake/CPM.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(CPM_DOWNLOAD_VERSION 0.28.3)
set(CPM_DOWNLOAD_VERSION 0.30.0)

if(CPM_SOURCE_CACHE)
# Expand relative path. This is important if the provided path contains a tilde (~)
Expand Down
3 changes: 2 additions & 1 deletion test/transitive_dependency/source/transitive_dependency.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <fmt/format.h>
#include <transitive_dependency/export.h>
#include <transitive_dependency/version.h>

void transitiveDependencyFunction() {
void TRANSITIVE_DEPENDENCY_EXPORT transitiveDependencyFunction() {
fmt::print("Using transitive_dependency version {}\n", TRANSITIVE_DEPENDENCY_VERSION);
}

0 comments on commit 18beef4

Please sign in to comment.