Reputation: 4327
Our project builds with CMake on several platforms, including Windows, Linux and cross-compilation on some embedded OSes, described with custom CMake toolchain files.
In case of cross-compilation, we have to maintain sets of preprocessor macros.
It is reflected in CMakeLists.txt
in the following fashion.
File embedded_os1.toolchain.cmake
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR ARM)
set(CMAKE_C_COMPILER /path/to/cross-compiler)
# blah-blah-blah
set(embedded_OS1 TRUE)
... and we have similar files for other embedded OSes.
File CMakeLists.txt
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
if(embedded_OS1)
add_definitions(-Dmacro1 -Dmacro2)
elseif(embedded_OS2)
add_definitions(-Dmacro3 -Dmacro4)
elseif(embedded_OS3)
add_definitions(-Dmacro1 -Dmacro4)
endif()
I'd like to perform some kind of automatic checking that all preprocessor macros are set correctly.
I can easily do it with unit-tests on Windows and Linux.
But there is no possibility to compile and run executable files on embedded OSes, I can compile only static libs, that are then signed, put in a firmware images, etc, etc. And all I have on PC besides library is the JSON file with compiler calls, generated by EXPORT_COMPILE_COMMANDS
.
What could you suggest?
Upvotes: 2
Views: 276
Reputation: 968
I'd do it with #warning
macro and check the compilation output with bash of whatever. Then you can set Werror
for these files and get compile-time check. Or simply use #error
(thanks to KamilCuk)
Another way is to dig into check binaries that help to see if the toolchain has threading or something else.
Upvotes: 1