[x265-commits] [x265] cmake: add ENABLE_SHARED build option for creating a shar...

Steve Borho steve at borho.org
Sun Oct 6 09:36:16 CEST 2013


details:   http://hg.videolan.org/x265/rev/33ea0f317564
branches:  
changeset: 4248:33ea0f317564
user:      Steve Borho <steve at borho.org>
date:      Wed Oct 02 22:54:42 2013 -0500
description:
cmake: add ENABLE_SHARED build option for creating a shared library (dll/so)
Subject: [x265] cmake: use add_definitions() instead of modifying CMAKE_CXX_FLAGS manually

details:   http://hg.videolan.org/x265/rev/c010342f7605
branches:  
changeset: 4249:c010342f7605
user:      Steve Borho <steve at borho.org>
date:      Sun Oct 06 02:09:00 2013 -0500
description:
cmake: use add_definitions() instead of modifying CMAKE_CXX_FLAGS manually

diffstat:

 source/CMakeLists.txt        |  21 +++++++++++++++------
 source/common/common.cpp     |   6 +++---
 source/common/primitives.cpp |   2 +-
 source/dllmain.cpp           |  34 ++++++++++++++++++++++++++++++++++
 source/encoder/encoder.cpp   |  10 +++++-----
 source/x265.h                |  28 +++++++++++++++++-----------
 6 files changed, 75 insertions(+), 26 deletions(-)

diffs (278 lines):

diff -r 2190f2f036a1 -r c010342f7605 source/CMakeLists.txt
--- a/source/CMakeLists.txt	Sun Oct 06 00:36:24 2013 -0500
+++ b/source/CMakeLists.txt	Sun Oct 06 02:09:00 2013 -0500
@@ -73,7 +73,7 @@ if (GCC)
         add_definitions(-Werror)
     endif(WARNINGS_AS_ERRORS)
     if(X64 AND NOT WIN32)
-        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
+        add_definitions(-fPIC)
     endif(X64 AND NOT WIN32)
 endif(GCC)
 
@@ -140,11 +140,15 @@ 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)
 
-set(LIBS common encoder)
 if(ENABLE_PRIMITIVES_VEC)
     set(LIBS ${LIBS} PrimitivesVec)
 endif(ENABLE_PRIMITIVES_VEC)
@@ -152,8 +156,12 @@ endif(ENABLE_PRIMITIVES_VEC)
 if(ENABLE_PRIMITIVES_ASM)
     set(LIBS ${LIBS} PrimitivesASM)
 endif(ENABLE_PRIMITIVES_ASM)
+set(LIBS ${LIBS} encoder common)
 
-if(NOT XCODE)
+if(ENABLE_SHARED)
+    add_library(x265 SHARED dllmain.cpp)
+    target_link_libraries(x265 ${LIBS})
+elseif(NOT XCODE)
     include(mergestaticlibs)
     merge_static_libs(x265 ${LIBS})
 endif()
@@ -179,13 +187,14 @@ if(ENABLE_CLI)
 
     include(version) # determine X265_VERSION
     set_source_files_properties(x265.cpp PROPERTIES COMPILE_FLAGS -DX265_VERSION=${X265_VERSION})
-    add_executable(cli ${EXTRAS} ../COPYING ${InputFiles} ${OutputFiles}
+    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} ${PLATFORM_LIBS})
+    target_link_libraries(cli ${LIBS})
 else()
-    target_link_libraries(cli x265 ${PLATFORM_LIBS})
+    target_link_libraries(cli x265)
 endif()
+    target_link_libraries(cli ${PLATFORM_LIBS})
     SET_TARGET_PROPERTIES(cli PROPERTIES OUTPUT_NAME x265)
 endif(ENABLE_CLI)
diff -r 2190f2f036a1 -r c010342f7605 source/common/common.cpp
--- a/source/common/common.cpp	Sun Oct 06 00:36:24 2013 -0500
+++ b/source/common/common.cpp	Sun Oct 06 02:09:00 2013 -0500
@@ -117,7 +117,7 @@ void x265_log(x265_param_t *param, int l
 }
 
 extern "C"
