From: Guido Kanschat
- For larger projects the simple In order to specify multiple executable targets, simply repeat the last two lines of the simple
+ Adding a library is as simple as adding an executable target. We
+ specify the library name and then have to tell cmake that the
+ executables depend on it. The code in the simple file below the
+ project definition accordingly changes for instance to:
+ When you have multiple targets,
+repeat the last line of code for each of them. Accordingly,
+a loop becomes even more
+attractive. If you only have a single file or few files with common source
+code, an alternative to creating a library might be the option: You should be aware though that CMakeLists.txt
CMakeLists.txt
CMakeLists.txt
@@ -61,19 +62,19 @@
Simple CMakeLists.txt
CMakeLists.txt
presented
- above tends to be too inflexible. So, if you wish to have more
- control about targets the DEAL_II_SETUP_TARGET
macro
- might be of interest for you. Here is a full example
- (plain text version):
+ In this section, we start out with a
+ minimal CMakeLists.txt
based on
+ the DEAL_II_SETUP_TARGET
macro. This method gives
+ full control of what's happening and is easily extensible to
+ more complex projects, as exemplified in the subsections here an
+ later in the section on advanced
+ topics. Here is a full example
+ (plain text
+ version):
TODO: Fix plain text after finalizing!
- TODO: Do some nicer formatting of pre. Here and possibly
- globally. Do not use indentation by hand for this.
-
-
+
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.8)
FIND_PACKAGE(deal.II 8.0 REQUIRED
@@ -93,7 +94,7 @@ DEAL_II_SETUP_TARGET(mycode)
Adding multiple executable targets
CMakeLists.txt
:
+
ADD_EXECUTABLE(mycode2 mycode2.cc)
DEAL_II_SETUP_TARGET(mycode2)
@@ -105,6 +106,46 @@ If the list gets longer, consider using
a loop, possibly
with GLOB.
+
+
Adding libraries and common source files
+
+
+ADD_LIBRARY(mylib libsrc1.cc libsrc2.cc libsrc3.cc)
+
+ADD_EXECUTABLE(mycode mycode.cc)
+DEAL_II_SETUP_TARGET(mycode)
+TARGET_LINK_LIBRARIES(mycode mylib)
+
+
+
+ADD_EXECUTABLE(mycode mycode.cc common.cc)
+DEAL_II_SETUP_TARGET(mycode)
+
+ADD_EXECUTABLE(mycode2 mycode2.cc common.cc)
+DEAL_II_SETUP_TARGET(mycode2)
+
+
+common.cc
will be
+compiled for each target, not only once.Adding a "run" target
@@ -114,7 +155,7 @@ with GLOB.
can only run a single executable):
+ADD_CUSTOM_TARGET(run COMMAND mycode COMMENT "Run with ${CMAKE_BUILD_TYPE} configuration")@@ -134,7 +175,7 @@ ADD_CUSTOM_TARGET(run COMMAND mycode projects: -+FIND_PACKAGE(deal.II 8.0 REQUIRED HINTS ${DEAL_II_DIR} ../ ../../ $ENV{DEAL_II_DIR} @@ -209,7 +250,7 @@ $ cmake . variables beforeDEAL_II_INVOKE_AUTOPILOT()
is called (plain text version): -+# (Optional) # Specify a list of files (file globs) that will be removed # with the "make runclean" and "make distclean" targets. diff --git a/deal.II/doc/screen.css b/deal.II/doc/screen.css index 5ca7aa3459..dd6605493a 100644 --- a/deal.II/doc/screen.css +++ b/deal.II/doc/screen.css @@ -180,6 +180,16 @@ pre { line-height: 1.1em; } +pre.cmake { + padding: 1em; + text-align: left; + text-indent: 0; + border: 1px solid #d06fab; + color: Black; + background-color: #f9f9f9; + line-height: 1.1em; +} + pre.sample { padding: 1em; text-align: left;