Skip to content

Commit 18beef4

Browse files
feature: add handling to install dll too (#19)
* 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 <TheLartians@users.noreply.github.com> * 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 <TheLartians@users.noreply.github.com> * Update CMakeLists.txt fix typo Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com> Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com>
1 parent 0ef7d94 commit 18beef4

12 files changed

Lines changed: 62 additions & 39 deletions

File tree

.cmake-format

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,6 @@ parse:
5454
BINARY_DIR: 1
5555
COMPATIBILITY: 1
5656
VERSION_HEADER: 1
57+
EXPORT_HEADER: 1
58+
DISABLE_VERSION_SUFFIX: 1
5759
DEPENDENCIES: +

.github/workflows/style.yml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
name: Style
23

34
on:
@@ -12,17 +13,17 @@ jobs:
1213
style:
1314

1415
runs-on: macos-latest
15-
16+
1617
steps:
17-
- uses: actions/checkout@v1
18-
19-
- name: Install format dependencies
20-
run: |
21-
brew install clang-format
22-
pip3 install cmake_format==0.6.11 pyyaml
18+
- uses: actions/checkout@v1
19+
20+
- name: Install format dependencies
21+
run: |
22+
brew install clang-format
23+
pip3 install cmake_format==0.6.13 pyyaml
2324
24-
- name: configure
25-
run: cmake -Stest/style -Bbuild/style
25+
- name: configure
26+
run: cmake -S test/style -B build/style
2627

27-
- name: check style
28-
run: cmake --build build/style --target check-format
28+
- name: check style
29+
run: cmake --build build/style --target check-format

.github/workflows/test.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
name: Test
23

34
on:
@@ -27,12 +28,12 @@ jobs:
2728
- name: test and install local build
2829
run: |
2930
cmake -S test -B build/local
30-
cmake --build build/local
31-
./build/local/test
31+
cmake --build build/local
32+
cmake --build build/local --target test
3233
sudo cmake --build build/local --target install
3334
3435
- name: test installed build
3536
run: |
3637
cmake -S test -B build/installed -D TEST_INSTALLED_VERSION=1
37-
cmake --build build/installed
38-
./build/installed/test
38+
cmake --build build/installed
39+
cmake --build build/installed --target test

CMakeLists.txt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function(packageProject)
1212
cmake_parse_arguments(
1313
PROJECT
1414
""
15-
"NAME;VERSION;INCLUDE_DIR;INCLUDE_DESTINATION;BINARY_DIR;COMPATIBILITY;VERSION_HEADER;NAMESPACE;DISABLE_VERSION_SUFFIX;ARCH_INDEPENDENT"
15+
"NAME;VERSION;INCLUDE_DIR;INCLUDE_DESTINATION;BINARY_DIR;COMPATIBILITY;EXPORT_HEADER;VERSION_HEADER;NAMESPACE;DISABLE_VERSION_SUFFIX;ARCH_INDEPENDENT"
1616
"DEPENDENCIES"
1717
${ARGN}
1818
)
@@ -26,7 +26,6 @@ function(packageProject)
2626
set(PROJECT_VERSION_SUFFIX -${PROJECT_VERSION})
2727
endif()
2828

29-
# handle default arguments:
3029
if(NOT DEFINED PROJECT_COMPATIBILITY)
3130
set(PROJECT_COMPATIBILITY AnyNewerVersion)
3231
endif()
@@ -39,14 +38,23 @@ function(packageProject)
3938
add_library(${PROJECT_NAMESPACE}${PROJECT_NAME} ALIAS ${PROJECT_NAME})
4039
endif()
4140

42-
if(DEFINED PROJECT_VERSION_HEADER)
41+
if(DEFINED PROJECT_VERSION_HEADER OR DEFINED PROJECT_EXPORT_HEADER)
4342
set(PROJECT_VERSION_INCLUDE_DIR ${PROJECT_BINARY_DIR}/PackageProjectInclude)
4443

45-
string(TOUPPER ${PROJECT_NAME} UPPERCASE_PROJECT_NAME)
46-
configure_file(
47-
${PACKAGE_PROJECT_ROOT_PATH}/version.h.in
48-
${PROJECT_VERSION_INCLUDE_DIR}/${PROJECT_VERSION_HEADER} @ONLY
49-
)
44+
if(DEFINED PROJECT_EXPORT_HEADER)
45+
include(GenerateExportHeader)
46+
generate_export_header(
47+
${PROJECT_NAME} EXPORT_FILE_NAME ${PROJECT_VERSION_INCLUDE_DIR}/${PROJECT_EXPORT_HEADER}
48+
)
49+
endif()
50+
51+
if(DEFINED PROJECT_VERSION_HEADER)
52+
string(TOUPPER ${PROJECT_NAME} UPPERCASE_PROJECT_NAME)
53+
configure_file(
54+
${PACKAGE_PROJECT_ROOT_PATH}/version.h.in
55+
${PROJECT_VERSION_INCLUDE_DIR}/${PROJECT_VERSION_HEADER} @ONLY
56+
)
57+
endif()
5058

5159
get_target_property(target_type ${PROJECT_NAME} TYPE)
5260
if(target_type STREQUAL "INTERFACE_LIBRARY")

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ packageProject(
3131
# (optional) create a header containing the version info
3232
# Note: that the path to headers should be lowercase
3333
VERSION_HEADER "${PROJECT_NAME}/version.h"
34+
# (optional) create a export header using GenerateExportHeader module
35+
EXPORT_HEADER "${PROJECT_NAME}/export.h"
3436
# (optional) install your library with a namespace (Note: do NOT add extra '::')
3537
NAMESPACE ${PROJECT_NAMESPACE}
3638
# (optional) define the project's version compatibility, defaults to `AnyNewerVersion`

test/CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
1+
cmake_minimum_required(VERSION 3.14)
22

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

@@ -18,8 +18,11 @@ else()
1818
add_subdirectory(transitive_dependency)
1919
endif()
2020

21-
add_executable(test main.cpp)
21+
add_executable(main main.cpp)
2222

2323
target_link_libraries(
24-
test dependency ns::namespaced_dependency transitive_dependency::transitive_dependency
24+
main dependency ns::namespaced_dependency transitive_dependency::transitive_dependency
2525
)
26+
27+
enable_testing()
28+
add_test(NAME test COMMAND main)

test/dependency/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
1+
cmake_minimum_required(VERSION 3.14)
22

33
project(
44
dependency
55
VERSION 1.2.3
66
LANGUAGES CXX
77
)
88

9-
add_library(dependency source/dependency.cpp)
9+
add_library(dependency STATIC source/dependency.cpp)
1010

1111
target_include_directories(
1212
dependency PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
1313
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
1414
)
1515

16-
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../.. ${CMAKE_CURRENT_BINARY_DIR}/PackageProject)
16+
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../.. PackageProject)
1717

