From 6706c0e7506db8c56cb0e52c6aad239a95a39c5f Mon Sep 17 00:00:00 2001 From: Kolan Sh Date: Tue, 22 May 2012 16:53:07 +0400 Subject: [PATCH] Install phase added for cmake_tutorial. --- c/cmake_tutorial/step3/CMakeLists.txt | 35 +++++++++++++++++++ .../step3/MathFunctions/CMakeLists.txt | 5 +++ .../step3/MathFunctions/MathFunctions.h | 1 + .../step3/MathFunctions/mysqrt.cxx | 7 ++++ c/cmake_tutorial/step3/MathFunctions/mysqrt.h | 2 ++ c/cmake_tutorial/step3/TutorialConfig.h.in | 4 +++ c/cmake_tutorial/step3/tutorial.cxx | 32 +++++++++++++++++ 7 files changed, 86 insertions(+) create mode 100644 c/cmake_tutorial/step3/CMakeLists.txt create mode 100644 c/cmake_tutorial/step3/MathFunctions/CMakeLists.txt create mode 100644 c/cmake_tutorial/step3/MathFunctions/MathFunctions.h create mode 100644 c/cmake_tutorial/step3/MathFunctions/mysqrt.cxx create mode 100644 c/cmake_tutorial/step3/MathFunctions/mysqrt.h create mode 100644 c/cmake_tutorial/step3/TutorialConfig.h.in create mode 100644 c/cmake_tutorial/step3/tutorial.cxx diff --git a/c/cmake_tutorial/step3/CMakeLists.txt b/c/cmake_tutorial/step3/CMakeLists.txt new file mode 100644 index 0000000..aa6257d --- /dev/null +++ b/c/cmake_tutorial/step3/CMakeLists.txt @@ -0,0 +1,35 @@ +cmake_minimum_required (VERSION 2.6) +project (Tutorial) +# The version number. +set (Tutorial_VERSION_MAJOR 1) +set (Tutorial_VERSION_MINOR 0) + +# configure a header file to pass some of the CMake setting +# to the source code +configure_file ( + "${PROJECT_SOURCE_DIR}/TutorialConfig.h.in" + "${PROJECT_BINARY_DIR}/TutorialConfig.h" + ) + +# add the binary tree to the search path for include files +# so that we will find TutorialConfig.h +include_directories ("${PROJECT_BINARY_DIR}") + +# should we use our own math functions? +option (USE_MYMATH + "Use tutorial provided math implementation" ON) + +if (USE_MYMATH) + include_directories ("${PROJECT_SOURCE_DIR}/MathFunctions") + add_subdirectory (MathFunctions) + set (EXTRA_LIBS ${EXTRA_LIBS} MathFunctions) +endif (USE_MYMATH) + +# add the executable +add_executable (Tutorial tutorial.cxx) +target_link_libraries (Tutorial ${EXTRA_LIBS}) + +# add the install targets and files +install (TARGETS Tutorial DESTINATION bin) +install (FILES "${PROJECT_BINARY_DIR}/TutorialConfig.h" + DESTINATION include) diff --git a/c/cmake_tutorial/step3/MathFunctions/CMakeLists.txt b/c/cmake_tutorial/step3/MathFunctions/CMakeLists.txt new file mode 100644 index 0000000..e2bdd06 --- /dev/null +++ b/c/cmake_tutorial/step3/MathFunctions/CMakeLists.txt @@ -0,0 +1,5 @@ +add_library (MathFunctions mysqrt.cxx) + +# add the install targets and files +install (TARGETS MathFunctions DESTINATION bin) +install (FILES MathFunctions.h DESTINATION include) diff --git a/c/cmake_tutorial/step3/MathFunctions/MathFunctions.h b/c/cmake_tutorial/step3/MathFunctions/MathFunctions.h new file mode 100644 index 0000000..54c682a --- /dev/null +++ b/c/cmake_tutorial/step3/MathFunctions/MathFunctions.h @@ -0,0 +1 @@ +#include "mysqrt.h" diff --git a/c/cmake_tutorial/step3/MathFunctions/mysqrt.cxx b/c/cmake_tutorial/step3/MathFunctions/mysqrt.cxx new file mode 100644 index 0000000..9283fa0 --- /dev/null +++ b/c/cmake_tutorial/step3/MathFunctions/mysqrt.cxx @@ -0,0 +1,7 @@ +#include + +double +mysqrt (double x) +{ + return sqrt (x); +} diff --git a/c/cmake_tutorial/step3/MathFunctions/mysqrt.h b/c/cmake_tutorial/step3/MathFunctions/mysqrt.h new file mode 100644 index 0000000..948a44c --- /dev/null +++ b/c/cmake_tutorial/step3/MathFunctions/mysqrt.h @@ -0,0 +1,2 @@ +double +mysqrt (double); diff --git a/c/cmake_tutorial/step3/TutorialConfig.h.in b/c/cmake_tutorial/step3/TutorialConfig.h.in new file mode 100644 index 0000000..e23f521 --- /dev/null +++ b/c/cmake_tutorial/step3/TutorialConfig.h.in @@ -0,0 +1,4 @@ +// the configured options and settings for Tutorial +#define Tutorial_VERSION_MAJOR @Tutorial_VERSION_MAJOR@ +#define Tutorial_VERSION_MINOR @Tutorial_VERSION_MINOR@ +#cmakedefine USE_MYMATH diff --git a/c/cmake_tutorial/step3/tutorial.cxx b/c/cmake_tutorial/step3/tutorial.cxx new file mode 100644 index 0000000..a5cc6fe --- /dev/null +++ b/c/cmake_tutorial/step3/tutorial.cxx @@ -0,0 +1,32 @@ +// A simple program that computes the square root of a number +#include +#include +#include +#include "TutorialConfig.h" +#ifdef USE_MYMATH +#include "MathFunctions.h" +#endif + +int main (int argc, char *argv[]) +{ + if (argc < 2) + { + fprintf(stdout,"%s Version %d.%d\n", + argv[0], + Tutorial_VERSION_MAJOR, + Tutorial_VERSION_MINOR); + fprintf(stdout,"Usage: %s number\n",argv[0]); + return 1; + } + double inputValue = atof(argv[1]); +#ifdef USE_MYMATH + puts ("Using mysqrt ()\n"); + double outputValue = mysqrt(inputValue); +#else + puts ("Using system sqrt ()\n"); + double outputValue = sqrt(inputValue); +#endif + fprintf(stdout,"The square root of %g is %g\n", + inputValue, outputValue); + return 0; +}