0

I am trying to create a library or possibly better to make two libraries. The file structure is below (with generic names). I am trying to get the ExampleProject to be able to include messageA.h, which would include MessageUtilitiesA.h. Currently it can find the messageA.cpp but then it cannot find MessageUtitlities.h

project
|.   CMakeLists.txt
|----src
|.        classA.cpp
|----include
|         classA.h
|----SecondFolder
|         include
|              Messages
                  |   messageA.h // this includes messageUtilityA.h
|.                |.  messageB.h // etc
|              MessageUtilities
}                 |.  messageUtilityA.h
|
|----ExampleProject
|         src 
|              example.cpp // needs to be able to include ClassA.h, and messageA.h

classA.cpp needs to be able to #include "Messages/messageA.h"

example.cpp needs to be able to #include "classA.h" and #include "Messages/messageA.h"

I am currently using Conan and CMake. Do I just need to make SecondFolder it's own library. In the cmake I am doing

project(base CXX)
add_library(base
     src/classA.cpp
)
target_include_directories(base
    PUBLIC
        include
        SecondFolder/include

set_target_properties(base PROPERTIES PUBLIC_HEADER "include classA.h;{PROJECT_SOURCE_DIR}/SecondFolder/include/Messages/include/MessageA.h") # might just need to glob all the .h's from the entire folder perhaps

install(TARGETS base)

Maybe I just need to add more to the cmake target_properties, make a second library just for the SecondFolder?

the CMakeLists.txt for the example is able to target_link_libraries(example base::base) and it finds the messageA.h but then complains that it cannot include messageUtilityA.h which messageA.h includes. So it cannot find the #include "<namespace>/messageUtilityA.h.

conan file does have exports_source = "CMakeLists.txt", "src/*", "include/*", "SecondFolder/*"

4
  • Please show a minimal reproducible example Commented Jun 5 at 5:02
  • 1
    How is Conan involved in it? The tag is listed, but there is no mention in the question. Please clarify your question better. Commented Jun 5 at 5:52
  • There is no problem in using "generic names" when describe the problem. But make sure to use consistent names. Currently your post notes MessageUtilitiesA.h, MessageUtitlities.h, messageUtilityA.h, MessageUtiltiesA.h which seems about the same header file. This is very confusing and it smells like a simple typo in your code when you include that header. But since your code (and description) are impresize, we cannot show the place of the typo. Commented Jun 5 at 6:28
  • Please, add to the question post complete error message which you got. It should not only contain a line like "cannot find a file", but should also include a stack of #include calls and names of files which performs such inclusions. Like in that question: stackoverflow.com/questions/61384481/… Commented Jun 6 at 6:19

1 Answer 1

0

What I figured out was that the include list does not take merely from adding the set_target_include_directories in the cmakelists.txt, it is insufficient for whatever reason. So adding to the conan file as well was needed:

self.cpp_info.includedirs = ['include', "SecondFolder"]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.