Skip to content

Help writing a CMakeLists #6716

@VictorEijkhout

Description

@VictorEijkhout

As a regression test I want to compile & run one of the sources in the unit_tests directory. Unforunately the CMakeLists there is not usable since it can only be used when called from the main build.

Here is my attempt at a CMakeLists.txt:

cmake_minimum_required(VERSION 3.31.5)

project( ${PROJECTNAME}
  DESCRIPTION "C++ programs for Aspect testing"
  VERSION 1.0 )

add_executable( ${PROJECTNAME} ${PROJECTNAME}.cpp )

find_package( MPI )
# nope find_package( deal.II REQUIRED )
find_package( Aspect REQUIRED )

find_package( PkgConfig REQUIRED )
pkg_check_modules( CATCH2 REQUIRED catch2-with-main )
target_include_directories(
        ${PROJECTNAME} PUBLIC
        ${CATCH2_INCLUDE_DIRS}
        )
target_link_directories(
        ${PROJECTNAME} PUBLIC
        ${CATCH2_LIBRARY_DIRS}
        )
target_link_libraries(
        ${PROJECTNAME} PUBLIC
        ${CATCH2_LIBRARIES}
        )

DEAL_II_INITIALIZE_CACHED_VARIABLES()

ASPECT_SETUP_PLUGIN(${PROJECTNAME})

install( TARGETS ${PROJECTNAME} DESTINATION . )

This leads to an error:

-- Found PkgConfig: /usr/bin/pkg-config (found version "1.7.3")
-- Checking for module 'catch2-with-main'
--   Found catch2-with-main, version 3.8.1
###
#
#  WARNING:
#
#  CMAKE_BUILD_TYPE "" unsupported by current installation!
#  deal.II was configured with "DebugRelease".
#
#  CMAKE_BUILD_TYPE was forced to "Debug".
#
###
-- Setting up plugin:
--   name <first>
--   using ASPECT_DIR /home1/apps/gcc13/impi21/aspect/3.0.0/bin
--   setting up RELEASE variant
CMake Error at /home1/apps/gcc13/impi21/dealii/9.6.2/share/deal.II/macros/macro_deal_ii_setup_target.cmake:103 (target_link_libraries):
  The keyword signature for target_link_libraries has already been used with
  the target "first".  All uses of target_link_libraries with a target must
  be either all-keyword or all-plain.

  The uses of the keyword signature are here:

   * CMakeLists.txt:23 (target_link_libraries)

Call Stack (most recent call first):
  /home1/apps/gcc13/impi21/aspect/3.0.0/lib/cmake/Aspect/AspectConfig.cmake:73 (deal_ii_setup_target)
  CMakeLists.txt:30 (ASPECT_SETUP_PLUGIN)


-- Configuring incomplete, errors occurred!

Can I get a hint?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions