diff --git a/CMakeLists.txt b/CMakeLists.txt
index 376b06b36dcaa0450f21629f4ac17046fa1b3f56..92dfd40bd12b7c4e82ec8117f20b8b89939a3214 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -116,10 +116,10 @@ endif()
 # ==============================================================================
 
 if (WITH_FIXSTARS)
-	find_package(LibSGM REQUIRED)
-	if (LibSGM_FOUND)
-		set(HAVE_LIBSGM true)
-	endif()
+	set(HAVE_LIBSGM true)
+	add_subdirectory(lib/libsgm)
+	include_directories(lib/libsgm/include)
+	set_property(TARGET sgm PROPERTY FOLDER "dependencies")
 endif()
 
 if (WITH_CERES)
@@ -400,7 +400,7 @@ if (BUILD_CALIBRATION)
 	if (NOT HAVE_CERES)
 		message(ERROR "Ceres is required")
 	endif()
-	
+
 	add_subdirectory(applications/calibration-ceres)
 	add_subdirectory(applications/calibration-multi)
 endif()
diff --git a/lib/libsgm/CMakeLists.txt b/lib/libsgm/CMakeLists.txt
index 22f6e557cb0a02c2f44d0065a5cf7729a2b150a9..497411f85b8f667e0bbb3516fa3e61782f3a34ec 100644
--- a/lib/libsgm/CMakeLists.txt
+++ b/lib/libsgm/CMakeLists.txt
@@ -26,8 +26,8 @@ if(BUILD_OPENCV_WRAPPER)
 	include_directories(${OpenCV_INCLUDE_DIRS})
 endif()
 
-configure_file(${CMAKE_SOURCE_DIR}/include/libsgm_config.h.in
-               ${CMAKE_SOURCE_DIR}/include/libsgm_config.h
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/libsgm_config.h.in
+               ${CMAKE_CURRENT_SOURCE_DIR}/include/libsgm_config.h
 )
 
 add_subdirectory(src)