Skip to content

Commit

Permalink
a few simple cmake examples
Browse files Browse the repository at this point in the history
  • Loading branch information
cbernet committed Jun 18, 2014
0 parents commit 039ba2d
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 0 deletions.
13 changes: 13 additions & 0 deletions LibraryAndExecutable/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 2.8)

project(app_project)

add_library(hello SHARED hello.cc)

add_executable(myapp main.cc)
target_link_libraries(myapp hello)

set(CMAKE_INSTALL_PREFIX _install)
install(TARGETS hello DESTINATION lib)
install(FILES hello.h DESTINATION include)
install(TARGETS myapp DESTINATION bin)
7 changes: 7 additions & 0 deletions LibraryAndExecutable/hello.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "hello.h"

#include <iostream>

void hello() {
std::cout<<"hello world!"<<std::endl;
}
3 changes: 3 additions & 0 deletions LibraryAndExecutable/hello.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include <iostream>

void hello();
22 changes: 22 additions & 0 deletions LibraryAndExecutable/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// A simple program that computes the square root of a number
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#include "hello.h"

int main (int argc, char *argv[])
{
if (argc < 2)
{
fprintf(stdout,"Usage: %s number\n",argv[0]);
return 1;
}
double inputValue = atof(argv[1]);
double outputValue = sqrt(inputValue);
fprintf(stdout,"The square root of %g is %g\n",
inputValue, outputValue);

hello();
return 0;
}
7 changes: 7 additions & 0 deletions SimpleExecutable/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 2.8)

project(app_project)

add_executable(myapp main.cc)
set(CMAKE_INSTALL_PREFIX _install)
install(TARGETS myapp DESTINATION bin)
3 changes: 3 additions & 0 deletions SimpleExecutable/hello.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include <iostream>

void hello();
22 changes: 22 additions & 0 deletions SimpleExecutable/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// A simple program that computes the square root of a number
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

// #include "hello.h"

int main (int argc, char *argv[])
{
if (argc < 2)
{
fprintf(stdout,"Usage: %s number\n",argv[0]);
return 1;
}
double inputValue = atof(argv[1]);
double outputValue = sqrt(inputValue);
fprintf(stdout,"The square root of %g is %g\n",
inputValue, outputValue);

// hello();
return 0;
}
14 changes: 14 additions & 0 deletions SourceOrganized/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 2.8)

project(hello)

set(hello_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)

include_directories(${hello_INCLUDE_DIR})
add_executable(test_hello main.cc)
target_link_libraries(test_hello hello)

set(CMAKE_INSTALL_PREFIX _install)
install(TARGETS test_hello DESTINATION bin)

add_subdirectory(src)
3 changes: 3 additions & 0 deletions SourceOrganized/include/hello.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include <iostream>

void hello();
22 changes: 22 additions & 0 deletions SourceOrganized/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// A simple program that computes the square root of a number
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#include "hello.h"

int main (int argc, char *argv[])
{
if (argc < 2)
{
fprintf(stdout,"Usage: %s number\n",argv[0]);
return 1;
}
double inputValue = atof(argv[1]);
double outputValue = sqrt(inputValue);
fprintf(stdout,"The square root of %g is %g\n",
inputValue, outputValue);

hello();
return 0;
}
8 changes: 8 additions & 0 deletions SourceOrganized/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 2.8)

project(lib_hello)

add_library(hello SHARED hello.cc)

install(TARGETS hello DESTINATION lib)
install(FILES ${hello_INCLUDE_DIR}/hello.h DESTINATION include)
7 changes: 7 additions & 0 deletions SourceOrganized/src/hello.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "hello.h"

#include <iostream>

void hello() {
std::cout<<"hello world!"<<std::endl;
}
Empty file added good_links.txt
Empty file.

0 comments on commit 039ba2d

Please sign in to comment.