From b228660e1d433b48d82593dea91e3c50df5afef8 Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Fri, 17 Feb 2017 18:37:45 -0600 Subject: [PATCH] CMake: Compile examples if examples component is set up --- examples/CMakeLists.txt | 70 ++++++++++++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 12 deletions(-) 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() -- 2.39.5