Use interface libraries for vendor libraries

This commit is contained in:
Sebastian Messmer 2019-10-19 18:35:03 -07:00
parent b228c4dd0d
commit 6164453c77
8 changed files with 13 additions and 26 deletions

View File

@ -1,11 +1,11 @@
project(mycryptopp)
add_library(cryptopp dummy.cpp)
add_library(cryptopp INTERFACE)
# note: include directory is called vendor_cryptopp instead of cryptopp to avoid include clashes with system headers
target_include_directories(cryptopp SYSTEM INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
# Forward debug build info (i.e. set CRYPTOPP_DEBUG variable if building in debug mode)
target_compile_definitions(cryptopp PUBLIC $<$<CONFIG:Debug>:CRYPTOPP_DEBUG>) # add to all targets depending on this
target_compile_definitions(cryptopp INTERFACE $<$<CONFIG:Debug>:CRYPTOPP_DEBUG>) # add to all targets depending on this
add_compile_options($<$<CONFIG:Debug>:-DCRYPTOPP_DEBUG>) # add to stuff built in subdirectories (like the actual library)
if(NOT DISABLE_OPENMP)
@ -68,8 +68,8 @@ if(NOT DISABLE_OPENMP)
target_link_libraries(OpenMP_TARGET INTERFACE ${OpenMP_CXX_FLAGS} ${Additional_OpenMP_Libraries_Workaround})
endif()
target_link_libraries(cryptopp PUBLIC ${OpenMP_CXX_FLAGS}) # Workaround for Ubuntu 18.04 that otherwise doesn't set -fopenmp for linking
target_link_libraries(cryptopp PUBLIC OpenMP::OpenMP_CXX)
target_link_libraries(cryptopp INTERFACE ${OpenMP_CXX_FLAGS}) # Workaround for Ubuntu 18.04 that otherwise doesn't set -fopenmp for linking
target_link_libraries(cryptopp INTERFACE OpenMP::OpenMP_CXX)
# also add these flags to the third party Crypto++ build setup that is built in a subdirectory
message(STATUS "OpenMP flags: ${OpenMP_CXX_FLAGS}")
@ -87,4 +87,4 @@ set(BUILD_STATIC ON CACHE BOOL "")
set(cryptocpp_DISPLAY_CMAKE_SUPPORT_WARNING OFF CACHE BOOL "")
add_subdirectory(vendor_cryptopp EXCLUDE_FROM_ALL)
target_link_libraries(cryptopp PRIVATE cryptopp-static)
target_link_libraries(cryptopp INTERFACE cryptopp-static)

View File

View File

@ -7,13 +7,12 @@ if (BUILD_TESTING)
set(INSTALL_GMOCK off CACHE BOOL "" FORCE)
add_subdirectory(gtest EXCLUDE_FROM_ALL)
project (googletest)
add_library(${PROJECT_NAME} dummy.cpp)
target_link_libraries(${PROJECT_NAME} PUBLIC gtest gmock)
target_include_directories(${PROJECT_NAME} SYSTEM INTERFACE ${gtest_INCLUDE_DIRS}/include SYSTEM ${gmock_INCLUDE_DIRS}/include)
add_library(googletest INTERFACE)
target_link_libraries(googletest INTERFACE gtest gmock)
target_include_directories(googletest SYSTEM INTERFACE ${gtest_INCLUDE_DIRS}/include SYSTEM INTERFACE ${gmock_INCLUDE_DIRS}/include)
# Disable "missing override" warning because gmock MOCK_METHOD() don't use override :(
if (NOT WIN32)
target_compile_options(${PROJECT_NAME} PUBLIC "-Wno-inconsistent-missing-override")
target_compile_options(googletest INTERFACE "-Wno-inconsistent-missing-override")
endif()
endif()

View File

View File

@ -1,8 +1,2 @@
project (range-v3)
set(SOURCES
dummy.cpp
)
add_library(${PROJECT_NAME} STATIC EXCLUDE_FROM_ALL ${SOURCES})
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/range-v3/include)
add_library(range-v3 INTERFACE)
target_include_directories(range-v3 SYSTEM INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/range-v3/include)

View File

View File

@ -1,8 +1,2 @@
project (spdlog)
set(SOURCES
dummy.cpp
)
add_library(${PROJECT_NAME} STATIC ${SOURCES})
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
add_library(spdlog INTERFACE)
target_include_directories(spdlog SYSTEM INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})

View File