2a156e
--- CMakeLists.txt	2010-02-19 19:18:30.000000000 +0100
2a156e
+++ CMakeLists2.txt	2010-02-19 19:21:51.000000000 +0100
2a156e
@@ -197,7 +197,7 @@
2a156e
 
2a156e
 IF(NOT GDCM_INSTALL_LIB_DIR)
2a156e
   #SET(GDCM_INSTALL_LIB_DIR "lib/${PROJECT_NAME}")
2a156e
-  SET(GDCM_INSTALL_LIB_DIR "lib")
2a156e
+  SET(GDCM_INSTALL_LIB_DIR "lib${LIB_SUFFIX}")
2a156e
 ENDIF(NOT GDCM_INSTALL_LIB_DIR)
2a156e
 
2a156e
 IF(NOT GDCM_INSTALL_DATA_DIR)
2a156e
@@ -261,6 +261,11 @@
2a156e
 OPTION(GDCM_USE_SYSTEM_EXPAT "Use system expat" OFF)
2a156e
 OPTION(GDCM_USE_SYSTEM_LJPEG "Use system ljpeg (ijg lib)" OFF)
2a156e
 OPTION(GDCM_USE_SYSTEM_OPENJPEG "Use system openjpeg (1.x)" OFF)
2a156e
+IF(GDCM_USE_JPEGLS)
2a156e
+   OPTION(GDCM_USE_SYSTEM_JPEGLS "Use system JPEGLS (CharLS)" OFF)
2a156e
+   MARK_AS_ADVANCED(GDCM_USE_SYSTEM_JPEGLS)
2a156e
+ENDIF(GDCM_USE_JPEGLS)
2a156e
+
2a156e
 MARK_AS_ADVANCED(GDCM_USE_SYSTEM_ZLIB GDCM_USE_SYSTEM_UUID GDCM_USE_SYSTEM_EXPAT GDCM_USE_SYSTEM_OPENSSL)
2a156e
 MARK_AS_ADVANCED(GDCM_USE_SYSTEM_OPENJPEG GDCM_USE_SYSTEM_LJPEG)
2a156e
 OPTION(GDCM_USE_SYSTEM_POPPLER "Use system poppler (pdf)" OFF)
2a156e
@@ -283,6 +288,14 @@
2a156e
   SET(GDCM_OPENJPEG_LIBRARIES gdcmopenjpeg)
2a156e
 ENDIF(GDCM_USE_SYSTEM_OPENJPEG)
2a156e
 
2a156e
+IF(GDCM_USE_SYSTEM_JPEGLS)
2a156e
+  FIND_PACKAGE(CharLS REQUIRED)
2a156e
+  SET(GDCM_CHARLS_LIBRARIES ${CHARLS_LIBRARIES})
2a156e
+ELSE(GDCM_USE_SYSTEM_JPEGLS)
2a156e
+  SET(GDCM_CHARLS_LIBRARIES gdcmcharls)
2a156e
+ENDIF(GDCM_USE_SYSTEM_JPEGLS)
2a156e
+
2a156e
+
2a156e
 # Very advanced user option:
2a156e
 # This will cause building of the broken JPEG library released by the Standford PVRG group:
2a156e
 OPTION(GDCM_USE_PVRG "Use pvrg lib, only turn it on if you know what you are doing." OFF)
2a156e
2a156e
--- Utilities/CMakeLists.txt	2009-11-12 23:09:48.000000000 +0100
2a156e
+++ Utilities/CMakeLists2.txt	2010-02-19 19:21:59.000000000 +0100
2a156e
@@ -35,12 +35,14 @@
2a156e
 # Do jpegls (JPEG-LS aka near lossless implementation)
2a156e
 APPEND_COPYRIGHT(${CMAKE_CURRENT_SOURCE_DIR}/gdcmcharls/License.txt)
2a156e
 IF(GDCM_USE_JPEGLS)
