Skip to content

Commit 535c2e3

Browse files
committed
use single config file with three separate targets to support components
1 parent 8cb2545 commit 535c2e3

9 files changed

+73
-94
lines changed

cmake_modules/BuildUtils.cmake

+13-8
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,15 @@ function(ADD_ICEBERG_LIB LIB_NAME)
137137
endif()
138138

139139
set_target_properties(${LIB_NAME}_shared
140-
PROPERTIES LINK_FLAGS "${ARG_SHARED_LINK_FLAGS}"
141-
OUTPUT_NAME ${LIB_NAME})
140+
PROPERTIES LINK_FLAGS "${ARG_SHARED_LINK_FLAGS}" OUTPUT_NAME
141+
${LIB_NAME})
142142

143143
target_link_libraries(${LIB_NAME}_shared
144144
PUBLIC "$<BUILD_INTERFACE:${ARG_SHARED_LINK_LIBS}>"
145145
"$<INSTALL_INTERFACE:${ARG_SHARED_INSTALL_INTERFACE_LIBS}>"
146146
PRIVATE ${ARG_SHARED_PRIVATE_LINK_LIBS})
147147

148-
install(TARGETS ${LIB_NAME}_shared ${INSTALL_IS_OPTIONAL}
148+
install(TARGETS ${LIB_NAME}_shared
149149
EXPORT ${LIB_NAME}_targets
150150
ARCHIVE DESTINATION ${INSTALL_ARCHIVE_DIR}
151151
LIBRARY DESTINATION ${INSTALL_LIBRARY_DIR}
@@ -187,20 +187,20 @@ function(ADD_ICEBERG_LIB LIB_NAME)
187187
set(LIB_NAME_STATIC ${LIB_NAME})
188188
endif()
189189

190-
set_target_properties(${LIB_NAME}_static
191-
PROPERTIES OUTPUT_NAME ${LIB_NAME_STATIC})
190+
set_target_properties(${LIB_NAME}_static PROPERTIES OUTPUT_NAME ${LIB_NAME_STATIC})
192191

193192
if(ARG_STATIC_INSTALL_INTERFACE_LIBS)
194193
target_link_libraries(${LIB_NAME}_static
195-
INTERFACE "$<INSTALL_INTERFACE:${ARG_STATIC_INSTALL_INTERFACE_LIBS}>")
194+
INTERFACE "$<INSTALL_INTERFACE:${ARG_STATIC_INSTALL_INTERFACE_LIBS}>"
195+
)
196196
endif()
197197

198198
if(ARG_STATIC_LINK_LIBS)
199199
target_link_libraries(${LIB_NAME}_static
200200
PUBLIC "$<BUILD_INTERFACE:${ARG_STATIC_LINK_LIBS}>")
201201
endif()
202202

203-
install(TARGETS ${LIB_NAME}_static ${INSTALL_IS_OPTIONAL}
203+
install(TARGETS ${LIB_NAME}_static
204204
EXPORT ${LIB_NAME}_targets
205205
ARCHIVE DESTINATION ${INSTALL_ARCHIVE_DIR}
206206
LIBRARY DESTINATION ${INSTALL_LIBRARY_DIR}
@@ -210,7 +210,12 @@ function(ADD_ICEBERG_LIB LIB_NAME)
210210
endif()
211211

212212
if(ARG_CMAKE_PACKAGE_NAME)
213-
iceberg_install_cmake_package(${ARG_CMAKE_PACKAGE_NAME} ${LIB_NAME}_targets)
213+
string(REPLACE "_" "-" LIB_NAME_DASHED ${LIB_NAME})
214+
set(TARGETS_CMAKE "${LIB_NAME_DASHED}-targets.cmake")
215+
install(EXPORT ${LIB_NAME}_targets
216+
DESTINATION "${ICEBERG_INSTALL_CMAKEDIR}/${ARG_CMAKE_PACKAGE_NAME}"
217+
NAMESPACE Iceberg::
218+
FILE "${TARGETS_CMAKE}")
214219
endif()
215220

216221
# Modify variable in calling scope

example/CMakeLists.txt

+5-6
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@ project(example)
2222

2323
set(CMAKE_CXX_STANDARD 20)
2424

25-
find_package(IcebergCore CONFIG REQUIRED)
26-
find_package(IcebergPuffin CONFIG REQUIRED)
27-
find_package(IcebergArrow CONFIG REQUIRED)
25+
find_package(Iceberg CONFIG REQUIRED COMPONENTS core puffin arrow)
26+
message(STATUS "Iceberg_FOUND: ${Iceberg_FOUND}")
27+
message(STATUS "Iceberg_VERSION: ${Iceberg_VERSION}")
2828

2929
add_executable(demo_example demo_example.cc)
3030

3131
target_link_libraries(demo_example
32-
PRIVATE IcebergCore::iceberg_core_static
33-
IcebergPuffin::iceberg_puffin_static
34-
IcebergArrow::iceberg_arrow_static)
32+
PRIVATE Iceberg::iceberg_core_static Iceberg::iceberg_puffin_static
33+
Iceberg::iceberg_arrow_static)

src/CMakeLists.txt

+11
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,14 @@
1818
add_subdirectory(arrow)
1919
add_subdirectory(core)
2020
add_subdirectory(puffin)
21+
22+
configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/config.cmake.in"
23+
"${CMAKE_CURRENT_BINARY_DIR}/iceberg-config.cmake"
24+
INSTALL_DESTINATION "${ICEBERG_INSTALL_CMAKEDIR}/Iceberg"
25+
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
26+
write_basic_package_version_file(
27+
"${CMAKE_CURRENT_BINARY_DIR}/iceberg-config-version.cmake"
28+
COMPATIBILITY SameMajorVersion)
29+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/iceberg-config.cmake"
30+
"${CMAKE_CURRENT_BINARY_DIR}/iceberg-config-version.cmake"
31+
DESTINATION "${ICEBERG_INSTALL_CMAKEDIR}/Iceberg")

src/arrow/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ endif()
4646
add_iceberg_lib(
4747
iceberg_arrow
4848
CMAKE_PACKAGE_NAME
49-
IcebergArrow
49+
Iceberg
5050
SOURCES
5151
${ICEBERG_ARROW_SOURCES}
5252
PRIVATE_INCLUDES

src/arrow/IcebergArrowConfig.cmake.in renamed to src/config.cmake.in

+41-13
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,63 @@
1717
#
1818
# This config sets the following variables in your project::
1919
#
20-
# IcebergArrow_FOUND - true if IcebergArrow found on the system
21-
# ICEBERG_ARROW_VERSION - version of the found IcebergArrow
20+
# Iceberg_FOUND - true if Iceberg found on the system
21+
# Iceberg_VERSION - version of the found Iceberg
2222
#
2323
# This config sets the following targets in your project::
2424
#
25-
# IcebergArrow::iceberg_arrow_shared - for linked as shared library if shared library is built
26-
# IcebergArrow::iceberg_arrow_static - for linked as static library if static library is built
25+
# Iceberg::iceberg_core_shared - for linked as shared library if shared library is built
26+
# Iceberg::iceberg_core_static - for linked as static library if static library is built
27+
# Iceberg::iceberg_puffin_shared - for linked as shared library if shared library is built
28+
# Iceberg::iceberg_puffin_static - for linked as static library if static library is built
29+
# Iceberg::iceberg_arrow_shared - for linked as shared library if shared library is built
30+
# Iceberg::iceberg_arrow_static - for linked as static library if static library is built
2731

2832
@PACKAGE_INIT@
2933

34+
include(CMakeFindDependencyMacro)
35+
36+
macro(iceberg_find_dependencies dependencies)
37+
if(DEFINED CMAKE_MODULE_PATH)
38+
set(ICEBERG_CMAKE_MODULE_PATH_OLD ${CMAKE_MODULE_PATH})
39+
else()
40+
unset(ICEBERG_CMAKE_MODULE_PATH_OLD)
41+
endif()
42+
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
43+
44+
foreach(dependency ${dependencies})
45+
find_dependency(${dependency})
46+
endforeach()
47+
48+
if(DEFINED ICEBERG_CMAKE_MODULE_PATH_OLD)
49+
set(CMAKE_MODULE_PATH ${ICEBERG_CMAKE_MODULE_PATH_OLD})
50+
unset(ICEBERG_CMAKE_MODULE_PATH_OLD)
51+
else()
52+
unset(CMAKE_MODULE_PATH)
53+
endif()
54+
endmacro()
55+
3056
set(ICEBERG_BUILD_STATIC "@ICEBERG_BUILD_STATIC@")
3157
set(ICEBERG_ARROW_VENDOR_DEPENDENCIES "@ICEBERG_ARROW_VENDOR_DEPENDENCIES@")
3258
set(ICEBERG_ARROW_SYSTEM_DEPENDENCIES "@ICEBERG_ARROW_SYSTEM_DEPENDENCIES@")
3359

34-
include(CMakeFindDependencyMacro)
35-
find_dependency(IcebergCore)
60+
set(_iceberg_supported_components core puffin arrow)
61+
62+
foreach(_comp ${Iceberg_FIND_COMPONENTS})
63+
if (NOT _comp IN_LIST _iceberg_supported_components)
64+
set(Iceberg_FOUND False)
65+
set(Iceberg_NOT_FOUND_MESSAGE "Unsupported component: ${_comp}")
66+
endif()
67+
include("${CMAKE_CURRENT_LIST_DIR}/iceberg-${_comp}-targets.cmake" REQUIRED)
68+
endforeach()
3669

3770
if(ICEBERG_BUILD_STATIC)
3871
iceberg_find_dependencies("${ICEBERG_ARROW_SYSTEM_DEPENDENCIES}")
3972
endif()
4073

41-
include("${CMAKE_CURRENT_LIST_DIR}/IcebergArrowTargets.cmake")
42-
4374
if(ICEBERG_BUILD_STATIC)
4475
get_target_property(
45-
iceberg_arrow_static_configurations IcebergArrow::iceberg_arrow_static
76+
iceberg_arrow_static_configurations Iceberg::iceberg_arrow_static
4677
IMPORTED_CONFIGURATIONS)
4778

4879
foreach(dependency ${ICEBERG_ARROW_VENDOR_DEPENDENCIES})
@@ -59,7 +90,7 @@ if(ICEBERG_BUILD_STATIC)
5990
foreach(CONFIGURATION ${iceberg_arrow_static_configurations})
6091
string(TOUPPER "${CONFIGURATION}" CONFIGURATION)
6192
get_target_property(
62-
iceberg_arrow_static_location IcebergArrow::iceberg_arrow_static
93+
iceberg_arrow_static_location Iceberg::iceberg_arrow_static
6394
LOCATION_${CONFIGURATION})
6495
get_filename_component(iceberg_arrow_lib_dir
6596
"${iceberg_arrow_static_location}" DIRECTORY)
@@ -73,7 +104,4 @@ if(ICEBERG_BUILD_STATIC)
73104
"${iceberg_arrow_lib_dir}/${static_lib_name}")
74105
endforeach()
75106
endforeach()
76-
77107
endif()
78-
79-
check_required_components(IcebergArrow)

src/core/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ set(ICEBERG_CORE_INCLUDES "${ICEBERG_API_DIR}")
2020

2121
add_iceberg_lib(iceberg_core
2222
CMAKE_PACKAGE_NAME
23-
IcebergCore
23+
Iceberg
2424
SOURCES
2525
${ICEBERG_CORE_SOURCES}
2626
PRIVATE_INCLUDES

src/core/IcebergCoreConfig.cmake.in

-42
This file was deleted.

src/puffin/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ set(ICEBERG_PUFFIN_INCLUDES "${ICEBERG_API_DIR}")
2020

2121
add_iceberg_lib(iceberg_puffin
2222
CMAKE_PACKAGE_NAME
23-
IcebergPuffin
23+
Iceberg
2424
SOURCES
2525
${ICEBERG_PUFFIN_SOURCES}
2626
PRIVATE_INCLUDES

src/puffin/IcebergPuffinConfig.cmake.in

-22
This file was deleted.

0 commit comments

Comments
 (0)