[x265] [PATCH RFC] cmake: add ENABLE_SHARED build option for creating a shared library (dll/so)
Steve Borho
steve at borho.org
Thu Oct 3 05:55:52 CEST 2013
# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1380772482 18000
# Wed Oct 02 22:54:42 2013 -0500
# Node ID 25366dc0fd1c06d3bb08cafcc2131fc1ffa76e1c
# Parent 2c73823af5223e38d019dbbca56c2aa7fe58245e
cmake: add ENABLE_SHARED build option for creating a shared library (dll/so)
Only tested on Windows, but it is generating DLLs which export our public C API
diff -r 2c73823af522 -r 25366dc0fd1c source/CMakeLists.txt
--- a/source/CMakeLists.txt Wed Oct 02 17:00:40 2013 +0530
+++ b/source/CMakeLists.txt Wed Oct 02 22:54:42 2013 -0500
@@ -140,6 +140,11 @@
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)
@@ -153,7 +158,10 @@
set(LIBS ${LIBS} PrimitivesASM)
endif(ENABLE_PRIMITIVES_ASM)
-if(NOT XCODE)
+if(ENABLE_SHARED)
+ add_library(x265 SHARED dllmain.cpp)
+ target_link_libraries(x265 ${LIBS} ${PLATFORM_LIBS})
+elseif(NOT XCODE)
include(mergestaticlibs)
merge_static_libs(x265 ${LIBS})
endif()
diff -r 2c73823af522 -r 25366dc0fd1c source/common/common.cpp
--- a/source/common/common.cpp Wed Oct 02 17:00:40 2013 +0530
+++ b/source/common/common.cpp Wed Oct 02 22:54:42 2013 -0500
@@ -117,7 +117,7 @@
}
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));
@@ -185,14 +185,14 @@
}
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 2c73823af522 -r 25366dc0fd1c source/common/primitives.cpp
--- a/source/common/primitives.cpp Wed Oct 02 17:00:40 2013 +0530
+++ b/source/common/primitives.cpp Wed Oct 02 22:54:42 2013 -0500
@@ -90,7 +90,7 @@
* 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 2c73823af522 -r 25366dc0fd1c source/dllmain.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/source/dllmain.cpp Wed Oct 02 22:54:42 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(¶m);
+ x265_t *enc = x265_encoder_open(¶m);
+ x265_encoder_close(enc, 0);
+}
diff -r 2c73823af522 -r 25366dc0fd1c source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp Wed Oct 02 17:00:40 2013 +0530
+++ b/source/encoder/encoder.cpp Wed Oct 02 22:54:42 2013 -0500
@@ -340,7 +340,7 @@
}
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 @@
}
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 @@
}
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 @@
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 2c73823af522 -r 25366dc0fd1c source/x265.h
--- a/source/x265.h Wed Oct 02 17:00:40 2013 +0530
+++ b/source/x265.h Wed Oct 02 22:54:42 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;
@@ -310,17 +316,17 @@
/***
* 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) */
@@ -328,7 +334,7 @@
/* (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
@@ -337,38 +343,38 @@
* 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-devel
mailing list