Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

header-only unzipped packages? #324

Closed
SamuelMarks opened this issue Jun 14, 2016 · 16 comments
Closed

header-only unzipped packages? #324

SamuelMarks opened this issue Jun 14, 2016 · 16 comments

Comments

@SamuelMarks
Copy link

SamuelMarks commented Jun 14, 2016

All the header-only projects I see in the conan repository are zipped.

Unzipped attempt:

from os.path import join as path_join
from conans import ConanFile, CMake

class RapidJSONConan(ConanFile):
    name = 'RapidJSON'
    version = '1.0.2'
    url = 'https://github.com/SamuelMarks/conan-rapidjson'
    license = 'SQLite'
    exports = 'FindRapidjson.cmake', '*rapidjson.h'
    settings = None
    options = None # {'header_only': [True]}

    def package(self):
        self.copy('FindRapidjson.cmake', '.', '.')
        self.copy(src='*rapidjson.h', dst='.', keep_path=False)

    def build(self): pass

    def package_info(self):
        self.cpp_info.libs = ['rapidjson']

Error:

RapidJSON/1.0.2@SamuelMarks/testing: Installing package 5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9
RapidJSON/1.0.2@SamuelMarks/testing: Looking for package 5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9 in remote 'conan.io' 
RapidJSON/1.0.2@SamuelMarks/testing: WARN: Binary for 5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9 not in remote: Package not found!
ERROR: Can't find a 'RapidJSON/1.0.2@SamuelMarks/testing' package for the specified options and settings

- Try to build from sources with "--build RapidJSON" parameter
- If it fails, you could try to contact the package author  at 'https://github.com/SamuelMarks/conan-rapidjson', report your configuration and try to collaborate to support it.

Package configuration:
- Settings: 
- Options:

What am I doing wrong?

@memsharded
Copy link
Member

Even if the package is header-only, what you are writing is a package recipe. You have to generate a package "binary", that in this case it just copies the headers. I think you can check:

Both are header-only. Note that I also include test_package for these packages, in order to check that all headers have in fact been packaged, in the correct directory. It sometimes happen to forget the *.hpp or *.hh headers.

Note that you can generate the package in any system, as it is independent from settings, so what I do to generate these packages is

$ git clone ..project && cd project
$ conan export user/channel
$ conan test_package
$ conan upload My/0.2@user/channel --all

If you are not using test_package the flow could be:

$ git clone ..project && cd project
$ conan export user/channel
$ conan install My/0.2@user/channel --build
$ conan upload My/0.2@user/channel --all

Note the third step uses the package reference so it is not using any conanfile, it is installing/building the exported code.

Please tell me if this makes sense.

PD: There is an open PR to automatically create the skeleton for packages, so the test_package folder and contents will be generated, so it will be faster. There is also an open issue trying to automatically call the conan export when conan test_package.

@SamuelMarks
Copy link
Author

SamuelMarks commented Jun 14, 2016

Thanks, but that didn't work either.

Also it'd be a little annoying to force the users to download a binary when all they need to use the package is a few source files.

Here's my latest attempt, go back one commit to see previous:
https://github.com/SamuelMarks/conan-rapidjson
https://www.conan.io/source/RapidJSON/1.0.2/SamuelMarks/testing

@memsharded
Copy link
Member

Actually, they don't have to download a "binary", it is actually not a binary, just a set of source files. But note that the package recipe might not have such headers, as they might be in another repository different from the recipe. So it is necessary to "build" a package, even if that build doesnt actually involve compiling it, but just getting the headers are putting them in an appropriate folder.

That is the case for header-only libraries. For source libraries, binaries are not necessary either, they can just be built locally, with the --build=Lib parameter.

What would be your suggestion to improve this?

(cloning your repo now to try it, will contact again soon)

@memsharded
Copy link
Member

