# - AddLibrary # To add a library # SET(myindent "${myindent}\t") message(STATUS "${myindent}# \"AddLibrary\" included!") if(__AddLibrary_INCLUDED) return() endif() set(__AddLibrary_INCLUDED TRUE) include(AddCommon) #--------------------------------------------------------------------------------------------------- # icedust_add_library( # source1 source2 ... # LINK_LIBRARIES library1 library2 ... # INCLUDE_DIRS dir1 package2 ... # [NO_PUBLIC_HEADERS | PUBLIC_HEADERS dir1 dir2 ...]) # # Extension of standard CMake 'add_library' command. # Create a library from the specified sources (glob patterns are allowed), linking # it with the libraries specified and adding the include directories to the search path. #--------------------------------------------------------------------------------------------------- function(icedust_add_library library) message(STATUS "${myindent}==>function(icedust_add_library ${library}) (${ARGN})") SET(myindent "${myindent}\t") CMAKE_PARSE_ARGUMENTS(ARG "NO_PUBLIC_HEADERS" "" "LIBRARIES;LINK_LIBRARIES;INCLUDE_DIRS;PUBLIC_HEADERS" ${ARGN}) message(STATUS "${myindent}ARG_INCLUDE_DIRS = \"${ARG_INCLUDE_DIRS}\"") icedust_common_add_build(${ARG_UNPARSED_ARGUMENTS} LIBRARIES ${ARG_LIBRARIES} LINK_LIBRARIES ${ARG_LINK_LIBRARIES} INCLUDE_DIRS ${ARG_INCLUDE_DIRS}) message(STATUS "${myindent}ARG_INCLUDE_DIRS = \"${ARG_INCLUDE_DIRS}\"") icedust_linkopt(-L${CMAKE_BINARY_DIR}/lib -l${library}) SET(ARG_LINK_LIBRARIES "-L${CMAKE_BINARY_DIR}/lib -l${library} ${ARG_LINK_LIBRARIES}") if(WIN32) add_library( ${library}-arc STATIC EXCLUDE_FROM_ALL ${library_srcs}) set_target_properties(${library}-arc PROPERTIES COMPILE_DEFINITIONS ICEDUST_LINKER_LIBRARY) add_custom_command( OUTPUT ${library}.def COMMAND ${genwindef_cmd} -o ${library}.def -l ${library} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/${library}-arc.lib DEPENDS ${library}-arc genwindef) #---Needed to create a dummy source file to please Windows IDE builds with the manifest file( WRITE ${CMAKE_CURRENT_BINARY_DIR}/${library}.cpp "// empty file\n" ) add_library( ${library} SHARED ${library}.cpp ${library}.def) target_link_libraries(${library} ${library}-arc ${ARG_LINK_LIBRARIES}) set_target_properties(${library} PROPERTIES LINK_INTERFACE_LIBRARIES "${ARG_LINK_LIBRARIES}" ) include_directories(${ARG_INCLUDE_DIRS}) else() add_library(${library} ${library_srcs}) set_target_properties(${library} PROPERTIES COMPILE_DEFINITIONS ICEDUST_LINKER_LIBRARY) message(STATUS "${myindent} include_directories(${ARG_INCLUDE_DIRS})") include_directories(${ARG_INCLUDE_DIRS}) message(STATUS "${myindent} target_link_libraries(${ARG_LINK_LIBRARIES})") target_link_libraries(${library} ${ARG_LINK_LIBRARIES}) _icedust_detach_debinfo(${library}) endif() # # Declare that the used headers are needed by the libraries linked against this one # set_target_properties(${library} PROPERTIES # SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" # REQUIRED_INCLUDE_DIRS "${ARG_INCLUDE_DIRS}" # REQUIRED_LIBRARIES "${ARG_LINK_LIBRARIES}") # set_property(GLOBAL APPEND PROPERTY LINKER_LIBRARIES ${library}) # icedust_add_genheader_dependencies(${library}) #----Installation details------------------------------------------------------- install(TARGETS ${library} EXPORT ${CMAKE_PROJECT_NAME}Exports DESTINATION lib OPTIONAL) # icedust_export(LIBRARY ${library}) # icedust_install_headers(${ARG_PUBLIC_HEADERS}) install(EXPORT ${CMAKE_PROJECT_NAME}Exports DESTINATION cmake OPTIONAL) message(STATUS "${myindent}<==function(icedust_add_library library)") string(REGEX REPLACE "(\t*)\t" "\\1" myindent "${myindent}") endfunction() string(REGEX REPLACE "(\t*)\t" "\\1" myindent "${myindent}")