Header-only Library how to include
See original GitHub issueI want to use a header only github project, so I created my conanfile.py
with this in it:
from conans import ConanFile, tools
class SimpleSignalConan(ConanFile):
name = "SimpleSignal"
version = "master"
def source(self):
git = tools.Git(folder=self.name)
git.clone('https://github.com/larspensjo/SimpleSignal.git', branch=self.version)
In my CMakeLists.txt
, I did the following:
if(CONAN_EXPORTED) # in conan local cache
# standard conan installation, deps will be defined in conanfile.py
# and not necessary to call conan again, conan is already running
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
else() # in user space
include(${CMAKE_BINARY_DIR}/conan.cmake)
# Make sure to use conanfile.py to define dependencies, to stay consistent
conan_cmake_run(CONANFILE conanfile.py
BASIC_SETUP)
endif()
In my main.cpp
, I tried doing #include <SimpleSignal.h>
, but it didn’t work.
What else do I need in order to be able to #include <SimpleSignal.h>
?
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
What's the proper way of using header-only library?
Traditionally you would include them in your include path, but you can also put them in your project. Including them in your project...
Read more >Building a header-only library — Hello World | by Ryan Graham
The first is the single header structure which features an include folder at the root of the repository with a single header file...
Read more >Header-only libraries | Advanced C++ Programming Cookbook
The benefit of header-only libraries is that they are easy to include in your project as you simply include the header and you...
Read more >What is a header-only library and how do you use it ... - Reddit
The main header file includes the entire library implementation so if you include MyHeaderOnlyLib.h in main.cpp and build main.cpp , you also ...
Read more >Header-only libraries
In modern C++, libraries often consist of just header files, without any source files to compile. To use such libraries, you need to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @smac89, Yes, you can use the variable
CONAN_EXPORTED
to check if you are running on Conan’s local cache or in user space. That way you can test your project using cmake-conan but also creating the package using Conan commands directly. I thought that for your case it was easier to explain it without making both things as you are just consuming the SimpleSignal package. I have created a complete example on how to use cmake-conan for both consuming and creating packages that maybe clears a little the explanation in the docs.I’m closing this issue, please feel free to reopen if you have more questions regarding this topic.