# Copyright (c) 2009 Sun Microsystems, Inc. # Use is subject to license terms. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # This script merges many static libraries into # one big library on Unix. SET(TARGET_LOCATION "@TARGET_LOCATION@") SET(TARGET "@TARGET@") SET(STATIC_LIBS "@STATIC_LIBS@") SET(CMAKE_CURRENT_BINARY_DIR "@CMAKE_CURRENT_BINARY_DIR@") SET(CMAKE_AR "@CMAKE_AR@") SET(CMAKE_RANLIB "@CMAKE_RANLIB@") SET(CMAKE_C_COMPILER "@CMAKE_C_COMPILER@") SET(CMAKE_C_COMPILER_ID "@CMAKE_C_COMPILER_ID@") SET(CMAKE_C_FLAGS "@CMAKE_C_FLAGS@") SET(CMAKE_C_FLAGS_DEBUG "@CMAKE_C_FLAGS_DEBUG@") SET(CMAKE_C_FLAGS_RELEASE "@CMAKE_C_FLAGS_RELEASE@") SET(CMAKE_BUILD_TYPE "@CMAKE_BUILD_TYPE@") SET(CMAKE_TOP_BINARY_DIR "@CMAKE_TOP_BINARY_DIR@") SET(LIBTOKUPORTABILITY "@LIBTOKUPORTABILITY@") SET(TEMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/merge_archives_${TARGET}) MAKE_DIRECTORY(${TEMP_DIR}) # Extract each archive to its own subdirectory(avoid object filename clashes) FOREACH(LIB ${STATIC_LIBS}) GET_FILENAME_COMPONENT(NAME_NO_EXT ${LIB} NAME_WE) SET(TEMP_SUBDIR ${TEMP_DIR}/${NAME_NO_EXT}) MAKE_DIRECTORY(${TEMP_SUBDIR}) EXECUTE_PROCESS( COMMAND ${CMAKE_AR} -x ${LIB} WORKING_DIRECTORY ${TEMP_SUBDIR} ) FILE(GLOB_RECURSE LIB_OBJECTS "${TEMP_SUBDIR}/*.ilo") if (NOT LIB_OBJECTS) FILE(GLOB_RECURSE NONIPO_LIB_OBJECTS "${TEMP_SUBDIR}/*.o") ENDIF () SET(OBJECTS ${OBJECTS} ${LIB_OBJECTS}) SET(EXTRA_OBJECTS ${EXTRA_OBJECTS} ${NONIPO_LIB_OBJECTS}) ENDFOREACH() # Use relative paths, makes command line shorter. GET_FILENAME_COMPONENT(ABS_TEMP_DIR ${TEMP_DIR} ABSOLUTE) FOREACH(OBJ ${OBJECTS}) FILE(RELATIVE_PATH OBJ ${ABS_TEMP_DIR} ${OBJ}) FILE(TO_NATIVE_PATH ${OBJ} OBJ) SET(ALL_OBJECTS ${ALL_OBJECTS} ${OBJ}) ENDFOREACH() FOREACH(OBJ ${EXTRA_OBJECTS}) FILE(RELATIVE_PATH OBJ ${ABS_TEMP_DIR} ${OBJ}) FILE(TO_NATIVE_PATH ${OBJ} OBJ) SET(ALL_EXTRA_OBJECTS ${ALL_EXTRA_OBJECTS} ${OBJ}) ENDFOREACH() SET(TARGET_O ${TARGET}_combined.o) IF(CMAKE_BUILD_TYPE STREQUAL Release AND CMAKE_C_COMPILER_ID STREQUAL Intel) SET(flags "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_RELEASE}") SEPARATE_ARGUMENTS(flags) EXECUTE_PROCESS( COMMAND ${CMAKE_C_COMPILER} ${flags} -ipo1 -ipo-c -diag-disable 10015 -o ${TARGET_O} ${ALL_OBJECTS} WORKING_DIRECTORY ${TEMP_DIR} ) SET(TARGET_OBJECTS ${TARGET_O} ${ALL_EXTRA_OBJECTS}) ELSE() SET(TARGET_OBJECTS ${ALL_OBJECTS} ${ALL_EXTRA_OBJECTS}) ENDIF() FILE(TO_NATIVE_PATH ${TARGET_LOCATION} ${TARGET_LOCATION}) # Now pack the objects into library with ar. EXECUTE_PROCESS( COMMAND ${CMAKE_AR} -r ${TARGET_LOCATION} ${TARGET_OBJECTS} WORKING_DIRECTORY ${TEMP_DIR} ) EXECUTE_PROCESS( COMMAND ${CMAKE_RANLIB} ${TARGET_LOCATION} WORKING_DIRECTORY ${TEMP_DIR} ) # Cleanup FILE(REMOVE_RECURSE ${TEMP_DIR})