@@ -5,19 +5,19 @@ Module defines the following `IMPORTED` target(s):
55
66* `Capstone::Capstone` - The package library, if found.
77
8- Result variables:
8+ ## Result variables
99
1010* `Capstone_FOUND` - Whether the package has been found.
1111* `Capstone_INCLUDE_DIRS` - Include directories needed to use this package.
1212* `Capstone_LIBRARIES` - Libraries needed to link to the package library.
1313* `Capstone_VERSION` - Package version, if found.
1414
15- Cache variables:
15+ ## Cache variables
1616
1717* `Capstone_INCLUDE_DIR` - Directory containing package library headers.
1818* `Capstone_LIBRARY` - The path to the package library.
1919
20- Hints:
20+ ## Hints
2121
2222The `Capstone_ROOT` variable adds custom search path.
2323#]=============================================================================]
@@ -34,7 +34,7 @@ set_package_properties(
3434
3535set (_reason "" )
3636
37- # Use pkgconf, if available on the system .
37+ # Try pkg-config .
3838find_package (PkgConfig QUIET )
3939if (PKG_CONFIG_FOUND)
4040 pkg_check_modules(PC_Capstone QUIET capstone)
@@ -72,19 +72,27 @@ block(PROPAGATE Capstone_VERSION)
7272 "^#[ \t ]*define[ \t ]+CS_(API_MAJOR|API_MINOR|VERSION_EXTRA)[ \t ]+[0-9]+[ \t ]*$"
7373 )
7474
75- unset (Capstone_VERSION)
75+ set (Capstone_VERSION)
7676
7777 foreach (item CS_API_MAJOR CS_API_MINOR CS_VERSION_EXTRA)
7878 foreach (line ${results} )
7979 if (line MATCHES "^#[ \t ]*define[ \t ]+${item} [ \t ]+([0-9]+)[ \t ]*$" )
80- if (DEFINED Capstone_VERSION)
80+ if (Capstone_VERSION)
8181 string (APPEND Capstone_VERSION ".${CMAKE_MATCH_1} " )
8282 else ()
8383 set (Capstone_VERSION "${CMAKE_MATCH_1} " )
8484 endif ()
8585 endif ()
8686 endforeach ()
8787 endforeach ()
88+
89+ if (
90+ NOT Capstone_VERSION
91+ AND PC_Capstone_VERSION
92+ AND Capstone_INCLUDE_DIR IN_LIST PC_Capstone_INCLUDE_DIRS
93+ )
94+ set (Capstone_VERSION ${PC_Capstone_VERSION} )
95+ endif ()
8896 endif ()
8997endblock()
9098
@@ -96,6 +104,7 @@ find_package_handle_standard_args(
96104 Capstone_LIBRARY
97105 Capstone_INCLUDE_DIR
98106 VERSION_VAR Capstone_VERSION
107+ HANDLE_VERSION_RANGE
99108 REASON_FAILURE_MESSAGE "${_reason} "
100109)
101110
@@ -109,20 +118,20 @@ endif()
109118# <capstone/capstone.h>. Here both include directories are added so the code can
110119# work with both includes. The "subdir" can be removed and simplified in the
111120# future. See: https://github.com/capstone-engine/capstone/issues/1982
112- block(PROPAGATE Capstone_INCLUDE_DIRS Capstone_LIBRARIES)
113- set (subdir "${Capstone_INCLUDE_DIR} /capstone" )
114-
115- set (Capstone_INCLUDE_DIRS ${Capstone_INCLUDE_DIR} ${subdir} )
116- set (Capstone_LIBRARIES ${Capstone_LIBRARY} )
121+ set (
122+ Capstone_INCLUDE_DIRS
123+ ${Capstone_INCLUDE_DIR}
124+ ${Capstone_INCLUDE_DIR} /capstone
125+ )
126+ set (Capstone_LIBRARIES ${Capstone_LIBRARY} )
117127
118- if (NOT TARGET Capstone::Capstone)
119- add_library (Capstone::Capstone UNKNOWN IMPORTED )
128+ if (NOT TARGET Capstone::Capstone)
129+ add_library (Capstone::Capstone UNKNOWN IMPORTED )
120130
121- set_target_properties (
122- Capstone::Capstone
123- PROPERTIES
124- IMPORTED_LOCATION "${Capstone_LIBRARY} "
125- INTERFACE_INCLUDE_DIRECTORIES "${Capstone_INCLUDE_DIR} ;${subdir} "
126- )
127- endif ()
128- endblock()
131+ set_target_properties (
132+ Capstone::Capstone
133+ PROPERTIES
134+ IMPORTED_LOCATION "${Capstone_LIBRARY} "
135+ INTERFACE_INCLUDE_DIRECTORIES "${Capstone_INCLUDE_DIRS} "
136+ )
137+ endif ()
0 commit comments