I understood that enable_language() must not be called before the first call to [project()
], and everything is okay if we follow this.
Since the end-user shares the sample, we want to retain their flow and scripts. The warning (shown below) was not present with the 3.29.7 version and is seen only with the latest release (3.30.2).
cmake -G “Unix Makefiles” -S . -B build
– Defaulting build type to Debug.
CMake Warning (dev) at bsp/toolchain.cmake:45 (enable_language):
project() should be called prior to this enable_language() call.
Call Stack (most recent call first):
bsp/CMakeLists.txt:3 (include)
This warning is for project developers. Use -Wno-dev to suppress it.
The languages required for us are ASM, C, and CXX (c++).
I read by default C
and CXX
are enabled if no language options are given with ‘project’. In that case, what about ‘ASM’, and what will be the method/suggestion to overcome this warning with the least impact or the best method to resolve this?
- Removing “enable_language” from the toolchain detailed (toolchain.cmake).
- Use the -Wno-dev flag to suppress.
- Re-write the CMakeLists.txt (we had 2 files: main and sub-directory).
- Anything else?
Thank you in advance and let me know for any further details.
The warning was added by merge request 9396 in response to issue 25550.
- Toolchain files must not try to enable languages. The point at which
project()
tries to enable languages assumes the toolchain file has finished being read.
- The
-Wno-dev
flag is not appropriate. It doesn’t solve the problem, it just hides the warning for now.
- You haven’t provided enough detail about the situation you’re facing. You mention “end-user” and “sample”, but you also talk about having a main and subdirectory. Without further information, it’s difficult to say where changes need to be made, but I would expect it will be somewhere in the project’s CMakeLists.txt files.
1 Like
Thank you @craig.scott. The first point itself clears the solution and I understood from the merge request 9396 that we introduce an additional warning (regarding enable_language) from the 3.30 version onwards (the reason we are not seeing this warning with v3.29.7).
Just to answer your #3, I am sharing the main contents of two CMakeLists.txt files and the toolchain file.
One CMakeLists.txt file is at our top level and the other two files are in the sub-folder ‘bsp’.
- CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
add_subdirectory(bsp bsp)
include(bsp/toolchain.cmake)
project(hello)
add_executable(hello.elf)
target_sources(hello.elf
PRIVATE
hello.c
)
…
- bsp/CMakeLists.txt
cmake_minimum_required(VERSION 3.13)
include(toolchain.cmake)
project(bsp)
set(BspLibraryName “hal2_bsp” CACHE STRING “The BSP library name.”)
set(BspLinkerScript “${CMAKE_CURRENT_SOURCE_DIR}/linker.x” CACHE STRING
“The linker script an app should use.”)
add_library(“${BspLibraryName}” STATIC “”)
target_include_directories(“${BspLibraryName}” PUBLIC
.
HAL/inc
drivers/inc
)
target_sources(“${BspLibraryName}”
PRIVATE
…
- bsp/toolchain.cmake
set(CMAKE_AR riscv32-unknown-elf-ar)
set(CMAKE_ASM_COMPILER riscv32-unknown-elf-gcc)
set(CMAKE_C_COMPILER riscv32-unknown-elf-gcc)
set(CMAKE_CXX_COMPILER riscv32-unknown-elf-g++)
set(ToolchainObjdump riscv32-unknown-elf-objdump CACHE STRING “Objdump executable.” FORCE)
set(ToolchainObjdumpFlags -Sdtx CACHE STRING “Objdump flags.” FORCE)
set(CMAKE_C_FLAGS_DEBUG “-g”)
set(CMAKE_CXX_FLAGS_DEBUG “-g”)
set(CMAKE_C_FLAGS_RELEASE “-O2”)
set(CMAKE_CXX_FLAGS_RELEASE “-O2”)
add_compile_options(
$<$<COMPILE_LANGUAGE:ASM>:-Wa,-gdwarf2>
-Wall -Wformat-security
-march=rv32ia -mabi=ilp32
)
add_link_options(
-march=rv32ia -mabi=ilp32
)
enable_language(ASM)
enable_language(C)
enable_language(CXX)
Hope the details are clear now.
Your project files are doing some things they must not do:
- The first call to
project()
must occur in the top level CMakeLists.txt
file. That isn’t the case for you, the one in bps/CMakeLists.txt
will be the first one that is reached.
- As mentioned in my earlier reply, your toolchain file enables the ASM, C and CXX languages. They must not do that. Only project code should be enabling languages.
2 Likes