changed cmake behaviour: executables are now always statically linked. When -DBUIL_SHARED_LIBS option is ON (the default), the shared versions of the libraries are also built (but executables remain linked against the static libraries).

This commit is contained in:
Antonin Descampe 2010-11-28 17:07:04 +00:00
parent 389166e86e
commit eb5694ca2a
9 changed files with 133 additions and 53 deletions

View File

@ -5,6 +5,9 @@ What's New for OpenJPEG
! : changed
+ : added
November 28, 2010
! [antonin] changed cmake behaviour: executables are now always statically linked. When -DBUIL_SHARED_LIBS option is ON (the default), the shared versions of the libraries are also built (but not linked against executables).
November 25, 2010
* [antonin] fix compilation and DLL creation of libopenjpeg with MSYS/MinGW (from vincent.torri, see issue 47 on googlecode)

View File

@ -126,7 +126,7 @@ CONFIGURE_FILE(
#-----------------------------------------------------------------------------
# OpenJPEG build configuration options.
OPTION(BUILD_SHARED_LIBS "Build OpenJPEG with shared libraries." ON)
OPTION(BUILD_SHARED_LIBS "Build OpenJPEG shared libraries." ON)
#-----------------------------------------------------------------------------
SET (EXECUTABLE_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all executables.")

View File

@ -51,10 +51,12 @@ else:
make clean
Binaries are located in the 'bin' directory.
Executables are always statically linked.
Main available cmake flags:
* To specify the install path: '-DCMAKE_INSTALL_PREFIX=/path'
* To build the shared libraries: '-DBUILD_SHARED_LIBS:bool=on' (default: 'ON')
Note: when using this option, shared libraries are built but executables remain linked against the corresponding static libraries.
* To build the CODEC executables: '-DBUILD_CODEC:bool=on' (default: 'ON')
* To build the MJ2 executables: '-DBUILD_MJ2:bool=on' (default: 'OFF')
* To build the JPWL executables and JPWL library: '-DBUILD_JPWL:bool=on' (default: 'OFF')

View File

@ -16,9 +16,7 @@ ENDIF(DONT_HAVE_GETOPT)
# Do the proper thing when building static...if only there was configured
# headers or def files instead
IF(NOT BUILD_SHARED_LIBS)
ADD_DEFINITIONS(-DOPJ_STATIC)
ENDIF(NOT BUILD_SHARED_LIBS)
ADD_DEFINITIONS(-DOPJ_STATIC)
# Headers file are located here:
INCLUDE_DIRECTORIES(
@ -35,7 +33,7 @@ ENDIF(TIFF_FOUND)
# Loop over all executables:
FOREACH(exe j2k_to_image image_to_j2k j2k_dump)
ADD_EXECUTABLE(${exe} ${exe}.c ${common_SRCS})
TARGET_LINK_LIBRARIES(${exe} ${OPJ_PREFIX}openjpeg ${LCMS_LIB})
TARGET_LINK_LIBRARIES(${exe} ${OPENJPEG_LIBRARY_NAME}.static ${LCMS_LIB})
IF(PNG_FOUND)
TARGET_LINK_LIBRARIES(${exe} ${PNG_LIBRARIES})
ENDIF(PNG_FOUND)

View File

@ -27,16 +27,14 @@ ENDIF(DONT_HAVE_GETOPT)
# Do the proper thing when building static...if only there was configured
# headers or def files instead
IF(NOT BUILD_SHARED_LIBS)
ADD_DEFINITIONS(-DOPJ_STATIC)
ENDIF(NOT BUILD_SHARED_LIBS)
ADD_DEFINITIONS(-DOPJ_STATIC)
#FIND_PACKAGE(TIFF REQUIRED)
# Loop over all executables:
FOREACH(exe jp3d_to_volume volume_to_jp3d)
ADD_EXECUTABLE(${exe} ${exe}.c ${common_SRCS})
TARGET_LINK_LIBRARIES(${exe} ${OPJ_PREFIX}openjp3dvm) # ${TIFF_LIBRARIES})
TARGET_LINK_LIBRARIES(${exe} ${OPENJPEG_LIBRARY_NAME}_JP3D.static) # ${TIFF_LIBRARIES})
# On unix you need to link to the math library:
IF(UNIX)
TARGET_LINK_LIBRARIES(${exe} m)

View File

@ -10,25 +10,54 @@ SET(JP3DVM_SRCS
bio.c cio.c dwt.c event.c jp3d.c jp3d_lib.c mct.c mqc.c openjpeg.c pi.c raw.c t1.c t1_3d.c t2.c tcd.c tgt.c volume.c
)
# Pass proper definition to preprocessor to generate shared lib
IF(WIN32)
IF(BUILD_SHARED_LIBS)
ADD_DEFINITIONS(-DOPJ_EXPORTS)
ELSE(BUILD_SHARED_LIBS)
ADD_DEFINITIONS(-DOPJ_STATIC)
ENDIF(BUILD_SHARED_LIBS)
ENDIF(WIN32)
IF(LCMS_INCLUDE_DIR)
INCLUDE_DIRECTORIES( ${LCMS_INCLUDE_DIR} )
ENDIF(LCMS_INCLUDE_DIR)
# Create the library
#ADD_LIBRARY(${OPENJPEG_LIBRARY_NAME} ${OPENJPEG_SRCS})
ADD_LIBRARY(${OPJ_PREFIX}openjp3dvm ${JP3DVM_SRCS})
SET_TARGET_PROPERTIES(${OPJ_PREFIX}openjp3dvm
# Build the static library
IF(WIN32)
ADD_DEFINITIONS(-DOPJ_STATIC)
ENDIF(WIN32)
ADD_LIBRARY(${OPENJPEG_LIBRARY_NAME}_JP3D.static STATIC ${JP3DVM_SRCS})
SET_TARGET_PROPERTIES(${OPENJPEG_LIBRARY_NAME}_JP3D.static PROPERTIES OUTPUT_NAME ${OPENJPEG_LIBRARY_NAME}_JP3D)
SET_TARGET_PROPERTIES(${OPENJPEG_LIBRARY_NAME}_JP3D.static
PROPERTIES
VERSION 1.3.0
SOVERSION 1)
IF(LCMS_LIB)
TARGET_LINK_LIBRARIES(${OPENJPEG_LIBRARY_NAME}_JP3D.static ${LCMS_LIB})
ENDIF(LCMS_LIB)
# Install library
INSTALL_TARGETS(/lib/ ${OPJ_PREFIX}openjp3dvm)
INSTALL(TARGETS ${OPENJPEG_LIBRARY_NAME}_JP3D.static
DESTINATION ${OPENJPEG_INSTALL_LIB_DIR} COMPONENT Libraries
)
# If BUILD_SHARED_LIBS is ON, also build the shared library
IF(BUILD_SHARED_LIBS)
# replace flag for static build with flag for shared build
IF(WIN32)
REMOVE_DEFINITIONS(-DOPJ_STATIC)
ADD_DEFINITIONS(-DOPJ_EXPORTS)
ENDIF(WIN32)
# Create the shared library
ADD_LIBRARY(${OPENJPEG_LIBRARY_NAME}_JP3D.shared SHARED ${JP3DVM_SRCS})
SET_TARGET_PROPERTIES(${OPENJPEG_LIBRARY_NAME}_JP3D.shared PROPERTIES OUTPUT_NAME ${OPENJPEG_LIBRARY_NAME}_JP3D)
SET_TARGET_PROPERTIES(${OPENJPEG_LIBRARY_NAME}_JP3D.shared
PROPERTIES
VERSION 1.3.0
SOVERSION 1)
IF(LCMS_LIB)
TARGET_LINK_LIBRARIES(${OPENJPEG_LIBRARY_NAME}_JP3D.shared ${LCMS_LIB})
ENDIF(LCMS_LIB)
# Install library
INSTALL(TARGETS ${OPENJPEG_LIBRARY_NAME}_JP3D.shared
DESTINATION ${OPENJPEG_INSTALL_LIB_DIR} COMPONENT Libraries
)
IF(WIN32)
REMOVE_DEFINITIONS(-DOPJ_EXPORTS)
ENDIF(WIN32)
ENDIF(BUILD_SHARED_LIBS)
# Install includes files
INSTALL(FILES openjpeg.h

View File

@ -33,19 +33,51 @@ IF(DONT_HAVE_GETOPT)
)
ENDIF(DONT_HAVE_GETOPT)
ADD_LIBRARY(openjpeg_JPWL ${JPWL_SRCS} ${OPJ_SRCS})
SET_TARGET_PROPERTIES(openjpeg_JPWL PROPERTIES
${OPENJPEG_LIBRARY_PROPERTIES})
IF(LCMS_INCLUDE_DIR)
INCLUDE_DIRECTORIES( ${LCMS_INCLUDE_DIR} )
ENDIF(LCMS_INCLUDE_DIR)
INSTALL(TARGETS openjpeg_JPWL
# Build the static library
IF(WIN32)
ADD_DEFINITIONS(-DOPJ_STATIC)
ENDIF(WIN32)
ADD_LIBRARY(${OPENJPEG_LIBRARY_NAME}_JPWL.static STATIC ${JPWL_SRCS} ${OPJ_SRCS})
SET_TARGET_PROPERTIES(${OPENJPEG_LIBRARY_NAME}_JPWL.static PROPERTIES OUTPUT_NAME ${OPENJPEG_LIBRARY_NAME}_JPWL)
SET_TARGET_PROPERTIES(${OPENJPEG_LIBRARY_NAME}_JPWL.static PROPERTIES ${OPENJPEG_LIBRARY_PROPERTIES})
IF(LCMS_LIB)
TARGET_LINK_LIBRARIES(${OPENJPEG_LIBRARY_NAME}_JPWL.static ${LCMS_LIB})
ENDIF(LCMS_LIB)
# Install library
INSTALL(TARGETS ${OPENJPEG_LIBRARY_NAME}_JPWL.static
DESTINATION ${OPENJPEG_INSTALL_LIB_DIR} COMPONENT Libraries
)
# If BUILD_SHARED_LIBS is ON, also build the shared library
IF(BUILD_SHARED_LIBS)
# replace flag for static build with flag for shared build
IF(WIN32)
REMOVE_DEFINITIONS(-DOPJ_STATIC)
ADD_DEFINITIONS(-DOPJ_EXPORTS)
ENDIF(WIN32)
# Create the shared library
ADD_LIBRARY(${OPENJPEG_LIBRARY_NAME}_JPWL.shared SHARED ${JPWL_SRCS} ${OPJ_SRCS})
SET_TARGET_PROPERTIES(${OPENJPEG_LIBRARY_NAME}_JPWL.shared PROPERTIES OUTPUT_NAME ${OPENJPEG_LIBRARY_NAME}_JPWL)
SET_TARGET_PROPERTIES(${OPENJPEG_LIBRARY_NAME}_JPWL.shared PROPERTIES ${OPENJPEG_LIBRARY_PROPERTIES})
IF(LCMS_LIB)
TARGET_LINK_LIBRARIES(${OPENJPEG_LIBRARY_NAME}_JPWL.shared ${LCMS_LIB})
ENDIF(LCMS_LIB)
# Install library
INSTALL(TARGETS ${OPENJPEG_LIBRARY_NAME}_JPWL.shared
DESTINATION ${OPENJPEG_INSTALL_LIB_DIR} COMPONENT Libraries
)
IF(WIN32)
REMOVE_DEFINITIONS(-DOPJ_EXPORTS)
ENDIF(WIN32)
ENDIF(BUILD_SHARED_LIBS)
# Do the proper thing when building static...if only there was configured
# headers or def files instead
IF(NOT BUILD_SHARED_LIBS)
ADD_DEFINITIONS(-DOPJ_STATIC)
ENDIF(NOT BUILD_SHARED_LIBS)
ADD_DEFINITIONS(-DOPJ_STATIC)
INCLUDE_DIRECTORIES(
${OPENJPEG_SOURCE_DIR}/libopenjpeg
@ -64,7 +96,7 @@ ADD_EXECUTABLE(JPWL_j2k_to_image
../codec/index.c
../codec/j2k_to_image.c
)
TARGET_LINK_LIBRARIES(JPWL_j2k_to_image ${OPJ_PREFIX}openjpeg_JPWL ${LCMS_LIB})
TARGET_LINK_LIBRARIES(JPWL_j2k_to_image ${OPENJPEG_LIBRARY_NAME}_JPWL.static ${LCMS_LIB})
IF(PNG_FOUND)
TARGET_LINK_LIBRARIES(JPWL_j2k_to_image ${PNG_LIBRARIES})
ENDIF(PNG_FOUND)
@ -81,7 +113,7 @@ ADD_EXECUTABLE(JPWL_image_to_j2k
../codec/index.c
../codec/image_to_j2k.c
)
TARGET_LINK_LIBRARIES(JPWL_image_to_j2k ${OPJ_PREFIX}openjpeg_JPWL ${LCMS_LIB})
TARGET_LINK_LIBRARIES(JPWL_image_to_j2k ${OPENJPEG_LIBRARY_NAME}_JPWL.static ${LCMS_LIB})
IF(PNG_FOUND)
TARGET_LINK_LIBRARIES(JPWL_image_to_j2k ${PNG_LIBRARIES})
ENDIF(PNG_FOUND)

View File

@ -21,31 +21,51 @@ SET(OPENJPEG_SRCS
tgt.c
opj_convert.c
)
IF(LCMS_INCLUDE_DIR)
INCLUDE_DIRECTORIES( ${LCMS_INCLUDE_DIR} )
ENDIF(LCMS_INCLUDE_DIR)
# Pass proper definition to preprocessor to generate shared lib
IF(WIN32)
IF(BUILD_SHARED_LIBS)
ADD_DEFINITIONS(-DOPJ_EXPORTS)
ELSE(BUILD_SHARED_LIBS)
ADD_DEFINITIONS(-DOPJ_STATIC)
ENDIF(BUILD_SHARED_LIBS)
ENDIF(WIN32)
# Create the library
ADD_LIBRARY(${OPENJPEG_LIBRARY_NAME} ${OPENJPEG_SRCS})
SET_TARGET_PROPERTIES(${OPENJPEG_LIBRARY_NAME} PROPERTIES
${OPENJPEG_LIBRARY_PROPERTIES})
# Build the static library
IF(WIN32)
ADD_DEFINITIONS(-DOPJ_STATIC)
ENDIF(WIN32)
ADD_LIBRARY(${OPENJPEG_LIBRARY_NAME}.static STATIC ${OPENJPEG_SRCS})
SET_TARGET_PROPERTIES(${OPENJPEG_LIBRARY_NAME}.static PROPERTIES OUTPUT_NAME ${OPENJPEG_LIBRARY_NAME})
SET_TARGET_PROPERTIES(${OPENJPEG_LIBRARY_NAME}.static PROPERTIES ${OPENJPEG_LIBRARY_PROPERTIES})
IF(LCMS_LIB)
TARGET_LINK_LIBRARIES(${OPENJPEG_LIBRARY_NAME} ${LCMS_LIB})
TARGET_LINK_LIBRARIES(${OPENJPEG_LIBRARY_NAME}.static ${LCMS_LIB})
ENDIF(LCMS_LIB)
# Install library
INSTALL(TARGETS ${OPENJPEG_LIBRARY_NAME}
INSTALL(TARGETS ${OPENJPEG_LIBRARY_NAME}.static
EXPORT OpenJPEGTargets
DESTINATION ${OPENJPEG_INSTALL_LIB_DIR} COMPONENT Libraries
)
# If BUILD_SHARED_LIBS is ON, also build the shared library
IF(BUILD_SHARED_LIBS)
# replace flag for static build with flag for shared build
IF(WIN32)
REMOVE_DEFINITIONS(-DOPJ_STATIC)
ADD_DEFINITIONS(-DOPJ_EXPORTS)
ENDIF(WIN32)
# Create the shared library
ADD_LIBRARY(${OPENJPEG_LIBRARY_NAME}.shared SHARED ${OPENJPEG_SRCS})
SET_TARGET_PROPERTIES(${OPENJPEG_LIBRARY_NAME}.shared PROPERTIES OUTPUT_NAME ${OPENJPEG_LIBRARY_NAME})
SET_TARGET_PROPERTIES(${OPENJPEG_LIBRARY_NAME}.shared PROPERTIES ${OPENJPEG_LIBRARY_PROPERTIES})
IF(LCMS_LIB)
TARGET_LINK_LIBRARIES(${OPENJPEG_LIBRARY_NAME}.shared ${LCMS_LIB})
ENDIF(LCMS_LIB)
# Install library
INSTALL(TARGETS ${OPENJPEG_LIBRARY_NAME}.shared
EXPORT OpenJPEGTargets
DESTINATION ${OPENJPEG_INSTALL_LIB_DIR} COMPONENT Libraries
)
IF(WIN32)
REMOVE_DEFINITIONS(-DOPJ_EXPORTS)
ENDIF(WIN32)
ENDIF(BUILD_SHARED_LIBS)
# Install includes files
INSTALL(FILES openjpeg.h
DESTINATION ${OPENJPEG_INSTALL_INCLUDE_DIR}/${subdir} COMPONENT Headers

View File

@ -9,9 +9,7 @@ INCLUDE_DIRECTORIES(
# Do the proper thing when building static...if only there was configured
# headers or def files instead
IF(NOT BUILD_SHARED_LIBS)
ADD_DEFINITIONS(-DOPJ_STATIC)
ENDIF(NOT BUILD_SHARED_LIBS)
ADD_DEFINITIONS(-DOPJ_STATIC)
ADD_EXECUTABLE(frames_to_mj2
frames_to_mj2.c
@ -19,7 +17,7 @@ ADD_EXECUTABLE(frames_to_mj2
mj2_convert.c
mj2.c
)
TARGET_LINK_LIBRARIES(frames_to_mj2 ${OPJ_PREFIX}openjpeg ${LCMS_LIB})
TARGET_LINK_LIBRARIES(frames_to_mj2 ${OPENJPEG_LIBRARY_NAME}.static ${LCMS_LIB})
IF(UNIX)
TARGET_LINK_LIBRARIES(frames_to_mj2 m)
ENDIF(UNIX)
@ -30,7 +28,7 @@ ADD_EXECUTABLE(mj2_to_frames
mj2_convert.c
mj2.c
)
TARGET_LINK_LIBRARIES(mj2_to_frames ${OPJ_PREFIX}openjpeg ${LCMS_LIB})
TARGET_LINK_LIBRARIES(mj2_to_frames ${OPENJPEG_LIBRARY_NAME}.static ${LCMS_LIB})
IF(UNIX)
TARGET_LINK_LIBRARIES(mj2_to_frames m)
ENDIF(UNIX)
@ -38,7 +36,7 @@ ENDIF(UNIX)
ADD_EXECUTABLE(extract_j2k_from_mj2
extract_j2k_from_mj2.c
mj2.c )
TARGET_LINK_LIBRARIES(extract_j2k_from_mj2 ${OPJ_PREFIX}openjpeg ${LCMS_LIB})
TARGET_LINK_LIBRARIES(extract_j2k_from_mj2 ${OPENJPEG_LIBRARY_NAME}.static ${LCMS_LIB})
IF(UNIX)
TARGET_LINK_LIBRARIES(extract_j2k_from_mj2 m)
ENDIF(UNIX)
@ -46,7 +44,7 @@ ENDIF(UNIX)
ADD_EXECUTABLE(wrap_j2k_in_mj2
wrap_j2k_in_mj2.c
mj2.c )
TARGET_LINK_LIBRARIES(wrap_j2k_in_mj2 ${OPJ_PREFIX}openjpeg ${LCMS_LIB})
TARGET_LINK_LIBRARIES(wrap_j2k_in_mj2 ${OPENJPEG_LIBRARY_NAME}.static ${LCMS_LIB})
IF(UNIX)
TARGET_LINK_LIBRARIES(wrap_j2k_in_mj2 m)
ENDIF(UNIX)