An old question recently reoccurred: What is the correct way of setting CMAKE_MODULE_PATH
? But this applies to pretty much any list. However there might be a difference for general text, but IMO only when that text might contain semicolons.
Precondition: That variable might be unset, empty, or set
Options:
set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmakeModules ${CMAKE_MODULE_PATH})
set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmakeModules" ${CMAKE_MODULE_PATH})
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmakeModules)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmakeModules")
if (NOT CMAKE_MODULE_PATH) set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmakeModules") else() set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmakeModules;${CMAKE_MODULE_PATH}") endif()
To include some reasoning:
a) 1. might fail, when there are spaces in the path so one has to use 2. to avoid this. Is this correct?
b) 3/4 looks like the better/more concise way. Again are the spaces required?
c) 5. Has (ugly) special case handling which 1-4 avoid. Is this required?
Related: cmake: when to quote variables?
But I'm still unsure, when to use quotes especially when dealing with paths and lists.
Bonus: What exactly does happen during evaluation? If all ${...}
would get replaced by the value of the variable before it is passed to the function then e.g. the following would not work and requires spaces. But it does work as intended:
set(FOO_DIR "my space path")
set(CMAKE_LIST /usr)
set(CMAKE_LIST ${CMAKE_LIST} ${FOO_DIR}/foo)
oder: list(APPEND CMAKE_LIST ${FOO_DIR}/foo)
This also applies to calls to other functions. E.g.:
set_target_properties(MYTARGET PROPERTIES
IMPORTED_LOCATION ${FOO_DIR}/foo
)
Question is: Why? Where in the standard is this specified?