cmake: ninja usage build target

Fixed usage build target.

Previously, `ninja usage` would print:
Build flags:

  ninja VERBOSE=1 [targets] verbose build

This is clearly wrong, as VERBOSE=1 is for make targets.

To support both ninja based builds and make based build systems, the
CMAKE_MAKE_PROGRAM is now exported from the calling CMake / build
instance, and the verbose flag is set depending on whether ninja or
make is used as build program.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit is contained in:
Torsten Rasmussen 2020-02-25 11:42:00 +01:00 committed by Carles Cufí
parent 21080447a8
commit ad1fecc950
3 changed files with 16 additions and 5 deletions

View file

@ -1481,14 +1481,20 @@ macro(assert_exists var)
endmacro()
function(print_usage)
if(NOT CMAKE_MAKE_PROGRAM)
# Create dummy project, in order to obtain make program for correct usage printing.
project(NONE)
endif()
message("see usage:")
string(REPLACE ";" " " BOARD_ROOT_SPACE_SEPARATED "${BOARD_ROOT}")
string(REPLACE ";" " " SHIELD_LIST_SPACE_SEPARATED "${SHIELD_LIST}")
execute_process(
COMMAND
${CMAKE_COMMAND}
-DZEPHYR_BASE=${ZEPHYR_BASE}
-DBOARD_ROOT_SPACE_SEPARATED=${BOARD_ROOT_SPACE_SEPARATED}
-DSHIELD_LIST_SPACE_SEPARATED=${SHIELD_LIST_SPACE_SEPARATED}
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
-P ${ZEPHYR_BASE}/cmake/usage/usage.cmake
)
endfunction()

View file

@ -6,8 +6,10 @@ string(REPLACE ";" " " SHIELD_LIST_SPACE_SEPARATED "${SHIELD_LIST}")
add_custom_target(
usage
${CMAKE_COMMAND}
-DZEPHYR_BASE=${ZEPHYR_BASE}
-DBOARD_ROOT_SPACE_SEPARATED=${BOARD_ROOT_SPACE_SEPARATED}
-DSHIELD_LIST_SPACE_SEPARATED=${SHIELD_LIST_SPACE_SEPARATED}
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
-P ${CMAKE_CURRENT_SOURCE_DIR}/usage.cmake
)

View file

@ -1,13 +1,16 @@
# SPDX-License-Identifier: Apache-2.0
if(NOT DEFINED ENV{ZEPHYR_BASE})
if(NOT DEFINED ZEPHYR_BASE)
message(FATAL_ERROR "ZEPHYR_BASE not set")
endif()
include ($ENV{ZEPHYR_BASE}/cmake/boards.cmake)
include (${ZEPHYR_BASE}/cmake/boards.cmake)
# TODO: Set to make when make is used as a generator
set(CMAKE_MAKE_PROGRAM ninja)
get_filename_component(generator ${CMAKE_MAKE_PROGRAM} NAME)
if(${generator} STREQUAL ninja)
set(verbose "-v")
else()
set(verbose "VERBOSE=1")
endif()
string(REPLACE " " ";" BOARD_ROOT "${BOARD_ROOT_SPACE_SEPARATED}")
string(REPLACE " " ";" SHIELD_LIST "${SHIELD_LIST_SPACE_SEPARATED}")
@ -52,7 +55,7 @@ endforeach()
message("")
message("Build flags:")
message("")
message(" ${generator} VERBOSE=1 [targets] verbose build")
message(" ${generator} ${verbose} [targets] verbose build")
message(" cmake -DW=n Enable extra gcc checks, n=1,2,3 where")
message(" 1: warnings which may be relevant and do not occur too often")
message(" 2: warnings which occur quite often but may still be relevant")