Skip to content

Commit

Permalink
Usability improvements for submodule use.
Browse files Browse the repository at this point in the history
* Make all installation code conditional
* Add OPENEXR_INSTALL for the base library, and OPENEXR_INSTALL_TOOLS
  which can be used to disable installing the tools
* Improve ZLIB search logic -- if a ZLIB::ZLIB target is present, use
  that and skip searching for the ZLIB library
* Rename INSTALL_OPENEXR* to OPENEXR_INSTALL*
  • Loading branch information
Anteru committed Mar 8, 2021
1 parent 7671225 commit efc902d
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 33 deletions.
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,17 @@ set(OpenEXR_DIR "${CMAKE_CURRENT_BINARY_DIR}/cmake" CACHE PATH "" FORCE)
# Can be empty since we already defined the targets in add_subdirectory
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cmake/OpenEXRTargets.cmake" "# Dummy file")

option(INSTALL_OPENEXR_EXAMPLES "Install OpenEXR examples" ON)
if(INSTALL_OPENEXR_EXAMPLES)
option(OPENEXR_INSTALL_EXAMPLES "Install OpenEXR examples" ON)
if(OPENEXR_INSTALL_EXAMPLES)
add_subdirectory( src/examples )
endif()

option(OPENEXR_INSTALL "Install OpenEXR libraries" ON)
option(OPENEXR_INSTALL_TOOLS "Install OpenEXR tools" ON)
if(OPENEXR_INSTALL_TOOLS AND NOT OPENEXR_INSTALL)
message(SEND_ERROR "OPENEXR_INSTALL_TOOLS requires OPENEXR_INSTALL")
endif()

# If you want to use ctest to configure, build and
# upload the results, cmake has builtin support for
# submitting to CDash, or any server who speaks the
Expand Down
18 changes: 15 additions & 3 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@ endif()
configure_file(OpenEXRConfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/OpenEXRConfig.h)
configure_file(OpenEXRConfigInternal.h.in ${CMAKE_CURRENT_BINARY_DIR}/OpenEXRConfigInternal.h)

if(OPENEXR_INSTALL)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/OpenEXRConfig.h
DESTINATION
${CMAKE_INSTALL_INCLUDEDIR}/${OPENEXR_OUTPUT_SUBDIR}
)
endif()

