Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit 15bede5

Browse files
committed
CMake: Generate a package configuration file
A Package Configuration file lets other CMake projects easily use our own installed project, simply by calling find_package(ParameterFramework). Known issue: because of dependency leakage, the xmlserializer and pfw_utility static libraries are exported even though they are not supposed to be used by anyone. The related CMake documentation can be found at https://cmake.org/cmake/help/v3.2/manual/cmake-packages.7.html#package-configuration-file Signed-off-by: David Wagner <[email protected]>
1 parent 19f7443 commit 15bede5

File tree

9 files changed

+104
-20
lines changed

9 files changed

+104
-20
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,4 @@ add_subdirectory(doc)
130130
add_subdirectory(schemas)
131131

132132
add_subdirectory(cpack)
133+
add_subdirectory(cmake)

cmake/CMakeLists.txt

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright (c) 2016, Intel Corporation
2+
# All rights reserved.
3+
#
4+
# Redistribution and use in source and binary forms, with or without modification,
5+
# are permitted provided that the following conditions are met:
6+
#
7+
# 1. Redistributions of source code must retain the above copyright notice, this
8+
# list of conditions and the following disclaimer.
9+
#
10+
# 2. Redistributions in binary form must reproduce the above copyright notice,
11+
# this list of conditions and the following disclaimer in the documentation and/or
12+
# other materials provided with the distribution.
13+
#
14+
# 3. Neither the name of the copyright holder nor the names of its contributors
15+
# may be used to endorse or promote products derived from this software without
16+
# specific prior written permission.
17+
#
18+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
22+
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25+
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
29+
configure_file(ParameterFrameworkConfig.cmake
30+
"${CMAKE_CURRENT_BINARY_DIR}/ParameterFrameworkConfig.cmake"
31+
COPYONLY
32+
)
33+
configure_file(CMakeFindDependencyMacro.cmake
34+
"${CMAKE_CURRENT_BINARY_DIR}/CMakeFindDependencyMacro.cmake"
35+
COPYONLY)
36+
37+
include(CMakePackageConfigHelpers)
38+
write_basic_package_version_file(
39+
"${CMAKE_CURRENT_BINARY_DIR}/ParameterFrameworkConfigVersion.cmake"
40+
VERSION ${PF_VERSION_MAJOR}.${PF_VERSION_MINOR}.${PF_VERSION_PATCH}
41+
COMPATIBILITY SameMajorVersion)
42+
43+
export(EXPORT ParameterTargets
44+
FILE "${CMAKE_CURRENT_BINARY_DIR}/ParameterFrameworkTargets.cmake"
45+
NAMESPACE ParameterFramework::)
46+
47+
install(EXPORT ParameterTargets DESTINATION lib/cmake/ParameterFramework
48+
FILE ParameterFrameworkTargets.cmake
49+
NAMESPACE ParameterFramework::)
50+
install(FILES
51+
"${CMAKE_CURRENT_BINARY_DIR}/CMakeFindDependencyMacro.cmake"
52+
"${CMAKE_CURRENT_BINARY_DIR}/ParameterFrameworkConfig.cmake"
53+
"${CMAKE_CURRENT_BINARY_DIR}/ParameterFrameworkConfigVersion.cmake"
54+
DESTINATION lib/cmake/ParameterFramework
55+
COMPONENT Devel)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright (c) 2016, Intel Corporation
2+
# All rights reserved.
3+
#
4+
# Redistribution and use in source and binary forms, with or without modification,
5+
# are permitted provided that the following conditions are met:
6+
#
7+
# 1. Redistributions of source code must retain the above copyright notice, this
8+
# list of conditions and the following disclaimer.
9+
#
10+
# 2. Redistributions in binary form must reproduce the above copyright notice,
11+
# this list of conditions and the following disclaimer in the documentation and/or
12+
# other materials provided with the distribution.
13+
#
14+
# 3. Neither the name of the copyright holder nor the names of its contributors
15+
# may be used to endorse or promote products derived from this software without
16+
# specific prior written permission.
17+
#
18+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
22+
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25+
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
29+
include("${CMAKE_CURRENT_LIST_DIR}/ParameterFrameworkTargets.cmake")

parameter/CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,13 @@ target_link_libraries(parameter
133133
PRIVATE ${CMAKE_DL_LIBS})
134134

