diff --git a/CMakeLists.txt b/CMakeLists.txt index c3635e7..ab47dcd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,118 +1,91 @@ -#==================================================================================================# -# # -# (c - GPLv3) T.W.J. de Geus (Tom) | tom@geus.me | www.geus.me | github.com/tdegeus/GooseFEM # -# # -#==================================================================================================# +# +# (c - GPLv3) T.W.J. de Geus (Tom) | tom@geus.me | www.geus.me | github.com/tdegeus/GooseFEM +# cmake_minimum_required(VERSION 3.0) # Basic settings # ============== project(GooseFEM) option(BUILD_TESTS "Build tests" OFF) option(BUILD_EXAMPLES "Build examples" OFF) # Version # ======= -file( - STRINGS - "${CMAKE_CURRENT_SOURCE_DIR}/include/GooseFEM/config.h" - GooseFEM_version_defines - REGEX - "#define GOOSEFEM_VERSION_(MAJOR|MINOR|PATCH)") +file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/include/GooseFEM/config.h" GooseFEM_version_defines + REGEX "#define GOOSEFEM_VERSION_(MAJOR|MINOR|PATCH)") foreach(ver ${GooseFEM_version_defines}) if(ver MATCHES "#define GOOSEFEM_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$") - set(GOOSEFEM_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "") + set(GOOSEFEM_VERSION_${CMAKE_MATCH_1} + "${CMAKE_MATCH_2}" + CACHE INTERNAL "") endif() endforeach() -set(GOOSEFEM_VERSION - ${GOOSEFEM_VERSION_MAJOR}.${GOOSEFEM_VERSION_MINOR}.${GOOSEFEM_VERSION_PATCH}) +set(GOOSEFEM_VERSION ${GOOSEFEM_VERSION_MAJOR}.${GOOSEFEM_VERSION_MINOR}.${GOOSEFEM_VERSION_PATCH}) message(STATUS "Building GooseFEM v${GOOSEFEM_VERSION}") # Set target # ========== find_package(xtensor REQUIRED) add_library(GooseFEM INTERFACE) target_include_directories(GooseFEM INTERFACE $ $) target_link_libraries(GooseFEM INTERFACE xtensor) # Installation # ============ include(CMakePackageConfigHelpers) include(GNUInstallDirs) -install( - DIRECTORY - "${CMAKE_CURRENT_SOURCE_DIR}/include/" - DESTINATION - include) +install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" DESTINATION include) -install( - TARGETS - GooseFEM - EXPORT - GooseFEM-targets) +install(TARGETS GooseFEM EXPORT GooseFEM-targets) install( - EXPORT - GooseFEM-targets - FILE - GooseFEMTargets.cmake - DESTINATION - "${CMAKE_INSTALL_LIBDIR}/cmake/GooseFEM") + EXPORT GooseFEM-targets + FILE GooseFEMTargets.cmake + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/GooseFEM") set(_GOOSEFEM ${CMAKE_SIZEOF_VOID_P}) unset(CMAKE_SIZEOF_VOID_P) -write_basic_package_version_file( - "${CMAKE_CURRENT_BINARY_DIR}/GooseFEMConfigVersion.cmake" - VERSION - ${GOOSEFEM_VERSION} - COMPATIBILITY - AnyNewerVersion) +write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/GooseFEMConfigVersion.cmake" + VERSION ${GOOSEFEM_VERSION} + COMPATIBILITY AnyNewerVersion) set(CMAKE_SIZEOF_VOID_P ${_GOOSEFEM}) -install( - FILES - "${CMAKE_CURRENT_SOURCE_DIR}/GooseFEMConfig.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/GooseFEMConfigVersion.cmake" - DESTINATION - "${CMAKE_INSTALL_LIBDIR}/cmake/GooseFEM") +install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/GooseFEMConfig.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/GooseFEMConfigVersion.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/GooseFEM") -configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/GooseFEM.pc.in" - "${CMAKE_CURRENT_BINARY_DIR}/GooseFEM.pc" - @ONLY) +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/GooseFEM.pc.in" + "${CMAKE_CURRENT_BINARY_DIR}/GooseFEM.pc" @ONLY) -install( - FILES - "${CMAKE_CURRENT_BINARY_DIR}/GooseFEM.pc" - DESTINATION - "${CMAKE_INSTALL_LIBDIR}/pkgconfig/") +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/GooseFEM.pc" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/") # Add builds # ========== include("GooseFEMConfig.cmake") if(BUILD_TESTS) add_subdirectory(test) endif() if(BUILD_EXAMPLES) add_subdirectory(docs/examples) endif() diff --git a/GooseFEMConfig.cmake b/GooseFEMConfig.cmake index 0c8507c..fd5e49c 100644 --- a/GooseFEMConfig.cmake +++ b/GooseFEMConfig.cmake @@ -1,82 +1,78 @@ # GooseFEM cmake module # # This module sets the target: # # GooseFEM # # In addition, it sets the following variables: # # GooseFEM_FOUND - true if GooseFEM found # GooseFEM_VERSION - GooseFEM's version # GooseFEM_INCLUDE_DIRS - the directory containing GooseFEM headers # # The following support targets are defined to simplify things: # # GooseFEM::compiler_warnings - enable compiler warnings # GooseFEM::assert - enable GooseFEM assertions # GooseFEM::debug - enable all assertions (slow) include(CMakeFindDependencyMacro) # Define target "GooseFEM" -# ======================== if(NOT TARGET GooseFEM) include("${CMAKE_CURRENT_LIST_DIR}/GooseFEMTargets.cmake") get_target_property(GooseFEM_INCLUDE_DIRS GooseFEM INTERFACE_INCLUDE_DIRECTORIES) endif() # Find dependencies -# ================= find_dependency(xtensor) find_package(Eigen3 QUIET) if(NOT Eigen3_FOUND) find_package(PkgConfig) pkg_check_modules(EIGEN3 QUIET eigen3) endif() if(Eigen3_FOUND) target_include_directories(GooseFEM INTERFACE ${EIGEN3_INCLUDE_DIRS}) endif() # Define support target "GooseFEM::compiler_warnings" -# =================================================== -if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_GREATER_EQUAL 3.11) - if(NOT TARGET GooseFEM::compiler_warnings) - add_library(GooseFEM::compiler_warnings INTERFACE IMPORTED) - if(MSVC) - target_compile_options(GooseFEM::compiler_warnings INTERFACE - /W4) - else() - target_compile_options(GooseFEM::compiler_warnings INTERFACE - -Wall - -Wextra - -pedantic - -Wno-unknown-pragmas) - endif() +if(NOT TARGET GooseFEM::compiler_warnings) + add_library(GooseFEM::compiler_warnings INTERFACE IMPORTED) + if(MSVC) + set_property( + TARGET GooseFEM::compiler_warnings + PROPERTY INTERFACE_COMPILE_OPTIONS + /W4) + else() + set_property( + TARGET GooseFEM::compiler_warnings + PROPERTY INTERFACE_COMPILE_OPTIONS + -Wall -Wextra -pedantic -Wno-unknown-pragmas) endif() endif() # Define support target "GooseFEM::assert" -# ======================================== -if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_GREATER_EQUAL 3.11) - if(NOT TARGET GooseFEM::assert) - add_library(GooseFEM::assert INTERFACE IMPORTED) - target_compile_definitions(GooseFEM::assert INTERFACE GOOSEFEM_ENABLE_ASSERT) - endif() +if(NOT TARGET GooseFEM::assert) + add_library(GooseFEM::assert INTERFACE IMPORTED) + set_property( + TARGET GooseFEM::assert + PROPERTY INTERFACE_COMPILE_DEFINITIONS + GOOSEFEM_ENABLE_ASSERT) endif() -# Define support target "GooseEYE::debug" -# ======================================= +# Define support target "GooseFEM::debug" -if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_GREATER_EQUAL 3.11) - if(NOT TARGET GooseFEM::debug) - add_library(GooseFEM::debug INTERFACE IMPORTED) - target_compile_definitions(GooseFEM::debug INTERFACE GOOSEFEM_DEBUG) - endif() +if(NOT TARGET GooseFEM::debug) + add_library(GooseFEM::debug INTERFACE IMPORTED) + set_property( + TARGET GooseFEM::debug + PROPERTY INTERFACE_COMPILE_DEFINITIONS + XTENSOR_ENABLE_ASSERT GOOSEFEM_ENABLE_ASSERT) endif()