It seems it is a bug in the ``test_packagefunctionality. Please put thename` field in your package recipe with double quotes, while we fix this issue.

@memsharded
Copy link
Member

Submitted a PR to fix this: #328. Most likely will be in 0.10, but please remember to use double quotes until then. Thanks for reporting this!

@SamuelMarks
Copy link
Author

SamuelMarks commented Jun 14, 2016

Thanks, changing from ' to " got me a lot further than before.

Unfortunately the header files still aren't being packaged :(

In def package(self), I've tried:

self.copy(src="*rapidjson.h", dst=".", keep_path=False)
self.copy(src="*rapidjson.h", dst=".", keep_path=True)
elf.copy('*', dst='include', src='rapidjson/include/rapidjson')
self.copy("*.h")

@memsharded
Copy link
Member

I didn't check that, let me do it. I see that you are using submodules to get the code, wouldn't it be easier just to clone the sources in the source() method?

@memsharded
Copy link
Member

With this SamuelMarks/conan-rapidjson#1 it should work. Please check it. The main problem was the extra "rapidjson" in the include paths.

@SamuelMarks
Copy link
Author

SamuelMarks commented Jun 15, 2016

Thanks, this looks like it'll work. Down to one remaining bug. Can't #include the file. Here are the different attempts:

#include <rapidjson/writer.h>
#include <rapidjson/include/writer.h>
#include <include/rapidjson/include/writer.h>
#include <include/rapidjson/writer.h>

I have found it here:

.conan/data/RapidJSON/1.0.2/SamuelMarks/testing/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/writer.h

I have tried augmenting my CMakeLists.txt with:

FindRapidjson() // Error:Unknown CMake command "FindRapidjson".
find_package(RapidJSON REQUIRED)
// also tried: `find_package(FindRapidjson REQUIRED)`
Error:By not providing "FindRapidJSON.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "RapidJSON", but CMake did not find one.
Could not find a package configuration file provided by "RapidJSON" with any of the following names:
  RapidJSONConfig.cmake   rapidjson-config.cmake
Add the installation prefix of "RapidJSON" to CMAKE_PREFIX_PATH or set "RapidJSON_DIR" to a directory containing one of the above files.  If "RapidJSON" provides a separate development package or SDK, be sure it has been installed.

Neither FindRapidjson.cmake -> RapidJSONConfig.cmake nor RapidJSONConfig.cmake -> FindRapidJSON.cmake renames worked.

@memsharded
Copy link
Member

First a quick question. As it is just a header-only and then simple to get, do you really need the Find.cmake? Is it for compatibility with non-conan builds?

The bug that you say, how would you reproduce it? From a new project with a conanfile.txt? Do you have such project or steps? Because with test_package it finds the #includes fine. Please tell me so I can have a look, thank you!

@SamuelMarks
Copy link
Author

Happy not to have a Find.cmake.

Test project:

cmake_minimum_required(VERSION 3.5)
project(testttttt)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")

if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/build/conanbuildinfo.cmake) #Clion, with conanbuildinfo.cmake in build folder
    include(${CMAKE_CURRENT_SOURCE_DIR}/build/conanbuildinfo.cmake)
else ()
    include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) # Not CLion
endif ()

conan_basic_setup()
find_package(RapidJSON REQUIRED)
set(SOURCE_FILES main.cpp)
add_executable(testttttt ${SOURCE_FILES})
[requires]
RapidJSON/1.0.2@SamuelMarks/testing

[generators]
cmake
#include <iostream>
#include <rapidjson/rapidjson.h>

int main(void) {
    std::cout << RAPIDJSON_MAJOR_VERSION << std::endl;
}

@memsharded
Copy link
Member

It is working for me. It works also commenting out the find_package() line. Steps

$ cd project
$ mkdir build && cd build
$ conan install ..
$ cmake .. -G "Visual Studio 14"
$ cmake --build . --config Release
$ bin/testtttt.exe
1

Can you please copy the output and error? Thanks!

@memsharded
Copy link
Member

I will be on IRC for a while now, channel #conan, if you need it.

@SamuelMarks
Copy link
Author

Thanks, issue is now resolved AFAIK

PS: Maybe fix that install bug we chatted about on IRC?

@memsharded
Copy link
Member

Sorry, lost the IRC session, and can't remember. What would be the bug? Maybe open an issue for it?

@SamuelMarks
Copy link
Author

just remove all the files inside build and repeat "conan install .." Now, no downloads should appear, as the package is alreadly local

Issue is lack of cleanup. So I export a package, upload it to the conan.io servers—then to ensure I'm using the conan.io version—rm -rf ~/.conan/data/<package_name>. Finally I run conan install .. from inside a package that has <package_name> as a dependency, and it only brings down conanfile.py, conanmanifest.txt, *.cmake; i.e.: the exports folder.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants