cmake: Prevent redefinition of uninstall target
authorMark Lobodzinski <mark@lunarg.com>
Tue, 12 Jun 2018 16:30:18 +0000 (10:30 -0600)
committerKarl Schultz <karl@lunarg.com>
Tue, 12 Jun 2018 21:02:54 +0000 (15:02 -0600)
Allows for this repo to be included as a submodule of another
repo that defines its own uninstall target.  The uninstall target
is best defined at the top-level repo.

CMakeLists.txt

index d44a50b..f2a2981 100644 (file)
@@ -46,14 +46,16 @@ if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND WIN32)
 endif()
 
 # uninstall target
-configure_file(
-    "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
-    "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
-    IMMEDIATE @ONLY)
+if (NOT TARGET uninstall)
+    configure_file(
+        "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
+        "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
+        IMMEDIATE @ONLY)
 
-add_custom_target(uninstall
-    COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
-set_target_properties(uninstall PROPERTIES FOLDER ${TOOLS_TARGET_FOLDER})
+    add_custom_target(uninstall
+        COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
+    set_target_properties(uninstall PROPERTIES FOLDER ${TOOLS_TARGET_FOLDER})
+endif()
 
 if(APPLE)
     # CMake versions 3 or later need CMAKE_MACOSX_RPATH defined.