1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2024-12-01 01:45:42 +00:00
dindexer/cmake/Modules/set_switchable.cmake
King_DuckZ a48742c0b0 Add a DINDEXER_INST_MODE cmake switch.
Attempt to clean up the path mess in cmake and improve scalability.
Previously, paths such as action search path and config file path had to
be given manually and were likely to be wrong if running make install or
if running the program from the build directory directly.

This commit introduces set_switchable(), along with the
DINDEXER_INST_MODE. Whenever relevant, paths come with a regular and an
INST variant (eg: DINDEXER_QML_PATH and DINDEXER_INST_QML_PATH), which
are CACHE variables so users can customize them and expect their setting
to be persistent.
set_switchable() then sets a CURR variant of the same variable (eg:
DINDEXER_CURR_QML_PATH), which is set to either of the above two values
depending on if DINDEXER_INST_MODE is on or off. This way the rest of
the cmake code can just use the CURR variable and expect it to be set to
the right value.
2016-10-12 23:08:29 +02:00

52 lines
1.7 KiB
CMake

function(set_switchable)
set(options "")
set(one_value_args PREFIX INFIX OUT_INFIX NAME)
set(multi_value_args ONVALUE OFFVALUE)
cmake_parse_arguments(SS "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN})
if (NOT SS_PREFIX)
message(FATAL_ERROR "No PREFIX given")
endif()
if (NOT SS_INFIX)
set(SS_INFIX "ENABLED")
endif()
if (NOT SS_OUT_INFIX)
set(SS_OUT_INFIX "CURR")
endif()
if (NOT SS_NAME)
message(FATAL_ERROR "No NAME given")
endif()
list(FIND SS_ONVALUE CACHE on_is_cachevar)
list(FIND SS_ONVALUE PARENT_SCOPE on_is_parentscope)
list(FIND SS_OFFVALUE CACHE off_is_cachevar)
list(FIND SS_OFFVALUE PARENT_SCOPE off_is_parentscope)
set(on_parentscope)
if (${on_is_cachevar} LESS 0 AND ${on_is_parentscope} LESS 1)
list(APPEND on_parentscope "PARENT_SCOPE")
endif()
set(off_parentscope)
if (${off_is_cachevar} LESS 0 AND ${off_is_parentscope} LESS 1)
list(APPEND off_parentscope "PARENT_SCOPE")
endif()
#Set some alisases to make the following code less yelling-at-me
set(prefix "${SS_PREFIX}")
set(infix "${SS_INFIX}")
set(out_infix "${SS_OUT_INFIX}")
set(suffix "${SS_NAME}")
set(${prefix}_${infix}_${suffix} ${SS_ONVALUE} ${on_parentscope})
set(${prefix}_${suffix} ${SS_OFFVALUE} ${off_parentscope})
#message(STATUS "${prefix}_${suffix} set to \"${${prefix}_${suffix}}\"")
#message(STATUS "${prefix}_${infix}_${suffix} set to \"${${prefix}_${infix}_${suffix}}\"")
if (${prefix}_${infix}_MODE)
set(${prefix}_${out_infix}_${suffix} "${${prefix}_${infix}_${suffix}}" PARENT_SCOPE)
else()
set(${prefix}_${out_infix}_${suffix} "${${prefix}_${suffix}}" PARENT_SCOPE)
endif()
endfunction()