Skip to content

Commit

Permalink
Add an option to generate a shared library.
Browse files Browse the repository at this point in the history
  • Loading branch information
Life4gal committed May 16, 2023
1 parent 00d3fea commit 5395479
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
38 changes: 24 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set(

set(
${PROJECT_NAME_PREFIX}PATCH_VERSION
1
2
)

set(${PROJECT_NAME_PREFIX}VERSION ${${PROJECT_NAME_PREFIX}MAJOR_VERSION}.${${PROJECT_NAME_PREFIX}MINOR_VERSION}.${${PROJECT_NAME_PREFIX}PATCH_VERSION})
Expand Down Expand Up @@ -102,6 +102,7 @@ option(${PROJECT_NAME_PREFIX}DOC "Generate the doc target." ${${PROJECT_NAME_PRE
option(${PROJECT_NAME_PREFIX}INSTALL "Generate the install target." ${${PROJECT_NAME_PREFIX}MASTER_PROJECT})
option(${PROJECT_NAME_PREFIX}TEST "Generate the test target." ${${PROJECT_NAME_PREFIX}MASTER_PROJECT})
option(${PROJECT_NAME_PREFIX}SYSTEM_HEADERS "Expose headers with marking them as system.(This allows other libraries that use this library to ignore the warnings generated by this library.)" OFF)
option(${PROJECT_NAME_PREFIX}BUILD_SHARED "Build shared library.)" OFF)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
#set(CMAKE_POSITION_INDEPENDENT_CODE ON)
Expand Down Expand Up @@ -204,12 +205,30 @@ set(
)

# LIBRARY
add_library(
if(${PROJECT_NAME_PREFIX}BUILD_SHARED OR BUILD_SHARED_LIBS)
add_library(
${PROJECT_NAME}
SHARED

${${PROJECT_NAME_PREFIX}HEADER}
${${PROJECT_NAME_PREFIX}SOURCE}
)

target_compile_definitions(
${PROJECT_NAME}
PUBLIC

${${PROJECT_NAME_PREFIX}HEADER}
${${PROJECT_NAME_PREFIX}SOURCE}
)
${PROJECT_NAME_PREFIX}SHARED_LIBRARY
)
else()
add_library(
${PROJECT_NAME}
STATIC

${${PROJECT_NAME_PREFIX}HEADER}
${${PROJECT_NAME_PREFIX}SOURCE}
)
endif(${PROJECT_NAME_PREFIX}BUILD_SHARED OR BUILD_SHARED_LIBS)

# LIBRARY ALIAS
add_library(
Expand Down Expand Up @@ -259,15 +278,6 @@ target_compile_definitions(
# clang-format on
)

# build .dll/.so
if (BUILD_SHARED_LIBS)
target_compile_definitions(
${PROJECT_NAME}
PRIVATE ${PROJECT_NAME_PREFIX}EXPORT
INTERFACE ${PROJECT_NAME_PREFIX}SHARED
)
endif ()

# SET FEATURES
target_compile_features(
${PROJECT_NAME}
Expand Down
10 changes: 7 additions & 3 deletions include/ini/internal/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@
#define GAL_INI_CONSTEVAL consteval
#endif

#if defined(GAL_INI_PLATFORM_WINDOWS)
#define GAL_INI_SYMBOL_EXPORT __declspec(dllexport)
#if defined(GAL_INI_SHARED_LIBRARY)
#if defined(GAL_INI_PLATFORM_WINDOWS)
#define GAL_INI_SYMBOL_EXPORT __declspec(dllexport)
#else
#define GAL_INI_SYMBOL_EXPORT __attribute__((visibility("default")))
#endif
#else
#define GAL_INI_SYMBOL_EXPORT// __attribute__((visibility("default")))
#define GAL_INI_SYMBOL_EXPORT
#endif

namespace gal::ini
Expand Down

0 comments on commit 5395479

Please sign in to comment.