From b9d3f4855c39db9be4905c87d0306df8afbcd95c Mon Sep 17 00:00:00 2001
From: Antonio Flores Montoya <afloresmontoya@grammatech.com>
Date: Mon, 29 Jul 2019 16:24:23 -0400
Subject: [PATCH] adjust build scripts and add description in README

---
 CMakeLists.txt |  6 +++++-
 README.md      | 21 ++++++++++++++++++++-
 src/SConscript | 11 ++++++++++-
 3 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 422f7f0..a6d3515 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,12 +11,16 @@ PROJECT(ehp)
 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
 
+option(USE_ELFIO "Use the elfio library to parse elf files" OFF)
+if(USE_ELFIO)
+   add_definitions(-DUSE_ELFIO)
+endif()
+
 # Use C++17
 set(CMAKE_CXX_STANDARD 17)
 # Error if it's not available
 set(CMAKE_CXX_STANDARD_REQUIRED ON)
 
-
 # Base include path for ehp
 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
 
diff --git a/README.md b/README.md
index 4855dbb..b6b0f28 100644
--- a/README.md
+++ b/README.md
@@ -10,4 +10,23 @@ Notes:
 1. Additional documentation will be provided in later versions 
 1. API is incomplete and untested in some areas.  Future versions will improve stability.
 1. Use `git clone --recursive` to pull down required submodules
-1. Build with `scons`, add `debug=1` for debug build
+1. Build with `scons`, add `debug=1` for debug build, add '--no_elfio' to compile without the third party libraries
+
+## Compilation with cmake
+
+To compile with cmake type:
+
+```
+cmake . -Bbuild
+cd build
+cmake --build .
+```
+
+In contrast to scons, the default compilation in cmake is **without** the elfio library. If you want to compile with elfio
+use the following commands:
+
+```
+cmake . -Bbuild  -DUSE_ELFIO=ON
+cd build
+cmake --build .
+```
\ No newline at end of file
diff --git a/src/SConscript b/src/SConscript
index 8d25ba5..6acef90 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -26,11 +26,20 @@ cpppath='''
 	'''
 cpppath=cpppath+Dir('.').srcnode().abspath+'/../third-party/elfio-code'
 
+AddOption('--no_elfio',
+          dest='no_elfio',
+          action='store_true',
+          default=False,
+          help='Do not use Elfio library to parse elf files')
+
+cpp_defines={}
+if( not GetOption('no_elfio')):
+    cpp_defines['USE_ELFIO']=1
 
 LIBPATH="$SECURITY_TRANSFORMS_HOME/lib"
 LIBS=Split("")
 
-myenv=myenv.Clone(CPPPATH=Split(cpppath))
+myenv=myenv.Clone(CPPPATH=Split(cpppath),CPPDEFINES=cpp_defines)
 myenv.Append(CXXFLAGS = " -std=c++11 -Wall -Werror -fmax-errors=2 -fPIC ")
 
 lib1=myenv.Library("ehp",  Split(files), LIBPATH=LIBPATH, LIBS=LIBS)
-- 
GitLab