Skip to content

Commit

Permalink
creates alternative cmake targets
Browse files Browse the repository at this point in the history
This adds alternative CMake targets by creating an extra module and
adding it to the cpp_info.build_modules property exposed by recent
Conan versions.
  • Loading branch information
TimSimpson committed Jun 23, 2020
1 parent cc4875a commit b2e5f3c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,5 @@ write_basic_package_version_file(

install(FILES "${PROJECT_BINARY_DIR}/lp3-mainConfig.cmake"
"${PROJECT_BINARY_DIR}/lp3-mainConfigVersion.cmake"
${CMAKE_CURRENT_SOURCE_DIR}/cmake/ConanFindModuleExtra.cmake
DESTINATION lib/cmake/lp3-main)
19 changes: 19 additions & 0 deletions cmake/ConanFindModuleExtra.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This is included from the find modules generated by Conan. It creates
# different targets.
function(create_target_from_conan_name cmake_name conan_name)
add_library(${cmake_name} INTERFACE IMPORTED)

if(${conan_name}_INCLUDE_DIRS)
set_target_properties(${cmake_name} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
"${${conan_name}_INCLUDE_DIRS}")
endif()
set_property(TARGET ${cmake_name} PROPERTY INTERFACE_LINK_LIBRARIES
"${${conan_name}_LIBRARIES_TARGETS};${${conan_name}_LINKER_FLAGS_LIST}")
set_property(TARGET ${cmake_name} PROPERTY INTERFACE_COMPILE_DEFINITIONS
${${conan_name}_COMPILE_DEFINITIONS})
set_property(TARGET ${cmake_name} PROPERTY INTERFACE_COMPILE_OPTIONS
"${${conan_name}_COMPILE_OPTIONS_LIST}")
endfunction()


create_target_from_conan_name(lp3::main lp3-main)
8 changes: 7 additions & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def build_requirements(self):
generators = "cmake_find_package"

exports_sources = (
"src/*", "include/*", "demos/*", "tests/*", "CMakeLists.txt"
"src/*", "include/*", "demos/*", "tests/*", "CMakeLists.txt", "cmake/*",
)

def _configed_cmake(self):
Expand All @@ -59,3 +59,9 @@ def package(self):
def package_info(self):
self.cpp_info.name = "lp3-main"
self.cpp_info.libs = [ "lp3-main" ]
self.cpp_info.build_modules = [
os.path.join(
self.package_folder,
"lib/cmake/lp3-main/ConanFindModuleExtra.cmake"
)
]
2 changes: 1 addition & 1 deletion test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ set(CMAKE_CXX_STANDARD 17)
find_package(lp3-main REQUIRED)

add_executable(main_test ${CMAKE_CURRENT_SOURCE_DIR}/main_test.cpp)
target_link_libraries(main_test PUBLIC lp3-main::lp3-main)
target_link_libraries(main_test PUBLIC lp3::main)
# add_test(main_test main_test)

0 comments on commit b2e5f3c

Please sign in to comment.