diff --git a/CMakeLists.txt b/CMakeLists.txt
index 78372cafbaad7cecafee8d4c79fc5d14cd3cca85..411122e610c8da1c712bb99a39ab14ff05ce7c5f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -16,7 +16,10 @@ endif(DEFINED CMAKE_BUILD_TYPE)
 
 project(gmsh CXX C)
 
+option(ENABLE_ACIS "Enable ACIS geometrical models" ON)
 option(ENABLE_ANN "Enable ANN to compute Approximate Nearest Neighbors" ON)
+option(ENABLE_BAMG "Enable Bamg mesh generator" ON)
+option(ENABLE_BFGS "Enable BFGS" ON)
 option(ENABLE_BLAS_LAPACK "Use BLAS/Lapack for basic linear algebra" ON)
 option(ENABLE_CGNS "Enable CGNS mesh export" OFF)
 option(ENABLE_CHACO "Enable Chaco mesh partitioner" ON)
@@ -38,14 +41,12 @@ option(ENABLE_MPI "Enable MPI parallelization" OFF)
 option(ENABLE_MSVC_STATIC_RUNTIME "Use static Visual C++ runtime" OFF)
 option(ENABLE_NATIVE_FILE_CHOOSER "Enable native file chooser in GUI" ON)
 option(ENABLE_NETGEN "Enable Netgen mesh generator" ON)
-option(ENABLE_BAMG "Enable Bamg mesh generator" ON)
 option(ENABLE_OCC "Enable Open CASCADE geometrical models" ON)
-option(ENABLE_ACIS "Enable ACIS geometrical models" ON)
 option(ENABLE_OSMESA "Use OSMesa for offscreen rendering" OFF)
 option(ENABLE_PARSER "Build the GEO file parser" ON)
 option(ENABLE_PETSC "Enable PETSc linear algebra solvers" OFF)
-option(ENABLE_POST "Build the post-processing module" ON)
 option(ENABLE_PLUGINS "Build the post-processing plugins" ON)
+option(ENABLE_POST "Build the post-processing module" ON)
 option(ENABLE_QT "Build QT GUI" OFF)
 option(ENABLE_READLINE "Enable Readline in Lua prompt" ON)
 option(ENABLE_SLEPC "Enable SLEPc eigensolvers" ON)
@@ -439,8 +440,11 @@ if(ENABLE_CHACO)
   set_config_option(HAVE_CHACO "Chaco")
 endif(ENABLE_CHACO)
 
-add_subdirectory(contrib/lbfgs)
-include_directories(contrib/lbfgs)
+if(ENABLE_BFGS)
+  add_subdirectory(contrib/lbfgs)
+  include_directories(contrib/lbfgs)
+  set_config_option(HAVE_BFGS "Bfgs")
+endif(ENABLE_BFGS)
 
 if(ENABLE_DINTEGRATION)
   add_subdirectory(contrib/DiscreteIntegration)
diff --git a/Common/GmshConfig.h.in b/Common/GmshConfig.h.in
index 48ff64e93e7b8b9fc58bd942cda662f414a92e64..1823f159857a1d0f1b43d8aa7d481cadd3cc98f4 100644
--- a/Common/GmshConfig.h.in
+++ b/Common/GmshConfig.h.in
@@ -10,6 +10,7 @@
 #cmakedefine HAVE_ACIS
 #cmakedefine HAVE_ANN
 #cmakedefine HAVE_BAMG
+#cmakedefine HAVE_BFGS
 #cmakedefine HAVE_BLAS
 #cmakedefine HAVE_CHACO
 #cmakedefine HAVE_DLOPEN