Package that contains packageConfig.cmake only

asked 2018-11-01 21:47:12 -0500

KenYN gravatar image

updated 2018-11-01 22:07:49 -0500

We have a whole bunch of packages with CMakeLists.txt that share code like

set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(project_cxx_flags -Wall)
set(project_cuda_flags -gencode arch=compute_61,code=compute61 -gencode ..62 -gencode ..52)

Along with other code for doing stuff on either x64 or arm64 (we also should only build CUDA 6.2 on ARM, 5.2 on x64, etc) that really should be made common.

Reading the documentation for find_package() it seems it should be possible to create a new package inside our main project and then use:

find_package(common_stuff)

To load up common_stuffConfig.cmake.

NOTE: I know I could use CMAKE_MODULE_PATH but I would have to reconfigure a good number of machines, so I want a solution that uses the existing code tree.

My current directory structure looks like

catkin_root\src
+--foo
    +--various files...
+--bar
    +--various files...
+--common_stuff
    +--CmakeLists.txt (empty file)
    +--Findcommon_stuff.cmake
    +--package.xml
    +--common_stuffConfig.cmake

So, currently I do this:

find_package(common_stuff REQUIRED MODULE)
# or
find_package(common_stuff REQUIRED)

This fails with the error:

No "Findcommon_stuff_build.cmake" found in CMAKE_MODULE_PATH.
edit retag flag offensive close merge delete