add macro to link shared dependencies to target

This commit is contained in:
Stephen Birarda 2014-08-08 11:45:10 -07:00
parent fc92b93326
commit 26f7b1ba62
30 changed files with 121 additions and 65 deletions

View file

@ -1,6 +1,6 @@
set(TARGET_NAME assignment-client) set(TARGET_NAME assignment-client)
setup_hifi_project(${TARGET_NAME} TRUE) setup_hifi_project(${TARGET_NAME} Core Gui Network Script Widgets)
include_glm(${TARGET_NAME}) include_glm(${TARGET_NAME})
@ -11,8 +11,7 @@ link_hifi_libraries(${TARGET_NAME}
) )
if (UNIX) if (UNIX)
target_link_libraries(${TARGET_NAME} ${DEPENDENCY_LIBRARIES} ${CMAKE_DL_LIBS}) list(APPEND ${TARGET_NAME}_LIBRARIES_TO_LINK ${CMAKE_DL_LIBS})
endif (UNIX) endif (UNIX)
find_package(Qt5 COMPONENTS Gui Network Script Widgets) link_shared_dependencies_to_target(${TARGET_NAME})
target_link_libraries(${TARGET_NAME} Qt5::Gui Qt5::Network Qt5::Script Qt5::Widgets)

View file

@ -22,13 +22,12 @@ macro(LINK_HIFI_LIBRARIES TARGET)
add_dependencies(${TARGET} ${HIFI_LIBRARY}) add_dependencies(${TARGET} ${HIFI_LIBRARY})
# link the actual library
list(APPEND ${TARGET}_LIBRARIES_TO_LINK ${HIFI_LIBRARY})
# ask the library what its dynamic dependencies are and link them
get_target_property(LINKED_TARGET_DEPENDENCY_LIBRARIES ${HIFI_LIBRARY} DEPENDENCY_LIBRARIES) get_target_property(LINKED_TARGET_DEPENDENCY_LIBRARIES ${HIFI_LIBRARY} DEPENDENCY_LIBRARIES)
list(APPEND ${TARGET}_LIBRARIES_TO_LINK ${LINKED_TARGET_DEPENDENCY_LIBRARIES})
if (LINKED_TARGET_DEPENDENCY_LIBRARIES)
target_link_libraries(${TARGET} ${HIFI_LIBRARY} ${LINKED_TARGET_DEPENDENCY_LIBRARIES})
else ()
target_link_libraries(${TARGET} ${HIFI_LIBRARY})
endif ()
endforeach() endforeach()

View file

@ -0,0 +1,25 @@
#
# LinkHifiLibrary.cmake
# cmake/macros
#
# Copyright 2014 High Fidelity, Inc.
# Created by Stephen Birarda on August 8, 2014
#
# Distributed under the Apache License, Version 2.0.
# See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
#
macro(LINK_SHARED_DEPENDENCIES_TO_TARGET TARGET)
if (${TARGET}_LIBRARIES_TO_LINK)
list(REMOVE_DUPLICATES ${TARGET}_LIBRARIES_TO_LINK)
# link these libraries to our target
target_link_libraries(${TARGET} ${${TARGET}_LIBRARIES_TO_LINK})
endif ()
# we've already linked our Qt modules, but we need to bubble them up to parents
list(APPEND ${TARGET}_LIBRARIES_TO_LINK "${${TARGET}_QT_MODULES_TO_LINK}")
# set the property on this target so it can be retreived by targets linking to us
set_target_properties(${TARGET_NAME} PROPERTIES DEPENDENCY_LIBRARIES "${${TARGET}_LIBRARIES_TO_LINK}")
endmacro(LINK_SHARED_DEPENDENCIES_TO_TARGET _target)

View file

