CMakeLists.txt files for building applications

The CMakeLists.txt file for building an application must contain the following commands:

Example CMakeLists.txt file for building a simple application

CMakeLists.txt

project (hello)

# Include the CMake library named nk for working with the NK compiler (nk-gen-c).

include (platform/nk)

# Set the linker and compiler flags.

project_header_default ("STANDARD_GNU_17:YES" "STRICT_WARNINGS:NO")

# Define the name of the project that includes the program.

set (LOCAL_MODULE_NAME "example")

# Define the program name.

set (TASK_NAME "Hello")

# Please note the contents of the init.yaml.in and security.psl.in templates

# They define program names as ${LOCAL_MODULE_NAME}.${TASK_NAME}

# Define the targets that will be used to create the generated files of the program.

set (TASK_IDL_TARGET ${TASK_NAME}_idl)

set (TASK_CDL_TARGET ${TASK_NAME}_cdl)

set (TASK_EDL_TARGET ${TASK_NAME}_edl)

# Add the idl.h file build target.

nk_build_idl_files (${TASK_IDL_TARGET}

NK_MODULE ${LOCAL_MODULE_NAME}

IDL "../resources/Hello.idl"

)

# Add the cdl.h file build target.

nk_build_cdl_files (${TASK_CDL_TARGET}

IDL_TARGET ${TASK_IDL_TARGET}

NK_MODULE ${LOCAL_MODULE_NAME}

CDL "../resources/Hello.cdl"

)

# Add the EDL file build target.The EDL_FILE variable is exported

# and contains the path to the generated EDL file.

generate_edl_file (${TASK_NAME}

PREFIX ${LOCAL_MODULE_NAME}

)

# Add the edl.h file build target.

nk_build_edl_files (${TASK_EDL_TARGET}

NK_MODULE ${LOCAL_MODULE_NAME}

EDL ${EDL_FILE}

)

# Define the target for the program build.

add_executable (${TASK_NAME} "src/hello.c")

# Libraries that are linked to the program during the build.

target_link_libraries (${TASK_NAME}

PUBLIC vfs::client # The program uses file I/O

# and must be connected as a client to VFS

)

# Add a dependency on the Hello_edl target to the Hello target.

# The edl.h file must be generated before the Hello target is built.

add_dependencies (${TASK_NAME} ${TASK_EDL_TARGET})

Page top