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

Commit eaecc74

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). Also, Instead of linking against ParameterFramework::parameter, plugins may now link against ParameterFramework::plugin. This has the added value of preventing the installation of libxmlserializer.a and libpfw_utility.a. 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 eaecc74

File tree

11 files changed

+111
-27
lines changed

11 files changed

+111
-27
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)

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ build_script:
8888
# %INSTALL%\bin is where parameter.dll is installed
8989
# Also add the path where the release libxml2.dll has been extracted
9090
- set TEST_PATH=%RELEASE_LIBXML2_PATH%\bin;%INSTALL%\lib;%INSTALL%\bin
91-
- cmake -G "Visual Studio 14 2015 Win64" -DCMAKE_INSTALL_PREFIX=%INSTALL% -DCMAKE_PREFIX_PATH=%INSTALL% %APPVEYOR_BUILD_FOLDER%\skeleton-subsystem
91+
- cmake -G "Visual Studio 14 2015 Win64" -DCMAKE_INSTALL_PREFIX=%INSTALL% -DCMAKE_PREFIX_PATH="%INSTALL%;%RELEASE_LIBXML2_PATH%" %APPVEYOR_BUILD_FOLDER%\skeleton-subsystem
9292
# Unfortunately, the skeleton test currently doesn't work on
9393
# multi-configuration build systems (Visual Studio is one of those) without
9494
# installing the plugin

cmake/CMakeLists.txt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
34+
include(CMakePackageConfigHelpers)
35+
write_basic_package_version_file(
36+
"${CMAKE_CURRENT_BINARY_DIR}/ParameterFrameworkConfigVersion.cmake"
37+
VERSION ${PF_VERSION_MAJOR}.${PF_VERSION_MINOR}.${PF_VERSION_PATCH}
38+
COMPATIBILITY SameMajorVersion)
39+
40+
export(EXPORT ParameterTargets
41+
FILE "${CMAKE_CURRENT_BINARY_DIR}/ParameterFrameworkTargets.cmake"
42+
NAMESPACE ParameterFramework::)
43+
44+
install(EXPORT ParameterTargets DESTINATION lib/cmake/ParameterFramework
45+
FILE ParameterFrameworkTargets.cmake
46+
NAMESPACE ParameterFramework::)
47+
install(FILES
48+
"${CMAKE_CURRENT_BINARY_DIR}/ParameterFrameworkConfig.cmake"
49+
"${CMAKE_CURRENT_BINARY_DIR}/ParameterFrameworkConfigVersion.cmake"
50+
DESTINATION lib/cmake/ParameterFramework)
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: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,32 @@ endif()
127127
configure_file(version.h.in "${CMAKE_CURRENT_BINARY_DIR}/version.h")
128128

129129
target_link_libraries(parameter
130-
# Unfortunately xmlSink and xmlSource need to be exposed to the plugins
131-
PUBLIC xmlserializer
132-
PRIVATE pfw_utility remote-processor
130+
PRIVATE xmlserializer pfw_utility remote-processor
133131
PRIVATE ${CMAKE_DL_LIBS})
134132

135133
target_include_directories(parameter
136-
PUBLIC include
137-
PUBLIC log/include)
134+
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
135+
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/log/include>)
136+
137+
install(TARGETS parameter EXPORT ParameterTargets
138+
LIBRARY DESTINATION lib RUNTIME DESTINATION bin ARCHIVE DESTINATION lib
139+
INCLUDES DESTINATION "include/parameter/client" "include/parameter/plugin")
140+
141+
# Export an interface library for plugins to use (after the ParameterFramework
142+
# project is built and installed). It makes them link against libparameter and
143+
# use xmlserializer's and pfw_utilify's include directories.
144+
add_library(plugin INTERFACE)
145+
target_link_libraries(plugin INTERFACE parameter)
146+
install(TARGETS plugin EXPORT ParameterTargets
147+
INCLUDES DESTINATION "include/parameter/xmlserializer" "include/parameter/utility")
148+
# Unfortunately, while the "plugin" interface library is suitable for external
149+
# plugins (built using the installed Parameter Framework) we want to build some
150+
# plugins before the whole project is installed. Therefore, they need to get
151+
# xmlserializer's and pfw_utility's headers from the build tree. This
152+
# "plugin-internal-hack" is for them.
153+
add_library(plugin-internal-hack INTERFACE)
154+
target_link_libraries(plugin-internal-hack INTERFACE parameter xmlserializer)
138155

139-
install(TARGETS parameter LIBRARY DESTINATION lib RUNTIME DESTINATION bin ARCHIVE DESTINATION lib)
140156
# Client headers
141157
install(FILES
142158
"${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 PRIVATE ParameterFramework::plugin)
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}"

test/introspection-subsystem/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,5 @@ if (BUILD_TESTING)
5454
target_include_directories(introspection-subsystem
5555
PUBLIC "include")
5656

57-
target_link_libraries(introspection-subsystem PRIVATE parameter)
57+
target_link_libraries(introspection-subsystem PRIVATE plugin-internal-hack)
5858
endif()

test/test-subsystem/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ if (BUILD_TESTING)
3535
TESTSubsystemString.cpp
3636
TESTSubsystemBuilder.cpp)
3737

38-
target_link_libraries(test-subsystem PRIVATE parameter)
38+
target_link_libraries(test-subsystem PRIVATE plugin-internal-hack)
3939
endif()

0 commit comments

Comments
 (0)