diff --git a/IlmBase/CMakeLists.txt b/IlmBase/CMakeLists.txt index e04255f8..b349d562 100644 --- a/IlmBase/CMakeLists.txt +++ b/IlmBase/CMakeLists.txt @@ -3,6 +3,9 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8) PROJECT ( ILMBase ) +# Allow the developer to select if Dynamic or Static libraries are built +OPTION (BUILD_SHARED_LIBS "Build Shared Libraries" ON) + IF ( NOT WIN32) ADD_DEFINITIONS ( -pthread ) ENDIF () @@ -59,6 +62,14 @@ MACRO(GET_TARGET_PROPERTY_WITH_DEFAULT _variable _target _property _default_valu INSTALL( FILES ${_laname} DESTINATION ${CMAKE_INSTALL_PREFIX}${_install_DIR}) ENDMACRO(CREATE_LIBTOOL_FILE) +SET (LIB_TYPE STATIC) +IF (BUILD_SHARED_LIBS) + # User wants to build Dynamic Libraries, so change the LIB_TYPE variable to CMake keyword 'SHARED' + SET (LIB_TYPE SHARED) + ADD_DEFINITIONS(-DOPENEXR_DLL) +ENDIF (BUILD_SHARED_LIBS) + + ADD_SUBDIRECTORY ( Half ) ADD_SUBDIRECTORY ( Iex ) ADD_SUBDIRECTORY ( IexMath ) diff --git a/IlmBase/Half/CMakeLists.txt b/IlmBase/Half/CMakeLists.txt index 3b97d7e1..50ebe966 100644 --- a/IlmBase/Half/CMakeLists.txt +++ b/IlmBase/Half/CMakeLists.txt @@ -32,7 +32,11 @@ SET_SOURCE_FILES_PROPERTIES( ${CMAKE_CURRENT_SOURCE_DIR}/toFloat.h ) -ADD_LIBRARY ( Half STATIC +IF(BUILD_SHARED_LIBS) + ADD_DEFINITIONS(-DHALF_EXPORTS) +ENDIF() + +ADD_LIBRARY ( Half ${LIB_TYPE} half.cpp ) diff --git a/IlmBase/Half/halfExport.h b/IlmBase/Half/halfExport.h index c6bb7152..3a0c86a2 100644 --- a/IlmBase/Half/halfExport.h +++ b/IlmBase/Half/halfExport.h @@ -11,28 +11,16 @@ // This copyright notice does not imply publication. // -#if defined(PLATFORM_WINDOWS) -# if defined(PLATFORM_BUILD_STATIC) -# define PLATFORM_EXPORT_DEFINITION -# define PLATFORM_IMPORT_DEFINITION -# else -# define PLATFORM_EXPORT_DEFINITION __declspec(dllexport) -# define PLATFORM_IMPORT_DEFINITION __declspec(dllimport) -# endif -#else // linux/macos -# if defined(PLATFORM_VISIBILITY_AVAILABLE) -# define PLATFORM_EXPORT_DEFINITION __attribute__((visibility("default"))) -# define PLATFORM_IMPORT_DEFINITION -# else -# define PLATFORM_EXPORT_DEFINITION -# define PLATFORM_IMPORT_DEFINITION -# endif -#endif - -#if defined(HALF_EXPORTS) // create library -# define HALF_EXPORT PLATFORM_EXPORT_DEFINITION -#else // use library -# define HALF_EXPORT PLATFORM_IMPORT_DEFINITION +#if defined(OPENEXR_DLL) + #if defined(HALF_EXPORTS) + #define HALF_EXPORT __declspec(dllexport) + #else + #define HALF_EXPORT __declspec(dllimport) + #endif + #define HALF_EXPORT_CONST +#else + #define HALF_EXPORT + #define HALF_EXPORT_CONST const #endif #endif // #ifndef HALFEXPORT_H diff --git a/IlmBase/Imath/CMakeLists.txt b/IlmBase/Imath/CMakeLists.txt index a4f471f6..afea1fad 100644 --- a/IlmBase/Imath/CMakeLists.txt +++ b/IlmBase/Imath/CMakeLists.txt @@ -1,6 +1,10 @@ # yue.nicholas@gmail.com -ADD_LIBRARY ( Imath STATIC +IF(BUILD_SHARED_LIBS) + ADD_DEFINITIONS(-DIMATH_EXPORTS) +ENDIF() + +ADD_LIBRARY ( Imath ${LIB_TYPE} ImathBox.cpp ImathRandom.cpp ImathColorAlgo.cpp @@ -9,6 +13,8 @@ ADD_LIBRARY ( Imath STATIC ImathVec.cpp ImathMatrixAlgo.cpp ) +TARGET_LINK_LIBRARIES(Imath Iex) + INSTALL ( TARGETS Imath