[x265] [PATCH 2 of 4] cmake: add install targets, machine generate x265.def and x265_config.h

Steve Borho steve at borho.org
Sat Oct 12 23:10:27 CEST 2013


# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1381607058 18000
#      Sat Oct 12 14:44:18 2013 -0500
# Node ID 1097e547c441831734d3c66998325fe5532620a0
# Parent  28690748ab1d6d913c2e0bab4d0365e0b6cc6db4
cmake: add install targets, machine generate x265.def and x265_config.h

Now X265_BUILD is maintained in just a single place, souce/CMakeLists.txt.

The shared library is only installed if a valid tag is found; meaning the user
must be building a Mercurial clone or a release tarball with .hg_archive.txt
file in it (otherwise they must install the shared library themselves)

diff -r 28690748ab1d -r 1097e547c441 source/CMakeLists.txt
--- a/source/CMakeLists.txt	Sat Oct 12 14:51:04 2013 -0500
+++ b/source/CMakeLists.txt	Sat Oct 12 14:44:18 2013 -0500
@@ -143,12 +143,20 @@
     endif(WINXP_SUPPORT)
 endif()
 
-include_directories(. Lib common encoder)
+# X265_BUILD must be incremented each time the public API is changed
+set(X265_BUILD 1)
+configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
+               "${PROJECT_BINARY_DIR}/x265.def")
+configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
+               "${PROJECT_BINARY_DIR}/x265_config.h")
+
+include_directories(. Lib common encoder "${PROJECT_BINARY_DIR}")
 add_subdirectory(common)
 add_subdirectory(encoder)
 
-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>)
+add_library(x265-shared SHARED dllmain.cpp "${PROJECT_BINARY_DIR}/x265.def"
+                               $<TARGET_OBJECTS:encoder> $<TARGET_OBJECTS:common>)
 if(ENABLE_PRIMITIVES_ASM AND (MSVC_IDE OR XCODE))
     SET(EXTRA_LIBS ${EXTRA_LIBS} assembly)
 endif()
@@ -165,6 +173,21 @@
 # MINGW builds static: libx265-static.a shared: libx265.dll + libx265.dll.a
 # *NIX  builds static: libx265.a        shared: libx265.so
 
+include(version) # determine X265_VERSION and X265_LATEST_TAG
+if(X265_LATEST_TAG)
+    # shared library is not installed if a tag is not found
+    set_target_properties(x265-shared PROPERTIES VERSION ${X265_LATEST_TAG} SOVERSION ${X265_BUILD})
+    install(TARGETS x265-shared
+            RUNTIME DESTINATION bin
+            LIBRARY DESTINATION lib
+            ARCHIVE DESTINATION lib/x265)
+endif()
+install(TARGETS x265-static
+        RUNTIME DESTINATION bin
+        LIBRARY DESTINATION lib
+        ARCHIVE DESTINATION lib/x265)
+install(FILES x265.h "${PROJECT_BINARY_DIR}/x265_config.h" DESTINATION include)
+
 # Main CLI application
 option(ENABLE_CLI "Build standalone CLI application" ON)
 if(ENABLE_CLI)
@@ -178,13 +201,14 @@
         set_source_files_properties(compat/msvc/getopt.c PROPERTIES COMPILE_FLAGS "-Wno-unused-parameter")
     endif()
 
-    include(version) # determine X265_VERSION
     set_source_files_properties(x265.cpp PROPERTIES COMPILE_FLAGS -DX265_VERSION=${X265_VERSION})
     add_executable(cli ../COPYING ${InputFiles} ${OutputFiles}
         x265.cpp x265opts.h x265.h
         compat/msvc/getopt.c compat/msvc/getopt.h)
     target_link_libraries(cli x265-static ${PLATFORM_LIBS})
     set_target_properties(cli PROPERTIES OUTPUT_NAME x265)
+
+    install(TARGETS cli DESTINATION bin)
 endif(ENABLE_CLI)
 
 # Test applications
diff -r 28690748ab1d -r 1097e547c441 source/cmake/version.cmake
--- a/source/cmake/version.cmake	Sat Oct 12 14:51:04 2013 -0500
+++ b/source/cmake/version.cmake	Sat Oct 12 14:44:18 2013 -0500
@@ -25,6 +25,7 @@
         set(X265_VERSION ${HG_REVISION} CACHE STRING "x265 version string.")
     else()
         set(X265_VERSION ${hg_tag} CACHE STRING "x265 version string.")
+        set(X265_LATEST_TAG ${hg_tag})
     endif()
 elseif(DEFINED ENV{X265_VERSION})
     set(X265_VERSION $ENV{X265_REVISION})
@@ -60,6 +61,7 @@
         elseif(HG_REVISION_TAG MATCHES "^r")
             STRING(SUBSTRING ${HG_REVISION_TAG} 1 -1 HG_REVISION_TAG)
         endif()
+        set(X265_LATEST_TAG ${HG_REVISION_TAG})
         if(HG_REVISION_DIST STREQUAL "0")
             SET(HG_REVISION ${HG_REVISION_TAG})
         else()
diff -r 28690748ab1d -r 1097e547c441 source/x265.def
--- a/source/x265.def	Sat Oct 12 14:51:04 2013 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,12 +0,0 @@
-EXPORTS
-x265_encoder_open_1
-x265_setup_primitives
-x265_param_default
-x265_picture_init
-x265_param_apply_profile
-x265_max_bit_depth
-x265_encoder_headers
-x265_encoder_encode
-x265_encoder_get_stats
-x265_encoder_close
-x265_cleanup
diff -r 28690748ab1d -r 1097e547c441 source/x265.def.in
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/x265.def.in	Sat Oct 12 14:44:18 2013 -0500
@@ -0,0 +1,12 @@
+EXPORTS
+x265_encoder_open_${X265_BUILD}
+x265_setup_primitives
+x265_param_default
+x265_picture_init
+x265_param_apply_profile
+x265_max_bit_depth
+x265_encoder_headers
+x265_encoder_encode
+x265_encoder_get_stats
+x265_encoder_close
+x265_cleanup
diff -r 28690748ab1d -r 1097e547c441 source/x265.h
--- a/source/x265.h	Sat Oct 12 14:51:04 2013 -0500
+++ b/source/x265.h	Sat Oct 12 14:44:18 2013 -0500
@@ -25,14 +25,12 @@
 #define X265_X265_H
 
 #include <stdint.h>
+#include "x265_config.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-/* Until we have a permanent solution, the x265.def file must be updated each time this is changed */
-#define X265_BUILD 1
-
 /* x265_t:
  *      opaque handler for encoder */
 typedef struct x265_t x265_t;
diff -r 28690748ab1d -r 1097e547c441 source/x265_config.h.in
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/x265_config.h.in	Sat Oct 12 14:44:18 2013 -0500
@@ -0,0 +1,34 @@
+/*****************************************************************************
+ * Copyright (C) 2013 x265 project
+ *
+ * Authors: Steve Borho <steve at borho.org>
+ *
+ * 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; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 Street, Fifth Floor, Boston, MA  02111, USA.
+ *
+ * This program is also available under a commercial proprietary license.
+ * For more information, contact us at licensing at multicorewareinc.com.
+ *****************************************************************************/
+
+#ifndef X265_CONFIG_H
+#define X265_CONFIG_H
+
+/* Defines generated at build time */
+
+/* Incremented each time public API is changed, X265_BUILD is used as
+ * the shared library SONAME on platforms which support it. It also
+ * prevents linking against a different version of the static lib */
+#define X265_BUILD ${X265_BUILD}
+
+#endif


More information about the x265-devel mailing list