How to add conditional compilation in .Camkes files
Hi, I try to add support for UART on one platform and disable this UART for another platform. As my application is Camkes based, I need to define the UART connections (Dataport, Interface functions etc) between the 2 Camkes components. However I need to use the same application on another platform without UART support. How can this be got in .Camkes files ? I already tried including a .h file where I define something like this In main.h #ifdef PLATFORM_X #define UART 1 #else #define UART 0 #endif Then include main.h file in Camkes files using a .idl4 file . However it did not work. .Camkes file is not able to see these defines to use it further for conditional compilation in .camkes files to enable or disable UART between the two components. Is there any way to get it done ? Regards yk
Hi yk,
The .camkes files can be preprocessed by the C preprocessor.
To do this, you'll need to turn on the CAmkESCPP CMake flag by appending this line to the CMakeLists.txt file for your CAmkES component:
set(CAmkESCPP ON CACHE BOOL "" FORCE)
You could then define flags inside a header file and include it into the .camkes file for your application.
For example, given a header file called main.h, add this line to the .camkes file for your application:
#include "main.h"
or similar.
Sincerely,
Damon
________________________________
From: Devel
Hi Damon, Thanks for the reply. In my CmakeLists.txt, I have added the define as you mentioned: DeclareCAmkESComponent(MAIN INCLUDES "src" SOURCES "src/main.c" C_FLAGS -Wall -Werror ) *set(CAmkESCPP ON CACHE BOOL "" FORCE) * ####################################################################################################### In main.h, I added #define UART_ON 1 Include the main.h in my .Camkes file, but I still find UART_ON is set to 0 as the code is not enabled In .Camkes file, import "main.h"; #if UART_ON { // uart code goes here... } Even with UART_ON is 1, the code is always disabled. I tried options like moving *set(CAmkESCPP ON CACHE BOOL "" FORCE) * to the top of file etc, but this did not help. Regards yk On Mon, May 20, 2019 at 4:22 AM Lee, Damon (Data61, Kensington NSW) < Damon.Lee@data61.csiro.au> wrote:
Hi yk,
The .camkes files can be preprocessed by the C preprocessor.
To do this, you'll need to turn on the CAmkESCPP CMake flag by appending this line to the CMakeLists.txt file for your CAmkES component:
set(CAmkESCPP ON CACHE BOOL "" FORCE)
You could then define flags inside a header file and include it into the .camkes file for your application.
For example, given a header file called main.h, add this line to the .camkes file for your application:
#include "main.h"
or similar.
Sincerely, Damon ------------------------------ *From:* Devel
on behalf of yogidk < yogidk@gmail.com> *Sent:* Sunday, 19 May 2019 4:43 AM *To:* devel@sel4.systems *Subject:* [seL4] How to add conditional compilation in .Camkes files Hi,
I try to add support for UART on one platform and disable this UART for another platform.
As my application is Camkes based, I need to define the UART connections (Dataport, Interface functions etc) between the 2 Camkes components. However I need to use the same application on another platform without UART support.
How can this be got in .Camkes files ?
I already tried including a .h file where I define something like this In main.h #ifdef PLATFORM_X #define UART 1 #else #define UART 0 #endif
Then include main.h file in Camkes files using a .idl4 file . However it did not work. .Camkes file is not able to see these defines to use it further for conditional compilation in .camkes files to enable or disable UART between the two components.
Is there any way to get it done ?
Regards yk
Hi yk,
In the .camkes file, could you change the `import "main.h";` line so that it becomes `#include "main.h"`?
E.g. the resulting .camkes file should look like:
#include "main.h"
#if UART_ON
{
// uart code goes here...
}
Sincerely,
Damon
________________________________
From: yogidk
Hallo Damon, Thanks. ! Perfect. Now its working with #include instead of import. Regards Yogesh On Tue, May 21, 2019 at 5:24 AM Lee, Damon (Data61, Kensington NSW) < Damon.Lee@data61.csiro.au> wrote:
Hi yk,
In the .camkes file, could you change the `import "main.h";` line so that it becomes `#include "main.h"`?
E.g. the resulting .camkes file should look like:
*#include "main.h"* #if UART_ON { // uart code goes here... }
Sincerely, Damon
------------------------------ *From:* yogidk
*Sent:* Monday, 20 May 2019 7:12 PM *To:* Lee, Damon (Data61, Kensington NSW); devel@sel4.systems *Subject:* Re: [seL4] How to add conditional compilation in .Camkes files Hi Damon,
Thanks for the reply.
In my CmakeLists.txt, I have added the define as you mentioned:
DeclareCAmkESComponent(MAIN INCLUDES "src" SOURCES "src/main.c" C_FLAGS -Wall -Werror )
*set(CAmkESCPP ON CACHE BOOL "" FORCE) *
####################################################################################################### In main.h, I added #define UART_ON 1
Include the main.h in my .Camkes file, but I still find UART_ON is set to 0 as the code is not enabled
In .Camkes file,
import "main.h"; #if UART_ON { // uart code goes here... }
Even with UART_ON is 1, the code is always disabled. I tried options like moving *set(CAmkESCPP ON CACHE BOOL "" FORCE) * to the top of file etc, but this did not help.
Regards yk
On Mon, May 20, 2019 at 4:22 AM Lee, Damon (Data61, Kensington NSW) < Damon.Lee@data61.csiro.au> wrote:
Hi yk,
The .camkes files can be preprocessed by the C preprocessor.
To do this, you'll need to turn on the CAmkESCPP CMake flag by appending this line to the CMakeLists.txt file for your CAmkES component:
set(CAmkESCPP ON CACHE BOOL "" FORCE)
You could then define flags inside a header file and include it into the .camkes file for your application.
For example, given a header file called main.h, add this line to the .camkes file for your application:
#include "main.h"
or similar.
Sincerely, Damon ------------------------------ *From:* Devel
on behalf of yogidk < yogidk@gmail.com> *Sent:* Sunday, 19 May 2019 4:43 AM *To:* devel@sel4.systems *Subject:* [seL4] How to add conditional compilation in .Camkes files Hi,
I try to add support for UART on one platform and disable this UART for another platform.
As my application is Camkes based, I need to define the UART connections (Dataport, Interface functions etc) between the 2 Camkes components. However I need to use the same application on another platform without UART support.
How can this be got in .Camkes files ?
I already tried including a .h file where I define something like this In main.h #ifdef PLATFORM_X #define UART 1 #else #define UART 0 #endif
Then include main.h file in Camkes files using a .idl4 file . However it did not work. .Camkes file is not able to see these defines to use it further for conditional compilation in .camkes files to enable or disable UART between the two components.
Is there any way to get it done ?
Regards yk
participants (2)
-
Lee, Damon (Data61, Kensington NSW)
-
yogidk