Browse Source

Add CMake Target Exporting & option to disable testing in the build (#2329)

* Fix cmake install

* Option to build without testing

* Add target exporting and SpineConfig.cmake

* Revert relative install paths to Spine preferred ones
Andrew Wilson 2 years ago
parent
commit
373a163c3f
3 changed files with 23 additions and 6 deletions
  1. 12 4
      CMakeLists.txt
  2. 1 0
      SpineConfig.cmake.in
  3. 10 2
      spine-cpp/CMakeLists.txt

+ 12 - 4
CMakeLists.txt

@@ -5,8 +5,9 @@ if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
 	set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR} CACHE PATH "Install location" FORCE)
 endif()
 set(CMAKE_VERBOSE_MAKEFILE ON)
-set(SPINE_SFML FALSE CACHE BOOL FALSE)
-set(SPINE_SANITIZE FALSE CACHE BOOL FALSE)
+option(SPINE_SFML "Build spine SFML API" OFF)
+option(SPINE_SANITIZE "Build with sanitization" OFF)
+option(BUILD_TESTING "Build with testing" ON)
 
 if(MSVC)
 	message("MSCV detected")
@@ -42,5 +43,12 @@ elseif((${SPINE_SDL}) OR (${CMAKE_CURRENT_BINARY_DIR} MATCHES "spine-sdl"))
 else()
 	add_subdirectory(spine-c)
 	add_subdirectory(spine-cpp)
-	add_subdirectory(spine-cpp/spine-cpp-unit-tests)
-endif()
+	if (${BUILD_TESTING})
+		add_subdirectory(spine-cpp/spine-cpp-unit-tests)
+	endif()
+endif()
+
+# Create config file that include the exported targets
+configure_file(SpineConfig.cmake.in
+	"${CMAKE_CURRENT_BINARY_DIR}/SpineConfig.cmake"
+	@ONLY)

+ 1 - 0
SpineConfig.cmake.in

@@ -0,0 +1 @@
+include("@CMAKE_CURRENT_BINARY_DIR@/spine-cpp/spine-cppTargets.cmake")

+ 10 - 2
spine-cpp/CMakeLists.txt

@@ -13,5 +13,13 @@ file(GLOB SOURCES "spine-cpp/src/**/*.cpp")
 
 add_library(spine-cpp STATIC ${SOURCES} ${INCLUDES})
 target_include_directories(spine-cpp PUBLIC spine-cpp/include)
-install(TARGETS spine-cpp DESTINATION dist/lib)
-install(FILES ${INCLUDES} DESTINATION dist/include)
+
+# Install target
+install(TARGETS spine-cpp EXPORT spine-cpp_TARGETS DESTINATION dist/lib)
+install(FILES ${INCLUDES} DESTINATION dist/include)
+
+# Export target
+export(
+	EXPORT spine-cpp_TARGETS
+	FILE ${CMAKE_CURRENT_BINARY_DIR}/spine-cppTargets.cmake
+	NAMESPACE "Spine::")