wjwwood / serial

Cross-platform, Serial Port library written in C++
http://wjwwood.github.com/serial/
MIT License
2.11k stars 1.02k forks source link

Cmake: Make static libs #254

Closed Mr-Bossman closed 1 year ago

Mr-Bossman commented 3 years ago

Some people may want a static lib...

lp35 commented 1 year ago

Hey MrBossman!

Normally the cmake variable BUILD_SHARED_LIBS should be used prior to hard-coded static library.

If you want to use it in a subdirectory, you might use the following syntax:

set(BUILD_SHARED_LIBS OFF)
add_subdirectory(lib/serial)

In the case you are compiling the library alone, you can use

-DBUILD_SHARED_LIBS=OFF

on the command line.

Last suggestion, as BUILD_SHARED_LIBS is often tedious to maintain when a lot of libraries are used in a project, as this flag can change the behaviour of other libraries inclusion:

set(WJWSERIAL_BUILD_SHARED "ON" CACHE BOOL "Force build of the shared version.")

then

if(WJWSERIAL_BUILD_SHARED)
add_library(..... SHARED ...)
else()
add_library(.... STATIC ...)
endif()
Mr-Bossman commented 1 year ago

Hey MrBossman!

Normally the cmake variable BUILD_SHARED_LIBS should be used prior to hard-coded static library.

Interesting not too experienced with Cmake. Do you happen to know a lot about Automake?

If you want to use it in a subdirectory, you might use the following syntax:

set(BUILD_SHARED_LIBS OFF)
add_subdirectory(lib/serial)

In the case you are compiling the library alone, you can use

-DBUILD_SHARED_LIBS=OFF

on the command line.

Last suggestion, as BUILD_SHARED_LIBS is often tedious to maintain when a lot of libraries are used in a project, as this flag can change the behaviour of other libraries inclusion:

So this builds both when OFF?

set(WJWSERIAL_BUILD_SHARED "ON" CACHE BOOL "Force build of the shared version.")

then

if(WJWSERIAL_BUILD_SHARED)
add_library(..... SHARED ...)
else()
add_library(.... STATIC ...)
endif()