Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[question] How conan-workspace works with cmake-install? #6086

Closed
guestliu opened this issue Nov 18, 2019 · 2 comments
Closed

[question] How conan-workspace works with cmake-install? #6086

guestliu opened this issue Nov 18, 2019 · 2 comments

Comments

@guestliu
Copy link

guestliu commented Nov 18, 2019

Our team develop a big project with many modules, I have organized the modules by cmake-packages. A module generates a package with include, lib files and FindXXX.cmake file. The module users use find_package to find the package.

Now I want to use conan workspace to make the workflow better, reference:
https://docs.conan.io/en/latest/developing_packages/workspaces.html

I found the workspace mode can not work perfect with the cmake-install.
For example, my findXXX.cmake just like:

find_path(RPC_INCLUDE_DIRS
  NAMES header.pb.h
  PATHS ${CONAN_RPC_ROOT}/include
  NO_DEFAULT_PATH)

find_library(RPC_LIBRARIES
  NAME rpc_proto
  PATHS ${CONAN_RPC_ROOT}/lib
  NO_DEFAULT_PATH)
endif()

if (NOT TARGET rpc_proto)
  add_library(rpc_proto SHARED IMPORTED)
  set_target_properties(rpc_proto PROPERTIES IMPORTED_LOCATION ${RPC_LIBRARIES}
    INTERFACE_INCLUDE_DIRECTORIES "${RPC_INCLUDE_DIRS};/usr/local/include"
    INTERFACE_LINK_LIBRARIES "/usr/local/lib/libprotobuf.so")
endif()

The script finds lib and include files from the cmake environment variable CONAN_RPC_ROOT, but CONAN_RPC_ROOT in workspace-mode is the source code directory itself whose tree graph is not consistent with the build directory. To make find_package(RPC) OK, CONAN_RPC_ROOT must be:
-include/...
-lib/...
-proto/...
-python/...

These files are generate by the install statements in the rpc/CMakeList.txt, just like:

protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${PROTO_FILES})
protobuf_generate(APPEND_PATH
                  LANGUAGE
                  python
                  OUT_VAR
                  PY_SRCS
                  IMPORT_DIRS
                  ${Protobuf_IMPORT_DIRS}
                  PROTOC_OUT_DIR
                  ${CMAKE_CURREnt_BINARY_DIR}
                  PROTOS
                  ${PROTO_FILES})
install(TARGETS ${LIB_NAME} EXPORT RpcExport DESTINATION lib)
install(FILES ${PROTO_FILES} DESTINATION proto)
install(FILES ${PROTO_HDRS} DESTINATION include)
install(FILES ${PY_SRCS} DESTINATION python)

To handle with conan-workspace, I changed my FindRPC.cmake like this:

if (DEFINED CONAN_INCLUDE_DIRS_RPC)
  set(RPC_INCLUDE_DIRS "${CONAN_INCLUDE_DIRS_RPC}")
else()
  find_path(RPC_INCLUDE_DIRS
    NAMES header.pb.h
    PATHS ${CONAN_RPC_ROOT}/include
    NO_DEFAULT_PATH)
endif()

if (DEFINED CONAN_LIB_DIRS_RPC)
  set(RPC_LIBRARIES "${CONAN_LIB_DIRS_RPC})")
else()
  find_library(RPC_LIBRARIES
    NAME rpc_proto
    PATHS ${CONAN_RPC_ROOT}/lib
    NO_DEFAULT_PATH)
  if (NOT RPC_LIBRARIES)
    message(FATAL_ERROR "RPC_LIBRARIES NOT FOUND")
  endif()
endif()

I found the cmake variables CONAN_INCLUDE_DIRS_RPC and CONAN_LIB_DIRS_RPC generated by 'conan workspace install' . I try to use them but it still doesn't work. The build folder tree graph is not consistent with the install directory.

source dir like:
src/proto/xxx.proto

build dir like:
src/proto/xxx.pb.h
src/proto/xxx.pb.cc
src/proto/xxx.proto
src/proto/xxx_pb2.py
lib/libxxx.so

after install :
include/xxx.pb.h
proto/xxx.proto
python/xxx_pb2.py
lib/libxxx.so

Are there any easy ways to use my self-defined install statements in my CMakeLists.txt with conan-workspace?

@wpalfi
Copy link

wpalfi commented Apr 25, 2020

Dont know if that helps: Workspaces are experimental and very limited. In our company, instead of using workspaces, we manually remove the concerned requirements from the conanfile and use cmake to create and link the libraries. I explained that in #6844.

@memsharded
Copy link
Member

Workspaces were removed in 2.0, but the plan is to resume work on them in the 2.X roadmap.
Please track progress in #12466, closing this

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

No branches or pull requests

3 participants