2a156e
-  SET(CHARLS_NAMESPACE "GDCMCHARLS")
2a156e
-  SET(CHARLS_INSTALL_NO_LIBRARIES ${GDCM_INSTALL_NO_LIBRARIES})
2a156e
-  SET(CHARLS_INSTALL_BIN_DIR      ${GDCM_INSTALL_BIN_DIR})
2a156e
-  SET(CHARLS_INSTALL_LIB_DIR      ${GDCM_INSTALL_LIB_DIR})
2a156e
-  SET(CHARLS_INSTALL_INCLUDE_DIR  ${GDCM_INSTALL_INCLUDE_DIR})
2a156e
-  SUBDIRS(gdcmcharls)
2a156e
+  IF(NOT GDCM_USE_SYSTEM_JPEGLS)
2a156e
+    SET(CHARLS_NAMESPACE "GDCMCHARLS")
2a156e
+    SET(CHARLS_INSTALL_NO_LIBRARIES ${GDCM_INSTALL_NO_LIBRARIES})
2a156e
+    SET(CHARLS_INSTALL_BIN_DIR      ${GDCM_INSTALL_BIN_DIR})
2a156e
+    SET(CHARLS_INSTALL_LIB_DIR      ${GDCM_INSTALL_LIB_DIR})
2a156e
+    SET(CHARLS_INSTALL_INCLUDE_DIR  ${GDCM_INSTALL_INCLUDE_DIR})
2a156e
+    SUBDIRS(gdcmcharls)
2a156e
+  ENDIF(NOT GDCM_USE_SYSTEM_JPEGLS)
2a156e
 ENDIF(GDCM_USE_JPEGLS)
2a156e
 
2a156e
 # Do md5
2a156e
--- Source/MediaStorageAndFileFormat/CMakeLists.txt	2009-11-12 23:09:48.000000000 +0100
2a156e
+++ Source/MediaStorageAndFileFormat/CMakeLists2.txt	2010-02-19 19:22:23.000000000 +0100
2a156e
@@ -132,7 +132,7 @@
2a156e
 TARGET_LINK_LIBRARIES(gdcmMSFF gdcmIOD gdcmDSED gdcmDICT ${GDCM_LJPEG_LIBRARIES} ${GDCM_OPENJPEG_LIBRARIES})
2a156e
 SET_TARGET_PROPERTIES(gdcmMSFF PROPERTIES ${GDCM_LIBRARY_PROPERTIES} LINK_INTERFACE_LIBRARIES "gdcmDSED;gdcmDICT;gdcmIOD")
2a156e
 IF(GDCM_USE_JPEGLS)
2a156e
-  TARGET_LINK_LIBRARIES(gdcmMSFF gdcmcharls)
2a156e
+  TARGET_LINK_LIBRARIES(gdcmMSFF ${GDCM_CHARLS_LIBRARIES})
2a156e
 ENDIF(GDCM_USE_JPEGLS)
2a156e
 
2a156e
 IF(CMAKE_COMPILER_IS_GNUCXX AND MINGW)
2a156e
--- Source/MediaStorageAndFileFormat/gdcmJPEGLSCodec.cxx	2009-11-12 23:09:48.000000000 +0100
2a156e
+++ Source/MediaStorageAndFileFormat/gdcmJPEGLSCodec2.cxx	2010-02-19 19:22:09.000000000 +0100
2a156e
@@ -18,6 +18,16 @@
2a156e
 #include "gdcmDataElement.h"
2a156e
 
2a156e
 // CharLS includes
2a156e
+#ifdef GDCM_USE_SYSTEM_EXPAT
2a156e
+#include "CharLS/stdafx.h" // sigh...
2a156e
+#include "CharLS/interface.h"
2a156e
+#include "CharLS/util.h"
2a156e
+#include "CharLS/defaulttraits.h"
2a156e
+#include "CharLS/losslesstraits.h"
2a156e
+#include "CharLS/colortransform.h"
2a156e
+#include "CharLS/streams.h"
2a156e
+#include "CharLS/processline.h"
2a156e
+#else
2a156e
 #include "gdcmcharls/stdafx.h" // sigh...
2a156e
 #include "gdcmcharls/interface.h"
2a156e
 #include "gdcmcharls/util.h"
2a156e
@@ -26,6 +36,8 @@
2a156e
 #include "gdcmcharls/colortransform.h"
2a156e
 #include "gdcmcharls/streams.h"
2a156e
 #include "gdcmcharls/processline.h"
2a156e
+#endif
2a156e
+
2a156e
 
2a156e
 
2a156e
 namespace gdcm