Skip to content

Commit dd41dfa

Browse files
authored
CMake: Add a cmake option to make flashfetch target optional (#1455)
Introduces the `-DBUILD_FLASHFETCH='ON'/'OFF'` build option so one can skip the `flashfetch` target (both from executable and install targets, option at `ON` by default to preserve compatibility with the current default behavior). This is useful when distributing pre-built downstream packages (e.g. for Linux distributions packaging `fastfetch`) as building and shipping the `flashfetch` binary in such pre-built packages serves little to no purpose.
1 parent 14d6157 commit dd41dfa

File tree

1 file changed

+38
-19
lines changed

1 file changed

+38
-19
lines changed

CMakeLists.txt

+38-19
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ cmake_dependent_option(ENABLE_PCIACCESS "Enable libpciaccess" ON "NetBSD OR Open
8686
option(ENABLE_SYSTEM_YYJSON "Use system provided (instead of fastfetch embedded) yyjson library" OFF)
8787
option(ENABLE_ASAN "Build fastfetch with ASAN (address sanitizer)" OFF)
8888
option(ENABLE_LTO "Enable link-time optimization in release mode if supported" ON)
89+
option(BUILD_FLASHFETCH "Build flashfetch" ON) # Also build the flashfetch binary
8990
option(BUILD_TESTS "Build tests" OFF) # Also create test executables
9091
option(SET_TWEAK "Add tweak to project version" ON) # This is set to off by github actions for release builds
9192
option(IS_MUSL "Build with musl libc" OFF) # Used by Github Actions
@@ -1611,41 +1612,52 @@ target_link_libraries(fastfetch
16111612
PRIVATE libfastfetch
16121613
)
16131614

1614-
add_executable(flashfetch
1615-
src/flashfetch.c
1616-
)
1617-
target_compile_definitions(flashfetch
1618-
PRIVATE FASTFETCH_TARGET_BINARY_NAME=flashfetch
1619-
)
1620-
target_link_libraries(flashfetch
1621-
PRIVATE libfastfetch
1622-
)
1623-
16241615
# Prevent fastfetch from linking to libstdc++
16251616
set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "")
16261617
set(CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "")
16271618
set_target_properties(fastfetch PROPERTIES LINKER_LANGUAGE C)
1628-
set_target_properties(flashfetch PROPERTIES LINKER_LANGUAGE C)
16291619

16301620
if(WIN32)
16311621
target_sources(fastfetch
16321622
PRIVATE src/util/windows/version.rc
16331623
)
1634-
target_sources(flashfetch
1635-
PRIVATE src/util/windows/version.rc
1636-
)
16371624
elseif(APPLE)
16381625
target_link_options(fastfetch
16391626
PRIVATE LINKER:-sectcreate,__TEXT,__info_plist,Info.plist
16401627
)
1641-
target_link_options(flashfetch
1642-
PRIVATE LINKER:-sectcreate,__TEXT,__info_plist,Info.plist
1643-
)
16441628
endif()
16451629

16461630
if(BINARY_LINK_TYPE STREQUAL "static")
16471631
target_link_options(fastfetch PRIVATE "-static")
1648-
target_link_options(flashfetch PRIVATE "-static")
1632+
endif()
1633+
1634+
# Apply all above parameters to flashfetch if it is built
1635+
if (BUILD_FLASHFETCH)
1636+
add_executable(flashfetch
1637+
src/flashfetch.c
1638+
)
1639+
target_compile_definitions(flashfetch
1640+
PRIVATE FASTFETCH_TARGET_BINARY_NAME=flashfetch
1641+
)
1642+
target_link_libraries(flashfetch
1643+
PRIVATE libfastfetch
1644+
)
1645+
1646+
set_target_properties(flashfetch PROPERTIES LINKER_LANGUAGE C)
1647+
1648+
if(WIN32)
1649+
target_sources(flashfetch
1650+
PRIVATE src/util/windows/version.rc
1651+
)
1652+
elseif(APPLE)
1653+
target_link_options(flashfetch
1654+
PRIVATE LINKER:-sectcreate,__TEXT,__info_plist,Info.plist
1655+
)
1656+
endif()
1657+
1658+
if(BINARY_LINK_TYPE STREQUAL "static")
1659+
target_link_options(flashfetch PRIVATE "-static")
1660+
endif()
16491661
endif()
16501662

16511663
###################
@@ -1687,10 +1699,17 @@ endif()
16871699
include(GNUInstallDirs)
16881700

16891701
install(
1690-
TARGETS fastfetch flashfetch
1702+
TARGETS fastfetch
16911703
DESTINATION "${CMAKE_INSTALL_BINDIR}"
16921704
)
16931705

1706+
if (TARGET flashfetch)
1707+
install(
1708+
TARGETS flashfetch
1709+
DESTINATION "${CMAKE_INSTALL_BINDIR}"
1710+
)
1711+
endif()
1712+
16941713
if (TARGET ffwinrt)
16951714
install(
16961715
TARGETS ffwinrt

0 commit comments

Comments
 (0)