From 8d8cba9367cbfa5fb111136b5a2f2f3470dac358 Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Thu, 26 Jan 2023 19:12:19 -0600 Subject: [PATCH] doc/users: update to new cmake syntax, update to recent changes --- doc/users/CMakeLists.txt.sample | 12 +- doc/users/CMakeLists.txt.sample2 | 14 +-- doc/users/CMakeLists.txt.sample3 | 18 +-- doc/users/cmake_user.html | 190 +++++++++++++++---------------- doc/users/testsuite.html | 8 +- 5 files changed, 121 insertions(+), 121 deletions(-) diff --git a/doc/users/CMakeLists.txt.sample b/doc/users/CMakeLists.txt.sample index dd60c95177..29dd27009f 100644 --- a/doc/users/CMakeLists.txt.sample +++ b/doc/users/CMakeLists.txt.sample @@ -1,11 +1,11 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 3.3.0) +cmake_minimum_required(VERSION 3.13.4) -FIND_PACKAGE(deal.II 9.5.0 REQUIRED +find_package(deal.II 9.5.0 REQUIRED HINTS ${DEAL_II_DIR} ../ ../../ $ENV{DEAL_II_DIR} ) -DEAL_II_INITIALIZE_CACHED_VARIABLES() +deal_ii_initialize_cached_variables() -PROJECT(myproject) +project(myproject) -ADD_EXECUTABLE(mycode mycode.cc) -DEAL_II_SETUP_TARGET(mycode) +add_executable(mycode mycode.cc) +deal_ii_setup_target(mycode) diff --git a/doc/users/CMakeLists.txt.sample2 b/doc/users/CMakeLists.txt.sample2 index a9fc3a5494..33989d825e 100644 --- a/doc/users/CMakeLists.txt.sample2 +++ b/doc/users/CMakeLists.txt.sample2 @@ -1,4 +1,4 @@ -FIND_PACKAGE(deal.II 9.5.0 REQUIRED +find_package(deal.II 9.5.0 REQUIRED HINTS ${DEAL_II_DIR} ../ ../../ $ENV{DEAL_II_DIR} # You can specify additional hints for search paths here, e.g. @@ -6,7 +6,7 @@ FIND_PACKAGE(deal.II 9.5.0 REQUIRED ) # Set the name of the project and target: -SET(TARGET "step-1") +set(TARGET "step-1") # Declare all source files the target consists of. Here, this is only # the one step-X.cc file, but as you expand your project you may wish @@ -18,11 +18,11 @@ SET(TARGET "step-1") # or switch altogether to the large project CMakeLists.txt file discussed # in the "CMake in user projects" page accessible from the "User info" # page of the documentation. -SET(TARGET_SRC +set(TARGET_SRC ${TARGET}.cc ) -CMAKE_MINIMUM_REQUIRED(VERSION 3.3.0) -DEAL_II_INITIALIZE_CACHED_VARIABLES() -PROJECT(${TARGET} CXX) -DEAL_II_INVOKE_AUTOPILOT() +cmake_minimum_required(VERSION 3.13.4) +deal_ii_initialize_cached_variables() +project(${TARGET} CXX) +deal_ii_invoke_autopilot() diff --git a/doc/users/CMakeLists.txt.sample3 b/doc/users/CMakeLists.txt.sample3 index 1165bf65cb..7eb2cd95d0 100644 --- a/doc/users/CMakeLists.txt.sample3 +++ b/doc/users/CMakeLists.txt.sample3 @@ -1,4 +1,4 @@ -FIND_PACKAGE(deal.II 9.5.0 REQUIRED +find_package(deal.II 9.5.0 REQUIRED HINTS ${DEAL_II_DIR} ../ ../../ $ENV{DEAL_II_DIR} # You can specify additional hints for search paths here, e.g. @@ -6,7 +6,7 @@ FIND_PACKAGE(deal.II 9.5.0 REQUIRED ) # Set the name of the project and target: -SET(TARGET "step-1") +set(TARGET "step-1") # Declare all source files the target consists of. Here, this is only # the one step-X.cc file, but as you expand your project you may wish @@ -18,24 +18,24 @@ SET(TARGET "step-1") # or switch altogether to the large project CMakeLists.txt file discussed # in the "CMake in user projects" page accessible from the "User info" # page of the documentation. -SET(TARGET_SRC +set(TARGET_SRC ${TARGET}.cc ) # Specify a list of files (file globs) that will be removed # with the "make runclean" and "make distclean" targets. # (If empty, sensible default values will be used.) -SET(CLEAN_UP_FILES +set(CLEAN_UP_FILES # a custom list of globs, e.g. *.log *.vtk ) # A custom command line that should be invoked by "make run". # (If empty, ./${TARGET} will be invoked.) -SET(TARGET_RUN +set(TARGET_RUN # a custom command line, e.g. mpirun -np 2 ${TARGET} ) -CMAKE_MINIMUM_REQUIRED(VERSION 3.3.0) -DEAL_II_INITIALIZE_CACHED_VARIABLES() -PROJECT(${TARGET} CXX) -DEAL_II_INVOKE_AUTOPILOT() +cmake_minimum_required(VERSION 3.13.4) +deal_ii_initialize_cached_variables() +project(${TARGET} CXX) +deal_ii_invoke_autopilot() diff --git a/doc/users/cmake_user.html b/doc/users/cmake_user.html index d847e43f3b..ae95d239c2 100644 --- a/doc/users/cmake_user.html +++ b/doc/users/cmake_user.html @@ -63,17 +63,17 @@ version):
-CMAKE_MINIMUM_REQUIRED(VERSION 3.3.0)
+cmake_minimum_required(VERSION 3.13.4)
 
-FIND_PACKAGE(deal.II 9.4.0 REQUIRED
+find_package(deal.II 9.5.0 REQUIRED
   HINTS ${DEAL_II_DIR} ../ ../../ $ENV{DEAL_II_DIR}
   )
-DEAL_II_INITIALIZE_CACHED_VARIABLES()
+deal_ii_initialize_cached_variables()
 
-PROJECT(myproject)
+project(myproject)
 
-ADD_EXECUTABLE(mycode mycode.cc)
-DEAL_II_SETUP_TARGET(mycode)
+add_executable(mycode mycode.cc)
+deal_ii_setup_target(mycode)
 

@@ -100,7 +100,7 @@ DEAL_II_SETUP_TARGET(mycode)

After finding the deal.II project, we fetch a set of cached variables with the - DEAL_II_INITIALIZE_CACHED_VARIABLES macro. You + deal_ii_initialize_cached_variables macro. You can inspect these for instance with ccmake.

@@ -112,7 +112,7 @@ DEAL_II_SETUP_TARGET(mycode)

Finally, the last two lines define the executable that is to be produced and its source code. The - DEAL_II_SETUP_TARGET macro will set up necessary include + deal_ii_setup_target macro will set up necessary include directories, compile flags, compile definitions, link flags and the link interface.

@@ -126,11 +126,11 @@ DEAL_II_SETUP_TARGET(mycode)

-ADD_EXECUTABLE(mycode2 mycode2.cc)
-DEAL_II_SETUP_TARGET(mycode2)
+add_executable(mycode2 mycode2.cc)
+deal_ii_setup_target(mycode2)
 
-ADD_EXECUTABLE(mycode3 mycode3.cc)
-DEAL_II_SETUP_TARGET(mycode3)
+add_executable(mycode3 mycode3.cc)
+deal_ii_setup_target(mycode3)
 
If the list gets longer, consider using @@ -148,12 +148,12 @@ with GLOB.

-ADD_LIBRARY(mylib libsrc1.cc libsrc2.cc libsrc3.cc)
-DEAL_II_SETUP_TARGET(mylib)
+add_library(mylib libsrc1.cc libsrc2.cc libsrc3.cc)
+deal_ii_setup_target(mylib)
 
-ADD_EXECUTABLE(mycode mycode.cc)
-DEAL_II_SETUP_TARGET(mycode)
-TARGET_LINK_LIBRARIES(mycode mylib)
+add_executable(mycode mycode.cc)
+deal_ii_setup_target(mycode)
+target_link_libraries(mycode mylib)
 

When you have multiple targets, @@ -165,11 +165,11 @@ attractive.

code, an alternative to creating a library might be the option:

-ADD_EXECUTABLE(mycode mycode.cc common.cc)
-DEAL_II_SETUP_TARGET(mycode)
+add_executable(mycode mycode.cc common.cc)
+deal_ii_setup_target(mycode)
 
-ADD_EXECUTABLE(mycode2 mycode2.cc common.cc)
-DEAL_II_SETUP_TARGET(mycode2)
+add_executable(mycode2 mycode2.cc common.cc)
+deal_ii_setup_target(mycode2)
 

You should be aware though that in this case common.cc will @@ -178,14 +178,14 @@ still don't want to use a shared library or static archive, another option is to create an OBJECT "library":

-ADD_LIBRARY(common OBJECT common.cc)
-DEAL_II_SETUP_TARGET(common)
+add_library(common OBJECT common.cc)
+deal_ii_setup_target(common)
 
-ADD_EXECUTABLE(mycode mycode.cc $<TARGET_OBJECTS:common>)
-DEAL_II_SETUP_TARGET(mycode)
+add_executable(mycode mycode.cc $<TARGET_OBJECTS:common>)
+deal_ii_setup_target(mycode)
 
-ADD_EXECUTABLE(mycode2 mycode2.cc $<TARGET_OBJECTS:common>)
-DEAL_II_SETUP_TARGET(mycode2)
+add_executable(mycode2 mycode2.cc $<TARGET_OBJECTS:common>)
+deal_ii_setup_target(mycode2)
 
This will compile common.cc once for the object target common and link the resulting object file into the two @@ -213,13 +213,13 @@ Alternatively, you can specify custom targets to switch the build type and compile automatically:
-ADD_CUSTOM_TARGET(debug
+add_custom_target(debug
   COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug ${CMAKE_SOURCE_DIR}
   COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target all
   COMMENT "Switch CMAKE_BUILD_TYPE to Debug"
   )
 
-ADD_CUSTOM_TARGET(release
+add_custom_target(release
   COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Release ${CMAKE_SOURCE_DIR}
   COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target all
   COMMENT "Switch CMAKE_BUILD_TYPE to Release"
@@ -241,7 +241,7 @@ tutorial, specify one this way (obviously, a single "run" target can only
 run a single executable): 

-ADD_CUSTOM_TARGET(run COMMAND mycode
+add_custom_target(run COMMAND mycode
   COMMENT "Run with ${CMAKE_BUILD_TYPE} configuration"
   )
 
@@ -271,29 +271,29 @@ mycode/include/*.h In this case the top level CMakeLists.txt file may be:
 # top level CMakeLists.txt
-CMAKE_MINIMUM_REQUIRED(VERSION 3.3.0)
-FIND_PACKAGE(deal.II 9.4.0 REQUIRED)
+cmake_minimum_required(VERSION 3.13.4)
+find_package(deal.II 9.5.0 REQUIRED)
 
-DEAL_II_INITIALIZE_CACHED_VARIABLES()
-PROJECT(myproject)
+deal_ii_initialize_cached_variables()
+project(myproject)
 
-ADD_SUBDIRECTORY(mylib)
-ADD_SUBDIRECTORY(mycode)
+add_subdirectory(mylib)
+add_subdirectory(mycode)
 
-The ADD_SUBDIRECTORY statement will include the CMakeLists.txt +The add_subdirectory statement will include the CMakeLists.txt file in the specified subdirectory. In our case:
 # mylib/CMakeLists.txt
 
-INCLUDE_DIRECTORIES(include)
+include_directories(include)
 
-ADD_LIBRARY(mylib
+add_library(mylib
   source/mylib1.cc
   source/mylib2.cc
   )
 
-DEAL_II_SETUP_TARGET(mylib)
+deal_ii_setup_target(mylib)
 
We have to add the directory include for the header files to @@ -305,22 +305,22 @@ like:
 # mycode/CMakeLists.txt
 
-INCLUDE_DIRECTORIES(
+include_directories(
   include
   ${CMAKE_SOURCE_DIR}/mylib/include
   )
 
-ADD_EXECUTABLE(mycode source/mycode.cc)
-DEAL_II_SETUP_TARGET(mycode)
+add_executable(mycode source/mycode.cc)
+deal_ii_setup_target(mycode)
 
-TARGET_LINK_LIBRARIES(mycode mylib)
+target_link_libraries(mycode mylib)
 

Please note that CMakeLists.txt files have directory scope. Any manipulation of properties and variables have only effect in the current directory (and subdirectories, included with -ADD_SUBDIRECTORY. The level above will not be affected. +add_subdirectory. The level above will not be affected. Therefore, we have to specify the include directories for "mylib" again in the subdirectory mycode - this time with full path ${CMAKE_SOURCE_DIR}/mylib/include. @@ -352,36 +352,36 @@ CMAKE_CURRENT_BINARY_DIR

Control statements in CMake take the following form:

-IF(<expression>)
+if(<expression>)
   ...
-ENDIF()
+endif()
 
or in long form:
-IF(<expression1>)
+if(<expression1>)
   ...
-ELSEIF(<expression2>)
+elseif(<expression2>)
   ...
-ELSE()
+else()
   ...
-ENDIF()
+endif()
 
Please note the (somehow uncommon) empty, opening and closing brackets -behind ELSE() and ENDIF(). +behind else() and endif(). <expression> can take a multitude of different forms, have a look at the CMake documentation for a complete list. Important examples are:
-IF(${variable})
+if(${variable})
   - the body will be evaluated if the variable "variable" is defined and
     synonymous to true, e.g. 1, TRUE, ON, YES (modulo case insensitivity)
 
-IF(variable MATCHES <regular expression>)
+if(variable MATCHES <regular expression>)
   - the body will be evaluated if the variable "variable" is defined and
     matches the specified regular expression
 
-IF("${variable}" STREQUAL "foobar")
+if("${variable}" STREQUAL "foobar")
   - the body will be evaluated if both strings are equal. Note that
     "${variable}" will be replaced by the content of the (string)
     variable "variable"
@@ -398,23 +398,23 @@ ENDIF()
 FOR statements. The former takes the same
 <expression> as the IF statement:

-WHILE(<expression>)
+while(<expression>)
   ...
-ENDWHILE()
+endwhile()
 
Given a variable list containing a list, the individual elements element can be accessed with a FOREACH statement:
-FOREACH(element ${list})
+foreach(element ${list})
   ...
-ENDFOREACH()
+endforeach()
 
Note: It is also possible to specify the list directly:
-FOREACH(element foo bar baz)
+foreach(element foo bar baz)
   # The variable element will iterate through foo, bar and baz.
-ENDFOREACH
+endforeach
 
@@ -429,8 +429,8 @@ The following example will pick up every source file under SOURCE_DIR/sources/ and add it to an executable:

-FILE(GLOB sources ${CMAKE_SOURCE_DIR}/source/*.cc)
-ADD_EXECUTABLE(mycode ${sources})
+file(GLOB sources ${CMAKE_SOURCE_DIR}/source/*.cc)
+add_executable(mycode ${sources})
 

Please be aware of one caveat of this approach: Due to the fact that @@ -442,11 +442,11 @@ source file you have to touch a CMakeLists.txt file or to run -

DEAL_II_SETUP_TARGET revisited

+

deal_ii_setup_target revisited

- The DEAL_II_SETUP_TARGET macro is responsible for setting up + The deal_ii_setup_target macro is responsible for setting up a target to compile and link against deal.II. It will append the - INCLUDE_DIRECTORIES property with the location of the + include_directories property with the location of the deal.II include directories, and append the properties COMPILE_FLAGS, COMPILE_DEFINITIONS and LINK_FLAGS by their respective values from the deal.II @@ -460,7 +460,7 @@ source file you have to touch a CMakeLists.txt file or to run

- Optionally, the DEAL_II_SETUP_TARGET macro takes an + Optionally, the deal_ii_setup_target macro takes an additional argument DEBUG, or RELEASE, after the target name to explicitly state the library flavor the target should be set up for. If the parameter is omitted, the correct choice is deduced @@ -500,11 +500,11 @@ The DEAL_II_INITIALIZE_CACHED_VARIABLES macro is responsible for setting up cached variables and has to invoked before the PROJECT call:

-FIND_PACKAGE(deal.II 9.4.0 REQUIRED)
+find_package(deal.II 9.5.0 REQUIRED)
 
-DEAL_II_INITIALIZE_CACHED_VARIABLES()
+deal_ii_initialize_cached_variables()
 
-PROJECT(myproject)
+project(myproject)
 
The macro will set an uninitialized CMAKE_BUILD_TYPE variable to the build type of deal.II, i.e. DEAL_II_BUILD_TYPE. If @@ -523,10 +523,10 @@ string.

Note: If you wish to override the flags and definitions set by the -DEAL_II_SETUP_TARGET macro you have to override the +deal_ii_setup_target macro you have to override the corresponding DEAL_II_* variable instead. See the documentation of DEAL_II_SETUP_TARGET +href="#cmakeadvanced.setup_target">deal_ii_setup_target for further details.

@@ -540,11 +540,11 @@ href="http://cmake.org/cmake/help/v2.8.8/cmake.html">CMake documentation for further details):
-INCLUDE_DIRECTORIES(include1 include2)
+include_directories(include1 include2)
 
-ADD_DEFINITIONS(-DFOO -DBAR="BAZ")
+add_definitions(-DFOO -DBAR="BAZ")
 
-ADD_EXECUTABLE(...) # or ADD_LIBRARY(...)
+add_executable(...) # or add_library(...)
 

@@ -557,7 +557,7 @@ a CMake find module is available, including this external library in your project is more or less straightforward. E.g. to require an external project "foo" at least of version 8.0 write:
-FIND_PACKAGE(foo 8.0 REQUIRED)
+find_package(foo 8.0 REQUIRED)
 
Alternatively, the version number and REQUIRED keyword can be omitted. Depending on the external library, the project configuration or @@ -566,16 +566,16 @@ and FOO_LIBRARIES that can be directly used in your CMakeLists.txt file:
-INCLUDE_DIRECTORIES(${FOO_INCLUDE_DIRS})
+include_directories(${FOO_INCLUDE_DIRS})
 
-ADD_EXECUTABLE(mycode mycode.cc)
-DEAL_II_SETUP_TARGET(mycode)
+add_executable(mycode mycode.cc)
+deal_ii_setup_target(mycode)
 
-TARGET_LINK_LIBRARIES(mycode ${FOO_LIBRARIES})
+target_link_libraries(mycode ${FOO_LIBRARIES})
 
The first statement will set up the include directories for the following targets as explained above. The last statement with -TARGET_LINK_LIBRARIES will add the libraries in the +target_link_libraries will add the libraries in the FOO_LIBRARIES variable to the link interface of the target mycode.

@@ -591,13 +591,13 @@ a copy of a skeleton run folder from the source directory:
 # Copy folder run from the source to the build directory:
-FILE(COPY ${CMAKE_SOURCE_DIR}/run DESTINATION ${CMAKE_BINARY_DIR})
+file(COPY ${CMAKE_SOURCE_DIR}/run DESTINATION ${CMAKE_BINARY_DIR})
 
-ADD_EXECUTABLE(mycode mycode.cc)
-SET_PROPERTY(TARGET mycode
+add_executable(mycode mycode.cc)
+set_property(TARGET mycode
   PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run
   )
-ADD_CUSTOM_TARGET(run
+add_custom_target(run
   COMMAND mycode
   WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/run
   )
@@ -639,12 +639,12 @@ INSTALL(DIRECTORY run DESTINATION share/mycode/run)
   write a CMakeLists.txt file may be to use
   an "autopilot" style macro. Here is a minimalistic example for the
   step-1 tutorial program (plain text version) that can be used for simple
+  target="_top">plain text version) that can be used for simple
   projects:
 

-FIND_PACKAGE(deal.II 9.4.0 REQUIRED
+find_package(deal.II 9.5.0 REQUIRED
   HINTS
     ${DEAL_II_DIR} ../ ../../ $ENV{DEAL_II_DIR}
     # You can specify additional hints for search paths here, e.g.
@@ -652,18 +652,18 @@ FIND_PACKAGE(deal.II 9.4.0 REQUIRED
 )
 
 # Set the name of the project and target:
-SET(TARGET "step-1")
+set(TARGET "step-1")
 
 # Declare all source files the target consists of:
-SET(TARGET_SRC
+set(TARGET_SRC
   step-1.cc
   # You can specify additional files here!
 )
 
-CMAKE_MINIMUM_REQUIRED(VERSION 3.3.0)
-DEAL_II_INITIALIZE_CACHED_VARIABLES()
-PROJECT(${TARGET} CXX)
-DEAL_II_INVOKE_AUTOPILOT()
+cmake_minimum_required(VERSION 3.13.4)
+deal_ii_initialize_cached_variables()
+project(${TARGET} CXX)
+deal_ii_invoke_autopilot()
 
@@ -721,14 +721,14 @@ $ cmake . # Specify a list of files (file globs) that will be removed # with the "make runclean" and "make distclean" targets. # (If empty, sensible default values will be used.) -SET(CLEAN_UP_FILES +set(CLEAN_UP_FILES # a custom list of globs, e.g. *.log *.vtk ) # (Optional) # A custom command line that should be invoked by "make run". # (If empty, ./${TARGET} will be invoked.) -SET(TARGET_RUN +set(TARGET_RUN # a custom command line, e.g. mpirun -np 2 ${TARGET} )
diff --git a/doc/users/testsuite.html b/doc/users/testsuite.html index 21fd677cb8..324f1fc2ad 100644 --- a/doc/users/testsuite.html +++ b/doc/users/testsuite.html @@ -110,8 +110,8 @@ tests/my_test.prm
SET(TARGET step-1) SET(TARGET_SRC step-1.cc) -CMAKE_MINIMUM_REQUIRED(VERSION 3.3.0) -FIND_PACKAGE(deal.II 9.4.0 REQUIRED +CMAKE_MINIMUM_REQUIRED(VERSION 3.13.4) +FIND_PACKAGE(deal.II 9.5.0 REQUIRED HINTS ${deal.II_DIR} ${DEAL_II_DIR} ../ ../../ $ENV{DEAL_II_DIR} ) @@ -215,8 +215,8 @@ tests/support/my_test_2.output
 # top-level CMakelists.txt
 
-CMAKE_MINIMUM_REQUIRED(VERSION 3.3.0)
-FIND_PACKAGE(deal.II 9.4.0 REQUIRED
+CMAKE_MINIMUM_REQUIRED(VERSION 3.13.4)
+FIND_PACKAGE(deal.II 9.5.0 REQUIRED
   HINTS ${deal.II_DIR} ${DEAL_II_DIR} ../ ../../ $ENV{DEAL_II_DIR}
   )
 
-- 
2.39.5