From 98fe8a63c4757c571952d82e4b6394097208025c Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Mon, 12 Nov 2018 10:14:16 -0600 Subject: [PATCH] Some minor refactoring: - remove unnecessary variables - fuse for loops - adhere to coding styles --- cmake/config/CMakeLists.txt | 217 +++++++++--------- .../{deal.II_base.pc.in => config_base.pc.in} | 8 +- ...deal.II_debug.pc.in => config_debug.pc.in} | 7 +- ....II_release.pc.in => config_release.pc.in} | 5 +- cmake/setup_deal_ii.cmake | 2 + 5 files changed, 117 insertions(+), 122 deletions(-) rename cmake/config/{deal.II_base.pc.in => config_base.pc.in} (53%) rename cmake/config/{deal.II_debug.pc.in => config_debug.pc.in} (73%) rename cmake/config/{deal.II_release.pc.in => config_release.pc.in} (90%) diff --git a/cmake/config/CMakeLists.txt b/cmake/config/CMakeLists.txt index 8b558d5e75..cf6face967 100644 --- a/cmake/config/CMakeLists.txt +++ b/cmake/config/CMakeLists.txt @@ -135,7 +135,6 @@ SET(CONFIG_INCLUDE_DIRS ${DEAL_II_USER_INCLUDE_DIRS} ) - CONFIGURE_FILE( ${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in ${CMAKE_BINARY_DIR}/${DEAL_II_PROJECT_CONFIG_RELDIR}/${DEAL_II_PROJECT_CONFIG_NAME}Config.cmake @@ -222,8 +221,13 @@ FOREACH(_name ${_deal_ii_features_sorted}) ENDFOREACH() ENDFOREACH() -##################################################################### -# pkgconfig files + +######################################################################## +# # +# pkgconfig files # +# # +######################################################################## + # # Set up the pkgconfig configuration files consisting of # @@ -244,144 +248,137 @@ ENDFOREACH() # # -# For binary dir (AKA build dir): +# Build up the link line from our list of libraries: # -set(DEAL_II_PATH_PC ${CMAKE_BINARY_DIR}) +FOREACH(_build ${DEAL_II_BUILD_TYPES}) + STRING(TOLOWER ${_build} _build_lowercase) -set (CONFIG_INCLUDE_DIRS_PC "") -foreach(_dir ${CONFIG_INCLUDE_DIRS}) - string(CONCAT CONFIG_INCLUDE_DIRS_PC "${CONFIG_INCLUDE_DIRS_PC} -I${_dir} " ) -endforeach() + SET(_name "${DEAL_II_BASE_NAME}${DEAL_II_${_build}_SUFFIX}") -# populate the variables -# CONFIG_LIBRARIES_DEBUG_PC -# CONFIG_LIBRARIES_RELEASE_PC + SET(CONFIG_RPATH_${_build}_PC "") + SET(CONFIG_LIBRARIES_${_build}_PC "-L\${libdir} -l${_name}") -foreach (_build ${DEAL_II_BUILD_TYPES}) - if(_build MATCHES DEBUG) - set(_build "debug") - else() - set(_build "release") - endif() + FOREACH(_lib ${DEAL_II_LIBRARIES_${_build}} ${DEAL_II_LIBRARIES}) - string(TOUPPER ${_build} _B) - set(PC_LIBRARIES ${CONFIG_LIBRARIES_${_B}}) - set(CONFIG_LIBRARIES_PC "") - foreach(_lib ${PC_LIBRARIES}) - # _lib can be of two types - # 1. something like "/home/alberto/opt/lib/trilinos/lib/libteuchoscore.so" - # 2. or simply "m" for the math lib + GET_FILENAME_COMPONENT(_name ${_lib} NAME) + GET_FILENAME_COMPONENT(_dir ${_lib} PATH) - get_filename_component(_libname ${_s} NAME) - get_filename_component(_libdir ${_s} PATH) + IF("${_dir}" STREQUAL "") + # ${_lib} is a simple library name, just add it to the link line: + SET(_library_string "-l${_lib}") - if(IS_DIRECTORY ${_libdir}) # i.e., we are in the first case - # we have to add -L flag - string(CONCAT CONFIG_LIBRARIES_PC " ${CONFIG_LIBRARIES_PC} -L${_libdir} ") - # and add the path to the rpath - list(APPEND PC_RPATH ${_libdir}) - endif() + ELSE() + # ${_lib} is a full library path: + + # + # Only append a library directory if it is new ... + # + + list (FIND CONFIG_RPATH_${_build}_PC "${_dir}" _index) + IF (${_index} EQUAL -1) + SET(_library_string "-L${_dir} ") + LIST(APPEND CONFIG_RPATH_${_build}_PC ${_dir}) + ELSE() + SET(_library_string "") + ENDIF() - # check if the library name begins with lib - # we are dealing with the first case - string(SUBSTRING ${_libname} 0 3 _beg) + # Recover short name: + STRING(REGEX REPLACE + "^(${CMAKE_STATIC_LIBRARY_PREFIX}|${CMAKE_SHARED_LIBRARY_PREFIX})" + "" _name "${_name}" + ) + STRING(REGEX REPLACE + "(${CMAKE_STATIC_LIBRARY_SUFFIX}|${CMAKE_SHARED_LIBRARY_SUFFIX})$" + "" _name "${_name}" + ) + SET(_library_string "${_library_string}-l${_name}") + ENDIF() - if(${_beg} MATCHES "lib") - string(CONCAT CONFIG_LIBRARIES_PC " ${CONFIG_LIBRARIES_PC} ${_libname} ") - else() - # second case - string(CONCAT CONFIG_LIBRARIES_PC " ${CONFIG_LIBRARIES_PC} -l${_libname} " ) - endif() - endforeach() + SET(CONFIG_LIBRARIES_${_build}_PC + "${CONFIG_LIBRARIES_${_build}_PC} ${_library_string}" + ) + ENDFOREACH() - set(CONFIG_LIBRARIES_${_B}_PC ${CONFIG_LIBRARIES_PC}) - - list(REMOVE_DUPLICATES PC_RPATH) - foreach(_dir ${PC_RPATH}) - string(CONCAT CONFIG_LIBRARIES_${_B}_PC " ${CONFIG_LIBRARIES_${_B}_PC} -Wl,-rpath,${_dir} " ) - endforeach() + TO_STRING_AND_ADD_PREFIX(CONFIG_RPATH_${_build}_PC + "-Wl,-rpath," ${CONFIG_RPATH_${_build}_PC} + ) +ENDFOREACH() -endforeach() -configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/deal.II_base.pc.in - ${CMAKE_BINARY_DIR}/${DEAL_II_LIBRARY_RELDIR}/pkgconfig/${DEAL_II_PROJECT_CONFIG_NAME}_base.pc - @ONLY +# +# For binary dir (aka build dir): +# + +SET(CONFIG_PATH_PC "${CMAKE_BINARY_DIR}") + +TO_STRING_AND_ADD_PREFIX(CONFIG_INCLUDE_DIRS_PC "-I" + \\\${prefix}/include + ${CMAKE_SOURCE_DIR}/include + ${DEAL_II_BUNDLED_INCLUDE_DIRS} + ${DEAL_II_USER_INCLUDE_DIRS} ) -# generate the requested .pc files -foreach (_build ${DEAL_II_BUILD_TYPES}) - if(_build MATCHES DEBUG) - set(_build "debug") - else() - set(_build "release") - endif() - - configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/deal.II_${_build}.pc.in - ${CMAKE_BINARY_DIR}/${DEAL_II_LIBRARY_RELDIR}/pkgconfig/${DEAL_II_PROJECT_CONFIG_NAME}_${_build}.pc +FOREACH(_build ${DEAL_II_BUILD_TYPES}) + STRING(TOLOWER ${_build} _build_lowercase) + + SET(_config_directory "${CMAKE_BINARY_DIR}/${DEAL_II_PKGCONF_RELDIR}") + + CONFIGURE_FILE( + ${CMAKE_CURRENT_SOURCE_DIR}/config_${_build_lowercase}.pc.in + ${_config_directory}/${DEAL_II_PROJECT_CONFIG_NAME}_${_build_lowercase}.pc @ONLY ) -endforeach() +ENDFOREACH() + +CONFIGURE_FILE( + ${CMAKE_CURRENT_SOURCE_DIR}/config_base.pc.in + ${_config_directory}/${DEAL_II_PROJECT_CONFIG_NAME}_base.pc + @ONLY + ) -############################################################################# # # For installation: # -set(DEAL_II_PATH_PC ${CMAKE_INSTALL_PREFIX}) +SET(CONFIG_PATH_PC "${CMAKE_INSTALL_PREFIX}") -set (CONFIG_INCLUDE_DIRS_PC "") -foreach(_dir ${CONFIG_INCLUDE_DIRS}) - string(CONCAT CONFIG_INCLUDE_DIRS_PC "${CONFIG_INCLUDE_DIRS_PC} -I${_dir} " ) -endforeach() - -configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/deal.II_base.pc.in - ${CMAKE_CURRENT_BINARY_DIR}/${DEAL_II_PROJECT_CONFIG_NAME}_base.pc - @ONLY - ) - -install(FILES - ${CMAKE_CURRENT_BINARY_DIR}/${DEAL_II_PROJECT_CONFIG_NAME}_base.pc - DESTINATION ${DEAL_II_LIBRARY_RELDIR}/pkgconfig - COMPONENT library +TO_STRING_AND_ADD_PREFIX(CONFIG_INCLUDE_DIRS_PC "-I" + \\\${prefix}/include + ${CMAKE_SOURCE_DIR}/include + ${DEAL_II_BUNDLED_INCLUDE_DIRS} + ${DEAL_II_USER_INCLUDE_DIRS} ) +FOREACH(_build ${DEAL_II_BUILD_TYPES}) + STRING(TOLOWER ${_build} _build_lowercase) -# generate the requested .pc files -foreach (_build ${DEAL_II_BUILD_TYPES}) - if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "DebugRelease") - set(_build "general") - else() - if(_build MATCHES DEBUG) - set(_build "debug") - else() - set(_build "release") - endif() - endif() - - configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/deal.II_${_build}.pc.in - ${CMAKE_CURRENT_BINARY_DIR}/${DEAL_II_PROJECT_CONFIG_NAME}_${_build}.pc + CONFIGURE_FILE( + ${CMAKE_CURRENT_SOURCE_DIR}/config_${_build_lowercase}.pc.in + ${CMAKE_CURRENT_BINARY_DIR}/${DEAL_II_PROJECT_CONFIG_NAME}_${_build_lowercase}.pc @ONLY ) - install(FILES - ${CMAKE_CURRENT_BINARY_DIR}/${DEAL_II_PROJECT_CONFIG_NAME}_${_build}.pc - DESTINATION ${DEAL_II_LIBRARY_RELDIR}/pkgconfig + INSTALL(FILES + ${CMAKE_CURRENT_BINARY_DIR}/${DEAL_II_PROJECT_CONFIG_NAME}_${_build_lowercase}.pc + DESTINATION ${DEAL_II_PKGCONF_RELDIR} COMPONENT library ) -endforeach() - - - - - - +ENDFOREACH() +CONFIGURE_FILE( + ${CMAKE_CURRENT_SOURCE_DIR}/config_base.pc.in + ${CMAKE_CURRENT_BINARY_DIR}/${DEAL_II_PROJECT_CONFIG_NAME}_base.pc + @ONLY + ) +INSTALL(FILES + ${CMAKE_CURRENT_BINARY_DIR}/${DEAL_II_PROJECT_CONFIG_NAME}_base.pc + DESTINATION ${DEAL_II_PKGCONF_RELDIR} + COMPONENT library + ) -# end of pkgconfig files -#################################################################### +# +# Jobs done. +# MESSAGE(STATUS "Setting up project configuration - Done") + diff --git a/cmake/config/deal.II_base.pc.in b/cmake/config/config_base.pc.in similarity index 53% rename from cmake/config/deal.II_base.pc.in rename to cmake/config/config_base.pc.in index 81d981162c..cd8573e8b4 100644 --- a/cmake/config/deal.II_base.pc.in +++ b/cmake/config/config_base.pc.in @@ -1,10 +1,10 @@ -DEAL_II_PATH=@DEAL_II_PATH_PC@ -DEAL_II_INCLUDE_RELDIR=@DEAL_II_INCLUDE_RELDIR@ -libdir=${DEAL_II_PATH}/@DEAL_II_LIBRARY_RELDIR@ +prefix=@CONFIG_PATH_PC@ +includedir=${prefix}/@DEAL_II_INCLUDE_RELDIR@ +libdir=${prefix}/@DEAL_II_LIBRARY_RELDIR@ Name: deal.II_base Description: base file used by the debug and release versions Version: @DEAL_II_VERSION@ URL: https://github.com/dealii/dealii Cflags: @DEAL_II_CXX_FLAGS@ @CONFIG_INCLUDE_DIRS_PC@ -Libs: -L${libdir} @DEAL_II_LINKER_FLAGS@ +Libs: @DEAL_II_LINKER_FLAGS@ diff --git a/cmake/config/deal.II_debug.pc.in b/cmake/config/config_debug.pc.in similarity index 73% rename from cmake/config/deal.II_debug.pc.in rename to cmake/config/config_debug.pc.in index 868cb996a8..0cd2b153d5 100644 --- a/cmake/config/deal.II_debug.pc.in +++ b/cmake/config/config_debug.pc.in @@ -1,10 +1,7 @@ -DEAL_II_PATH=@DEAL_II_PATH_PC@ Name: deal.II compiled in debug mode -Description: A C++ software library supporting the creation of finite element codes and an open community of users and developers. +Description: A C++ software library supporting the creation of finite element codes and an open community of users and developers. Version: @DEAL_II_VERSION@ URL: https://github.com/dealii/dealii Requires: deal.II_base Cflags: @DEAL_II_CXX_FLAGS_DEBUG@ -Libs: @DEAL_II_LINKER_FLAGS_DEBUG@ @CONFIG_LIBRARIES_DEBUG_PC@ - - +Libs: @DEAL_II_LINKER_FLAGS_DEBUG@ @CONFIG_LIBRARIES_DEBUG_PC@ @CONFIG_RPATH_DEBUG_PC@ diff --git a/cmake/config/deal.II_release.pc.in b/cmake/config/config_release.pc.in similarity index 90% rename from cmake/config/deal.II_release.pc.in rename to cmake/config/config_release.pc.in index daaf6cac57..208e5e0556 100644 --- a/cmake/config/deal.II_release.pc.in +++ b/cmake/config/config_release.pc.in @@ -1,8 +1,7 @@ -DEAL_II_PATH=@DEAL_II_PATH_PC@ Name: deal.II compiled in debug mode -Description: A C++ software library supporting the creation of finite element codes and an open community of users and developers. +Description: A C++ software library supporting the creation of finite element codes and an open community of users and developers. Version: @DEAL_II_VERSION@ URL: https://github.com/dealii/dealii Requires: deal.II_base Cflags: @DEAL_II_CXX_FLAGS_RELEASE@ -Libs: @DEAL_II_LINKER_FLAGS_RELEASE@ @CONFIG_LIBRARIES_RELEASE_PC@ +Libs: @DEAL_II_LINKER_FLAGS_RELEASE@ @CONFIG_LIBRARIES_RELEASE_PC@ @CONFIG_RPATH_RELEASE_PC@ diff --git a/cmake/setup_deal_ii.cmake b/cmake/setup_deal_ii.cmake index 6cd84dd2c2..1ab65989be 100644 --- a/cmake/setup_deal_ii.cmake +++ b/cmake/setup_deal_ii.cmake @@ -45,6 +45,7 @@ # DEAL_II_EXECUTABLE_RELDIR *) # DEAL_II_INCLUDE_RELDIR *) # DEAL_II_LIBRARY_RELDIR *) +# DEAL_II_PKGCONF_RELDIR *) # DEAL_II_PROJECT_CONFIG_RELDIR *) # DEAL_II_SHARE_RELDIR *) # DEAL_II_DOCREADME_RELDIR *) @@ -112,6 +113,7 @@ SET_IF_EMPTY(DEAL_II_RELEASE_SUFFIX "") SET_IF_EMPTY(DEAL_II_EXECUTABLE_RELDIR "bin") SET_IF_EMPTY(DEAL_II_INCLUDE_RELDIR "include") SET_IF_EMPTY(DEAL_II_LIBRARY_RELDIR "lib${LIB_SUFFIX}") +SET_IF_EMPTY(DEAL_II_PKGCONF_RELDIR "${DEAL_II_LIBRARY_RELDIR}/pkgconfig") SET_IF_EMPTY(DEAL_II_PROJECT_CONFIG_RELDIR "${DEAL_II_LIBRARY_RELDIR}/cmake/${DEAL_II_PROJECT_CONFIG_NAME}") SET_IF_EMPTY(DEAL_II_SHARE_RELDIR "share/${DEAL_II_PACKAGE_NAME}") # -- 2.39.5