Topics

Adding a costume module to my project #west


Stefan Hristozov
 

Hi,

I want to add a module to my project. My folder structure looks like this:

<top dir>
    |---modules
    |      |---module1
    |      |      |---CMakeLists.txt
    |      |      |---inc
    |      |      |---src
    |      |      |---zephyr
    |      |            |---module.yml
    |      |---module2
    |---app
           |---app1

Where modules/module1/CMakeLists.txt:

zephyr_interface_library_named(test)
target_include_directories(test INTERFACE inc)
zephyr_library()
zephyr_library_sources(
    src/test.c
)
zephyr_library_link_libraries(test)
target_link_libraries(test INTERFACE zephyr_interface)

modules/module1/zephyr/module.yml:

build:
  cmake: .

app/app1/CMakeLists.txt:
cmake_minimum_required(VERSION 3.13.1)
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(NONE)

set($ENV{ZEPHYR_EXTRA_MODULES} pbs_path/module1)


FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})
target_include_directories(app PRIVATE $ENV{ZEPHYR_BASE}/subsys/net/ip)

target_link_libraries(app PRIVATE test)

Unfortunately,  with this set up module1 doesn't get compiled and I get a linker error when I try to use functions from that module. I assume that something goes wrong with ZEPHYR_EXTRA_MODULES but I don't know what.

Best regards
Stefan


Bolivar, Marti
 

"stefan.hristozov via Lists.Zephyrproject.Org"
<stefan.hristozov=aisec.fraunhofer.de@lists.zephyrproject.org> writes:

Hi,

I want to add a module to my project. My folder structure looks like this:

<top dir>
|---modules
|      |---module1
|      |      |---CMakeLists.txt
|      |      |---inc
|      |      |---src
|      |      |---zephyr
|      |            |---module.yml
|      |---module2
|---app
|---app1

*Where modules/module1/CMakeLists.txt:*

zephyr_interface_library_named(test)
target_include_directories(test INTERFACE inc)
zephyr_library()
zephyr_library_sources(
src/test.c
)
zephyr_library_link_libraries(test)
target_link_libraries(test INTERFACE zephyr_interface)

*modules/module1/zephyr/module.yml:*

build:
cmake: .

