Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: Modernize exported CMake config files #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ list (SORT CommonAPI-SomeIP_SRC)
# CommonAPI
add_library (CommonAPI-SomeIP SHARED ${CommonAPI-SomeIP_SRC})
set_target_properties (CommonAPI-SomeIP PROPERTIES VERSION ${COMPONENT_VERSION} SOVERSION ${COMPONENT_VERSION})
target_link_libraries (CommonAPI-SomeIP CommonAPI vsomeip)
target_include_directories(CommonAPI-SomeIP INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${INSTALL_INCLUDE_DIR}>)
target_link_libraries(CommonAPI-SomeIP PUBLIC CommonAPI vsomeip)

if (MSVC)
target_link_libraries(CommonAPI-SomeIP ws2_32 Rpcrt4)
Expand Down Expand Up @@ -177,24 +180,15 @@ export (PACKAGE CommonAPI-SomeIP)
# Create the CommonAPI-SomeIPConfig.cmake and CommonAPI-SomeIPConfigVersion files
file (RELATIVE_PATH REL_INCLUDE_DIR "${ABSOLUTE_INSTALL_CMAKE_DIR}" "${ABSOLUTE_INSTALL_INCLUDE_DIR}")

# ... for the build tree
set (CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/include")
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/cmake/CommonAPI-SomeIPConfig.cmake.in
"${PROJECT_BINARY_DIR}/CommonAPI-SomeIPConfig.cmake" @ONLY)

# ... for the install tree
set (CONF_INCLUDE_DIRS "\${COMMONAPI_SOMEIP_CMAKE_DIR}/${REL_INCLUDE_DIR}")
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/cmake/CommonAPI-SomeIPConfig.cmake.in
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CommonAPI-SomeIPConfig.cmake" @ONLY)

# ... for both
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/cmake/CommonAPI-SomeIPConfigVersion.cmake.in
"${PROJECT_BINARY_DIR}/CommonAPI-SomeIPConfigVersion.cmake" @ONLY)

# Install the CommonAPI-SomeIPConfig.cmake and CommonAPI-SomeIPConfigVersion.cmake
install (
FILES
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CommonAPI-SomeIPConfig.cmake"
"${PROJECT_BINARY_DIR}/CommonAPI-SomeIPConfig.cmake"
"${PROJECT_BINARY_DIR}/CommonAPI-SomeIPConfigVersion.cmake"
DESTINATION "${INSTALL_CMAKE_DIR}"
)
Expand Down
3 changes: 1 addition & 2 deletions CommonAPI-SomeIP.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Name: @PROJECT@
Description: C++ CommonAPI SOME/IP Runtime
Version: @COMPONENT_VERSION@
Libs: -L${libdir} -lCommonAPI-SomeIP
Requires: CommonAPI
Requires.private: vsomeip
Requires: CommonAPI vsomeip
Cflags: -I${includedir}/CommonAPI-@COMMONAPI_API_HEADER_VERSION@

16 changes: 12 additions & 4 deletions cmake/CommonAPI-SomeIPConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
# Config file for the CommonAPI-SomeIP package
# It defines the following variables
# COMMONAPI_SOMEIP_INCLUDE_DIRS - include directories for CommonAPI-SomeIP
# Exports the follwing targets:
# CommonAPI-SomeIP - CMake target for CommonAPI SomeIP
# Additionally, the following variables are defined:
# COMMONAPI_SOMEIP_VERSION - The CommonAPI-SomeIP version number

# Find dependencies
find_package(CommonAPI REQUIRED)
find_package(vsomeip REQUIRED)

# Compute paths
get_filename_component (COMMONAPI_SOMEIP_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
set (COMMONAPI_SOMEIP_INCLUDE_DIRS "@CONF_INCLUDE_DIRS@")

include ("${COMMONAPI_SOMEIP_CMAKE_DIR}/CommonAPI-SomeIPTargets.cmake")

# Legacy variable, kept for compatibility
get_target_property(COMMONAPI_SOMEIP_INCLUDE_DIRS CommonAPI-SomeIP INTERFACE_INCLUDE_DIRECTORIES)

set(COMMONAPI_SOMEIP_VERSION @PACKAGE_VERSION@)
set(COMMONAPI_SOMEIP_VERSION_STRING "@PACKAGE_VERSION@")
set(COMMONAPI_SOMEIP_VERSION_STRING "@PACKAGE_VERSION@")