###################################################
####### IexConfig.h and IexConfigInternal.h
Expand Down Expand Up @@ -119,6 +121,7 @@ configure_file(IlmThreadConfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/IlmThreadConfig.
###################################################
####### Install public config headers

if(OPENEXR_INSTALL)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/OpenEXRConfig.h
Expand All @@ -127,6 +130,7 @@ install(
DESTINATION
${CMAKE_INSTALL_INCLUDEDIR}/${OPENEXR_OUTPUT_SUBDIR}
)
endif()

###################################################
####### Interface libraries for configs
Expand All @@ -137,7 +141,9 @@ target_include_directories(OpenEXRConfig INTERFACE
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${OPENEXR_OUTPUT_SUBDIR}>)

install(TARGETS OpenEXRConfig EXPORT ${PROJECT_NAME})
if(OPENEXR_INSTALL)
install(TARGETS OpenEXRConfig EXPORT ${PROJECT_NAME})
endif()
add_library(${PROJECT_NAME}::Config ALIAS OpenEXRConfig)

add_library(IexConfig INTERFACE)
Expand All @@ -146,7 +152,9 @@ target_include_directories(IexConfig INTERFACE
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${OPENEXR_OUTPUT_SUBDIR}>)

install(TARGETS IexConfig EXPORT ${PROJECT_NAME})
if(OPENEXR_INSTALL)
install(TARGETS IexConfig EXPORT ${PROJECT_NAME})
endif()
add_library(${PROJECT_NAME}::Config ALIAS IexConfig)

add_library(IlmThreadConfig INTERFACE)
Expand All @@ -155,7 +163,9 @@ target_include_directories(IlmThreadConfig INTERFACE
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${OPENEXR_OUTPUT_SUBDIR}>)

install(TARGETS IlmThreadConfig EXPORT ${PROJECT_NAME})
if(OPENEXR_INSTALL)
install(TARGETS IlmThreadConfig EXPORT ${PROJECT_NAME})
endif()
add_library(${PROJECT_NAME}::Config ALIAS IlmThreadConfig)

###################################################
Expand Down Expand Up @@ -204,6 +214,7 @@ endif()
# and replaces the Find*.cmake of the "old" cmake
include(CMakePackageConfigHelpers)

if(OPENEXR_INSTALL)
configure_package_config_file(${PROJECT_NAME}Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
Expand All @@ -224,3 +235,4 @@ install(EXPORT ${PROJECT_NAME}
NAMESPACE ${PROJECT_NAME}::
EXPORT_LINK_INTERFACE_LIBRARIES
)
endif()
20 changes: 11 additions & 9 deletions cmake/LibraryDefine.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,17 @@ function(OPENEXR_DEFINE_LIBRARY libname)
)
add_library(${PROJECT_NAME}::${libname} ALIAS ${libname})

install(TARGETS ${libname}
EXPORT ${PROJECT_NAME}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
PUBLIC_HEADER
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${OPENEXR_OUTPUT_SUBDIR}
)
if(OPENEXR_INSTALL)
install(TARGETS ${libname}
EXPORT ${PROJECT_NAME}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
PUBLIC_HEADER
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${OPENEXR_OUTPUT_SUBDIR}
)
endif()
if(BUILD_SHARED_LIBS AND (NOT "${OPENEXR_LIB_SUFFIX}" STREQUAL "") AND NOT WIN32)
set(verlibname ${CMAKE_SHARED_LIBRARY_PREFIX}${libname}${OPENEXR_LIB_SUFFIX}${CMAKE_SHARED_LIBRARY_SUFFIX})
set(baselibname ${CMAKE_SHARED_LIBRARY_PREFIX}${libname}${CMAKE_SHARED_LIBRARY_SUFFIX})
Expand Down
20 changes: 11 additions & 9 deletions cmake/OpenEXRLibraryDefine.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,17 @@ function(OPENEXR_DEFINE_LIBRARY libname)
)
add_library(${PROJECT_NAME}::${libname} ALIAS ${libname})

install(TARGETS ${libname}
EXPORT ${PROJECT_NAME}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
PUBLIC_HEADER
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${OPENEXR_OUTPUT_SUBDIR}
)
if(OPENEXR_INSTALL)
install(TARGETS ${libname}
EXPORT ${PROJECT_NAME}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
PUBLIC_HEADER
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${OPENEXR_OUTPUT_SUBDIR}
)
endif()
if(BUILD_SHARED_LIBS AND (NOT "${OPENEXR_LIB_SUFFIX}" STREQUAL "") AND NOT WIN32)
set(verlibname ${CMAKE_SHARED_LIBRARY_PREFIX}${libname}${OPENEXR_LIB_SUFFIX}${CMAKE_SHARED_LIBRARY_SUFFIX})
set(baselibname ${CMAKE_SHARED_LIBRARY_PREFIX}${libname}${CMAKE_SHARED_LIBRARY_SUFFIX})
Expand Down
6 changes: 4 additions & 2 deletions cmake/OpenEXRSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,11 @@ endif()

