Use modern target_link_libraries scopes so libraries publish their transitive requirements and executables keep theirs private. This preserves schema test linkage with current CMake versions.
104 lines
3.8 KiB
CMake
104 lines
3.8 KiB
CMake
macro(SC_ADDEXEC execname)
|
|
set(_addexec_opts NO_INSTALL TESTABLE)
|
|
set(_addexec_multikw SOURCES LINK_LIBRARIES)
|
|
string(TOUPPER "SC_ADDEXEC_${execname}_ARG" _arg_prefix)
|
|
cmake_parse_arguments(${_arg_prefix} "${_addexec_opts}" "" "${_addexec_multikw}" ${ARGN})
|
|
|
|
if(NOT DEFINED "${_arg_prefix}_SOURCES")
|
|
message(SEND_ERROR "SC_ADDEXEC usage error!")
|
|
endif()
|
|
|
|
add_executable(${execname} ${${_arg_prefix}_SOURCES})
|
|
|
|
if(BUILD_STATIC_LIBS)
|
|
target_compile_definitions(${execname} PRIVATE SC_STATIC)
|
|
endif()
|
|
|
|
if(DEFINED "${_arg_prefix}_LINK_LIBRARIES")
|
|
foreach(_lib ${${_arg_prefix}_LINK_LIBRARIES})
|
|
if($CACHE{SC_STATIC_UTILS})
|
|
get_property(_lib_type TARGET ${_lib} PROPERTY TYPE)
|
|
if(NOT _lib_type STREQUAL "STATIC_LIBRARY")
|
|
message(SEND_ERROR "SC_ADDEXEC usage error - expected STATIC LINK_LIBRARIES targets (${_lib})")
|
|
endif()
|
|
endif()
|
|
# Executables consume their dependencies but do not publish an
|
|
# interface to downstream targets.
|
|
target_link_libraries(${execname} PRIVATE ${_lib})
|
|
endforeach()
|
|
target_link_libraries(${execname} PRIVATE ${${_arg_prefix}_LINK_LIBRARIES})
|
|
endif()
|
|
|
|
if(NOT ${_arg_prefix}_NO_INSTALL AND NOT ${_arg_prefix}_TESTABLE)
|
|
install(TARGETS ${execname}
|
|
RUNTIME DESTINATION ${BIN_DIR}
|
|
LIBRARY DESTINATION ${LIB_DIR}
|
|
ARCHIVE DESTINATION ${LIB_DIR}
|
|
)
|
|
endif()
|
|
|
|
if(NOT SC_ENABLE_TESTING AND ${_arg_prefix}_TESTABLE)
|
|
set_target_properties(${execname} PROPERTIES EXCLUDE_FROM_ALL ON)
|
|
endif()
|
|
endmacro()
|
|
|
|
macro(SC_ADDLIB _addlib_target)
|
|
set(_addlib_opts SHARED STATIC NO_INSTALL TESTABLE)
|
|
set(_addlib_multikw SOURCES LINK_LIBRARIES)
|
|
string(TOUPPER "SC_ADDLIB_${_addlib_target}_ARG" _arg_prefix)
|
|
cmake_parse_arguments(${_arg_prefix} "${_addlib_opts}" "" "${_addlib_multikw}" ${ARGN})
|
|
|
|
if(NOT DEFINED ${_arg_prefix}_SOURCES)
|
|
message(SEND_ERROR "SC_ADDLIB usage error!")
|
|
endif()
|
|
|
|
if(${_arg_prefix}_SHARED)
|
|
add_library(${_addlib_target} SHARED ${${_arg_prefix}_SOURCES})
|
|
if(OPENBSD)
|
|
set_target_properties(${_addlib_target} PROPERTIES VERSION ${SC_VERSION_MAJOR}.${SC_VERSION_MINOR})
|
|
else(OPENBSD)
|
|
set_target_properties(${_addlib_target} PROPERTIES VERSION ${SC_VERSION} SOVERSION ${SC_VERSION_MAJOR})
|
|
endif(OPENBSD)
|
|
if(APPLE)
|
|
set_target_properties(${_addlib_target} PROPERTIES LINK_FLAGS "-flat_namespace -undefined suppress")
|
|
endif(APPLE)
|
|
elseif(${_arg_prefix}_STATIC)
|
|
add_library(${_addlib_target} STATIC ${${_arg_prefix}_SOURCES})
|
|
target_compile_definitions(${_addlib_target} PRIVATE SC_STATIC)
|
|
else()
|
|
message(SEND_ERROR "SC_ADDLIB usage error!")
|
|
endif()
|
|
|
|
if(DEFINED ${_arg_prefix}_LINK_LIBRARIES)
|
|
foreach(_lib ${${_arg_prefix}_LINK_LIBRARIES})
|
|
if(${_arg_prefix}_STATIC AND TARGET ${_lib})
|
|
get_property(_libtype TARGET ${_lib} PROPERTY TYPE)
|
|
if(NOT ${_libtype} STREQUAL "STATIC_LIBRARY")
|
|
message(SEND_ERROR "SC_ADDLIB usage error - expected (static) LINK_LIBRARIES targets (${_lib})")
|
|
endif()
|
|
endif()
|
|
# Schema libraries are consumed directly by generated test programs.
|
|
# Publish their link requirements explicitly; the legacy unscoped
|
|
# signature does not reliably provide a transitive interface with
|
|
# current CMake versions.
|
|
target_link_libraries(${_addlib_target} PUBLIC ${_lib})
|
|
endforeach()
|
|
target_link_libraries(${_addlib_target} ${_lib})
|
|
endif()
|
|
|
|
if(NOT ${_arg_prefix}_NO_INSTALL AND NOT ${_arg_prefix}_TESTABLE)
|
|
install(TARGETS ${_addlib_target}
|
|
RUNTIME DESTINATION ${BIN_DIR}
|
|
LIBRARY DESTINATION ${LIB_DIR}
|
|
ARCHIVE DESTINATION ${LIB_DIR}
|
|
)
|
|
endif()
|
|
endmacro()
|
|
|
|
# Local Variables:
|
|
# tab-width: 8
|
|
# mode: cmake
|
|
# indent-tabs-mode: t
|
|
# End:
|
|
# ex: shiftwidth=2 tabstop=8
|