Skip to content

Commit 528b80c

Browse files
committed
use generate_export_header
1 parent 64c8e29 commit 528b80c

File tree

10 files changed

+29
-59
lines changed

10 files changed

+29
-59
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ endif()
5454
include(CMakeParseArguments)
5555
include(BuildUtils)
5656
include(ThirdpartyToolchain)
57+
include(GenerateExportHeader)
5758

5859
add_subdirectory(src)
5960

cmake_modules/BuildUtils.cmake

+11-10
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,17 @@ function(add_iceberg_lib LIB_NAME)
211211
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
212212
endif()
213213

214+
# generate export header file
215+
string(TOUPPER ${LIB_NAME} LIB_NAME_UPPER)
216+
if(BUILD_SHARED)
217+
generate_export_header(${LIB_NAME}_shared BASE_NAME ${LIB_NAME_UPPER})
218+
if(BUILD_STATIC)
219+
set_target_properties(${LIB_NAME}_static PROPERTIES COMPILE_FLAGS "-D${LIB_NAME_UPPER}_STATIC_DEFINE")
220+
endif()
221+
elseif(BUILD_STATIC)
222+
generate_export_header(${LIB_NAME}_static BASE_NAME ${LIB_NAME_UPPER})
223+
endif()
224+
214225
# Modify variable in calling scope
215226
if(ARG_OUTPUTS)
216227
set(${ARG_OUTPUTS}
@@ -243,13 +254,3 @@ function(iceberg_install_all_headers PATH)
243254
endforeach()
244255
install(FILES ${PUBLIC_HEADERS} DESTINATION "${ICEBERG_INSTALL_INCLUDEDIR}/${PATH}")
245256
endfunction()
246-
247-
function(iceberg_set_export_definitions STATIC_TARGET LIB_TARGETS)
248-
if(ICEBERG_BUILD_STATIC AND WIN32)
249-
target_compile_definitions(${STATIC_TARGET} PUBLIC ICEBERG_STATIC)
250-
endif()
251-
252-
foreach(LIB_TARGET ${LIB_TARGETS})
253-
target_compile_definitions(${LIB_TARGET} PRIVATE ICEBERG_EXPORTING)
254-
endforeach()
255-
endfunction()

src/iceberg/CMakeLists.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@
1616
# under the License.
1717

1818
set(ICEBERG_SOURCES demo_table.cc)
19-
set(ICEBERG_INCLUDES "${CMAKE_SOURCE_DIR}/src")
19+
set(ICEBERG_INCLUDES "${CMAKE_SOURCE_DIR}/src" "${CMAKE_BINARY_DIR}/src")
2020

2121
add_iceberg_lib(iceberg
2222
SOURCES
2323
${ICEBERG_SOURCES}
24-
OUTPUTS
25-
ICEBERG_LIBRARIES
2624
PRIVATE_INCLUDES
2725
${ICEBERG_INCLUDES})
2826

29-
iceberg_set_export_definitions(iceberg_static "${ICEBERG_LIBRARIES}")
3027
iceberg_install_all_headers(iceberg)
3128

29+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/iceberg_export.h
30+
DESTINATION ${ICEBERG_INSTALL_INCLUDEDIR}/iceberg)
31+
3232
add_subdirectory(arrow)
3333
add_subdirectory(puffin)
3434

src/iceberg/arrow/CMakeLists.txt

+4-3
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ list(APPEND
6161
add_iceberg_lib(iceberg_arrow
6262
SOURCES
6363
${ICEBERG_ARROW_SOURCES}
64-
OUTPUTS
65-
ICEBERG_ARROW_LIBRARIES
6664
PRIVATE_INCLUDES
6765
${ICEBERG_ARROW_INCLUDES}
6866
SHARED_LINK_LIBS
@@ -74,5 +72,8 @@ add_iceberg_lib(iceberg_arrow
7472
SHARED_INSTALL_INTERFACE_LIBS
7573
${ICEBERG_ARROW_SHARED_INSTALL_INTERFACE_LIBS})
7674

77-
iceberg_set_export_definitions(iceberg_arrow_static "${ICEBERG_ARROW_LIBRARIES}")
75+
7876
iceberg_install_all_headers(iceberg/arrow)
77+
78+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/iceberg_arrow_export.h
79+
DESTINATION ${ICEBERG_INSTALL_INCLUDEDIR}/iceberg/arrow)

src/iceberg/arrow/demo_arrow.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121

2222
#include <string>
2323

24+
#include "iceberg/arrow/iceberg_arrow_export.h"
2425
#include "iceberg/table.h"
25-
#include "iceberg/visibility.h"
2626

2727
namespace iceberg::arrow {
2828

29-
class ICEBERG_EXPORT DemoArrow : public Table {
29+
class ICEBERG_ARROW_EXPORT DemoArrow : public Table {
3030
public:
3131
DemoArrow() = default;
3232
~DemoArrow() override = default;

src/iceberg/puffin.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
#include <string>
2323

24-
#include "iceberg/visibility.h"
24+
#include "iceberg/iceberg_export.h"
2525

2626
namespace iceberg {
2727

src/iceberg/puffin/CMakeLists.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ list(APPEND
3939
add_iceberg_lib(iceberg_puffin
4040
SOURCES
4141
${ICEBERG_PUFFIN_SOURCES}
42-
OUTPUTS
43-
ICEBERG_PUFFIN_LIBRARIES
4442
PRIVATE_INCLUDES
4543
${ICEBERG_PUFFIN_INCLUDES}
4644
SHARED_LINK_LIBS
@@ -52,5 +50,7 @@ add_iceberg_lib(iceberg_puffin
5250
SHARED_INSTALL_INTERFACE_LIBS
5351
${ICEBERG_PUFFIN_SHARED_INSTALL_INTERFACE_LIBS})
5452

55-
iceberg_set_export_definitions(iceberg_puffin_static "${ICEBERG_PUFFIN_LIBRARIES}")
5653
iceberg_install_all_headers(iceberg/puffin)
54+
55+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/iceberg_puffin_export.h
56+
DESTINATION ${ICEBERG_INSTALL_INCLUDEDIR}/iceberg/puffin)

src/iceberg/puffin/demo_puffin.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
#pragma once
2121

2222
#include "iceberg/puffin.h"
23+
#include "iceberg/puffin/iceberg_puffin_export.h"
2324

2425
namespace iceberg::puffin {
2526

26-
class ICEBERG_EXPORT DemoPuffin : public Puffin {
27+
class ICEBERG_PUFFIN_EXPORT DemoPuffin : public Puffin {
2728
public:
2829
DemoPuffin() = default;
2930
~DemoPuffin() override = default;

src/iceberg/table.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
#include <string>
2323

24-
#include "iceberg/visibility.h"
24+
#include "iceberg/iceberg_export.h"
2525

2626
namespace iceberg {
2727

src/iceberg/visibility.h

-34
This file was deleted.

0 commit comments

Comments
 (0)