Skip to content

Commit

Permalink
Try pull request avrdudes#960 for static and shared build
Browse files Browse the repository at this point in the history
Try the changes from avrdudes#960
  • Loading branch information
mcuee authored Oct 25, 2022
1 parent 7695311 commit c990334
Showing 1 changed file with 77 additions and 29 deletions.
106 changes: 77 additions & 29 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ endif()
# Setup target specific options
# =====================================

include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR})
add_compile_definitions(CONFIG_DIR=\"${CONFIG_DIR}\")

include_directories(
BEFORE ${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)

if(WIN32)
set(EXTRA_WINDOWS_RESOURCES "${PROJECT_BINARY_DIR}/src/windows.rc")
set(EXTRA_WINDOWS_LIBRARIES setupapi ws2_32)
Expand Down Expand Up @@ -132,7 +136,25 @@ add_custom_target(conf ALL DEPENDS avrdude.conf)
# Project
# =====================================

add_library(libavrdude
set(includes
"${PROJECT_SOURCE_DIR}"
"${PROJECT_BINARY_DIR}"
"${LIBUSB_COMPAT_DIR}"
"${EXTRA_WINDOWS_INCLUDES}"
)
set(deplibs
${LIB_MATH}
${LIB_LIBELF}
${LIB_LIBUSB}
${LIB_LIBUSB_1_0}
${LIB_LIBHID}
${LIB_LIBHIDAPI}
${LIB_LIBFTDI}
${LIB_LIBFTDI1}
${LIB_LIBREADLINE}
${EXTRA_WINDOWS_LIBRARIES}
)
set(sources
ac_cfg.h
arduino.h
arduino.c
Expand Down Expand Up @@ -242,35 +264,57 @@ add_library(libavrdude
"${EXTRA_WINDOWS_SOURCES}"
)

set_target_properties(libavrdude PROPERTIES
PREFIX ""
PUBLIC_HEADER "libavrdude.h"
VERSION 1.0.0
SOVERSION 1
)
if (MSVC)
set(BUILT_LIBS staticlib)
add_library(staticlib STATIC ${sources})
set_target_properties(staticlib PROPERTIES
PREFIX ""
OUTPUT_NAME "libavrdude"
PUBLIC_HEADER "libavrdude.h"
)
target_include_directories(staticlib PUBLIC ${includes})
target_link_libraries(staticlib PUBLIC ${deplibs})
else()
# build objects
add_library(objlib OBJECT ${sources})
target_include_directories(objlib PUBLIC ${includes})
set_target_properties(objlib PROPERTIES
POSITION_INDEPENDENT_CODE true)

target_include_directories(libavrdude
PUBLIC
"${PROJECT_SOURCE_DIR}"
"${PROJECT_BINARY_DIR}"
"${LIBUSB_COMPAT_DIR}"
"${EXTRA_WINDOWS_INCLUDES}"
)
# staticlib
set(BUILT_LIBS staticlib)
add_library(staticlib STATIC $<TARGET_OBJECTS:objlib>)
set_target_properties(staticlib PROPERTIES
PREFIX ""
OUTPUT_NAME "libavrdude"
PUBLIC_HEADER "libavrdude.h"
)
target_include_directories(staticlib PUBLIC ${includes})
target_link_libraries(staticlib PUBLIC ${deplibs})

target_link_libraries(libavrdude
PUBLIC
${LIB_MATH}
${LIB_LIBELF}
${LIB_LIBUSB}
${LIB_LIBUSB_1_0}
${LIB_LIBHID}
${LIB_LIBHIDAPI}
${LIB_LIBFTDI}
${LIB_LIBFTDI1}
${LIB_LIBREADLINE}
${EXTRA_WINDOWS_LIBRARIES}
)
# sharedlib
if(NOT WIN32) # DLL cannot have undefined references
set(BUILT_LIBS staticlib sharedlib)
add_library(sharedlib SHARED $<TARGET_OBJECTS:objlib>)
set_target_properties(sharedlib PROPERTIES
PREFIX ""
OUTPUT_NAME "libavrdude"
PUBLIC_HEADER "libavrdude.h"
VERSION 1.0.0
SOVERSION 1
)
target_include_directories(sharedlib PUBLIC ${includes})
target_link_libraries(sharedlib PUBLIC ${deplibs})
if (APPLE)
target_link_options(sharedlib
PRIVATE -undefined
PRIVATE dynamic_lookup
)
endif()
endif()
endif()

# executable
add_executable(avrdude
main.c
term.c
Expand All @@ -285,7 +329,11 @@ add_executable(avrdude
"${EXTRA_WINDOWS_RESOURCES}"
)

target_link_libraries(avrdude PUBLIC libavrdude)
if (sharedlib IN_LIST BUILT_LIBS)
target_link_libraries(avrdude PUBLIC sharedlib)
else()
target_link_libraries(avrdude PUBLIC staticlib)
endif()

# =====================================
# Install
Expand Down

0 comments on commit c990334

Please sign in to comment.