1818
packageProject(
1919
NAME ${PROJECT_NAME}

test/namespaced_dependency/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
1+
cmake_minimum_required(VERSION 3.14)
22

33
project(
44
namespaced_dependency
@@ -7,7 +7,7 @@ project(
77
)
88

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

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

19-
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../.. ${CMAKE_CURRENT_BINARY_DIR}/PackageProject)
19+
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../.. PackageProject)
2020

2121
packageProject(
2222
NAME ${PROJECT_NAME}

test/style/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
1+
cmake_minimum_required(VERSION 3.14)
22

33
project(StyleCheck)
44

test/transitive_dependency/CMakeLists.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
1+
cmake_minimum_required(VERSION 3.14)
22

33
project(
44
transitive_dependency
@@ -22,16 +22,20 @@ CPMAddPackage(
2222
OPTIONS "CXXOPTS_BUILD_EXAMPLES Off" "CXXOPTS_BUILD_TESTS Off"
2323
)
2424

25-
add_library(${PROJECT_NAME} source/transitive_dependency.cpp)
25+
# Set default visibility to hidden for all targets
26+
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
27+
set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)
28+
29+
add_library(${PROJECT_NAME} SHARED source/transitive_dependency.cpp)
2630
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
27-
target_link_libraries(${PROJECT_NAME} fmt cxxopts)
31+
target_link_libraries(${PROJECT_NAME} PUBLIC fmt::fmt-header-only cxxopts)
2832

2933
target_include_directories(
3034
transitive_dependency PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
3135
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
3236
)
3337

34-
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../.. ${CMAKE_CURRENT_BINARY_DIR}/PackageProject)
38+
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../.. PackageProject)
3539

3640
packageProject(
3741
NAME ${PROJECT_NAME}
@@ -41,5 +45,6 @@ packageProject(
4145
INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include
4246
INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION}
4347
VERSION_HEADER "transitive_dependency/version.h"
48+
EXPORT_HEADER "transitive_dependency/export.h"
4449
DEPENDENCIES "fmt 7.1.3;cxxopts 2.2.0"
4550
)

0 commit comments

Comments
 (0)