Disable the code generation module by default

After this patch, users have to add -DCODE_GENERATION=ON to the
cmake command, if they want to compile the code generation module.
A warning is printed if they enable code generation.

This informs the users that the code generation is still under
development and should be used with care. Also, we don't break
the master branch immediately if one of the bigger codegen
patches fails to build on some platform.

When this system is finished, we can enable it by default or
remove this option again.

Change-Id: Ib26498f0d5bd8b3c165807ffd774c057c2d21d39
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b727b06..48d01de 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -144,6 +144,10 @@
 option(BUILD_EXAMPLES "Build examples" ON)
 option(BUILD_BENCHMARKS "Build Ceres benchmarking suite" ON)
 option(BUILD_SHARED_LIBS "Build Ceres as a shared library." OFF)
+option(CODE_GENERATION "Build the code generation module." OFF)
+if(CODE_GENERATION)
+    message(WARNING "The code generation module is still under development. The functionality and API of the current implementation might change in the future.")
+endif(CODE_GENERATION)
 set(SANITIZERS "" CACHE STRING "Semicolon-separated list of sanitizers to use (e.g address, memory, thread)")
 include(EnableSanitizer)
 enable_sanitizer(${SANITIZERS})
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index a6d2ff6..e2f4df4 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -72,8 +72,10 @@
 add_executable(simple_bundle_adjuster simple_bundle_adjuster.cc)
 target_link_libraries(simple_bundle_adjuster ceres)
 
-add_executable(autodiff_codegen autodiff_codegen.cc)
-target_link_libraries(autodiff_codegen ceres)
+if(CODE_GENERATION)
+  add_executable(autodiff_codegen autodiff_codegen.cc)
+  target_link_libraries(autodiff_codegen ceres)
+endif(CODE_GENERATION)
 
 if (GFLAGS)
   add_executable(powell powell.cc)
diff --git a/internal/ceres/CMakeLists.txt b/internal/ceres/CMakeLists.txt
index 948c4b7..0733f47 100644
--- a/internal/ceres/CMakeLists.txt
+++ b/internal/ceres/CMakeLists.txt
@@ -60,7 +60,6 @@
     canonical_views_clustering.cc
     cgnr_solver.cc
     callbacks.cc
-    code_generator.cc
     compressed_col_sparse_matrix_utils.cc
     compressed_row_jacobian_writer.cc
     compressed_row_sparse_matrix.cc
@@ -83,9 +82,6 @@
     dynamic_sparse_normal_cholesky_solver.cc
     evaluator.cc
     eigensparse.cc
-    expression.cc
-    expression_graph.cc
-    expression_ref.cc
     file.cc
     float_suitesparse.cc
     float_cxsparse.cc
@@ -152,6 +148,16 @@
     wall_time.cc
 )
 
+if(CODE_GENERATION)
+  set(CERES_CODEGEN_SRC
+      code_generator.cc
+      expression.cc
+      expression_graph.cc
+      expression_ref.cc
+  )
+  list(APPEND CERES_INTERNAL_SRC ${CERES_CODEGEN_SRC})
+endif(CODE_GENERATION)
+
 # Also depend on the header files so that they appear in IDEs.
 file(GLOB CERES_INTERNAL_HDRS *.h)
 if (MINIGLOG)
@@ -497,6 +503,7 @@
 
   add_subdirectory(generated_bundle_adjustment_tests)
 
+  if(CODE_GENERATION)
   # Testing the AutoDiffCodegen system is more complicated, because function- and
   # constructor calls have side-effects. In C++ the evaluation order and
   # the elision of copies is implementation defined. Between different compilers,
@@ -524,6 +531,7 @@
       ceres_test(expression_graph)
       set(CMAKE_CXX_FLAGS ${CXX_FLAGS_OLD})
   endif()
+  endif()
 
 endif (BUILD_TESTING AND GFLAGS)