Introduce "Dev mode" option

When the option is On, CMake will have rules to generate the generated
files using scripts etc. When the option is Off, CMake will assume the
files are available from the source tree; in that mode, it won't require
any extra tools (Perl for example) compared to when we committed the
files to git.

The intention is that users will never need to adjust this option:

- in the development branch (and features branches etc.) the option is
always On (development mode);
- in released tarballs, which include the generated files, we'll switch
the option to Off (release mode) in the same commit that re-adds the
generated files.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
This commit is contained in:
Manuel Pégourié-Gonnard 2021-09-08 13:27:09 +02:00 committed by David Horstmann
parent 313bcfcde8
commit e90e405e15
6 changed files with 112 additions and 86 deletions

View file

@ -46,6 +46,7 @@ option(ENABLE_PROGRAMS "Build mbed TLS programs." ON)
option(UNSAFE_BUILD "Allow unsafe builds. These builds ARE NOT SECURE." OFF) option(UNSAFE_BUILD "Allow unsafe builds. These builds ARE NOT SECURE." OFF)
option(MBEDTLS_FATAL_WARNINGS "Compiler warnings treated as errors" ON) option(MBEDTLS_FATAL_WARNINGS "Compiler warnings treated as errors" ON)
option(DEV_MODE "Development mode: (re)generate some files as needed" ON)
string(REGEX MATCH "Clang" CMAKE_COMPILER_IS_CLANG "${CMAKE_C_COMPILER_ID}") string(REGEX MATCH "Clang" CMAKE_COMPILER_IS_CLANG "${CMAKE_C_COMPILER_ID}")
string(REGEX MATCH "GNU" CMAKE_COMPILER_IS_GNU "${CMAKE_C_COMPILER_ID}") string(REGEX MATCH "GNU" CMAKE_COMPILER_IS_GNU "${CMAKE_C_COMPILER_ID}")

View file

@ -109,10 +109,11 @@ set(src_tls
ssl_tls13_generic.c ssl_tls13_generic.c
) )
find_package(Perl REQUIRED) if(DEV_MODE)
find_package(Perl REQUIRED)
file(GLOB error_headers ${CMAKE_CURRENT_SOURCE_DIR}/../include/mbedtls/*.h) file(GLOB error_headers ${CMAKE_CURRENT_SOURCE_DIR}/../include/mbedtls/*.h)
add_custom_command( add_custom_command(
OUTPUT OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/error.c ${CMAKE_CURRENT_BINARY_DIR}/error.c
COMMAND COMMAND
@ -125,9 +126,9 @@ add_custom_command(
${CMAKE_CURRENT_SOURCE_DIR}/../scripts/generate_errors.pl ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/generate_errors.pl
${error_headers} ${error_headers}
${CMAKE_CURRENT_SOURCE_DIR}/../scripts/data_files/error.fmt ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/data_files/error.fmt
) )
add_custom_command( add_custom_command(
OUTPUT OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/version_features.c ${CMAKE_CURRENT_BINARY_DIR}/version_features.c
COMMAND COMMAND
@ -140,7 +141,11 @@ add_custom_command(
${CMAKE_CURRENT_SOURCE_DIR}/../scripts/generate_features.pl ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/generate_features.pl
${CMAKE_CURRENT_SOURCE_DIR}/../include/mbedtls/mbedtls_config.h ${CMAKE_CURRENT_SOURCE_DIR}/../include/mbedtls/mbedtls_config.h
${CMAKE_CURRENT_SOURCE_DIR}/../scripts/data_files/version_features.fmt ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/data_files/version_features.fmt
) )
else()
link_to_source(error.c)
link_to_source(version_features.c)
endif()
if(CMAKE_COMPILER_IS_GNUCC) if(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wmissing-prototypes") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wmissing-prototypes")

View file

@ -4,7 +4,8 @@ set(executables
psa_constant_names psa_constant_names
) )
add_custom_command( if(DEV_MODE)
add_custom_command(
OUTPUT OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/psa_constant_names_generated.c ${CMAKE_CURRENT_BINARY_DIR}/psa_constant_names_generated.c
COMMAND COMMAND
@ -17,7 +18,10 @@ add_custom_command(
${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/generate_psa_constants.py ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/generate_psa_constants.py
${CMAKE_CURRENT_SOURCE_DIR}/../../include/psa/crypto_values.h ${CMAKE_CURRENT_SOURCE_DIR}/../../include/psa/crypto_values.h
${CMAKE_CURRENT_SOURCE_DIR}/../../include/psa/crypto_extra.h ${CMAKE_CURRENT_SOURCE_DIR}/../../include/psa/crypto_extra.h
) )
else()
link_to_source(psa_constant_names_generated.c)
endif()
foreach(exe IN LISTS executables) foreach(exe IN LISTS executables)
add_executable(${exe} ${exe}.c $<TARGET_OBJECTS:mbedtls_test>) add_executable(${exe} ${exe}.c $<TARGET_OBJECTS:mbedtls_test>)
@ -26,9 +30,11 @@ foreach(exe IN LISTS executables)
endforeach() endforeach()
target_include_directories(psa_constant_names PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) target_include_directories(psa_constant_names PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
add_custom_target(generate_psa_constant_names_generated_c if(DEV_MODE)
add_custom_target(generate_psa_constant_names_generated_c
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/psa_constant_names_generated.c) DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/psa_constant_names_generated.c)
add_dependencies(psa_constant_names generate_psa_constant_names_generated_c) add_dependencies(psa_constant_names generate_psa_constant_names_generated_c)
endif()
install(TARGETS ${executables} install(TARGETS ${executables}
DESTINATION "bin" DESTINATION "bin"

View file

@ -18,14 +18,16 @@ set(executables
ssl_server2 ssl_server2
) )
# Inform CMake the the following file will be generated as part of the build if(DEV_MODE)
# process, so it doesn't complain that it doesn't exist yet. Starting from # Inform CMake the the following file will be generated as part of the build
# CMake 3.20, this will no longer be necessary as CMake will automatically # process, so it doesn't complain that it doesn't exist yet. Starting from
# propagate this information accross the tree, for now it's only visible # CMake 3.20, this will no longer be necessary as CMake will automatically
# inside the same directory, so we need to propagate manually. # propagate this information accross the tree, for now it's only visible
set_source_files_properties( # inside the same directory, so we need to propagate manually.
set_source_files_properties(
${CMAKE_CURRENT_BINARY_DIR}/../test/query_config.c ${CMAKE_CURRENT_BINARY_DIR}/../test/query_config.c
PROPERTIES GENERATED TRUE) PROPERTIES GENERATED TRUE)
endif()
foreach(exe IN LISTS executables) foreach(exe IN LISTS executables)
set(extra_sources "") set(extra_sources "")
@ -40,7 +42,9 @@ foreach(exe IN LISTS executables)
target_link_libraries(${exe} ${libs}) target_link_libraries(${exe} ${libs})
target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include) target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include)
if(exe STREQUAL "ssl_client2" OR exe STREQUAL "ssl_server2") if(exe STREQUAL "ssl_client2" OR exe STREQUAL "ssl_server2")
if(DEV_MODE)
add_dependencies(${exe} generate_query_config_c) add_dependencies(${exe} generate_query_config_c)
endif()
target_include_directories(${exe} target_include_directories(${exe}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../test) PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../test)
endif() endif()

View file

@ -27,9 +27,10 @@ if(TEST_CPP)
target_link_libraries(cpp_dummy_build ${mbedcrypto_target}) target_link_libraries(cpp_dummy_build ${mbedcrypto_target})
endif() endif()
find_package(Perl REQUIRED) if(DEV_MODE)
find_package(Perl REQUIRED)
add_custom_command( add_custom_command(
OUTPUT OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/query_config.c ${CMAKE_CURRENT_BINARY_DIR}/query_config.c
COMMAND COMMAND
@ -42,11 +43,14 @@ add_custom_command(
${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/generate_query_config.pl ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/generate_query_config.pl
${CMAKE_CURRENT_SOURCE_DIR}/../../include/mbedtls/mbedtls_config.h ${CMAKE_CURRENT_SOURCE_DIR}/../../include/mbedtls/mbedtls_config.h
${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/data_files/query_config.fmt ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/data_files/query_config.fmt
) )
# this file will also be used in anoter directory, so create a target, see # this file will also be used in anoter directory, so create a target, see
# https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#how-can-i-add-a-dependency-to-a-source-file-which-is-generated-in-a-subdirectory # https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#how-can-i-add-a-dependency-to-a-source-file-which-is-generated-in-a-subdirectory
add_custom_target(generate_query_config_c add_custom_target(generate_query_config_c
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/query_config.c) DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/query_config.c)
else()
link_to_source(query_config.c)
endif()
foreach(exe IN LISTS executables_libs executables_mbedcrypto) foreach(exe IN LISTS executables_libs executables_mbedcrypto)
set(extra_sources "") set(extra_sources "")

View file

@ -16,7 +16,8 @@ endif()
# generated .data files will go there # generated .data files will go there
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/suites) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/suites)
add_custom_command( if(DEV_MODE)
add_custom_command(
OUTPUT OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/suites/test_suite_psa_crypto_not_supported.generated.data ${CMAKE_CURRENT_BINARY_DIR}/suites/test_suite_psa_crypto_not_supported.generated.data
${CMAKE_CURRENT_BINARY_DIR}/suites/test_suite_psa_crypto_storage_format.current.data ${CMAKE_CURRENT_BINARY_DIR}/suites/test_suite_psa_crypto_storage_format.current.data
@ -32,7 +33,12 @@ add_custom_command(
${CMAKE_CURRENT_SOURCE_DIR}/../include/psa/crypto_config.h ${CMAKE_CURRENT_SOURCE_DIR}/../include/psa/crypto_config.h
${CMAKE_CURRENT_SOURCE_DIR}/../include/psa/crypto_values.h ${CMAKE_CURRENT_SOURCE_DIR}/../include/psa/crypto_values.h
${CMAKE_CURRENT_SOURCE_DIR}/../include/psa/crypto_extra.h ${CMAKE_CURRENT_SOURCE_DIR}/../include/psa/crypto_extra.h
) )
else()
link_to_source(suites/test_suite_psa_crypto_not_supported.generated.data)
link_to_source(suites/test_suite_psa_crypto_storage_format.current.data)
link_to_source(suites/test_suite_psa_crypto_storage_format.v0.data)
endif()
# Test suites caught by SKIP_TEST_SUITES are built but not executed. # Test suites caught by SKIP_TEST_SUITES are built but not executed.
# "foo" as a skip pattern skips "test_suite_foo" and "test_suite_foo.bar" # "foo" as a skip pattern skips "test_suite_foo" and "test_suite_foo.bar"