2012-04-17 22:31:10 -03:00
|
|
|
function(apm_option NAME)
|
2012-04-17 17:59:52 -03:00
|
|
|
cmake_parse_arguments(ARG
|
2012-04-19 00:15:29 -03:00
|
|
|
"ADVANCED;DEFINE_ONLY"
|
2012-04-17 22:31:10 -03:00
|
|
|
"TYPE;DESCRIPTION;DEFAULT" "OPTIONS;DEPENDS" ${ARGN})
|
2012-04-17 17:59:52 -03:00
|
|
|
|
2012-04-17 22:31:10 -03:00
|
|
|
#message(STATUS "parsing argument: ${NAME}")
|
2012-04-17 17:59:52 -03:00
|
|
|
|
2012-04-17 22:31:10 -03:00
|
|
|
# if option dependencies not met, hide the option
|
|
|
|
foreach(DEPEND ${ARG_DEPENDS})
|
|
|
|
if (NOT ${${DEPEND}})
|
|
|
|
#message(STATUS "\tfailed dep: ${DEPEND}")
|
|
|
|
set(ARG_TYPE "INTERNAL")
|
|
|
|
set("${NAME}" "${ARG_DEFAULT}" CACHE INTERNAL "${ARG_DESCRIPTION}" FORCE)
|
|
|
|
return()
|
2012-04-17 17:59:52 -03:00
|
|
|
endif()
|
2012-04-17 22:31:10 -03:00
|
|
|
endforeach()
|
|
|
|
|
|
|
|
# set variable
|
|
|
|
set("${NAME}" "${ARG_DEFAULT}" CACHE "${ARG_TYPE}" "${ARG_DESCRIPTION}")
|
|
|
|
|
|
|
|
# force variable reinit if it was internal (hidden)
|
|
|
|
get_property(VAR_TYPE CACHE ${NAME} PROPERTY TYPE)
|
|
|
|
if ("${VAR_TYPE}" STREQUAL "INTERNAL")
|
|
|
|
message(STATUS "\tVAR_TYPE: ${VAR_TYPE}")
|
|
|
|
set("${NAME}" "${ARG_DEFAULT}" CACHE "${ARG_TYPE}" "${ARG_DESCRIPTION}" FORCE)
|
2012-04-18 16:16:02 -03:00
|
|
|
|
|
|
|
# if not hidden, add it to the global options list
|
|
|
|
else()
|
|
|
|
set(APM_OPTIONS ${APM_OPTIONS} ${NAME} CACHE INTERNAL "list of all options")
|
|
|
|
list(REMOVE_DUPLICATES APM_OPTIONS)
|
|
|
|
#message(STATUS "APM_OPTIONS: ${APM_OPTIONS}")
|
2012-04-17 17:59:52 -03:00
|
|
|
endif()
|
|
|
|
|
2012-04-17 22:31:10 -03:00
|
|
|
# set options for combo box
|
|
|
|
set_property(CACHE "${NAME}" PROPERTY STRINGS ${ARG_OPTIONS})
|
|
|
|
|
|
|
|
# mark as advanced if advanced option given
|
|
|
|
if(ARG_ADVANCED)
|
2012-04-17 17:59:52 -03:00
|
|
|
mark_as_advanced(FORCE "${NAME}")
|
|
|
|
endif()
|
|
|
|
|
2012-04-19 00:15:29 -03:00
|
|
|
if(ARG_DEFINE_ONLY)
|
|
|
|
set("${NAME}_DEFINE_ONLY" TRUE CACHE INTERNAL "Define only?" FORCE)
|
|
|
|
else()
|
|
|
|
set("${NAME}_DEFINE_ONLY" FALSE CACHE INTERNAL "Define only?" FORCE)
|
|
|
|
endif()
|
|
|
|
|
2012-04-17 22:31:10 -03:00
|
|
|
endfunction()
|
2012-04-18 16:16:02 -03:00
|
|
|
|
|
|
|
function(apm_option_generate_config)
|
|
|
|
cmake_parse_arguments(ARG "" "FILE" "" ${ARGN})
|
|
|
|
list(REMOVE_DUPLICATES APM_OPTIONS)
|
|
|
|
file (WRITE "${CMAKE_BINARY_DIR}/${ARG_FILE}" "//automatically generated, do not edit\n")
|
|
|
|
file (APPEND "${CMAKE_BINARY_DIR}/${ARG_FILE}" "#define OFF 0\n#define ON 1\n")
|
|
|
|
foreach(ITEM ${APM_OPTIONS})
|
|
|
|
#message(STATUS "item: ${ITEM}")
|
|
|
|
get_property(ITEM_VALUE CACHE ${ITEM} PROPERTY VALUE)
|
|
|
|
get_property(ITEM_HELP CACHE ${ITEM} PROPERTY HELPSTRING)
|
2012-04-19 00:15:29 -03:00
|
|
|
if (${ITEM}_DEFINE_ONLY)
|
|
|
|
if (${ITEM}_VALUE)
|
|
|
|
file(APPEND "${CMAKE_BINARY_DIR}/${ARG_FILE}" "\n#define ${ITEM} // ${ITEM_HELP}")
|
|
|
|
else()
|
|
|
|
file(APPEND "${CMAKE_BINARY_DIR}/${ARG_FILE}" "\n//#define ${ITEM} // ${ITEM_HELP}")
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
file(APPEND "${CMAKE_BINARY_DIR}/${ARG_FILE}" "\n#define ${ITEM} ${ITEM_VALUE} // ${ITEM_HELP}")
|
|
|
|
endif()
|
2012-04-18 16:16:02 -03:00
|
|
|
endforeach()
|
|
|
|
endfunction()
|