@ -15,7 +15,7 @@ macro(SETUP_HIFI_LIBRARY TARGET)
file(GLOB LIB_SRCS src/*.h src/*.cpp) file(GLOB LIB_SRCS src/*.h src/*.cpp)
set(LIB_SRCS ${LIB_SRCS}) set(LIB_SRCS ${LIB_SRCS})
# create a library and set the property so it can be referenced later # create a library and set the property so it can be referenced later
add_library(${TARGET} ${LIB_SRCS} ${AUTOMTC_SRC}) add_library(${TARGET} ${LIB_SRCS} ${AUTOMTC_SRC})
set(QT_MODULES_TO_LINK ${ARGN}) set(QT_MODULES_TO_LINK ${ARGN})
@ -24,17 +24,10 @@ macro(SETUP_HIFI_LIBRARY TARGET)
find_package(Qt5 COMPONENTS ${QT_MODULES_TO_LINK}) find_package(Qt5 COMPONENTS ${QT_MODULES_TO_LINK})
foreach(QT_MODULE ${QT_MODULES_TO_LINK}) foreach(QT_MODULE ${QT_MODULES_TO_LINK})
# link this Qt module to ourselves
target_link_libraries(${TARGET} Qt5::${QT_MODULE})
get_target_property(QT_LIBRARY_LOCATION Qt5::${QT_MODULE} LOCATION) get_target_property(QT_LIBRARY_LOCATION Qt5::${QT_MODULE} LOCATION)
# add the actual path to the Qt module to a QT_LIBRARIES variable # add the actual path to the Qt module to our LIBRARIES_TO_LINK variable
list(APPEND QT_LIBRARIES ${QT_LIBRARY_LOCATION}) target_link_libraries(${TARGET} Qt5::${QT_MODULE})
list(APPEND ${TARGET}_QT_MODULES_TO_LINK ${QT_LIBRARY_LOCATION})
endforeach() endforeach()
if (QT_LIBRARIES)
set_target_properties(${TARGET} PROPERTIES DEPENDENCY_LIBRARIES "${QT_LIBRARIES}")
endif ()
endmacro(SETUP_HIFI_LIBRARY _target) endmacro(SETUP_HIFI_LIBRARY _target)

View file

@ -7,7 +7,7 @@
# See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html # See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
# #
macro(SETUP_HIFI_PROJECT TARGET INCLUDE_QT) macro(SETUP_HIFI_PROJECT TARGET)
project(${TARGET}) project(${TARGET})
# grab the implemenation and header files # grab the implemenation and header files
@ -23,10 +23,19 @@ macro(SETUP_HIFI_PROJECT TARGET INCLUDE_QT)
endforeach() endforeach()
# add the executable, include additional optional sources # add the executable, include additional optional sources
add_executable(${TARGET} ${TARGET_SRCS} ${ARGN}) add_executable(${TARGET} ${TARGET_SRCS} "${AUTOMTC_SRC}")
set(QT_MODULES_TO_LINK ${ARGN})
list(APPEND QT_MODULES_TO_LINK Core)
find_package(Qt5 COMPONENTS ${QT_MODULES_TO_LINK})
foreach(QT_MODULE ${QT_MODULES_TO_LINK})
target_link_libraries(${TARGET} Qt5::${QT_MODULE})
# add the actual path to the Qt module to our LIBRARIES_TO_LINK variable
get_target_property(QT_LIBRARY_LOCATION Qt5::${QT_MODULE} LOCATION)
list(APPEND ${TARGET}_QT_MODULES_TO_LINK ${QT_LIBRARY_LOCATION})
endforeach()
if (${INCLUDE_QT})
find_package(Qt5 COMPONENTS Core)
target_link_libraries(${TARGET} Qt5::Core)
endif ()
endmacro() endmacro()

View file

@ -1,6 +1,6 @@
set(TARGET_NAME domain-server) set(TARGET_NAME domain-server)
setup_hifi_project(${TARGET_NAME} TRUE) setup_hifi_project(${TARGET_NAME})
# remove and then copy the files for the webserver # remove and then copy the files for the webserver
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD add_custom_command(TARGET ${TARGET_NAME} POST_BUILD

View file

@ -3,4 +3,7 @@ set(TARGET_NAME animation)
# use setup_hifi_library macro to setup our project and link appropriate Qt modules # use setup_hifi_library macro to setup our project and link appropriate Qt modules
setup_hifi_library(${TARGET_NAME} Network Script) setup_hifi_library(${TARGET_NAME} Network Script)
link_hifi_libraries(${TARGET_NAME} shared fbx) link_hifi_libraries(${TARGET_NAME} shared fbx)
# call macro to link our dependencies and bubble them up via a property on our target
link_shared_dependencies_to_target(${TARGET_NAME})

View file

@ -5,4 +5,7 @@ setup_hifi_library(${TARGET_NAME} Network)
include_glm(${TARGET_NAME} "${ROOT_DIR}") include_glm(${TARGET_NAME} "${ROOT_DIR}")
link_hifi_libraries(${TARGET_NAME} networking shared) link_hifi_libraries(${TARGET_NAME} networking shared)
# call macro to link our dependencies and bubble them up via a property on our target
link_shared_dependencies_to_target(${TARGET_NAME})

View file

@ -6,4 +6,7 @@ setup_hifi_library(${TARGET_NAME} Network Script)
include_glm(${TARGET_NAME} "${ROOT_DIR}") include_glm(${TARGET_NAME} "${ROOT_DIR}")
link_hifi_libraries(${TARGET_NAME} shared octree voxels networking) link_hifi_libraries(${TARGET_NAME} shared octree voxels networking)
include_hifi_library_headers(fbx) include_hifi_library_headers(fbx)
# call macro to link our dependencies and bubble them up via a property on our target
link_shared_dependencies_to_target(${TARGET_NAME})

View file

@ -1,4 +1,7 @@
set(TARGET_NAME embedded-webserver) set(TARGET_NAME embedded-webserver)
# use setup_hifi_library macro to setup our project and link appropriate Qt modules # use setup_hifi_library macro to setup our project and link appropriate Qt modules
setup_hifi_library(${TARGET_NAME} Network) setup_hifi_library(${TARGET_NAME} Network)
# call macro to link our dependencies and bubble them up via a property on our target
link_shared_dependencies_to_target(${TARGET_NAME})

View file

@ -7,12 +7,9 @@ include_glm(${TARGET_NAME} "${ROOT_DIR}")
link_hifi_libraries(${TARGET_NAME} shared networking octree voxels) link_hifi_libraries(${TARGET_NAME} shared networking octree voxels)
# link ZLIB
find_package(ZLIB) find_package(ZLIB)
include_directories(SYSTEM "${ZLIB_INCLUDE_DIRS}") include_directories(SYSTEM "${ZLIB_INCLUDE_DIRS}")
list(APPEND ${TARGET_NAME}_LIBRARIES_TO_LINK "${ZLIB_LIBRARIES}")
# set a property indicating the libraries we are dependent on and link them to ourselves # call macro to link our dependencies and bubble them up via a property on our target
set(DEPENDENCY_LIBRARIES "${ZLIB_LIBRARIES}") link_shared_dependencies_to_target(${TARGET_NAME})
set_target_properties(${TARGET_NAME} PROPERTIES DEPENDENCY_LIBRARIES ${DEPENDENCY_LIBRARIES})
target_link_libraries(${TARGET_NAME} ${DEPENDENCY_LIBRARIES})

View file

@ -8,4 +8,7 @@ setup_hifi_library(${TARGET_NAME} Network Script Widgets)
# link in the networking library # link in the networking library
link_hifi_libraries(${TARGET_NAME} shared networking) link_hifi_libraries(${TARGET_NAME} shared networking)
include_glm(${TARGET_NAME} "${ROOT_DIR}") include_glm(${TARGET_NAME} "${ROOT_DIR}")
# call macro to link our dependencies and bubble them up via a property on our target
link_shared_dependencies_to_target(${TARGET_NAME})

View file

@ -5,4 +5,7 @@ setup_hifi_library(${TARGET_NAME} Network Script)
include_glm(${TARGET_NAME} "${ROOT_DIR}") include_glm(${TARGET_NAME} "${ROOT_DIR}")
link_hifi_libraries(${TARGET_NAME} shared octree fbx networking animation) link_hifi_libraries(${TARGET_NAME} shared octree fbx networking animation)
# call macro to link our dependencies and bubble them up via a property on our target
link_shared_dependencies_to_target(${TARGET_NAME})

View file

@ -3,4 +3,7 @@ set(TARGET_NAME networking)
# use setup_hifi_library macro to setup our project and link appropriate Qt modules # use setup_hifi_library macro to setup our project and link appropriate Qt modules
setup_hifi_library(${TARGET_NAME} Network) setup_hifi_library(${TARGET_NAME} Network)
link_hifi_libraries(${TARGET_NAME} shared) link_hifi_libraries(${TARGET_NAME} shared)
# call macro to link our dependencies and bubble them up via a property on our target
link_shared_dependencies_to_target(${TARGET_NAME})

View file

@ -7,13 +7,15 @@ include_glm(${TARGET_NAME} "${ROOT_DIR}")
link_hifi_libraries(${TARGET_NAME} shared networking) link_hifi_libraries(${TARGET_NAME} shared networking)
# link ZLIB # find ZLIB and OpenSSL
find_package(ZLIB) find_package(ZLIB)
find_package(OpenSSL REQUIRED) find_package(OpenSSL REQUIRED)
include_directories(SYSTEM "${ZLIB_INCLUDE_DIRS}" "${OPENSSL_INCLUDE_DIR}") include_directories(SYSTEM "${ZLIB_INCLUDE_DIRS}" "${OPENSSL_INCLUDE_DIR}")
# set a property indicating the libraries we are dependent on and link them to ourselves # append ZLIB and OpenSSL to our list of libraries to link
set(DEPENDENCY_LIBRARIES "${ZLIB_LIBRARIES}" "${OPENSSL_LIBRARIES}") list(APPEND ${TARGET_NAME}_LIBRARIES_TO_LINK "${ZLIB_LIBRARIES}")
set_target_properties(${TARGET_NAME} PROPERTIES DEPENDENCY_LIBRARIES ${DEPENDENCY_LIBRARIES}) list(APPEND ${TARGET_NAME}_LIBRARIES_TO_LINK "${OPENSSL_LIBRARIES}")
target_link_libraries(${TARGET_NAME} ${DEPENDENCY_LIBRARIES})
# call macro to link our dependencies and bubble them up via a property on our target
link_shared_dependencies_to_target(${TARGET_NAME})

View file

@ -6,4 +6,7 @@ setup_hifi_library(${TARGET_NAME} Gui Network Script)
include_glm(${TARGET_NAME} "${ROOT_DIR}") include_glm(${TARGET_NAME} "${ROOT_DIR}")
link_hifi_libraries(${TARGET_NAME} shared octree fbx networking animation) link_hifi_libraries(${TARGET_NAME} shared octree fbx networking animation)
include_hifi_library_headers(script-engine) include_hifi_library_headers(script-engine)
# call macro to link our dependencies and bubble them up via a property on our target
link_shared_dependencies_to_target(${TARGET_NAME})

View file

@ -5,4 +5,7 @@ setup_hifi_library(${TARGET_NAME} Gui Network Script Widgets)
include_glm(${TARGET_NAME} "${ROOT_DIR}") include_glm(${TARGET_NAME} "${ROOT_DIR}")
link_hifi_libraries(${TARGET_NAME} shared octree voxels fbx particles models animation) link_hifi_libraries(${TARGET_NAME} shared octree voxels fbx particles models animation)
# call macro to link our dependencies and bubble them up via a property on our target
link_shared_dependencies_to_target(${TARGET_NAME})

View file

@ -1,4 +1,7 @@
set(TARGET_NAME shared) set(TARGET_NAME shared)
# use setup_hifi_library macro to setup our project and link appropriate Qt modules # use setup_hifi_library macro to setup our project and link appropriate Qt modules
setup_hifi_library(${TARGET_NAME} Network Widgets) setup_hifi_library(${TARGET_NAME} Network Widgets)
# call macro to link our dependencies and bubble them up via a property on our target
link_shared_dependencies_to_target(${TARGET_NAME})

View file

@ -7,10 +7,12 @@ include_glm(${TARGET_NAME} "${ROOT_DIR}")
link_hifi_libraries(${TARGET_NAME} shared octree networking) link_hifi_libraries(${TARGET_NAME} shared octree networking)
# link ZLIB # find ZLIB
find_package(ZLIB) find_package(ZLIB)
include_directories(SYSTEM "${ZLIB_INCLUDE_DIRS}") include_directories(SYSTEM "${ZLIB_INCLUDE_DIRS}")
get_target_property(LINKED_LIBRARIES ${TARGET_NAME} DEPENDENCY_LIBRARIES) # add it to our list of libraries to link
list(APPEND DEPENDENCY_LIBRARIES "${ZLIB_LIBRARIES}") list(APPEND ${TARGET}_LIBRARIES_TO_LINK "${ZLIB_LIBRARIES}")
list(REMOVE_DUPLICATES DEPENDENCY_LIBRARIES)
# call macro to link our dependencies and bubble them up via a property on our target
link_shared_dependencies_to_target(${TARGET_NAME})

View file

@ -1,6 +1,6 @@
set(TARGET_NAME audio-tests) set(TARGET_NAME audio-tests)
setup_hifi_project(${TARGET_NAME} TRUE) setup_hifi_project(${TARGET_NAME})
#include glm #include glm
include_glm(${TARGET_NAME} ${ROOT_DIR}) include_glm(${TARGET_NAME} ${ROOT_DIR})

View file

@ -1,6 +1,6 @@
set(TARGET_NAME jitter-tests) set(TARGET_NAME jitter-tests)
setup_hifi_project(${TARGET_NAME} TRUE) setup_hifi_project(${TARGET_NAME})
# link in the shared libraries # link in the shared libraries
link_hifi_libraries(${TARGET_NAME} shared networking) link_hifi_libraries(${TARGET_NAME} shared networking)

View file

@ -4,7 +4,7 @@ find_package(Qt5 COMPONENTS Network Script Widgets)
auto_mtc(${TARGET_NAME} "${ROOT_DIR}") auto_mtc(${TARGET_NAME} "${ROOT_DIR}")
setup_hifi_project(${TARGET_NAME} TRUE "${AUTOMTC_SRC}") setup_hifi_project(${TARGET_NAME})
# link in the shared libraries # link in the shared libraries
link_hifi_libraries(${TARGET_NAME} metavoxels networking shared) link_hifi_libraries(${TARGET_NAME} metavoxels networking shared)

View file

@ -1,6 +1,6 @@
set(TARGET_NAME networking-tests) set(TARGET_NAME networking-tests)
setup_hifi_project(${TARGET_NAME} TRUE) setup_hifi_project(${TARGET_NAME})
# link in the shared libraries # link in the shared libraries
link_hifi_libraries(${TARGET_NAME} shared networking) link_hifi_libraries(${TARGET_NAME} shared networking)

View file

@ -1,6 +1,6 @@
set(TARGET_NAME octree-tests) set(TARGET_NAME octree-tests)
setup_hifi_project(${TARGET_NAME} TRUE) setup_hifi_project(${TARGET_NAME})
# link in the shared libraries # link in the shared libraries
link_hifi_libraries(${TARGET_NAME} octree) link_hifi_libraries(${TARGET_NAME} octree)

View file

@ -1,6 +1,6 @@
set(TARGET_NAME physics-tests) set(TARGET_NAME physics-tests)
setup_hifi_project(${TARGET_NAME} TRUE) setup_hifi_project(${TARGET_NAME})
# link in the shared libraries # link in the shared libraries
link_hifi_libraries(${TARGET_NAME} shared) link_hifi_libraries(${TARGET_NAME} shared)

View file

@ -1,6 +1,6 @@
set(TARGET_NAME shared-tests) set(TARGET_NAME shared-tests)
setup_hifi_project(${TARGET_NAME} TRUE) setup_hifi_project(${TARGET_NAME})
# link in the shared libraries # link in the shared libraries
link_hifi_libraries(${TARGET_NAME} shared) link_hifi_libraries(${TARGET_NAME} shared)

View file

@ -1,2 +1,2 @@
set(TARGET_NAME bitstream2json) set(TARGET_NAME bitstream2json)
setup_hifi_project(${TARGET_NAME} TRUE) setup_hifi_project(${TARGET_NAME})

View file

@ -1,2 +1,2 @@
set(TARGET_NAME json2bitstream) set(TARGET_NAME json2bitstream)
setup_hifi_project(${TARGET_NAME} TRUE) setup_hifi_project(${TARGET_NAME})

View file

@ -1,2 +1,2 @@
set(TARGET_NAME mtc) set(TARGET_NAME mtc)
setup_hifi_project(${TARGET_NAME} TRUE) setup_hifi_project(${TARGET_NAME})

View file

@ -1,3 +1,3 @@
set(TARGET_NAME voxel-edit) set(TARGET_NAME voxel-edit)
setup_hifi_project(${TARGET_NAME} TRUE) setup_hifi_project(${TARGET_NAME})