option(OPENEXR_FORCE_INTERNAL_ZLIB "Force using an internal zlib" OFF)
if (NOT OPENEXR_FORCE_INTERNAL_ZLIB)
find_package(ZLIB QUIET)
if(NOT TARGET ZLIB::ZLIB)
find_package(ZLIB QUIET)
endif()
endif()
if(OPENEXR_FORCE_INTERNAL_ZLIB OR NOT ZLIB_FOUND)
if(OPENEXR_FORCE_INTERNAL_ZLIB OR NOT TARGET ZLIB::ZLIB)
set(zlib_VER "1.2.11")
if(OPENEXR_FORCE_INTERNAL_ZLIB)
message(STATUS "Compiling internal copy of zlib version ${zlib_VER}")
Expand Down
4 changes: 3 additions & 1 deletion src/bin/exr2aces/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ target_link_libraries(exr2aces OpenEXR::OpenEXR)
set_target_properties(exr2aces PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
install(TARGETS exr2aces DESTINATION ${CMAKE_INSTALL_BINDIR})
if(OPENEXR_INSTALL_TOOLS)
install(TARGETS exr2aces DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
if(WIN32 AND BUILD_SHARED_LIBS)
target_compile_definitions(exr2aces PRIVATE OPENEXR_DLL)
endif()
4 changes: 3 additions & 1 deletion src/bin/exrenvmap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ target_link_libraries(exrenvmap OpenEXR::OpenEXR)
set_target_properties(exrenvmap PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
install(TARGETS exrenvmap DESTINATION ${CMAKE_INSTALL_BINDIR})
if(OPENEXR_INSTALL_TOOLS)
install(TARGETS exrenvmap DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
if(WIN32 AND BUILD_SHARED_LIBS)
target_compile_definitions(exrenvmap PRIVATE OPENEXR_DLL)
endif()
4 changes: 3 additions & 1 deletion src/bin/exrheader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ target_link_libraries(exrheader OpenEXR::OpenEXR)
set_target_properties(exrheader PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
install(TARGETS exrheader DESTINATION ${CMAKE_INSTALL_BINDIR})
if(OPENEXR_INSTALL_TOOLS)
install(TARGETS exrheader DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
if(WIN32 AND BUILD_SHARED_LIBS)
target_compile_definitions(exrheader PRIVATE OPENEXR_DLL)
endif()
4 changes: 3 additions & 1 deletion src/bin/exrmakepreview/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ target_link_libraries(exrmakepreview OpenEXR::OpenEXR)
set_target_properties(exrmakepreview PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
install(TARGETS exrmakepreview DESTINATION ${CMAKE_INSTALL_BINDIR})
if(OPENEXR_INSTALL_TOOLS)
install(TARGETS exrmakepreview DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
if(WIN32 AND BUILD_SHARED_LIBS)
target_compile_definitions(exrmakepreview PRIVATE OPENEXR_DLL)
endif()
4 changes: 3 additions & 1 deletion src/bin/exrmaketiled/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ target_link_libraries(exrmaketiled OpenEXR::OpenEXR)
set_target_properties(exrmaketiled PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
install(TARGETS exrmaketiled DESTINATION ${CMAKE_INSTALL_BINDIR})
if(OPENEXR_INSTALL_TOOLS)
install(TARGETS exrmaketiled DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
if(WIN32 AND BUILD_SHARED_LIBS)
target_compile_definitions(exrmaketiled PRIVATE OPENEXR_DLL)
endif()
4 changes: 3 additions & 1 deletion src/bin/exrmultipart/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ target_link_libraries(exrmultipart OpenEXR::OpenEXR)
set_target_properties(exrmultipart PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
install(TARGETS exrmultipart DESTINATION ${CMAKE_INSTALL_BINDIR})
if(OPENEXR_INSTALL_TOOLS)
install(TARGETS exrmultipart DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
if(WIN32 AND BUILD_SHARED_LIBS)
target_compile_definitions(exrmultipart PRIVATE OPENEXR_DLL)
endif()
4 changes: 3 additions & 1 deletion src/bin/exrmultiview/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ target_link_libraries(exrmultiview OpenEXR::OpenEXR)
set_target_properties(exrmultiview PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
install(TARGETS exrmultiview DESTINATION ${CMAKE_INSTALL_BINDIR})
if(OPENEXR_INSTALL_TOOLS)
install(TARGETS exrmultiview DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
if(WIN32 AND BUILD_SHARED_LIBS)
target_compile_definitions(exrmultiview PRIVATE OPENEXR_DLL)
endif()
4 changes: 3 additions & 1 deletion src/bin/exrstdattr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ target_link_libraries(exrstdattr OpenEXR::OpenEXR)
set_target_properties(exrstdattr PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
install(TARGETS exrstdattr DESTINATION ${CMAKE_INSTALL_BINDIR})
if(OPENEXR_INSTALL_TOOLS)
install(TARGETS exrstdattr DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
if(WIN32 AND BUILD_SHARED_LIBS)
target_compile_definitions(exrstdattr PRIVATE OPENEXR_DLL)
endif()

0 comments on commit efc902d

Please sign in to comment.