Skip to content

Commit

Permalink
Fix DependentOptions splitting arguments on spaces
Browse files Browse the repository at this point in the history
Fix broken x11.cc

Signed-off-by: Tin <[email protected]>
  • Loading branch information
Caellian committed Nov 10, 2023
1 parent 2aebf68 commit cc604bc
Show file tree
Hide file tree
Showing 3 changed files with 612 additions and 595 deletions.
20 changes: 11 additions & 9 deletions cmake/ConkyBuildOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ cmake_dependent_option(BUILD_HDDTEMP "Support for hddtemp" true
cmake_dependent_option(BUILD_IPV6 "Enable if you want IPv6 support" true
"OS_LINUX" false)
# nvidia may also work on FreeBSD, not sure
cmake_dependent_option(BUILD_NVIDIA "Enable nvidia support" false
"OS_LINUX" false)
dependent_option(BUILD_NVIDIA "Enable Nvidia stat support on Linux" false
"OS_LINUX;BUILD_X11" false
"Nvidia stat supports only Linux and requires X11")

# macOS Only
cmake_dependent_option(
Expand Down Expand Up @@ -165,6 +166,9 @@ else()
"Xfixes support requires X11")
endif(OS_DARWIN)

dependent_option(BUILD_ARGB "Build ARGB (real transparency) support" true
"OWN_WINDOW" false
"ARGB support requires OWN_WINDOW enabled")
dependent_option(BUILD_XINERAMA "Build Xinerama support" true
"BUILD_X11" false
"Xinerama support requires X11")
Expand All @@ -180,6 +184,9 @@ dependent_option(BUILD_IMLIB2 "Enable Imlib2 support" true
dependent_option(BUILD_XSHAPE "Enable Xshape support" true
"BUILD_X11" false
"Xshape support requires X11")
dependent_option(BUILD_XINPUT "Build Xinput 2 support" true
"BUILD_X11;BUILD_MOUSE_EVENTS" false
"Xinput 2 support requires X11 and BUILD_MOUSE_EVENTS enabled")

# if we build with any GUI support
if(BUILD_X11)
Expand All @@ -192,13 +199,6 @@ endif(BUILD_WAYLAND)
dependent_option(BUILD_MOUSE_EVENTS "Enable mouse event support" true
"BUILD_WAYLAND OR OWN_WINDOW" false
"Mouse event support requires Wayland or OWN_WINDOW enabled")
dependent_option(BUILD_XINPUT "Build Xinput 2 support" true
"BUILD_X11;BUILD_MOUSE_EVENTS" false
"Xinput 2 support requires X11 and BUILD_MOUSE_EVENTS enabled")

dependent_option(BUILD_ARGB "Build ARGB (real transparency) support" true
"OWN_WINDOW" false
"ARGB support requires OWN_WINDOW enabled")

# Lua library options
option(BUILD_LUA_CAIRO "Build cairo bindings for Lua" false)
Expand Down Expand Up @@ -247,6 +247,8 @@ option(BUILD_PULSEAUDIO
option(BUILD_INTEL_BACKLIGHT
"Enable support for Intel backlight" false)

run_dependency_checks()

message(STATUS "CMAKE_C_FLAGS: " ${CMAKE_C_FLAGS})
message(STATUS "CMAKE_CXX_FLAGS: " ${CMAKE_CXX_FLAGS})

Expand Down
52 changes: 38 additions & 14 deletions cmake/DependentOption.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,52 @@ https://github.com/Kitware/CMake/blob/master/Modules/CMakeDependentOption.cmake

Modified to so it produces warnings instead of hiding an option completely and
sets a default value.
Difference is that `depends` argument is ALWAYS a semicolon separated list of
<expr> tokens.

Argument meaning and order are the same, and there's an additional (warn)
argument which is the message printed if the end-user enabled a feature which
isn't "possible".

Actual checks are deferred until RUN_DEPENDENCY_CHECKS() is called in order to
allow out of order declaration of dependencies and dependecy graph cycles.
As the checks can affect each other they're run in a loop until the graph settles.
That means CMake can end up in an infinite loop, though it shouldn't happen with
normal use... (i.e. disable A if B not present)
#]=======================================================================]

set(__DEPENDENT_OPTIONS_CHANGE_HAPPENED true)
set(__DEPENDENT_OPTIONS_LATER_INVOKED_CODE "")

macro(DEPENDENT_OPTION option doc default depends else warn)
set(${option}_POSSIBLE 1)
foreach(d ${depends})
cmake_language(EVAL CODE "
if (${d})
option(${option} "${doc}" "${default}")

string(APPEND __DEPENDENT_OPTIONS_LATER_INVOKED_CODE "
set(${option}_POSSIBLE 1)
string(REGEX MATCHALL \"[^;]+\" __${option}_TOKENS \"${depends}\")
foreach(it \${__${option}_TOKENS})
cmake_language(EVAL CODE \"
if (\${it})
else()
set(${option}_POSSIBLE 0)
endif()"
)
endforeach()
option(${option} "${doc}" "${default}")
if(NOT ${option}_POSSIBLE)
if(NOT ${option} MATCHES ${else})
message(NOTICE "${warn}; setting to '${else}'.")
endif()\")
endforeach()
unset(__${option}_TOKENS)
if(NOT ${option}_POSSIBLE)
if(NOT \"\${${option}}\" STREQUAL \"${else}\")
message(NOTICE \"${warn}; setting to '${else}'.\")
set(${option} ${else} CACHE BOOL \"${doc}\" FORCE)
set(__DEPENDENT_OPTIONS_CHANGE_HAPPENED true)
endif()
endif()
set(${option} ${else} CACHE BOOL "${doc}" FORCE)
endif()
unset(${option}_POSSIBLE)
unset(${option}_POSSIBLE)")
endmacro()

macro(RUN_DEPENDENCY_CHECKS)
while(__DEPENDENT_OPTIONS_CHANGE_HAPPENED)
set(__DEPENDENT_OPTIONS_CHANGE_HAPPENED false)
cmake_language(EVAL CODE "${__DEPENDENT_OPTIONS_LATER_INVOKED_CODE}")
endwhile()
set(__DEPENDENT_OPTIONS_CHANGE_HAPPENED true)
set(__DEPENDENT_OPTIONS_LATER_INVOKED_CODE "")
endmacro()
Loading

0 comments on commit cc604bc

Please sign in to comment.