Skip to content

Conversation

@szy1210
Copy link

@szy1210 szy1210 commented Sep 4, 2019

Beside libogg.a, libogg.so is generated by modifying file CMakeLists.txt

Beside libogg.a, libogg.so is generated by modifying file CMakeLists.txt
@willson-chen
Copy link
Contributor

It works on Ubuntu 18.04.3 LTS with x86_64

@willson-chen
Copy link
Contributor

Also works on win10 with VS2019

@rillian
Copy link
Contributor

rillian commented Sep 5, 2019

@evpobr Would you mind reviewing this, please?

@evpobr
Copy link
Contributor

evpobr commented Sep 6, 2019

@willson-chen , what's wrong with standard BUILD_SHARED_LIBS option?

@willson-chen
Copy link
Contributor

Cmake generates dynamic lib or static lib according to configurations. This is not wrong but not so convenient for libogg users. Referring to automake which generates dynamic lib and static lib at the same time, I think it is reasonable to make cmake work as the same way. What do you think of it? @rillian @evpobr

@willson-chen
Copy link
Contributor

@evpobr , your comment reminded me about the option. If run cmake with BUILD_SHARED_LIBS, no static lib would be generated. @szy1210

@evpobr
Copy link
Contributor

evpobr commented Sep 7, 2019

Benefits

  • You can build static/shared library at once.

Disadvantages

  • Duplicated and overbloated code. You need options to control two targets (BUILD_SHARED_LIBS and BUILD_STATIC_LIBS) and add logic to prevent user to disable both of them. If some application uses libary in your project you need to add options to contol which library type must be linked to application and add code to detect wrong option combinations.

  • Not all plaftorms supports both static/shared libraries. By default CMake with select supported library type, but with separated library targets configuration will fail. Or you need add logic to detect it.

  • You don't need to build both static/shared builds at the same time very often. If you need it, you can always build and install static and shared libraries using different build directories:

    mkdir cmake-build-shared
    cd cmake-build-shared
    cmake .. -DBUILD_SHARED_LIBS=ON -D -DCMAKE_INSTALL_PREFIX=<SHARED_LIB_PATH>
    cmake --build . --config Debug --target INSTALL
    mkdir cmake-build-static
    cd cmake-build-static
    cmake .. -DBUILD_SHARED_LIBS=OFF -D -DCMAKE_INSTALL_PREFIX=<STATIC_LIB_PATH>
    cmake --build . --config Debug --target INSTALL
    

    After that use Ogg_DIR variable to set path to required build:

    cmake .. -DOgg_DIR=<SHARED_LIB_PATH>
    

    or

    cmake .. -DOgg_DIR=<STATIC_LIB_PATH>
    

    Or even better - you can use package manager to do it: Vcpkg, Conan etc.

    With Vcpkg:

    vcpkg install libogg:x64-windows
    vcpkg install libogg:x64-windows-static
    cmake .. -DVCPKG_TARGET_TRIPLET=x64-windows -DCMAKE_TOOLCHAIN_FILE=%VCPKG_ROOT%\scripts\buildsystems\vcpkg.cmake 
    cmake .. -DVCPKG_TARGET_TRIPLET=x64-windows-static -DCMAKE_TOOLCHAIN_FILE=%VCPKG_ROOT%\scripts\buildsystems\vcpkg.cmake 
    

@szy1210
Copy link
Author

szy1210 commented Sep 7, 2019

Thank you both @evpobr @willson-chen

@willson-chen
Copy link
Contributor

@evpobr , I have to raise my hat to you. I need to learn more about cmake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants