-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add help_options() function, rework multi_option.cmake to option.cmak… (
#76)
- Loading branch information
Showing
6 changed files
with
248 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
function(__define_socmake_option NAME TYPE DESCRIPTION DEFAULT) | ||
cmake_parse_arguments(ARG "" "" "POSSIBLE_VALUES" ${ARGN}) | ||
if(ARG_UNPARSED_ARGUMENTS) | ||
message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION} passed unrecognized argument " "${ARG_UNPARSED_ARGUMENTS}") | ||
endif() | ||
|
||
set_property(GLOBAL PROPERTY SOCMAKE_${NAME}_DESCRIPTION "${DESCRIPTION}") | ||
set_property(GLOBAL PROPERTY SOCMAKE_${NAME}_TYPE ${TYPE}) | ||
set_property(GLOBAL PROPERTY SOCMAKE_${NAME}_DEFAULT ${DEFAULT}) | ||
if(ARG_POSSIBLE_VALUES) | ||
set_property(GLOBAL PROPERTY SOCMAKE_${NAME}_VALUES ${ARG_POSSIBLE_VALUES}) | ||
endif() | ||
set_property(GLOBAL APPEND PROPERTY SOCMAKE_OPTIONS ${NAME}) | ||
endfunction() | ||
|
||
#[[[ | ||
# Create a CMake integer option that can be modified through CLI. | ||
# Option defined this way will be visible in `cmake-gui` interface as well as SoCMake `help_options()` help menu. | ||
# To override the variable use `cmake -D<VARIABLE>=<VALUE>` | ||
# | ||
# :param VARIABLE: name of the variable. | ||
# :type VARIABLE: string | ||
# :param DESCRIPTION: short description string for the variable | ||
# :type DESCRIPTION: string | ||
# :param ENUM_VALUES: possible values variable can have | ||
# :type ENUM_VALUES: list[string] | ||
# :param DEFAULT: default value of the variable | ||
# :type DEFAULT: integer | ||
#]] | ||
function(option_enum VARIABLE DESCRIPTION ENUM_VALUES DEFAULT) | ||
__define_socmake_option(${VARIABLE} "Enum" ${DESCRIPTION} ${DEFAULT} POSSIBLE_VALUES "${ENUM_VALUES}") | ||
|
||
set(${VARIABLE} ${DEFAULT} CACHE STRING "${DESCRIPTION}") | ||
set_property(CACHE ${VARIABLE} PROPERTY STRINGS "${ENUM_VALUES}") | ||
if(NOT ${VARIABLE}) | ||
set(${VARIABLE} ${DEFAULT}) | ||
set(${VARIABLE} ${DEFAULT} PARENT_SCOPE) | ||
endif() | ||
if(NOT "${${VARIABLE}}" IN_LIST ENUM_VALUES) | ||
message(FATAL_ERROR "The VARIABLE \"${VARIABLE}\" has an unknown value: ${${VARIABLE}}\nPossible values are: ${ENUM_VALUES}") | ||
endif() | ||
endfunction() | ||
|
||
function(option_string VARIABLE DESCRIPTION DEFAULT) | ||
__define_socmake_option(${VARIABLE} "String" ${DESCRIPTION} ${DEFAULT}) | ||
|
||
set(${VARIABLE} ${DEFAULT} CACHE STRING "${DESCRIPTION}") | ||
endfunction() | ||
|
||
#[[[ | ||
# Create a CMake integer option that can be modified through CLI. | ||
# Option defined this way will be visible in `cmake-gui` interface as well as SoCMake `help_options()` help menu. | ||
# To override the variable use `cmake -D<VARIABLE>=<VALUE>` | ||
# | ||
# :param VARIABLE: name of the variable. | ||
# :type VARIABLE: string | ||
# :param DESCRIPTION: short description string for the variable | ||
# :type DESCRIPTION: string | ||
# :param DEFAULT: default value of the variable | ||
# :type DEFAULT: integer | ||
#]] | ||
function(option_integer VARIABLE DESCRIPTION DEFAULT) | ||
__define_socmake_option(${VARIABLE} "Integer" ${DESCRIPTION} ${DEFAULT}) | ||
|
||
set(${VARIABLE} ${DEFAULT} CACHE STRING "${DESCRIPTION}") | ||
if(NOT ${${VARIABLE}} MATCHES "^[0-9]+$") | ||
message(FATAL_ERROR "The value of option \"${VARIABLE}\" must be a non-negative integer.") | ||
endif() | ||
endfunction() | ||
|
||
#[[[ | ||
# Create a CMake boolean option that can be modified through CLI. | ||
# Option defined this way will be visible in `cmake-gui` interface as well as SoCMake `help_options()` help menu. | ||
# To override the variable use `cmake -D<VARIABLE>=<VALUE>` | ||
# | ||
# :param VARIABLE: name of the variable. | ||
# :type VARIABLE: string | ||
# :param DESCRIPTION: short description string for the variable | ||
# :type DESCRIPTION: string | ||
# :param DEFAULT: default value of the variable | ||
# :type DEFAULT: boolean | ||
#]] | ||
function(option_boolean VARIABLE DESCRIPTION DEFAULT) | ||
__define_socmake_option(${VARIABLE} "Boolean" ${DESCRIPTION} ${DEFAULT} POSSIBLE_VALUES "ON;OFF") | ||
|
||
set(${VARIABLE} ${DEFAULT} CACHE STRING "${DESCRIPTION}") | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,4 +48,3 @@ ct_add_test(NAME ${TEST_NAME} EXPECTFAIL) | |
function(${${TEST_NAME}}) | ||
add_ip(vendor::::) | ||
endfunction() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,5 +30,3 @@ ct_add_test(NAME ${TEST_NAME} EXPECTFAIL) | |
function(${${TEST_NAME}}) | ||
add_ip(vendor::lib::ip::) | ||
endfunction() | ||
|
||
|