[x265-commits] [x265] cmake: use cmake 2.8 OBJECT target type to manage static ...

Steve Borho steve at borho.org
Wed Oct 9 06:59:14 CEST 2013


details:   http://hg.videolan.org/x265/rev/713c2133c77c
branches:  
changeset: 4294:713c2133c77c
user:      Steve Borho <steve at borho.org>
date:      Mon Oct 07 20:09:06 2013 -0500
description:
cmake: use cmake 2.8 OBJECT target type to manage static and share libs

With the OBJECT target type, the common and encoder folders are compiled to
object files but not linked until main static or shared library is built. This
removes the need for mergestatic.cmake and cleans up a lot of messy problems -
at the cost of requiring a somewhat recent cmake.

For MSVC (and presumably Xcode) we must keep the assembly as a static lib since
it uses custom build commands which do not work with OBJECT target types.  This
static lib is then linked with the main x265.lib or x265.dll

The X265_EXPORT macro is no longer necessary since we are generating both the
static library and shared library from one compile we are forced to use an
x265.def file to define DLL exports.  x265.exe must link with the static library
because on Windows the static lib will be empty if no EXE links with it.

x265_mdate() was moved into the CLI x265.cpp so the CLI could link with the
shared library if necessary (x265_mdate is not exported)
Subject: [x265] cmake: tweak static library names to avoid conflict

details:   http://hg.videolan.org/x265/rev/4b354b902b50
branches:  
changeset: 4295:4b354b902b50
user:      Steve Borho <steve at borho.org>
date:      Tue Oct 08 22:19:16 2013 -0500
description:
cmake: tweak static library names to avoid conflict

MSVC was trying to write both the static library and the DLL shim loader to
x265.lib.  After this change, the static library is now x265-static.lib and
the shim loader is x265.lib (corresponding with x265.dll)
Subject: [x265] cmake: fixes for non-assembly builds and windows builds

details:   http://hg.videolan.org/x265/rev/4737b5423ea4
branches:  
changeset: 4296:4737b5423ea4
user:      Steve Borho <steve at borho.org>
date:      Tue Oct 08 23:58:54 2013 -0500
description:
cmake: fixes for non-assembly builds and windows builds

diffstat:

 source/CMakeLists.txt              |   44 ++++-------
 source/cmake/mergestaticlibs.cmake |  124 --------------------------------
 source/common/CMakeLists.txt       |  143 ++++++++++++++++++++++++++++++++++--
 source/common/common.cpp           |   27 +------
 source/common/common.h             |    4 -
 source/common/primitives.cpp       |    2 +-
 source/common/vec/CMakeLists.txt   |   67 -----------------
 source/common/x86/CMakeLists.txt   |   60 ---------------
 source/encoder/CMakeLists.txt      |    2 +-
 source/encoder/encoder.cpp         |   10 +-
 source/test/CMakeLists.txt         |    4 +-
 source/x265.cpp                    |   22 +++++-
 source/x265.def                    |   12 +++
 source/x265.h                      |   28 ++----
 14 files changed, 207 insertions(+), 342 deletions(-)

diffs (truncated from 805 to 300 lines):

diff -r 3202ca7a44bb -r 4737b5423ea4 source/CMakeLists.txt
--- a/source/CMakeLists.txt	Tue Oct 08 15:07:35 2013 -0500
+++ b/source/CMakeLists.txt	Tue Oct 08 23:58:54 2013 -0500
@@ -6,7 +6,7 @@ if(NOT CMAKE_BUILD_TYPE)
 endif()
 
 project (x265)
-cmake_minimum_required (VERSION 2.6)
+cmake_minimum_required (VERSION 2.8)
 
 SET(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" "${CMAKE_MODULE_PATH}")
 
@@ -140,31 +140,24 @@ if (WIN32)
     endif(WINXP_SUPPORT)
 endif()
 
-option(ENABLE_SHARED "Build shared x265 library (.dll/.so)" OFF)
-if(ENABLE_SHARED)
-    add_definitions(-Dx265_EXPORTS)
-endif()
-
 include_directories(. Lib common encoder)
 add_subdirectory(common)
 add_subdirectory(encoder)
 
-if(ENABLE_PRIMITIVES_VEC)
-    set(LIBS ${LIBS} PrimitivesVec)
-endif(ENABLE_PRIMITIVES_VEC)
-
-if(ENABLE_PRIMITIVES_ASM)
-    set(LIBS ${LIBS} PrimitivesASM)
-endif(ENABLE_PRIMITIVES_ASM)
-set(LIBS ${LIBS} encoder common)
-
-if(ENABLE_SHARED)
-    add_library(x265 SHARED dllmain.cpp)
-    target_link_libraries(x265 ${LIBS})
-elseif(NOT XCODE)
-    include(mergestaticlibs)
-    merge_static_libs(x265 ${LIBS})
+add_library(x265-shared SHARED dllmain.cpp x265.def $<TARGET_OBJECTS:encoder> $<TARGET_OBJECTS:common>)
+add_library(x265-static STATIC $<TARGET_OBJECTS:encoder> $<TARGET_OBJECTS:common>)
+if(ENABLE_PRIMITIVES_VEC AND (MSVC OR XCODE))
+    target_link_libraries(x265-shared assembly)
+    target_link_libraries(x265-static assembly)
 endif()
+set_target_properties(x265-shared PROPERTIES OUTPUT_NAME x265)
+if(NOT WIN32)
+    set_target_properties(x265-static PROPERTIES OUTPUT_NAME x265)
+    set_target_properties(x265-shared PROPERTIES LINK_FLAGS "-Wl,-Bsymbolic")
+endif()
+# WIN32 builds static: x265-static.lib  shared: x265.dll + x265.lib (shim loader)
+# MINGW builds static: libx265-static.a shared: libx265.dll + libx265.dll.a
+# *NIX  builds static: libx265.a        shared: libx265.so
 
 # Main CLI application
 option(ENABLE_CLI "Build standalone CLI application" ON)
@@ -184,13 +177,8 @@ if(ENABLE_CLI)
     add_executable(cli ../COPYING ${InputFiles} ${OutputFiles}
         x265.cpp x265opts.h x265.h
         compat/msvc/getopt.c compat/msvc/getopt.h)
-    if(XCODE OR MSVC)
-        target_link_libraries(cli ${LIBS})
-    else()
-        target_link_libraries(cli x265)
-    endif()
-    target_link_libraries(cli ${PLATFORM_LIBS})
-    SET_TARGET_PROPERTIES(cli PROPERTIES OUTPUT_NAME x265)
+    target_link_libraries(cli x265-static ${PLATFORM_LIBS})
+    set_target_properties(cli PROPERTIES OUTPUT_NAME x265)
 endif(ENABLE_CLI)
 
 # Test applications
diff -r 3202ca7a44bb -r 4737b5423ea4 source/cmake/mergestaticlibs.cmake
--- a/source/cmake/mergestaticlibs.cmake	Tue Oct 08 15:07:35 2013 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,124 +0,0 @@
-#    Copyright (C) 2012 Modelon AB
-
-#    This program is free software: you can redistribute it and/or modify
-#    it under the terms of the BSD style 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
-#    FMILIB_License.txt file for more details.
-
-#    You should have received a copy of the FMILIB_License.txt file
-#    along with this program. If not, contact Modelon AB <http://www.modelon.com>.
-
-# Merge_static_libs(outlib lib1 lib2 ... libn) merges a number of static
-# libs into a single static library
-function(merge_static_libs outlib )
-    set(libs ${ARGV})
-    list(REMOVE_AT libs 0)
-    # Create a dummy file that the target will depend on
-    set(dummyfile ${CMAKE_CURRENT_BINARY_DIR}/${outlib}_dummy.c)
-    file(WRITE ${dummyfile} "const char * dummy = \"${dummyfile}\";")
-
-    add_library(${outlib} STATIC ${dummyfile})
-
-    if("${CMAKE_CFG_INTDIR}" STREQUAL ".")
-        set(multiconfig FALSE)
-    else()
-        set(multiconfig TRUE)
-    endif()
-
-    # First get the file names of the libraries to be merged
-    foreach(lib ${libs})
-        get_target_property(libtype ${lib} TYPE)
-        if(NOT libtype STREQUAL "STATIC_LIBRARY")
-            message(FATAL_ERROR "Merge_static_libs can only process static libraries")
-        endif()
-        if(multiconfig)
-            foreach(CONFIG_TYPE ${CMAKE_CONFIGURATION_TYPES})
-                get_target_property("libfile_${CONFIG_TYPE}" ${lib} "LOCATION_${CONFIG_TYPE}")
-                list(APPEND libfiles_${CONFIG_TYPE} ${libfile_${CONFIG_TYPE}})
-            endforeach()
-        else()
-            get_target_property(libfile ${lib} LOCATION)
-            list(APPEND libfiles "${libfile}")
-        endif(multiconfig)
-    endforeach()
-    message(STATUS "will be merging ${libfiles}")
-    # Just to be sure: cleanup from duplicates
-    if(multiconfig)
-        foreach(CONFIG_TYPE ${CMAKE_CONFIGURATION_TYPES})
-            list(REMOVE_DUPLICATES libfiles_${CONFIG_TYPE})
-            set(libfiles ${libfiles} ${libfiles_${CONFIG_TYPE}})
-        endforeach()
-    endif()
-    list(REMOVE_DUPLICATES libfiles)
-
-    # Now the easy part for MSVC and for MAC
-    if(MSVC)
-        # lib.exe does the merging of libraries just need to conver the list into string
-        foreach(CONFIG_TYPE ${CMAKE_CONFIGURATION_TYPES})
-            set(flags "")
-            foreach(lib ${libfiles_${CONFIG_TYPE}})
-                set(flags "${flags} ${lib}")
-            endforeach()
-            string(TOUPPER "STATIC_LIBRARY_FLAGS_${CONFIG_TYPE}" PROPNAME)
-            set_target_properties(${outlib} PROPERTIES ${PROPNAME} "${flags}")
-        endforeach()
-
-    elseif(APPLE)
-        # Use OSX's libtool to merge archives
-        if(multiconfig)
-            message(FATAL_ERROR "Multiple configurations are not supported")
-        endif()
-        get_target_property(outfile ${outlib} LOCATION)  
-        add_custom_command(TARGET ${outlib} POST_BUILD
-            COMMAND rm ${outfile}
-            COMMAND /usr/bin/libtool -static -o ${outfile} 
-            ${libfiles})
-    else() 
-        # general UNIX - need to "ar -x" and then "ar -ru"
-        if(multiconfig)
-            message(FATAL_ERROR "Multiple configurations are not supported")
-        endif()
-        get_target_property(outfile ${outlib} LOCATION)
-        message(STATUS "outfile location is ${outfile}")
-        foreach(lib ${libfiles})
-            # objlistfile will contain the list of object files for the library
-            set(objlistfile ${lib}.objlist)
-            set(objdir ${lib}.objdir)
-            set(objlistcmake  ${objlistfile}.cmake)
-            # we only need to extract files once 
-            if(${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/cmake.check_cache IS_NEWER_THAN ${objlistcmake})
-                file(WRITE ${objlistcmake}
-"# Extract object files from the library
-message(STATUS \"Extracting object files from ${lib}\")
-
-                execute_process(COMMAND ${CMAKE_AR} -x ${lib}
-                    WORKING_DIRECTORY ${objdir})
-                # save the list of object files
-                execute_process(COMMAND ls .
-                    OUTPUT_FILE ${objlistfile}
-                    WORKING_DIRECTORY ${objdir})")
-                file(MAKE_DIRECTORY ${objdir})
-                add_custom_command(
-                    OUTPUT ${objlistfile}
-                    COMMAND ${CMAKE_COMMAND} -P ${objlistcmake}
-                    DEPENDS ${lib})
-            endif()
-            list(APPEND extrafiles "${objlistfile}")
-            add_custom_command(TARGET ${outlib} POST_BUILD
-                COMMAND ${CMAKE_COMMAND} -E echo "Running: ${CMAKE_AR} ru ${outfile} \\$$\\(cat ${objlistfile}\\)"
-                COMMAND ${CMAKE_AR} ru "${outfile}" $$\(cat "${objlistfile}"\)
-                WORKING_DIRECTORY ${objdir})
-        endforeach()
-        add_custom_command(TARGET ${outlib} POST_BUILD
-            COMMAND ${CMAKE_COMMAND} -E echo "Running: ${CMAKE_RANLIB} ${outfile}"
-            COMMAND ${CMAKE_RANLIB} ${outfile})
-    endif()
-    file(WRITE ${dummyfile}.base "const char* ${outlib}_sublibs=\"${libs}\";")
-    add_custom_command( 
-        OUTPUT  ${dummyfile}
-        COMMAND ${CMAKE_COMMAND}  -E copy ${dummyfile}.base ${dummyfile}
-        DEPENDS ${libs} ${extrafiles})
-endfunction()
diff -r 3202ca7a44bb -r 4737b5423ea4 source/common/CMakeLists.txt
--- a/source/common/CMakeLists.txt	Tue Oct 08 15:07:35 2013 -0500
+++ b/source/common/CMakeLists.txt	Tue Oct 08 23:58:54 2013 -0500
@@ -81,8 +81,141 @@ if(MSVC)
     endif()
 endif(MSVC)
 
-add_library(common STATIC ../../COPYING
+if(ENABLE_PRIMITIVES_VEC)
+    if (MSVC)
+        add_definitions(/wd4127) # conditional expression is constant
+        add_definitions(/wd4244) # 'argument' : conversion from 'int' to 'char', possible loss of data
+        if ("$ENV{CXX}" STREQUAL "icl")
+            add_definitions(/Qwd111)    # statement is unreachable
+            add_definitions(/Qwd128)    # loop is unreachable
+            add_definitions(/Qwd177)    # declared function is unused
+            add_definitions(/Qwd185)    # dynamic initialization in unreachable code
+            add_definitions(/Qwd280)    # conditional expression is constant
+            add_definitions(/Qwd13200)  # function using MMX does not call EMMS
+        endif()
+        set(PRIMITIVES vec/blockcopy-sse3.cpp
+            vec/pixel-sse3.cpp vec/pixel-ssse3.cpp vec/pixel-sse41.cpp
+            vec/dct-sse3.cpp vec/dct-ssse3.cpp vec/dct-sse41.cpp
+            vec/ipfilter-ssse3.cpp vec/ipfilter-sse41.cpp
+            vec/intra-sse3.cpp vec/intra-sse41.cpp)
+        if (NOT X64)
+            # x64 implies SSE4, so this flag would have no effect (and it issues a warning)
+            set_source_files_properties(vec/blockcopy-sse3.cpp
+                vec/pixel-sse3.cpp vec/pixel-ssse3.cpp vec/pixel-sse41.cpp
+                vec/dct-sse3.cpp vec/dct-ssse3.cpp vec/dct-sse41.cpp
+                vec/ipfilter-ssse3.cpp vec/ipfilter-sse41.cpp
+                vec/intra-sse3.cpp vec/intra-sse41.cpp
+                PROPERTIES COMPILE_FLAGS /arch:SSE2)
+        endif()
+        if (MSVC_VERSION EQUAL 1700 OR "$ENV{CXX}" STREQUAL "icl")
+            set(PRIMITIVES ${PRIMITIVES} vec/blockcopy-avx2.cpp vec/pixel-avx2.cpp)
+            set_source_files_properties(vec/blockcopy-avx2.cpp vec/pixel-avx2.cpp
+                PROPERTIES COMPILE_FLAGS /arch:AVX)
+        endif()
+    endif()
+    if(GCC)
+        if ("$ENV{CXX}" STREQUAL "icpc")
+            add_definitions(-wd13200)  # function using MMX does not call EMMS
+        endif()
+        if("$ENV{CXX}" STREQUAL "icpc" OR NOT GCC_VERSION VERSION_LESS 4.3)
+            set(PRIMITIVES vec/blockcopy-sse3.cpp
+                vec/pixel-sse3.cpp vec/pixel-ssse3.cpp vec/pixel-sse41.cpp
+                vec/ipfilter-ssse3.cpp vec/ipfilter-sse41.cpp
+                vec/dct-sse3.cpp vec/dct-ssse3.cpp vec/dct-sse41.cpp
+                vec/intra-sse3.cpp vec/intra-sse41.cpp)
+            set_source_files_properties(
+                vec/blockcopy-sse3.cpp vec/pixel-sse3.cpp vec/dct-sse3.cpp vec/intra-sse3.cpp
+                PROPERTIES COMPILE_FLAGS "-msse3")
+            set_source_files_properties(
+                vec/ipfilter-ssse3.cpp vec/pixel-ssse3.cpp vec/dct-ssse3.cpp
+                PROPERTIES COMPILE_FLAGS "-mssse3")
+            set_source_files_properties(
+                vec/pixel-sse41.cpp vec/ipfilter-sse41.cpp vec/dct-sse41.cpp vec/intra-sse41.cpp
+                PROPERTIES COMPILE_FLAGS "-msse4.1")
+        endif()
+        if("$ENV{CXX}" STREQUAL "icpc" OR NOT GCC_VERSION VERSION_LESS 4.7)
+            set(PRIMITIVES ${PRIMITIVES}
+                vec/blockcopy-avx2.cpp vec/pixel-avx2.cpp)
+            set_source_files_properties(
+                vec/blockcopy-avx2.cpp vec/pixel-avx2.cpp
+                PROPERTIES COMPILE_FLAGS "-march=core-avx2")
+        endif()
+    endif(GCC)
+
+    set(VEC_PRIMITIVES vec/vec-primitives.cpp ${PRIMITIVES})
+    source_group(Intrinsics FILES ${VEC_PRIMITIVES})
+endif(ENABLE_PRIMITIVES_VEC)
+
+if(ENABLE_PRIMITIVES_ASM)
+    if (GCC)
+        add_definitions(-DHAVE_ALIGNED_STACK=1)
+        add_definitions(-Wno-error=unused-parameter)
+    else()
+        add_definitions(-DHAVE_ALIGNED_STACK=0)
+    endif()
+
+    set(ASMS pixel-a.asm const-a.asm cpu-a.asm sad-a.asm mc-a.asm mc-a2.asm ipfilter8.asm)
+    if (X64)
+        add_definitions(-DARCH_X86_64=1)
+    else()
+        add_definitions(-DARCH_X86_64=0)
+        set(ASMS ${ASMS} pixel-32.asm)
+    endif()
+    foreach(ASM ${ASMS})
+        set(FULLPATHASM ${FULLPATHASM} x86/${ASM})
+    endforeach()
+
+    if(XCODE)
+        if (X64)
+            set(FLAGS -f macho64 -m amd64 -DPREFIX -DPIC -DARCH_X86_64=1 -DHAVE_ALIGNED_STACK=1)
+        else()
+            set(FLAGS -f macho -DPREFIX -DPIC -DARCH_X86_64=0 -DHAVE_ALIGNED_STACK=1)
+        endif()
+        if (HIGH_BIT_DEPTH)


More information about the x265-commits mailing list