HI, Ah, you only focus on our CMake configuration, right? (You don't focus on downstream users, right?)
And you want to simplify our CMake configuration, right? We can do it. Let's open a new issue and PR for it. Thanks, -- kou In <CAHgae5GLrYu9exfvis-QcXX8fn5bW1N61zhyur9A34Ay=4u...@mail.gmail.com> "Re: [C++] Static/Shared Linkage in CMakeLists.txt" on Tue, 3 Jun 2025 18:14:23 +0800, Eddie Chang <kalcifer7...@gmail.com> wrote: > Hi Kou, > >> What does "only one version of the library" mean here? Only >> shared version or only static version? If we use >> -DARROW_BUILD_SHARED=ON and -DARROW_BUILD_STATIC=ON, we can >> build both of shared version and static version in the same >> build process. Am I missing something? > > That was a mistake on my part. What I meant was that, for "executable" > targets, only one version can be linked: > [1] > https://github.com/apache/arrow/blob/acbad2942be80e9a76b888f99fe3b9ebdc4f2941/cpp/examples/arrow/CMakeLists.txt#L144-L148 > [2] > https://github.com/apache/arrow/blob/acbad2942be80e9a76b888f99fe3b9ebdc4f2941/cpp/examples/parquet/CMakeLists.txt#L51-L56 > [3] > https://github.com/apache/arrow/blob/acbad2942be80e9a76b888f99fe3b9ebdc4f2941/cpp/tools/parquet/CMakeLists.txt#L29-L33 > > Should we set an alias target in one place for such usages, for example: > > if(ARROW_BUILD_SHARED) > add_library(parquet_lib ALIAS parquet_shared) > else() > add_library(parquet_lib ALIAS parquet_static) > endif() > > , or just leave it be until there are more occurrences? > > Thanks, > Eddie > > Sutou Kouhei <k...@clear-code.com> 於 2025年6月3日 週二 下午4:44寫道: > >> Hi, >> >> > However, with the current implementation, only one version of the library >> > actually exists within a single build process. >> >> What does "only one version of the library" mean here? Only >> shared version or only static version? If we use >> -DARROW_BUILD_SHARED=ON and -DARROW_BUILD_STATIC=ON, we can >> build both of shared version and static version in the same >> build process. Am I missing something? >> >> >> Thanks, >> -- >> kou >> >> In <cahgae5exol+9ohtujp+-n3vpssrgeajbxn1do0dlegbqsz6...@mail.gmail.com> >> "Re: [C++] Static/Shared Linkage in CMakeLists.txt" on Tue, 3 Jun 2025 >> 16:37:42 +0800, >> Eddie Chang <kalcifer7...@gmail.com> wrote: >> >> > Hi Kou, >> > >> > Building both shared and static versions of the library simultaneously is >> > certainly possible. My current focus is on the fact that we have multiple >> > build targets linking against the same library, and each time we do so, >> we >> > repeat the same if-else logic to decide which version to link. >> > >> > However, with the current implementation, only one version of the library >> > actually exists within a single build process. So we only need to >> determine >> > whether to build the static or shared version once―when building the >> > library itself―instead of repeating the same check every time a build >> > target links against the same library. >> > >> > If you'd like to support both versions, I suppose you already need to >> build >> > twice (with different build options) with the current implementation? >> > Thanks, >> > Eddie >> > >> > Sutou Kouhei <k...@clear-code.com> 於 2025年6月3日 週二 下午3:10寫道: >> > >> >> Hi, >> >> >> >> How to support a use case that wants both of shared library >> >> and static library with your suggested approach? Do you >> >> build Apache Arrow C++ twice for shared library and static >> >> library? >> >> >> >> If so, what CMake package name is used for them? >> >> "ArrowShared" and "ArrowStatic"? >> >> >> >> >> >> Thanks, >> >> -- >> >> kou >> >> >> >> In <cahgae5er0+vbomjv7w8_dt068yhabclqdkkigo_qp8lz4vr...@mail.gmail.com> >> >> "RE: Re: [C++] Static/Shared Linkage in CMakeLists.txt" on Tue, 3 Jun >> >> 2025 14:49:02 +0800, >> >> Eddie Chang <kalcifer7...@gmail.com> wrote: >> >> >> >> > Just to clarify, my suggestion was assuming that each build only >> produces >> >> > either static or shared libraries, not both. >> >> > >> >> > Given that assumption, wouldn't it be better to define targets using a >> >> > single name (without `_static` or `_shared` suffix), and decide in one >> >> > place whether that target is defined as STATIC or SHARED depending on >> the >> >> > `ARROW_BUILD_SHARED`? >> >> > >> >> > That way, we wouldn't need to switch on `ARROW_BUILD_SHARED` >> repeatedly >> >> to >> >> > determine which target name to link. >> >> > >> >> > On 2025/06/03 06:05:45 Sutou Kouhei wrote: >> >> >> Hi, >> >> >> >> >> >> Do you want a CMake target that can be used for shared >> >> >> linking and static linking? For example, you want to use >> >> >> Parquet::parquet for shared linking and static linking, >> >> >> right? >> >> >> >> >> >> In my understanding, we can't do it with CMake. We need to >> >> >> specify "SHARED" or "STATIC" when create a CMake target by >> >> >> add_library(). >> >> >> See also: >> >> >> https://cmake.org/cmake/help/latest/command/add_library.html#normal >> >> >> >> >> >> Thanks, >> >> >> -- >> >> >> kou >> >> >> >> >> >> In <ca...@mail.gmail.com> >> >> >> "[C++] Static/Shared Linkage in CMakeLists.txt" on Tue, 3 Jun 2025 >> >> > 13:45:36 +0800, >> >> >> Eddie Chang <ka...@gmail.com> wrote: >> >> >> >> >> >> > Hello everyone, I've noticed that in our CMakeLists.txt files, we >> have >> >> >> > multiple instances where we conditionally select either the static >> or >> >> >> > shared version of a linked target based on a cache variable such as >> >> >> > ARROW_BUILD_SHARED. For example, the following pattern appears in >> >> > several >> >> >> > places: >> >> >> > >> >> >> > if(ARROW_BUILD_SHARED) >> >> >> > set(PARQUET_EXAMPLE_LINK_LIBS parquet_shared) >> >> >> > else() >> >> >> > set(PARQUET_EXAMPLE_LINK_LIBS parquet_static) >> >> >> > endif() >> >> >> > >> >> >> > I’m wondering if there is a specific reason we don’t set the >> >> > static/shared >> >> >> > property of the libraries in a single location, and instead >> continue >> >> >> > duplicating this kind of logic throughout the codebase? >> >> >> >> >> >>