135135
target_include_directories(parameter
136-
PUBLIC include
137-
PUBLIC log/include)
136+
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
137+
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/log/include>)
138+
139+
install(TARGETS parameter EXPORT ParameterTargets
140+
LIBRARY DESTINATION lib RUNTIME DESTINATION bin ARCHIVE DESTINATION lib
141+
INCLUDES DESTINATION "include/parameter/client" "include/parameter/plugin")
138142

139-
install(TARGETS parameter LIBRARY DESTINATION lib RUNTIME DESTINATION bin ARCHIVE DESTINATION lib)
140143
# Client headers
141144
install(FILES
142145
"${CMAKE_CURRENT_BINARY_DIR}/parameter_export.h"

remote-processor/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,5 @@ find_package(Threads REQUIRED)
4242

4343
target_link_libraries(remote-processor PRIVATE pfw_utility asio ${CMAKE_THREAD_LIBS_INIT})
4444

45-
install(TARGETS remote-processor LIBRARY DESTINATION lib RUNTIME DESTINATION bin)
45+
install(TARGETS remote-processor EXPORT ParameterTargets
46+
LIBRARY DESTINATION lib RUNTIME DESTINATION bin)

skeleton-subsystem/CMakeLists.txt

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ cmake_minimum_required(VERSION 2.8.12)
3131

3232
project(parameter-framework-plugins-skeleton)
3333

34+
find_package(ParameterFramework REQUIRED)
35+
3436
if(WIN32)
3537
# Force include iso646.h to support alternative operator form (and, or, not...)
3638
# Such support is require by the standard and can be enabled with /Za
@@ -49,25 +51,12 @@ set(CMAKE_VISIBILITY_INLINES_HIDDEN true)
4951
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
5052
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
5153

52-
#
53-
# Find PFW libraries and include directories
54-
#
55-
find_path(PFW_INCLUDE_ROOT NAMES parameter/plugin/Plugin.h)
56-
57-
find_library(PFW_CORE_LIBRARY NAMES parameter)
58-
59-
set(PFW_INCLUDE_DIRS
60-
${PFW_INCLUDE_ROOT}/parameter/plugin
61-
${PFW_INCLUDE_ROOT}/parameter/xmlserializer
62-
${PFW_INCLUDE_ROOT}/parameter/utility)
63-
6454
add_library(skeleton-subsystem MODULE
6555
SkeletonSubsystemBuilder.cpp
6656
SkeletonSubsystem.cpp
6757
SkeletonSubsystemObject.cpp)
6858

69-
target_include_directories(skeleton-subsystem PRIVATE ${PFW_INCLUDE_DIRS})
70-
target_link_libraries(skeleton-subsystem ${PFW_CORE_LIBRARY})
59+
target_link_libraries(skeleton-subsystem ParameterFramework::parameter)
7160

7261
install(TARGETS skeleton-subsystem
7362
LIBRARY DESTINATION lib

skeleton-subsystem/test/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ configure_file(structure.xml "${CMAKE_CURRENT_BINARY_DIR}" COPYONLY)
3030
configure_file(toplevel.xml "${CMAKE_CURRENT_BINARY_DIR}" COPYONLY)
3131

3232
add_executable(skeleton-test main.cpp)
33-
target_include_directories(skeleton-test PRIVATE "${PFW_INCLUDE_ROOT}/parameter/client")
34-
target_link_libraries(skeleton-test "${PFW_CORE_LIBRARY}")
33+
target_link_libraries(skeleton-test PRIVATE ParameterFramework::parameter)
3534

3635
add_test(NAME skeleton-test
3736
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"

utility/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ add_library(pfw_utility STATIC
4141
# Needed for linking against shared libraries on Linux (no-op on Windows)
4242
set_target_properties(pfw_utility PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
4343

44+
install(TARGETS pfw_utility EXPORT ParameterTargets
45+
ARCHIVE DESTINATION lib
46+
INCLUDES DESTINATION "include/parameter/utility")
47+
4448
install(FILES
4549
NonCopyable.hpp
4650
ErrorContext.hpp

xmlserializer/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ target_link_libraries(xmlserializer
6464
PUBLIC pfw_utility # For NonCopyable and ErrorContext
6565
PRIVATE LibXml2::libxml2)
6666

67+
install(TARGETS xmlserializer EXPORT ParameterTargets
68+
ARCHIVE DESTINATION lib
69+
INCLUDES DESTINATION "include/parameter/xmlserializer")
6770

6871
install(FILES
6972
XmlSink.h

0 commit comments

Comments
 (0)