Skip to content

Commit

Permalink
add support for static linking of applications
Browse files Browse the repository at this point in the history
By default, the pre-builts that are used during linking are shared
libraries. This changes seeks for their static counterparts and uses
them during linking. The '-static' flags also added to perform a
complete static link

Build: cmake -G Ninja -DBUILD_UHDR_SHARED_LIBS=0
Test: ./ultrahdr_app
  • Loading branch information
ram-mohan committed Aug 31, 2024
1 parent 3250b81 commit 9f17641
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ if(BUILD_SHARED_LIBS)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)
add_compile_options(-DUHDR_BUILDING_SHARED_LIBRARY)
else()
if(WIN32)
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a)
else()
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
endif()
endif()
if(UHDR_ENABLE_LOGS)
add_compile_options(-DLOG_NDEBUG)
Expand Down Expand Up @@ -524,6 +530,9 @@ target_link_libraries(${UHDR_CORE_LIB_NAME} PRIVATE ${COMMON_LIBS_LIST} ${IMAGEI
if(UHDR_BUILD_EXAMPLES)
add_executable(ultrahdr_app "${EXAMPLES_DIR}/ultrahdr_app.cpp")
add_dependencies(ultrahdr_app ${UHDR_CORE_LIB_NAME})
if(NOT BUILD_SHARED_LIBS AND NOT MSVC)
target_link_options(ultrahdr_app PRIVATE -static)
endif()
if(UHDR_BUILD_FUZZERS)
target_link_options(ultrahdr_app PRIVATE -fsanitize=fuzzer-no-link)
endif()
Expand Down Expand Up @@ -553,6 +562,9 @@ if(UHDR_BUILD_TESTS)
${PRIVATE_INCLUDE_DIR}
${GTEST_INCLUDE_DIRS}
)
if(NOT BUILD_SHARED_LIBS AND NOT MSVC)
target_link_options(ultrahdr_unit_test PRIVATE -static)
endif()
if(UHDR_BUILD_FUZZERS)
target_link_options(ultrahdr_unit_test PRIVATE -fsanitize=fuzzer-no-link)
endif()
Expand All @@ -567,6 +579,9 @@ if(UHDR_BUILD_BENCHMARK)
${PRIVATE_INCLUDE_DIR}
${BENCHMARK_INCLUDE_DIR}
)
if(NOT BUILD_SHARED_LIBS AND NOT MSVC)
target_link_options(ultrahdr_bm PRIVATE -static)
endif()
if(UHDR_BUILD_FUZZERS)
target_link_options(ultrahdr_bm PRIVATE -fsanitize=fuzzer-no-link)
endif()
Expand Down Expand Up @@ -617,6 +632,9 @@ if(UHDR_BUILD_FUZZERS)
else()
target_link_options(ultrahdr_enc_fuzzer PRIVATE -fsanitize=fuzzer)
endif()
if(NOT BUILD_SHARED_LIBS AND NOT MSVC)
target_link_options(ultrahdr_enc_fuzzer PRIVATE -static)
endif()
target_link_libraries(ultrahdr_enc_fuzzer ${UHDR_CORE_LIB_NAME})

add_executable(ultrahdr_dec_fuzzer ${FUZZERS_DIR}/ultrahdr_dec_fuzzer.cpp)
Expand All @@ -627,6 +645,9 @@ if(UHDR_BUILD_FUZZERS)
else()
target_link_options(ultrahdr_dec_fuzzer PRIVATE -fsanitize=fuzzer)
endif()
if(NOT BUILD_SHARED_LIBS AND NOT MSVC)
target_link_options(ultrahdr_dec_fuzzer PRIVATE -static)
endif()
target_link_libraries(ultrahdr_dec_fuzzer ${UHDR_CORE_LIB_NAME})
endif()

Expand Down

0 comments on commit 9f17641

Please sign in to comment.