Skip to content

Commit cbefc1d

Browse files
tanquerfacebook-github-bot
authored andcommitted
Add CMake option to prefer static deps rather than dynamic deps
Summary: We would like to build a version of torchcomms that has minimal dependencies on dynamic libraries. I saw that there is an option `USE_STATIC_DEPS_ON_UNIX` introduced in D17228181. However, currently when we enable `USE_STATIC_DEPS_ON_UNIX=ON` to build folly, it will fail by ``` -- Could NOT find LIBUNWIND (missing: LIBUNWIND_LIBRARY) CMake Error at build/fbcode_builder/CMake/FindLibEvent.cmake:68 (message): Could NOT find libevent. Call Stack (most recent call first): CMake/folly-deps.cmake:73 (find_package) CMakeLists.txt:145 (include) -- Configuring incomplete, errors occurred! ``` That is because we only set ".a" to `CMAKE_FIND_LIBRARY_SUFFIXES` and there exists a special library libunwind that does not provide static linking library. To set `CMAKE_FIND_LIBRARY_SUFFIXES = ".a" ".so"`, we can let cmake first look for `libname.a` and then `libname.so` if `.a` is not found. Reviewed By: d4l3k Differential Revision: D81062853 fbshipit-source-id: ce901b03473c82032c75742302ee3ed875d6af49
1 parent 376dbf0 commit cbefc1d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

build/fbcode_builder/CMake/FBBuildOptions.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,16 @@ function (fb_activate_static_library_option)
1212
if(UNIX AND USE_STATIC_DEPS_ON_UNIX)
1313
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a" PARENT_SCOPE)
1414
endif()
15+
16+
option(PREFER_STATIC_DEPS_ON_UNIX
17+
"If enabled, use static dependencies on unix systems as possible as we can. This is generally discouraged."
18+
OFF
19+
)
20+
# Mark PREFER_STATIC_DEPS_ON_UNIX as an "advanced" option, since enabling it
21+
# is generally discouraged.
22+
mark_as_advanced(PREFER_STATIC_DEPS_ON_UNIX)
23+
24+
if(UNIX AND PREFER_STATIC_DEPS_ON_UNIX)
25+
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a" ".so" PARENT_SCOPE)
26+
endif()
1527
endfunction()

0 commit comments

Comments
 (0)