Skip to content

Commit

Permalink
Fixes for static build.
Browse files Browse the repository at this point in the history
  • Loading branch information
bluescarni committed Jan 5, 2023
1 parent 8d26ac3 commit 961bbec
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
14 changes: 10 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ message(STATUS "System name: ${CMAKE_SYSTEM_NAME}")
message(STATUS "obake version: ${obake_VERSION}")

# The build options.
option(OBAKE_BUILD_STATIC_LIBRARY "Build static library." OFF)
option(OBAKE_BUILD_STATIC_LIBRARY "Build obake as a static library, instead of dynamic." OFF)
option(OBAKE_BUILD_TESTS "Build unit tests." OFF)
option(OBAKE_BUILD_BENCHMARKS "Build benchmarks." OFF)
option(OBAKE_WITH_LIBBACKTRACE "Use libbacktrace for improved stack traces." OFF)
Expand Down Expand Up @@ -322,21 +322,27 @@ if(YACMA_COMPILER_IS_MSVC)
endif()

if(OBAKE_BUILD_STATIC_LIBRARY)
# Setup of the obake static library.
message(STATUS "obake will be built as a static library.")
set(OBAKE_STATIC_BUILD "#define OBAKE_STATIC_BUILD")
add_library(obake STATIC "${OBAKE_SRC_FILES}")
target_compile_definitions(obake PUBLIC OBAKE_STATIC_BUILD)
else()
# Setup of the obake shared library.
add_library(obake SHARED "${OBAKE_SRC_FILES}")
set_property(TARGET obake PROPERTY VERSION "8.0")
set_property(TARGET obake PROPERTY SOVERSION 8)
set_target_properties(obake PROPERTIES CXX_VISIBILITY_PRESET hidden)
set_target_properties(obake PROPERTIES VISIBILITY_INLINES_HIDDEN TRUE)
endif()

# Setup common to both the shared and static variants.
target_compile_options(obake PRIVATE
"$<$<CONFIG:Debug>:${OBAKE_CXX_FLAGS_DEBUG}>"
"$<$<CONFIG:Release>:${OBAKE_CXX_FLAGS_RELEASE}>"
"$<$<CONFIG:RelWithDebInfo>:${OBAKE_CXX_FLAGS_RELEASE}>"
"$<$<CONFIG:MinSizeRel>:${OBAKE_CXX_FLAGS_RELEASE}>"
)
set_target_properties(obake PROPERTIES CXX_VISIBILITY_PRESET hidden)
set_target_properties(obake PROPERTIES VISIBILITY_INLINES_HIDDEN TRUE)

# Ensure that C++20 is employed when both compiling and consuming obake.
target_compile_features(obake PUBLIC cxx_std_20)
# Ensure vanilla C++ is being used.
Expand Down
1 change: 1 addition & 0 deletions config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define OBAKE_VERSION_MINOR @obake_VERSION_MINOR@
#define OBAKE_VERSION_PATCH @obake_VERSION_PATCH@
@OBAKE_ENABLE_LIBBACKTRACE@
@OBAKE_STATIC_BUILD@
// clang-format on
// End of defines instantiated by CMake.

Expand Down
2 changes: 2 additions & 0 deletions include/obake/detail/visibility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#ifndef OBAKE_DETAIL_VISIBILITY_HPP
#define OBAKE_DETAIL_VISIBILITY_HPP

#include <obake/config.hpp>

#if defined(OBAKE_STATIC_BUILD)

#define OBAKE_DLL_PUBLIC
Expand Down

0 comments on commit 961bbec

Please sign in to comment.