-void x265_param_default(x265_param_t *param)
+X265_EXPORT void x265_param_default(x265_param_t *param)
 {
     memset(param, 0, sizeof(x265_param_t));
 
@@ -184,14 +184,14 @@ void x265_param_default(x265_param_t *pa
 }
 
 extern "C"
-void x265_picture_init(x265_param_t *param, x265_picture_t *pic)
+X265_EXPORT void x265_picture_init(x265_param_t *param, x265_picture_t *pic)
 {
     memset(pic, 0, sizeof(x265_picture_t));
     pic->bitDepth = param->internalBitDepth;
 }
 
 extern "C"
-int x265_param_apply_profile(x265_param_t *param, const char *profile)
+X265_EXPORT int x265_param_apply_profile(x265_param_t *param, const char *profile)
 {
     if (!profile)
         return 0;
diff -r 2190f2f036a1 -r c010342f7605 source/common/primitives.cpp
--- a/source/common/primitives.cpp	Sun Oct 06 00:36:24 2013 -0500
+++ b/source/common/primitives.cpp	Sun Oct 06 02:09:00 2013 -0500
@@ -90,7 +90,7 @@ using namespace x265;
  * cpuid > 0 -  force CPU type
  * cpuid < 0  - auto-detect if uninitialized */
 extern "C"
-void x265_setup_primitives(x265_param_t *param, int cpuid)
+X265_EXPORT void x265_setup_primitives(x265_param_t *param, int cpuid)
 {
     // initialize global variables
     initROM();
diff -r 2190f2f036a1 -r c010342f7605 source/dllmain.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/dllmain.cpp	Sun Oct 06 02:09:00 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.
+ *****************************************************************************/
+
+#include "x265.h"
+
+/* this unreachable function forces the MSVC linker to include the encoder
+ * and common libraries into the DLL */
+void dummy()
+{
+    x265_param_t param;
+    x265_param_default(&param);
+    x265_t *enc = x265_encoder_open(&param);
+    x265_encoder_close(enc, 0);
+}
diff -r 2190f2f036a1 -r c010342f7605 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Sun Oct 06 00:36:24 2013 -0500
+++ b/source/encoder/encoder.cpp	Sun Oct 06 02:09:00 2013 -0500
@@ -340,7 +340,7 @@ void x265_t::configure(x265_param_t *_pa
 }
 
 extern "C"
-x265_t *x265_encoder_open(x265_param_t *param)
+X265_EXPORT x265_t *x265_encoder_open(x265_param_t *param)
 {
     x265_setup_primitives(param, -1);  // -1 means auto-detect if uninitialized
 
@@ -369,7 +369,7 @@ x265_t *x265_encoder_open(x265_param_t *
 }
 
 extern "C"
-int x265_encoder_headers(x265_t *encoder, x265_nal_t **pp_nal, int *pi_nal)
+X265_EXPORT int x265_encoder_headers(x265_t *encoder, x265_nal_t **pp_nal, int *pi_nal)
 {
     if (!pp_nal)
         return 0;
@@ -401,7 +401,7 @@ int x265_encoder_headers(x265_t *encoder
 }
 
 extern "C"
-int x265_encoder_encode(x265_t *encoder, x265_nal_t **pp_nal, int *pi_nal, x265_picture_t *pic_in, x265_picture_t *pic_out)
+X265_EXPORT int x265_encoder_encode(x265_t *encoder, x265_nal_t **pp_nal, int *pi_nal, x265_picture_t *pic_in, x265_picture_t *pic_out)
 {
     NALUnitEBSP *nalunits[MAX_NAL_UNITS] = {0, 0, 0, 0, 0};
     int numEncoded = encoder->encode(!pic_in, pic_in, pic_out, nalunits);
@@ -429,13 +429,13 @@ int x265_encoder_encode(x265_t *encoder,
 EXTERN_CYCLE_COUNTER(ME);
 
 extern "C"
-void x265_encoder_get_stats(x265_t *encoder, x265_stats_t *outputStats)
+X265_EXPORT void x265_encoder_get_stats(x265_t *encoder, x265_stats_t *outputStats)
 {
     encoder->fetchStats(outputStats);
 }
 
 extern "C"
-void x265_encoder_close(x265_t *encoder, double *outPsnr)
+X265_EXPORT void x265_encoder_close(x265_t *encoder, double *outPsnr)
 {
     double globalPsnr = encoder->printSummary();
 
diff -r 2190f2f036a1 -r c010342f7605 source/x265.h
--- a/source/x265.h	Sun Oct 06 00:36:24 2013 -0500
+++ b/source/x265.h	Sun Oct 06 02:09:00 2013 -0500
@@ -30,6 +30,12 @@
 extern "C" {
 #endif
 
+#if defined(WIN32) && defined(x265_EXPORTS)
+#define X265_EXPORT __declspec(dllexport)
+#else
+#define X265_EXPORT
+#endif
+
 /* x265_t:
  *      opaque handler for encoder */
 typedef struct x265_t x265_t;
@@ -309,17 +315,17 @@ x265_param_t;
 /*** 
  * If not called, first encoder allocated will auto-detect the CPU and
  * initialize performance primitives, which are process global */
-void x265_setup_primitives(x265_param_t *param, int cpulevel);
+X265_EXPORT void x265_setup_primitives(x265_param_t *param, int cpulevel);
 
 /***
  * Initialize an x265_param_t structure to default values
  */
-void x265_param_default(x265_param_t *param);
+X265_EXPORT void x265_param_default(x265_param_t *param);
 
 /***
  * Initialize an x265_picture_t structure to default values
  */
-void x265_picture_init(x265_param_t *param, x265_picture_t *pic);
+X265_EXPORT void x265_picture_init(x265_param_t *param, x265_picture_t *pic);
 
 /* x265_param_apply_profile:
  *      Applies the restrictions of the given profile. (one of below) */
@@ -327,7 +333,7 @@ static const char * const x265_profile_n
 
 /*      (can be NULL, in which case the function will do nothing)
  *      returns 0 on success, negative on failure (e.g. invalid profile name). */
-int x265_param_apply_profile(x265_param_t *, const char *profile);
+X265_EXPORT int x265_param_apply_profile(x265_param_t *, const char *profile);
 
 /* x265_max_bit_depth:
  *      Specifies the maximum number of bits per pixel that x265 can input. This
@@ -336,38 +342,38 @@ int x265_param_apply_profile(x265_param_
  *      x265_max_bit_depth is 12, the internal and input bit depths can be
  *      either 8, 10, or 12. Note that the internal bit depth must be the same
  *      for all encoders allocated in the same process. */
-extern const int x265_max_bit_depth;
+X265_EXPORT extern const int x265_max_bit_depth;
 
 /* x265_encoder_open:
  *      create a new encoder handler, all parameters from x265_param_t are copied */
-x265_t *x265_encoder_open(x265_param_t *);
+X265_EXPORT x265_t* x265_encoder_open(x265_param_t *);
 
 /* x265_encoder_headers:
  *      return the SPS and PPS that will be used for the whole stream.
  *      *pi_nal is the number of NAL units outputted in pp_nal.
  *      returns negative on error.
  *      the payloads of all output NALs are guaranteed to be sequential in memory. */
-int     x265_encoder_headers(x265_t *, x265_nal_t **pp_nal, int *pi_nal);
+X265_EXPORT int x265_encoder_headers(x265_t *, x265_nal_t **pp_nal, int *pi_nal);
 
 /* x265_encoder_encode:
  *      encode one picture.
  *      *pi_nal is the number of NAL units outputted in pp_nal.
  *      returns negative on error, zero if no NAL units returned.
  *      the payloads of all output NALs are guaranteed to be sequential in memory. */
-int     x265_encoder_encode(x265_t *encoder, x265_nal_t **pp_nal, int *pi_nal, x265_picture_t *pic_in, x265_picture_t *pic_out);
+X265_EXPORT int x265_encoder_encode(x265_t *encoder, x265_nal_t **pp_nal, int *pi_nal, x265_picture_t *pic_in, x265_picture_t *pic_out);
 
 /* x265_encoder_stats:
 *       returns output stats from the encoder */
-void    x265_encoder_get_stats(x265_t *encoder, x265_stats_t *);
+X265_EXPORT void x265_encoder_get_stats(x265_t *encoder, x265_stats_t *);
 
 /* x265_encoder_close:
  *      close an encoder handler.  Optionally return the global PSNR value (6 * psnrY + psnrU + psnrV) / 8 */
-void    x265_encoder_close(x265_t *, double *globalPsnr);
+X265_EXPORT void x265_encoder_close(x265_t *, double *globalPsnr);
 
 /***
  * Release library static allocations
  */
-void x265_cleanup(void);
+X265_EXPORT void x265_cleanup(void);
 
 #ifdef __cplusplus
 }


More information about the x265-commits mailing list