2012-10-13 23:20:39 +04:00
|
|
|
|
2013-09-05 23:20:51 +04:00
|
|
|
|
|
|
|
include(EchoTarget)
|
2012-10-13 23:20:39 +04:00
|
|
|
include(CMakeParseArguments)
|
|
|
|
|
2014-04-22 18:55:09 +04:00
|
|
|
# - add a new library to a module for export
|
|
|
|
# MODULE - module the library belongs to
|
|
|
|
# LIBNAME - name of the library
|
|
|
|
# - if MODULE isn't set the NAME should must be in the form MODULE-NAME
|
|
|
|
function(export_complex_library)
|
|
|
|
set(PREFIX "EXPORT_COMPLEX_LIBRARY")
|
|
|
|
cmake_parse_arguments(${PREFIX}
|
|
|
|
""
|
|
|
|
"LIBNAME;MODULE"
|
|
|
|
""
|
|
|
|
${ARGN})
|
|
|
|
|
|
|
|
if (NOT ${PREFIX}_LIBNAME)
|
|
|
|
message(FATAL_ERROR "export_complex_library requires a name to be set")
|
|
|
|
endif()
|
|
|
|
if (NOT ${PREFIX}_MODULE)
|
2014-04-23 12:14:48 +04:00
|
|
|
# get the module prefix and remove it from libname
|
2014-04-22 18:55:09 +04:00
|
|
|
string(REPLACE "-" ";" LIBNAME_LIST "${${PREFIX}_LIBNAME}")
|
|
|
|
list(GET LIBNAME_LIST 0 MODULE)
|
2014-04-23 12:14:48 +04:00
|
|
|
list(REMOVE_AT LIBNAME_LIST 0)
|
|
|
|
string(REPLACE ";" "-" LIBNAME "${LIBNAME_LIST}")
|
2014-04-22 18:55:09 +04:00
|
|
|
else()
|
|
|
|
set(MODULE ${${PREFIX}_MODULE})
|
|
|
|
set(LIBNAME ${${PREFIX}_LIBNAME})
|
|
|
|
endif()
|
|
|
|
if (NOT MODULE)
|
|
|
|
message(FATAL_ERROR "export_complex_library couldn't identify MODULE")
|
|
|
|
endif()
|
|
|
|
get_property(MEXPORTS GLOBAL PROPERTY ${MODULE}_EXPORTS)
|
|
|
|
list(APPEND MEXPORTS ${LIBNAME})
|
|
|
|
set_property(GLOBAL PROPERTY ${MODULE}_EXPORTS "${MEXPORTS}")
|
|
|
|
endfunction(export_complex_library)
|
|
|
|
|
2012-10-13 23:20:39 +04:00
|
|
|
macro(add_complex_library)
|
|
|
|
|
|
|
|
set(PREFIX "COMPLEX_LIBRARY")
|
|
|
|
|
|
|
|
cmake_parse_arguments(${PREFIX}
|
2014-04-22 19:05:42 +04:00
|
|
|
"EXPORT"
|
2012-10-13 23:20:39 +04:00
|
|
|
"MODULE;TYPE;MONOLITHIC"
|
|
|
|
"SOURCES"
|
|
|
|
${ARGN})
|
2014-05-26 22:46:42 +04:00
|
|
|
|
|
|
|
string(TOUPPER "${${PREFIX}_MODULE}_TYPE" ${PREFIX}_TYPE_OPTION)
|
|
|
|
string(REGEX REPLACE "-" "_" ${PREFIX}_TYPE_OPTION ${${PREFIX}_TYPE_OPTION})
|
|
|
|
|
2012-10-13 23:20:39 +04:00
|
|
|
if(${${PREFIX}_MONOLITHIC})
|
|
|
|
add_library(${${PREFIX}_MODULE} ${${PREFIX}_TYPE} ${${PREFIX}_SOURCES})
|
|
|
|
else()
|
2014-05-26 22:46:42 +04:00
|
|
|
if (NOT DEFINED ${${PREFIX}_TYPE_OPTION})
|
|
|
|
add_library(${${PREFIX}_MODULE} ${${PREFIX}_SOURCES})
|
|
|
|
else()
|
|
|
|
add_library(${${PREFIX}_MODULE} ${${${PREFIX}_TYPE_OPTION}} ${${PREFIX}_SOURCES})
|
|
|
|
endif()
|
2012-10-13 23:20:39 +04:00
|
|
|
endif()
|
2014-04-22 19:05:42 +04:00
|
|
|
if (${PREFIX}_EXPORT)
|
|
|
|
export_complex_library(LIBNAME ${${PREFIX}_MODULE})
|
|
|
|
endif()
|
2012-10-13 23:20:39 +04:00
|
|
|
|
|
|
|
endmacro(add_complex_library)
|
2013-09-05 23:20:51 +04:00
|
|
|
|
|
|
|
if(${CMAKE_VERSION} VERSION_GREATER 2.8.8)
|
|
|
|
set(CMAKE_OBJECT_TARGET_SUPPORT 1)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
function(create_object_cotarget target)
|
|
|
|
|
|
|
|
set(cotarget "${target}-objects")
|
|
|
|
|
|
|
|
get_target_property(${target}_TYPE ${target} TYPE)
|
|
|
|
|
|
|
|
if(NOT ((${target}_TYPE MATCHES "SHARED_LIBRARY") OR (${target}_TYPE MATCHES "SHARED_LIBRARY")))
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
get_target_property(${target}_SOURCES ${target} SOURCES)
|
|
|
|
get_target_property(${target}_LINK_LIBRARIES ${target} LINK_LIBRARIES)
|
|
|
|
get_target_property(${target}_INCLUDE_DIRECTORIES ${target} INCLUDE_DIRECTORIES)
|
|
|
|
|
|
|
|
add_library(${cotarget} "OBJECT" ${${target}_SOURCES})
|
|
|
|
|
|
|
|
set_target_properties(${cotarget} PROPERTIES LINK_LIBRARIES "${${target}_LINK_LIBRARIES}")
|
|
|
|
set_target_properties(${cotarget} PROPERTIES INCLUDE_DIRECTORIES "${${target}_INCLUDE_DIRECTORIES}")
|
|
|
|
|
|
|
|
echo_target(${target})
|
|
|
|
echo_target(${cotarget})
|
|
|
|
|
|
|
|
endfunction()
|
|
|
|
|