if target nlohmann_json already exists in cmake, use that library
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 115c898..4946f09 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -19,11 +19,11 @@
 # set(CMAKE_BUILD_TYPE Release)
 # set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
 
-if (CMAKE_COMPILER_IS_GNUCC)
+if(CMAKE_COMPILER_IS_GNUCC)
   set(CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} -Wall")
 endif()
 
-if (MSVC)
+if(MSVC)
   set(CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} /W4")
 endif()
 
@@ -42,7 +42,7 @@
 
 if(INJA_USE_EMBEDDED_JSON)
   find_package(nlohmann_json QUIET)
-  if (NOT nlohmann_json_FOUND)
+  if(NOT nlohmann_json_FOUND)
     set(INJA_PACKAGE_USE_EMBEDDED_JSON ON)
     add_library(nlohmann_json INTERFACE)
     add_library(pantor::nlohmann_json ALIAS nlohmann_json)
@@ -61,8 +61,13 @@
     set(INJA_SELECTED_JSON_LIBRARY "nlohmann_json::nlohmann_json")
   endif()
 else()
-  find_package(nlohmann_json REQUIRED)
-  set(INJA_SELECTED_JSON_LIBRARY "nlohmann_json::nlohmann_json")
+  # If target already exists, e.g. by git submodules
+  if(TARGET nlohmann_json)
+    set(INJA_SELECTED_JSON_LIBRARY "nlohmann_json::nlohmann_json")
+  else()
+    find_package(nlohmann_json REQUIRED)
+    set(INJA_SELECTED_JSON_LIBRARY "nlohmann_json::nlohmann_json")
+  endif()
 endif()
 
 target_link_libraries(inja INTERFACE ${INJA_SELECTED_JSON_LIBRARY})
@@ -70,18 +75,6 @@
 execute_process(COMMAND scripts/update_single_include.sh WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
 
 
-if (COVERALLS)
-  include(Coveralls)
-  coveralls_turn_on_coverage()
-
-  file(GLOB_RECURSE COVERAGE_SRCS include/inja/*.hpp)
-
-  # set(COVERAGE_SRCS test/unit.cpp test/unit-renderer.cpp include/inja)
-
-  coveralls_setup("${COVERAGE_SRCS}" OFF) # If we should upload.
-endif()
-
-
 if(BUILD_TESTING)
   enable_testing()
 
@@ -115,6 +108,18 @@
 endif()
 
 
+if(COVERALLS)
+  include(Coveralls)
+  coveralls_turn_on_coverage()
+
+  file(GLOB_RECURSE COVERAGE_SRCS include/inja/*.hpp)
+
+  # set(COVERAGE_SRCS test/unit.cpp test/unit-renderer.cpp include/inja)
+
+  coveralls_setup("${COVERAGE_SRCS}" OFF) # If we should upload.
+endif()
+
+
 include(CMakePackageConfigHelpers)
 
 write_basic_package_version_file(
@@ -149,7 +154,7 @@
 )
 
 
-if (INJA_INSTALL)
+if(INJA_INSTALL)
   set(INJA_CONFIG_PATH "lib/cmake/inja")
 
   # install tree package config
@@ -182,6 +187,6 @@
 endif()
 
 
-if (INJA_EXPORT)
+if(INJA_EXPORT)
   export(PACKAGE inja)
 endif()