Skip to content

Commit

Permalink
use generate_export_header
Browse files Browse the repository at this point in the history
  • Loading branch information
wgtmac committed Jan 2, 2025
1 parent 64c8e29 commit 0d337bd
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 59 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ endif()
include(CMakeParseArguments)
include(BuildUtils)
include(ThirdpartyToolchain)
include(GenerateExportHeader)

add_subdirectory(src)

Expand Down
22 changes: 12 additions & 10 deletions cmake_modules/BuildUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,18 @@ function(add_iceberg_lib LIB_NAME)
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()

# generate export header file
string(TOUPPER ${LIB_NAME} LIB_NAME_UPPER)
if(BUILD_SHARED)
generate_export_header(${LIB_NAME}_shared BASE_NAME ${LIB_NAME_UPPER})
if(BUILD_STATIC)
set_target_properties(${LIB_NAME}_static
PROPERTIES COMPILE_FLAGS "-D${LIB_NAME_UPPER}_STATIC_DEFINE")
endif()
elseif(BUILD_STATIC)
generate_export_header(${LIB_NAME}_static BASE_NAME ${LIB_NAME_UPPER})
endif()

# Modify variable in calling scope
if(ARG_OUTPUTS)
set(${ARG_OUTPUTS}
Expand Down Expand Up @@ -243,13 +255,3 @@ function(iceberg_install_all_headers PATH)
endforeach()
install(FILES ${PUBLIC_HEADERS} DESTINATION "${ICEBERG_INSTALL_INCLUDEDIR}/${PATH}")
endfunction()

function(iceberg_set_export_definitions STATIC_TARGET LIB_TARGETS)
if(ICEBERG_BUILD_STATIC AND WIN32)
target_compile_definitions(${STATIC_TARGET} PUBLIC ICEBERG_STATIC)
endif()

foreach(LIB_TARGET ${LIB_TARGETS})
target_compile_definitions(${LIB_TARGET} PRIVATE ICEBERG_EXPORTING)
endforeach()
endfunction()
8 changes: 4 additions & 4 deletions src/iceberg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@
# under the License.

set(ICEBERG_SOURCES demo_table.cc)
set(ICEBERG_INCLUDES "${CMAKE_SOURCE_DIR}/src")
set(ICEBERG_INCLUDES "${CMAKE_SOURCE_DIR}/src" "${CMAKE_BINARY_DIR}/src")

add_iceberg_lib(iceberg
SOURCES
${ICEBERG_SOURCES}
OUTPUTS
ICEBERG_LIBRARIES
PRIVATE_INCLUDES
${ICEBERG_INCLUDES})

iceberg_set_export_definitions(iceberg_static "${ICEBERG_LIBRARIES}")
iceberg_install_all_headers(iceberg)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/iceberg_export.h
DESTINATION ${ICEBERG_INSTALL_INCLUDEDIR}/iceberg)

add_subdirectory(arrow)
add_subdirectory(puffin)

Expand Down
7 changes: 4 additions & 3 deletions src/iceberg/arrow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ list(APPEND
add_iceberg_lib(iceberg_arrow
SOURCES
${ICEBERG_ARROW_SOURCES}
OUTPUTS
ICEBERG_ARROW_LIBRARIES
PRIVATE_INCLUDES
${ICEBERG_ARROW_INCLUDES}
SHARED_LINK_LIBS
Expand All @@ -74,5 +72,8 @@ add_iceberg_lib(iceberg_arrow
SHARED_INSTALL_INTERFACE_LIBS
${ICEBERG_ARROW_SHARED_INSTALL_INTERFACE_LIBS})

iceberg_set_export_definitions(iceberg_arrow_static "${ICEBERG_ARROW_LIBRARIES}")

iceberg_install_all_headers(iceberg/arrow)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/iceberg_arrow_export.h
DESTINATION ${ICEBERG_INSTALL_INCLUDEDIR}/iceberg/arrow)
4 changes: 2 additions & 2 deletions src/iceberg/arrow/demo_arrow.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@

#include <string>

#include "iceberg/arrow/iceberg_arrow_export.h"
#include "iceberg/table.h"
#include "iceberg/visibility.h"

namespace iceberg::arrow {

class ICEBERG_EXPORT DemoArrow : public Table {
class ICEBERG_ARROW_EXPORT DemoArrow : public Table {
public:
DemoArrow() = default;
~DemoArrow() override = default;
Expand Down
2 changes: 1 addition & 1 deletion src/iceberg/puffin.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include <string>

#include "iceberg/visibility.h"
#include "iceberg/iceberg_export.h"

namespace iceberg {

Expand Down
6 changes: 3 additions & 3 deletions src/iceberg/puffin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ list(APPEND
add_iceberg_lib(iceberg_puffin
SOURCES
${ICEBERG_PUFFIN_SOURCES}
OUTPUTS
ICEBERG_PUFFIN_LIBRARIES
PRIVATE_INCLUDES
${ICEBERG_PUFFIN_INCLUDES}
SHARED_LINK_LIBS
Expand All @@ -52,5 +50,7 @@ add_iceberg_lib(iceberg_puffin
SHARED_INSTALL_INTERFACE_LIBS
${ICEBERG_PUFFIN_SHARED_INSTALL_INTERFACE_LIBS})

iceberg_set_export_definitions(iceberg_puffin_static "${ICEBERG_PUFFIN_LIBRARIES}")
iceberg_install_all_headers(iceberg/puffin)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/iceberg_puffin_export.h
DESTINATION ${ICEBERG_INSTALL_INCLUDEDIR}/iceberg/puffin)
3 changes: 2 additions & 1 deletion src/iceberg/puffin/demo_puffin.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
#pragma once

#include "iceberg/puffin.h"
#include "iceberg/puffin/iceberg_puffin_export.h"

namespace iceberg::puffin {

class ICEBERG_EXPORT DemoPuffin : public Puffin {
class ICEBERG_PUFFIN_EXPORT DemoPuffin : public Puffin {
public:
DemoPuffin() = default;
~DemoPuffin() override = default;
Expand Down
2 changes: 1 addition & 1 deletion src/iceberg/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include <string>

#include "iceberg/visibility.h"
#include "iceberg/iceberg_export.h"

namespace iceberg {

Expand Down
34 changes: 0 additions & 34 deletions src/iceberg/visibility.h

This file was deleted.

0 comments on commit 0d337bd

Please sign in to comment.