diff --git a/CMakeLists.txt b/CMakeLists.txt index 10fef39b909..07abab6b747 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,15 @@ cmake_minimum_required(VERSION 3.10) +# Determine if zstd is built as a subproject (using add_subdirectory) or if it +# is the master project. +if (NOT DEFINED ZSTD_MASTER_PROJECT) + set(ZSTD_MASTER_PROJECT OFF) + # Checking project name is more reliable than checking source directories. + if (NOT DEFINED PROJECT_NAME) + set(ZSTD_MASTER_PROJECT ON) + endif() +endif() + # Thin wrapper so `cmake -S .` behaves like `cmake -S build/cmake`. # Policy lives in build/cmake; keep parent project language-less. project(zstd-superbuild LANGUAGES NONE) diff --git a/build/cmake/CMakeModules/ZstdOptions.cmake b/build/cmake/CMakeModules/ZstdOptions.cmake index dc7813444e2..aaef1e0dba7 100644 --- a/build/cmake/CMakeModules/ZstdOptions.cmake +++ b/build/cmake/CMakeModules/ZstdOptions.cmake @@ -41,7 +41,7 @@ else() endif() # Build component options -option(ZSTD_BUILD_PROGRAMS "Build command-line programs" ON) +option(ZSTD_BUILD_PROGRAMS "Build command-line programs" ${ZSTD_MASTER_PROJECT}) option(ZSTD_BUILD_CONTRIB "Build contrib utilities" OFF) option(ZSTD_PROGRAMS_LINK_SHARED "Link programs against shared library" OFF)