Skip to content

Avoid building both a shared and static library #85

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ option(ENABLE_VENDOR_SRC "Enable vendor source" ON)
option(TEST_ENABLED "Enable unit test" OFF)
option(EXAMPLE_ENABLED "Build examples" OFF)

if (DEFINED "${PROJECT_NAME}_SHARED_LIBS")
set(BUILD_SHARED_LIBS "${${PROJECT_NAME}_SHARED_LIBS}")
endif()

if (WIN32)
# Needed on MinGW with GCC 10 or lower
add_compile_definitions(_WIN32_WINNT=0x0600)
Expand Down
9 changes: 8 additions & 1 deletion docs/source/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ In order to compile and install the library, type from the project's root direct
cmake ..
cmake --build . --target install

By default, this will build a static library. If a shared library is desired, add the following CMake option:

::

cmake -DEIPScanner_SHARED_LIBS=ON ..


Optionally, you can build the usage examples and the unit tests by adding the following CMake options:

::
Expand Down Expand Up @@ -56,7 +63,7 @@ First of all, we should create *CMakeLists.txt* with the following content:
Pay attention to the last two lines. Currently, **EIPScanner** doesn't provide a cmake module to help to find
the library on your machine and we have to do all manually. First, we point on the include directory whose path
should be `path/were/eipscanner/is/installed/` + `EIPScanner`. Second, we link our executable file with the library
`EIPScanner`. If you'd like to use the static library instead, use `EIPScannerS` name.
`EIPScanner`.

Okay, we have *CMakeLists.txt*. Now we should create *main.cpp* and place there this code:

Expand Down
6 changes: 2 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,10 @@ if(ENABLE_VENDOR_SRC)
add_subdirectory(vendor)
endif()

add_library(EIPScanner SHARED ${SOURCE_FILES} ${VENDOR_FILES})
add_library(EIPScannerS STATIC ${SOURCE_FILES} ${VENDOR_FILES})
add_library(EIPScanner ${SOURCE_FILES} ${VENDOR_FILES})

if(WIN32)
target_link_libraries(EIPScanner ws2_32)
target_link_libraries(EIPScannerS ws2_32)
endif()

set_target_properties(
Expand All @@ -64,7 +62,7 @@ set_target_properties(
VERSION ${EIPSCANNER_FULL_VERSION}
SOVERSION ${EIPSCANNER_MAJOR_VERSION})

install(TARGETS EIPScanner EIPScannerS
install(TARGETS EIPScanner
LIBRARY
DESTINATION lib
ARCHIVE
Expand Down