aboutsummaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
Diffstat (limited to 'cmake')
-rw-r--r--cmake/Findjson-c.cmake83
-rw-r--r--cmake/R2plugin.cmake5
2 files changed, 86 insertions, 2 deletions
diff --git a/cmake/Findjson-c.cmake b/cmake/Findjson-c.cmake
new file mode 100644
index 0000000..99e2586
--- /dev/null
+++ b/cmake/Findjson-c.cmake
@@ -0,0 +1,83 @@
+#
+# Tries to find json-c through the config
+# before trying to query for it
+#
+#
+
+if (json-c_FOUND)
+ return()
+endif()
+
+find_package(json-c CONFIG)
+
+if (JSONC_FOUND)
+ return()
+endif()
+
+find_package(PkgConfig QUIET)
+if (PKG_CONFIG_FOUND)
+ pkg_check_modules(_JSONC json-c)
+
+ if (BUILD_STATIC AND NOT _JSONC_FOUND)
+ message(FATAL_ERROR "Cannot find static build information")
+ endif()
+ set(json-c_FOUND 1)
+endif()
+
+if (json-c_FOUND) # we can rely on pkg-config
+ set(json-c_LINK_LIBRARIES ${_JSONC_LINK_LIBRARIES})
+ if (NOT BUILD_STATIC)
+ set(json-c_INCLUDE_DIRS ${_JSONC_INCLUDE_DIRS})
+ set(json-c_CFLAGS ${_JSONC_CFLAGS_OTHER})
+ else()
+ set(json-c_INCLUDE_DIRS ${_JSONC_STATIC_INCLUDE_DIRS})
+ set(json-c_CFLAGS ${_JSONC_STATIC_CFLAGS_OTHER})
+ endif()
+else()
+ if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ set(_lib_suffix 64)
+ else()
+ set(_lib_suffix 32)
+ endif()
+
+ find_path(JSONC_INC
+ NAMES json.h
+ HINTS
+ ENV jsoncPath${_lib_suffix}
+ ENV jsoncPath
+ ${_JSONC_INCLUDE_DIRS}
+ PATHS
+ /usr/include/json-c /usr/local/include/json-c)
+
+ find_library(JSONC_LIB
+ NAMES ${_JSONC_LIBRARIES} jsonc json-c
+ HINTS
+ ENV jsoncPath${_lib_suffix}
+ ENV jsoncPath
+ ${_JSONC_LIBRARY_DIRS}
+ ${_JSONC_STATIC_LIBRARY_DIRS}
+ PATHS
+ /usr/lib{_lib_suffix} /usr/local/lib{_lib_suffix}
+ /usr/lib /usr/local/lib)
+
+ include(FindPackageHandleStandardArgs)
+ find_package_handle_standard_args(json-c DEFAULT_MSG JSONC_LIB JSONC_INC)
+ mark_as_advanced(JSONC_INC JSONC_LIB)
+
+ if(json-c_FOUND)
+ set(json-c_INCLUDE_DIRS ${JSONC_INC})
+ set(json-c_LINK_LIBRARIES ${JSONC_LIB})
+ if (BUILD_STATIC)
+ set(json-c_LINK_LIBRARIES ${json-c_LINK_LIBRARIES} ${_JSONC_STATIC_LIBRARIES})
+ endif()
+ endif()
+endif()
+
+if (json-c_FOUND)
+ add_library(json-c::json-c UNKNOWN IMPORTED)
+ set_target_properties(json-c::json-c PROPERTIES
+ IMPORTED_LOCATION "${json-c_LINK_LIBRARIES}"
+ )
+ target_compile_definitions(json-c::json-c INTERFACE ${json-c_CFLAGS})
+ target_include_directories(json-c::json-c INTERFACE ${json-c_INCLUDE_DIRS})
+endif()
diff --git a/cmake/R2plugin.cmake b/cmake/R2plugin.cmake
index 107a981..584ef05 100644
--- a/cmake/R2plugin.cmake
+++ b/cmake/R2plugin.cmake
@@ -9,8 +9,6 @@ cmake_policy(SET CMP0057 NEW)
project(R2plugin)
-find_package(spdlog REQUIRED)
-find_package(NorthstarPluginABI REQUIRED)
if (NOT WIN32)
message(FATAL_ERROR "Northstar Plugins can only be compiled for Windows")
@@ -23,6 +21,9 @@ if (__R2PLUGIN_CMAKE_INCLUDED)
endif()
set(__R2PLUGIN_CMAKE_INCLUDED TRUE)
+find_package(spdlog REQUIRED)
+find_package(NorthstarPluginABI REQUIRED)
+
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
include(CheckLinkerFlag)