Sync with WRF updates for better option outputs
[WPS.git] / cmake / modules / FindJasper.cmake
blob541ecf2147c48caa392e417fecd684547901dfd2
1 # Find Jasper
2 # Eventually replace with Jasper's actual config if using that
3 # Once found this file will define:
4 #  Jasper_FOUND - System has Jasper
5 #  Jasper_INCLUDE_DIRS - The Jasper include directories
6 #  Jasper_LIBRARIES - The libraries needed to use Jasper
8 find_package( PkgConfig )
9 pkg_check_modules( PC_Jasper QUIET Jasper )
10 # set(CMAKE_FIND_DEBUG_MODE TRUE)
11 find_path(
12           Jasper_INCLUDE_DIR
13           NAMES jasper/jasper.h # Make it so we go up one dir
14           # Hints before PATHS
15           HINTS ${Jasper_ROOT} ${JASPERINC} ${JASPER_PATH} ENV Jasper_ROOT ENV JASPERINC ENV JASPER_PATH
16           PATHS ${PC_Jasper_INCLUDE_DIRS}
17           PATH_SUFFIXES Jasper jasper include #include/jasper
18         )
19 find_library(
20               Jasper_LIBRARY
21               NAMES jasper
22               # Hints before PATHS
23               HINTS ${Jasper_ROOT} ${JASPERLIB} ${JASPER_PATH} ENV Jasper_ROOT ENV JASPERLIB ENV JASPER_PATH
24               PATHS ${PC_Jasper_LIBRARY_DIRS}
25               PATH_SUFFIXES lib
26             )
28 # Ripped from https://github.com/Kitware/CMake/blob/master/Modules/FindJasper.cmake
29 if( Jasper_INCLUDE_DIR AND EXISTS "${Jasper_INCLUDE_DIR}/jasper/jas_config.h")
30   file(STRINGS "${Jasper_INCLUDE_DIR}/jasper/jas_config.h" jasper_version_str REGEX "^#define[\t ]+JAS_VERSION[\t ]+\".*\".*")
31   string(REGEX REPLACE "^#define[\t ]+JAS_VERSION[\t ]+\"([^\"]+)\".*" "\\1" Jasper_VERSION_STRING "${jasper_version_str}")
32 endif()
33 # set(CMAKE_FIND_DEBUG_MODE FALSE)
35 include(FindPackageHandleStandardArgs)
36 find_package_handle_standard_args(
37                                   Jasper
38                                   FOUND_VAR Jasper_FOUND
39                                   REQUIRED_VARS
40                                     Jasper_LIBRARY
41                                     Jasper_INCLUDE_DIR
42                                   VERSION_VAR Jasper_VERSION_STRING
43                                   HANDLE_VERSION_RANGE
44                                 )
46 if ( Jasper_FOUND AND NOT TARGET Jasper::Jasper )
47   add_library( Jasper::Jasper UNKNOWN IMPORTED )
48   set_target_properties(
49                         Jasper::Jasper
50                         PROPERTIES
51                           IMPORTED_LOCATION             "${Jasper_LIBRARY}"
52                           INTERFACE_COMPILE_OPTIONS     "${PC_Jasper_CFLAGS_OTHER}"
53                           INTERFACE_INCLUDE_DIRECTORIES "${Jasper_INCLUDE_DIR}"
54                         )
56   # Allow traditional/legacy style usage
57   set( Jasper_LIBRARIES    ${Jasper_LIBRARY}         )
58   set( Jasper_INCLUDE_DIRS ${Jasper_INCLUDE_DIR}     )
59   set( Jasper_DEFINITIONS  ${PC_Jasper_CFLAGS_OTHER} )
61   mark_as_advanced(
62                     Jasper_INCLUDE_DIR
63                     Jasper_LIBRARY
64                   )
65 endif()