Skip to content

Commit 62f91bb

Browse files
authored
Merge pull request #134 from Zer0xFF/patch-1
CMake: target condition zlib & zstd before adding them to the project
2 parents bdcba64 + fd3fbf8 commit 62f91bb

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

CMakeLists.txt

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,22 @@ include(GNUInstallDirs)
3434

3535

3636
# lzma
37-
add_subdirectory(deps/lzma-24.05 EXCLUDE_FROM_ALL)
38-
list(APPEND CHDR_LIBS lzma)
39-
list(APPEND CHDR_INCLUDES lzma)
37+
if(NOT TARGET lzma)
38+
add_subdirectory(deps/lzma-24.05 EXCLUDE_FROM_ALL)
39+
endif()
40+
list(APPEND CHDR_LIBS lzma)
41+
list(APPEND CHDR_INCLUDES lzma)
4042

4143
# zlib
4244
if (WITH_SYSTEM_ZLIB)
4345
find_package(ZLIB REQUIRED)
4446
list(APPEND PLATFORM_LIBS ZLIB::ZLIB)
4547
else()
46-
option(ZLIB_BUILD_EXAMPLES "Enable Zlib Examples" OFF)
47-
add_subdirectory(deps/zlib-1.3.1 EXCLUDE_FROM_ALL)
48-
set_target_properties(zlibstatic PROPERTIES POSITION_INDEPENDENT_CODE ON)
48+
if(NOT TARGET zlibstatic)
49+
option(ZLIB_BUILD_EXAMPLES "Enable Zlib Examples" OFF)
50+
add_subdirectory(deps/zlib-1.3.1 EXCLUDE_FROM_ALL)
51+
set_target_properties(zlibstatic PROPERTIES POSITION_INDEPENDENT_CODE ON)
52+
endif()
4953
list(APPEND CHDR_LIBS zlibstatic)
5054
endif()
5155

@@ -54,10 +58,12 @@ if (WITH_SYSTEM_ZSTD)
5458
find_package(zstd REQUIRED)
5559
list(APPEND PLATFORM_LIBS zstd::libzstd_shared)
5660
else()
57-
option(ZSTD_BUILD_SHARED "BUILD SHARED LIBRARIES" OFF)
58-
option(ZSTD_BUILD_PROGRAMS "BUILD PROGRAMS" OFF)
59-
option(ZSTD_LEGACY_SUPPORT "LEGACY SUPPORT" OFF)
60-
add_subdirectory(deps/zstd-1.5.6/build/cmake EXCLUDE_FROM_ALL)
61+
if(NOT TARGET libzstd_static)
62+
option(ZSTD_BUILD_SHARED "BUILD SHARED LIBRARIES" OFF)
63+
option(ZSTD_BUILD_PROGRAMS "BUILD PROGRAMS" OFF)
64+
option(ZSTD_LEGACY_SUPPORT "LEGACY SUPPORT" OFF)
65+
add_subdirectory(deps/zstd-1.5.6/build/cmake EXCLUDE_FROM_ALL)
66+
endif()
6167
list(APPEND CHDR_LIBS libzstd_static)
6268
endif()
6369
#--------------------------------------------------

0 commit comments

Comments
 (0)