Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Now CMake will build both static and shared libs #953

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ option(HAVE_PARPORT "Enable parallel port support" OFF)
option(USE_EXTERNAL "Use external libraries from AVRDUDE GitHub repositories" OFF)
option(USE_LIBUSBWIN32 "Prefer libusb-win32 over libusb" OFF)
option(DEBUG_CMAKE "Enable debugging output for this CMake project" OFF)
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)

include(CheckIncludeFile)
include(CheckSymbolExists)
Expand Down
52 changes: 33 additions & 19 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ 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_SOURCES "${PROJECT_BINARY_DIR}/src/windows.rc")
Expand Down Expand Up @@ -110,7 +113,7 @@ endif()
# Project
# =====================================

add_library(libavrdude
set(sources
ac_cfg.h
arduino.h
arduino.c
Expand Down Expand Up @@ -217,24 +220,13 @@ add_library(libavrdude
${FLEX_Parser_OUTPUTS}
${BISON_Parser_OUTPUTS}
)

set_target_properties(libavrdude PROPERTIES
PREFIX ""
PUBLIC_HEADER "libavrdude.h"
VERSION 1.0.0
SOVERSION 1
)

target_include_directories(libavrdude
PUBLIC
set(includes
"${PROJECT_SOURCE_DIR}"
"${PROJECT_BINARY_DIR}"
"${LIBUSB_COMPAT_DIR}"
"${EXTRA_WINDOWS_INCLUDES}"
)

target_link_libraries(libavrdude
PUBLIC
set(deplibs
${LIB_MATH}
${LIB_LIBELF}
${LIB_LIBUSB}
Expand All @@ -247,6 +239,29 @@ target_link_libraries(libavrdude
${EXTRA_WINDOWS_LIBRARIES}
)

# 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})

# sharedlib
add_library(sharedlib SHARED ${sources})
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})

# executable
add_executable(avrdude
main.c
term.c
Expand All @@ -255,18 +270,17 @@ add_executable(avrdude
whereami.h
"${EXTRA_WINDOWS_SOURCES}"
)

target_link_libraries(avrdude PUBLIC libavrdude)
target_link_libraries(avrdude PUBLIC staticlib)

# =====================================
# Install
# =====================================

install(TARGETS avrdude DESTINATION bin)
install(TARGETS libavrdude
install(TARGETS ${BUILT_LIBS}
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
PUBLIC_HEADER DESTINATION include COMPONENT dev
)
install(TARGETS avrdude DESTINATION bin)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/avrdude.conf" TYPE SYSCONF)
install(FILES avrdude.1 TYPE MAN)