Skip to content

Commit d7760db

Browse files
committed
Additional fixes to clean up use of LibRaw and install configuration
1 parent 76bd1cd commit d7760db

File tree

7 files changed

+190
-158
lines changed

7 files changed

+190
-158
lines changed

CMakeLists.txt

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,23 @@ add_executable( rawtoaces
8585
main.cpp
8686
)
8787

88-
target_include_directories( rawtoaces
89-
PUBLIC
88+
target_include_directories(rawtoaces
89+
PRIVATE
9090
${AcesContainer_INCLUDE_DIRS}
9191
)
9292

93-
target_link_libraries ( rawtoaces
94-
PUBLIC
93+
target_link_libraries(rawtoaces
94+
PRIVATE
9595
${RAWTOACESLIB}
96-
INTERFACE
97-
Boost::headers
96+
Boost::filesystem
97+
Boost::system
9898
)
9999

100100
if ( LIBRAW_CONFIG_FOUND )
101101
target_link_libraries ( rawtoaces PUBLIC libraw::raw )
102102
else ()
103-
target_link_directories(rawtoaces PUBLIC ${libraw_LIBRARY_DIRS} )
104-
target_link_libraries(rawtoaces PUBLIC ${libraw_LIBRARIES} ${libraw_LDFLAGS_OTHER} )
103+
target_link_directories(rawtoaces PUBLIC ${LibRaw_LIBRARY_DIRS} )
104+
target_link_libraries(rawtoaces PUBLIC ${LibRaw_LIBRARIES} ${LibRaw_LDFLAGS_OTHER} )
105105
endif ()
106106

107107
enable_testing()
@@ -131,15 +131,8 @@ configure_package_config_file(
131131
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
132132
)
133133

134-
install(
135-
TARGETS ${RAWTOACESIDTLIB} ${RAWTOACESLIB}
136-
EXPORT ${PROJECT_NAME}Targets
137-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
138-
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
139-
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
140-
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
141-
PUBLIC_HEADER
142-
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
134+
install(FILES cmake/modules/FindLibRaw.cmake
135+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}/modules
143136
)
144137

145138
install (

cmake/modules/FindlibRaw.cmake

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#
2+
# FindLibRaw.cmake - Locate LibRaw
3+
#
4+
# This will define:
5+
# LibRaw_FOUND - True if LibRaw was found
6+
# LibRaw_INCLUDE_DIRS - Include directories for LibRaw
7+
# LibRaw_LIBRARIES - Libraries to link against
8+
# LibRaw_VERSION - Detected version
9+
# And create imported target:
10+
# LibRaw::LibRaw
11+
#
12+
13+
find_package(PkgConfig QUIET)
14+
if(PKG_CONFIG_FOUND)
15+
pkg_check_modules(PC_LibRaw QUIET libraw)
16+
endif()
17+
18+
# Brew special handling for macOS
19+
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND PC_LibRaw_FOUND AND "${PC_LibRaw_INCLUDEDIR}" MATCHES ".*/Cellar/.*")
20+
set(_LibRaw_HINT_INCLUDE /usr/local/include)
21+
set(_LibRaw_HINT_LIB /usr/local/lib)
22+
endif()
23+
24+
# Hints from pkg-config
25+
if(PC_LibRaw_FOUND)
26+
set(LibRaw_CFLAGS ${PC_LibRaw_CFLAGS_OTHER})
27+
set(LibRaw_LIBRARY_DIRS ${PC_LibRaw_LIBRARY_DIRS})
28+
set(LibRaw_LDFLAGS ${PC_LibRaw_LDFLAGS_OTHER})
29+
if("${_LibRaw_HINT_INCLUDE}" STREQUAL "")
30+
set(_LibRaw_HINT_INCLUDE ${PC_LibRaw_INCLUDEDIR} ${PC_LibRaw_INCLUDE_DIRS})
31+
set(_LibRaw_HINT_LIB ${PC_LibRaw_LIBDIR} ${PC_LibRaw_LIBRARY_DIRS})
32+
endif()
33+
endif()
34+
35+
# Locate header
36+
find_path(LibRaw_INCLUDE_DIR libraw/libraw.h
37+
HINTS ${_LibRaw_HINT_INCLUDE}
38+
)
39+
# Detect version
40+
if(LibRaw_INCLUDE_DIR AND EXISTS "${LibRaw_INCLUDE_DIR}/libraw_version.h")
41+
file(STRINGS "${LibRaw_INCLUDE_DIR}/libraw_version.h" libraw_version_str
42+
REGEX "^#define[\t ]+LIBRAW_VERSION_STR[\t ]+\".*")
43+
string(REGEX REPLACE "^#define[\t ]+LIBRAW_VERSION_STR[\t ]+\"([^ \\n]*)\".*"
44+
"\\1" LibRaw_VERSION "${libraw_version_str}")
45+
endif()
46+
47+
# Locate library
48+
find_library(LibRaw_LIBRARY
49+
NAMES raw libraw
50+
HINTS ${_LibRaw_HINT_LIB}
51+
)
52+
53+
# Handle required variables
54+
include(FindPackageHandleStandardArgs)
55+
find_package_handle_standard_args(LibRaw
56+
REQUIRED_VARS LibRaw_LIBRARY LibRaw_INCLUDE_DIR
57+
VERSION_VAR LibRaw_VERSION
58+
)
59+
60+
# Set include and libs
61+
if(LibRaw_FOUND)
62+
set(LibRaw_INCLUDE_DIRS ${LibRaw_INCLUDE_DIR})
63+
set(LibRaw_LIBRARIES ${LibRaw_LIBRARY})
64+
65+
# Create imported target
66+
if(NOT TARGET LibRaw::LibRaw)
67+
add_library(LibRaw::LibRaw UNKNOWN IMPORTED)
68+
set_target_properties(LibRaw::LibRaw PROPERTIES
69+
IMPORTED_LOCATION "${LibRaw_LIBRARY}"
70+
INTERFACE_INCLUDE_DIRECTORIES "${LibRaw_INCLUDE_DIRS}"
71+
)
72+
endif()
73+
endif()
74+
75+
mark_as_advanced(LibRaw_INCLUDE_DIR LibRaw_LIBRARY)

cmake/modules/Findlibraw.cmake

Lines changed: 0 additions & 91 deletions
This file was deleted.

config/RAWTOACESConfig.cmake.in

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
@PACKAGE_INIT@
22

3+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/modules")
4+
35
# Find dependencies required by RawToAces
46
include ( CMakeFindDependencyMacro )
5-
find_dependency( Boost REQUIRED COMPONENTS headers system filesystem )
6-
find_dependency( Imath REQUIRED )
7+
find_dependency( Boost REQUIRED COMPONENTS filesystem system )
78
find_dependency( Eigen3 REQUIRED )
89
find_dependency( Ceres REQUIRED )
910

11+
find_package(LibRaw CONFIG QUIET)
12+
if(NOT LibRaw_FOUND)
13+
find_package(LibRaw MODULE REQUIRED)
14+
endif()
15+
1016
include( "${CMAKE_CURRENT_LIST_DIR}/@[email protected]" )
1117
check_required_components( "@PROJECT_NAME@" )

configure.cmake

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@ else ()
1919
find_package ( Ceres CONFIG REQUIRED )
2020
endif ()
2121

22-
find_package (libraw CONFIG QUIET )
22+
find_package (LibRaw CONFIG QUIET )
2323

24-
if (libraw_FOUND )
25-
message("STATUS LibRaw config found")
24+
if ( LibRaw_FOUND )
25+
message( "STATUS LibRaw config found" )
2626
set ( LIBRAW_CONFIG_FOUND TRUE )
2727
else ()
28-
message("WARNING LibRaw config not found, trying to find a module.")
29-
find_package(libraw MODULE REQUIRED)
28+
message( "WARNING LibRaw config not found, trying to find a module.")
29+
find_package( LibRaw MODULE REQUIRED )
30+
if (LibRaw_FOUND)
31+
message(STATUS "LibRaw found via module fallback")
32+
else()
33+
message(FATAL_ERROR "LibRaw could not be found even with module fallback")
34+
endif()
3035
endif ()

src/rawtoaces_idt/CMakeLists.txt

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,48 @@ include_directories( "${CMAKE_CURRENT_SOURCE_DIR}" )
33

44
add_library( ${RAWTOACESIDTLIB} ${DO_SHARED}
55
rta.cpp
6-
7-
# Make the headers visible in IDEs. This should not affect the builds.
86
../../include/rawtoaces/define.h
97
../../include/rawtoaces/mathOps.h
108
../../include/rawtoaces/rta.h
119
)
1210

11+
target_include_directories(${RAWTOACESIDTLIB}
12+
PUBLIC
13+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
14+
$<INSTALL_INTERFACE:include>
15+
)
16+
1317
target_link_libraries(
1418
${RAWTOACESIDTLIB}
1519
PUBLIC
16-
Boost::boost
17-
Boost::system
20+
Eigen3::Eigen
21+
)
22+
23+
target_link_libraries(${RAWTOACESIDTLIB}
24+
PRIVATE
25+
Eigen3::Eigen
1826
Boost::filesystem
27+
Boost::system
28+
)
29+
30+
if (TARGET libraw::raw)
31+
target_link_libraries(${RAWTOACESIDTLIB} PUBLIC libraw::raw)
32+
else()
33+
if (libraw_INCLUDE_DIRS)
34+
target_include_directories(${RAWTOACESIDTLIB} PUBLIC ${LibRaw_INCLUDE_DIRS})
35+
endif()
36+
if (libraw_LIBRARY_DIRS)
37+
target_link_directories(${RAWTOACESIDTLIB} PRIVATE ${LibRaw_LIBRARY_DIRS})
38+
endif()
39+
if (libraw_LIBRARIES)
40+
target_link_libraries(${RAWTOACESIDTLIB} PUBLIC ${LibRaw_LIBRARIES} ${LibRaw_LDFLAGS_OTHER})
41+
endif()
42+
endif()
43+
44+
target_link_libraries(${RAWTOACESIDTLIB}
45+
PRIVATE
1946
Imath::Imath
2047
Imath::ImathConfig
21-
Eigen3::Eigen
2248
)
2349

2450
if ( ${Ceres_VERSION_MAJOR} GREATER 1 )
@@ -28,18 +54,22 @@ else ()
2854
target_link_libraries(${RAWTOACESIDTLIB} PUBLIC ${CERES_LIBRARIES})
2955
endif ()
3056

31-
32-
set_target_properties( ${RAWTOACESIDTLIB} PROPERTIES
33-
SOVERSION ${RAWTOACES_MAJOR_VERSION}.${RAWTOACES_MINOR_VERSION}.${RAWTOACES_PATCH_VERSION}
34-
VERSION ${RAWTOACES_VERSION}
35-
)
36-
37-
install(FILES
57+
set(RAWTOACESIDT_HEADERS
3858
${PROJECT_SOURCE_DIR}/include/rawtoaces/define.h
3959
${PROJECT_SOURCE_DIR}/include/rawtoaces/mathOps.h
4060
${PROJECT_SOURCE_DIR}/include/rawtoaces/rta.h
61+
)
4162

42-
DESTINATION include/rawtoaces
63+
set_target_properties(${RAWTOACESIDTLIB} PROPERTIES
64+
SOVERSION ${RAWTOACES_MAJOR_VERSION}.${RAWTOACES_MINOR_VERSION}.${RAWTOACES_PATCH_VERSION}
65+
VERSION ${RAWTOACES_VERSION}
66+
PUBLIC_HEADER "${RAWTOACESIDT_HEADERS}"
4367
)
4468

45-
install( TARGETS ${RAWTOACESIDTLIB} DESTINATION lib )
69+
install(TARGETS ${RAWTOACESIDTLIB}
70+
EXPORT ${PROJECT_NAME}Targets
71+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
72+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
73+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
74+
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/rawtoaces
75+
)

0 commit comments

Comments
 (0)