*app/app1/CMakeLists.txt:*
cmake_minimum_required (VERSION 3.13.1)
include ( $ENV{ZEPHYR_BASE} /cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project (NONE)

set ( $ENV{ZEPHYR_EXTRA_MODULES} pbs_path/module1)
Looking at this quickly, ZEPHYR_EXTRA_MODULES needs to be set before
including the boilerplate file, not before. You can also set it as an
ordinary CMake variable; you don't need to set it in the environment.



FILE (GLOB app_sources src/*.c)
target_sources (app PRIVATE ${app_sources} )
target_include_directories (app PRIVATE $ENV{ZEPHYR_BASE} /subsys/net/ip)

target_link_libraries (app PRIVATE test)

Unfortunately,  with this set up module1 doesn't get compiled and I get a linker error when I try to use functions from that module. I assume that something goes wrong with ZEPHYR_EXTRA_MODULES but I don't know what.
HTH,
Marti

Best regards
Stefan


Stefan Hristozov
 

Hi,

I moved

set ( $ENV{ZEPHYR_EXTRA_MODULES} pbs_path/module1)

before

include ( $ENV{ZEPHYR_BASE} /cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project (NONE)


Unfortunately I am still getting the same linker error.

Best regards
Stefan


Am 01/29/2020 um 02:10 AM schrieb Bolivar, Marti:

"stefan.hristozov via Lists.Zephyrproject.Org"
<stefan.hristozov=aisec.fraunhofer.de@lists.zephyrproject.org> writes:

Hi,

I want to add a module to my project. My folder structure looks like this:

<top dir>
|---modules
| |---module1
| | |---CMakeLists.txt
| | |---inc
| | |---src
| | |---zephyr
| | |---module.yml
| |---module2
|---app
|---app1

*Where modules/module1/CMakeLists.txt:*

zephyr_interface_library_named(test)
target_include_directories(test INTERFACE inc)
zephyr_library()
zephyr_library_sources(
src/test.c
)
zephyr_library_link_libraries(test)
target_link_libraries(test INTERFACE zephyr_interface)

*modules/module1/zephyr/module.yml:*

build:
cmake: .

*app/app1/CMakeLists.txt:*
cmake_minimum_required (VERSION 3.13.1)
include ( $ENV{ZEPHYR_BASE} /cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project (NONE)

set ( $ENV{ZEPHYR_EXTRA_MODULES} pbs_path/module1)
Looking at this quickly, ZEPHYR_EXTRA_MODULES needs to be set before
including the boilerplate file, not before. You can also set it as an
ordinary CMake variable; you don't need to set it in the environment.


FILE (GLOB app_sources src/*.c)
target_sources (app PRIVATE ${app_sources} )
target_include_directories (app PRIVATE $ENV{ZEPHYR_BASE} /subsys/net/ip)

target_link_libraries (app PRIVATE test)

Unfortunately, with this set up module1 doesn't get compiled and I get a linker error when I try to use functions from that module. I assume that something goes wrong with ZEPHYR_EXTRA_MODULES but I don't know what.
HTH,
Marti

Best regards
Stefan

--
Stefan Hristozov
Department Hardware Security
Fraunhofer Institute for Applied and Integrated Security AISEC
Lichtenbergstraße 11, 85748 Garching near Munich, Germany
Tel. +49 89 32299 86 157
stefan.hristozov@aisec.fraunhofer.de
http://www.aisec.fraunhofer.de
http://twitter.com/FraunhoferAISEC


Bolivar, Marti
 

Hi,

Please check your build directory's zephyr_modules.txt file to make sure
it is being included in the list. If it's not, please check where you
are setting ZEPHYR_EXTRA_MODULES again.

If it is present in zephyr_modules.txt but you're not seeing it get
compiled, please try debugging with this PR:

https://github.com/zephyrproject-rtos/zephyr/pull/22321

If that patch doesn't generate any errors, I suspect your module's
CMakeLists.txt is not building the source code.

HTH,
Marti

"Stefan Hristozov via Lists.Zephyrproject.Org"
<stefan.hristozov=aisec.fraunhofer.de@lists.zephyrproject.org> writes:

Hi,

I moved

set ( $ENV{ZEPHYR_EXTRA_MODULES} pbs_path/module1)

before

include ( $ENV{ZEPHYR_BASE} /cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project (NONE)


Unfortunately I am still getting the same linker error.

Best regards
Stefan


Am 01/29/2020 um 02:10 AM schrieb Bolivar, Marti:
"stefan.hristozov via Lists.Zephyrproject.Org"
<stefan.hristozov=aisec.fraunhofer.de@lists.zephyrproject.org> writes:

Hi,

I want to add a module to my project. My folder structure looks like this:

<top dir>
|---modules
| |---module1
| | |---CMakeLists.txt
| | |---inc
| | |---src
| | |---zephyr
| | |---module.yml
| |---module2
|---app
|---app1

*Where modules/module1/CMakeLists.txt:*

zephyr_interface_library_named(test)
target_include_directories(test INTERFACE inc)
zephyr_library()
zephyr_library_sources(
src/test.c
)
zephyr_library_link_libraries(test)
target_link_libraries(test INTERFACE zephyr_interface)

*modules/module1/zephyr/module.yml:*

build:
cmake: .

*app/app1/CMakeLists.txt:*
cmake_minimum_required (VERSION 3.13.1)
include ( $ENV{ZEPHYR_BASE} /cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project (NONE)

set ( $ENV{ZEPHYR_EXTRA_MODULES} pbs_path/module1)
Looking at this quickly, ZEPHYR_EXTRA_MODULES needs to be set before
including the boilerplate file, not before. You can also set it as an
ordinary CMake variable; you don't need to set it in the environment.


FILE (GLOB app_sources src/*.c)
target_sources (app PRIVATE ${app_sources} )
target_include_directories (app PRIVATE $ENV{ZEPHYR_BASE} /subsys/net/ip)

target_link_libraries (app PRIVATE test)

Unfortunately, with this set up module1 doesn't get compiled and I get a linker error when I try to use functions from that module. I assume that something goes wrong with ZEPHYR_EXTRA_MODULES but I don't know what.
HTH,
Marti

Best regards
Stefan

--
Stefan Hristozov
Department Hardware Security
Fraunhofer Institute for Applied and Integrated Security AISEC
Lichtenbergstraße 11, 85748 Garching near Munich, Germany
Tel. +49 89 32299 86 157
stefan.hristozov@aisec.fraunhofer.de
http://www.aisec.fraunhofer.de
http://twitter.com/FraunhoferAISEC