0

I'd like to build a static library with following structure :

Foo/
|-- CMakeLists.txt
|-- file1.c
|-- some_definitions.h
|-- drivers/
    |-- file2.c

This is the cmake code

add_library(myHAL STATIC)


target_sources(myHAL 
    PRIVATE
         "${CMAKE_CURRENT_LIST_DIR}/file1.c"
         "${CMAKE_CURRENT_LIST_DIR}/drivers/file2.c"

)

target_include_directories(myHAL PUBLIC ${CMAKE_CURRENT_LIST_DIR}/)
target_include_directories(myHAL PUBLIC ${CMAKE_CURRENT_LIST_DIR}/drivers/)

file2 includes some_definitions.h . In some_definitions, there are some #defines located.

I am not able to build, the definitions are not found (e.g FLS_FEATURE_A undecleared (first use)) When I move the some_definitions.h in the drivers folder, I am able to build.

What I am doing wrong? I suppose the preprocessor does not lookup for the defines or some_definitions.h is not found.

  • CMake part is responsible for the header file being found. If the header file isn't found, the error message describes exactly that fact. As you have no such error message, then the **problem** is **inside** your **C code**. We need to see your code (and exact error message) for being able to help you. – Tsyvarev Oct 15 '18 at 16:46

1 Answers1

0

you need to use the target_include_directory or the include_directory(on older cmake versions) this will tell your cmake to add the directory to the include path (just like -I in regular make) this actually was discussed in a previous thread: How to properly add include directories with CMake

just include_directories("${CMAKE_CURRENT_LIST_DIR}")