From: Matthias Maier Date: Sat, 18 Feb 2017 00:37:45 +0000 (-0600) Subject: CMake: Compile examples if examples component is set up X-Git-Tag: v8.5.0-rc1~41^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b228660e1d433b48d82593dea91e3c50df5afef8;p=dealii.git CMake: Compile examples if examples component is set up --- diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index e5b030ac37..97b610cba4 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -46,17 +46,63 @@ IF(DEAL_II_COMPONENT_EXAMPLES) PATTERN "DTMB-5415_bulbous_bow.iges" # step-54 ) + IF(DEAL_II_COMPILE_EXAMPLES) + # + # Set up all executables: + # + FILE(GLOB _steps ${CMAKE_CURRENT_SOURCE_DIR}/step-*/*.cc) + FOREACH(_step ${_steps}) + GET_FILENAME_COMPONENT(_name ${_step} NAME_WE) + GET_FILENAME_COMPONENT(_directory ${_step} DIRECTORY) + + # + # Extract dependency information from CMakeLists.txt file. + # + SET(_dependency_string TRUE) + IF(EXISTS "${_directory}/CMakeLists.txt") + FILE(STRINGS "${_directory}/CMakeLists.txt" _dependency_string + REGEX "^IF.*DEAL_II.* # keep in one line$" + ) + STRING(REPLACE "IF(" "" _dependency_string "${_dependency_string}") + STRING(REPLACE ") # keep in one line" "" _dependency_string "${_dependency_string}") + IF("${_dependency_string}" STREQUAL "") + SET(_dependency_string "TRUE") + ELSE() + SET(_dependency_string "NOT (${_dependency_string})") + ENDIF() + ENDIF() + + # + # Now evaluate the _dependency_string and store the result in _setup. + # We have to be careful - ${_dependency_string} evaluating to true + # means that not all dependencies are fulfilled. + # + SET(_setup FALSE) + EVALUATE_EXPRESSION(" + IF(${_dependency_string}) + SET(_setup TRUE) + ENDIF()") + + IF(_setup) + FOREACH(_build ${DEAL_II_BUILD_TYPES}) + STRING(TOLOWER ${_build} _build_lowercase) + ADD_EXECUTABLE(${_name}.${_build_lowercase} ${_step}) + DEAL_II_INSOURCE_SETUP_TARGET(${_name}.${_build_lowercase} ${_build}) + SET_TARGET_PROPERTIES(${_name}.${_build_lowercase} + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${DEAL_II_EXECUTABLE_RELDIR}" + ) + ADD_DEPENDENCIES(examples ${_name}.${_build_lowercase}) + ENDFOREACH() + + ELSE() + + MESSAGE(STATUS " ${_name} - dependencies not satisfied") + ENDIF() + + ENDFOREACH() + ENDIF() + MESSAGE(STATUS "Setting up examples - Done") -ENDIF() -# -# Add a dummy target to make files known to IDEs like qtcreator -# - -FILE(GLOB _misc - ${CMAKE_CURRENT_SOURCE_DIR}/step-*/*.cc - ${CMAKE_CURRENT_SOURCE_DIR}/step-*/*.h -) -ADD_CUSTOM_TARGET(dummy_examples_files - SOURCES ${_misc} - ) +ENDIF()