diff --git a/cmake/BuildDynamicSample.in b/cmake/BuildDynamicSample.in
new file mode 100644
index 0000000..6ada3c7
--- /dev/null
+++ b/cmake/BuildDynamicSample.in
@@ -0,0 +1,83 @@
+# Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
+
+################################################################################
+# This file is part of NUISANCE.
+#
+# NUISANCE is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# NUISANCE is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with NUISANCE. If not, see .
+################################################################################
+
+#!/bin/bash
+
+if [ ! "${1}" ] || [ ! -e ${1} ] || [ ! "${2}" ]; then
+ echo "[USAGE]: ${0} input.cxx outputLibName.so"
+ exit 1
+fi
+
+CN=$(grep "class .*" $1 | sed "s/^class \([0-9a-zA-Z]\+\).*$/\1/g")
+
+if [ ! "${CN}" ]; then
+ echo "[ERROR]: Couldn't find class name -- Expected to find a line like: \"class XXXX : public Measurement1D\" in \"$1\"."
+ exit 1
+fi
+
+if [ ! -e compile.tmp ]; then
+ mkdir compile.tmp
+fi
+
+cat $1 > compile.tmp/$1
+
+echo -e "static char const * SampleNames[] = {\"${CN}\"};\n"\
+"static int const NSamples = 1;\n"\
+"\n"\
+"extern \"C\" {\n"\
+"int DSF_NSamples() { return NSamples; }\n"\
+"char const* DSF_GetSampleName(int i) {\n"\
+" if (i < NSamples) {\n"\
+" return SampleNames[i];\n"\
+" }\n"\
+" return 0;\n"\
+"}\n"\
+"MeasurementBase* DSF_GetSample(int i, void* samplekey) {\n"\
+" nuiskey* sk = reinterpret_cast(samplekey);\n"\
+" if (!sk) {\n"\
+" return 0;\n"\
+" }\n"\
+"\n"\
+" if (sk->GetS(\"name\") != DSF_GetSampleName(i)) {\n"\
+" std::cout\n"\
+" << \"[ERROR]: When instantiating dynamic sample. Samplekey named: \"\n"\
+" << sk->GetS(\"name\") << \", but requested sample named: \"\n"\
+" << DSF_GetSampleName(i)\n"\
+" << \". It is possible that the nuiskey object is lost in translation. \"\n"\
+" \"Was NUISANCE and this dynamic sample manifest built with the same \"\n"\
+" \"environment and compiler?\"\n"\
+" << std::endl;\n"\
+" }\n"\
+"\n"\
+" if (i == 0) {\n"\
+" return new ${CN}(*sk);\n"\
+" }\n"\
+" return 0;\n"\
+"}\n"\
+"void DSF_DestroySample(MeasurementBase* mb) { delete mb; }\n"\
+"}" >> compile.tmp/$1
+
+echo "g++ compile.tmp/$1 -shared -o $2 -fPIC @CMAKE_CXX_FLAGS@ -I@ALL_INCLUDES_STR@ @CMAKE_LINK_FLAGS@ @CMAKE_DEPENDLIB_FLAGS@"
+
+if ! g++ compile.tmp/$1 -shared -o $2 -fPIC @CMAKE_CXX_FLAGS@ -I@ALL_INCLUDES_STR@ @CMAKE_LINK_FLAGS@ @CMAKE_DEPENDLIB_FLAGS@; then
+ echo "[ERROR]: Failed to compile $1. Generated code can be found in ./compile.tmp/$1"
+else
+ rm -r compile.tmp
+ echo "Successfully build: $2."
+fi