Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. CMake adds unwanted files while installing
Forum Updated to NodeBB v4.3 + New Features

CMake adds unwanted files while installing

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
9 Posts 3 Posters 831 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GrassHopper90
    wrote on 1 May 2022, 17:43 last edited by
    #1

    Hi everyone.
    I started a project using CMake and i don't know why, it adds to the build list also files i excluded from build. My CMakeList.txt looks like this:

    cmake_minimum_required(VERSION 3.14)
    project(MyProj LANGUAGES CXX)
    
    set(CMAKE_INCLUDE_CURRENT_DIR ON)
    set(CMAKE_CXX_STANDARD 11)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    
    include(FetchContent)
    FetchContent_Declare(
      googletest
    )
    
    file(GLOB_RECURSE src_files CONFIGURE_DEPENDS
        "src/*"
    )
    
    file(GLOB_RECURSE test_files CONFIGURE_DEPENDS
        "test/*"
    )
    
    add_library(MyProj SHARED
      cpp.astylerc
      ${src_files}
    )
    
    target_compile_definitions(MyProj PRIVATE MYPROJ_LIBRARY)
    
    install(TARGETS MyProj DESTINATION lib)
    install(DIRECTORY src/. DESTINATION include/myproj)
    
    add_executable(test
      ${test_files}
    )
    
    target_include_directories(test PUBLIC
        "../Dist/include"
    )
    
    #find_library(MYPROJ_LIBRARY NAMES MyProj PATHS "../Dist/lib" PATH_SUFFIXES lib)
    #target_link_libraries(test LINK_PUBLIC ${MYPROJ_LIBRARY})
    
    find_library(GTEST_LIBRARY NAMES gtest PATHS "/usr/lib" PATH_SUFFIXES lib)
    target_link_libraries(test LINK_PUBLIC ${GTEST_LIBRARY})
    
    find_library(GTEST_MAIN_LIBRARY NAMES gtest_main PATHS "/usr/lib" PATH_SUFFIXES lib)
    target_link_libraries(test LINK_PUBLIC ${GTEST_MAIN_LIBRARY})
    
    

    I keep test and sources files in different directories (src and test) and everything works just fine until i try to deploy (install). When i switch to Debug, i build and i launch deploy, it behaves like it's trying to compile all the sources present in the project even if there's no test target specified..

    How can i exclude files in the test directory for install target? I missed something in the CMakeList.txt file (or did something wrong?).

    Cheers

    C 1 Reply Last reply 1 May 2022, 17:45
    0
    • G GrassHopper90
      1 May 2022, 17:43

      Hi everyone.
      I started a project using CMake and i don't know why, it adds to the build list also files i excluded from build. My CMakeList.txt looks like this:

      cmake_minimum_required(VERSION 3.14)
      project(MyProj LANGUAGES CXX)
      
      set(CMAKE_INCLUDE_CURRENT_DIR ON)
      set(CMAKE_CXX_STANDARD 11)
      set(CMAKE_CXX_STANDARD_REQUIRED ON)
      
      include(FetchContent)
      FetchContent_Declare(
        googletest
      )
      
      file(GLOB_RECURSE src_files CONFIGURE_DEPENDS
          "src/*"
      )
      
      file(GLOB_RECURSE test_files CONFIGURE_DEPENDS
          "test/*"
      )
      
      add_library(MyProj SHARED
        cpp.astylerc
        ${src_files}
      )
      
      target_compile_definitions(MyProj PRIVATE MYPROJ_LIBRARY)
      
      install(TARGETS MyProj DESTINATION lib)
      install(DIRECTORY src/. DESTINATION include/myproj)
      
      add_executable(test
        ${test_files}
      )
      
      target_include_directories(test PUBLIC
          "../Dist/include"
      )
      
      #find_library(MYPROJ_LIBRARY NAMES MyProj PATHS "../Dist/lib" PATH_SUFFIXES lib)
      #target_link_libraries(test LINK_PUBLIC ${MYPROJ_LIBRARY})
      
      find_library(GTEST_LIBRARY NAMES gtest PATHS "/usr/lib" PATH_SUFFIXES lib)
      target_link_libraries(test LINK_PUBLIC ${GTEST_LIBRARY})
      
      find_library(GTEST_MAIN_LIBRARY NAMES gtest_main PATHS "/usr/lib" PATH_SUFFIXES lib)
      target_link_libraries(test LINK_PUBLIC ${GTEST_MAIN_LIBRARY})
      
      

      I keep test and sources files in different directories (src and test) and everything works just fine until i try to deploy (install). When i switch to Debug, i build and i launch deploy, it behaves like it's trying to compile all the sources present in the project even if there's no test target specified..

      How can i exclude files in the test directory for install target? I missed something in the CMakeList.txt file (or did something wrong?).

      Cheers

      C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 1 May 2022, 17:45 last edited by
      #2

      @GrassHopper90 said in CMake adds unwanted files while installing:

      When i switch to Debug, i build and i launch deploy, it behaves like it's trying to compile all the sources present in the project even if there's no test target specified..

      Why should nothing gets compiled in Debug mode? And what has this to do with a test target (whatever this is in your case)?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      G 1 Reply Last reply 1 May 2022, 17:55
      0
      • C Christian Ehrlicher
        1 May 2022, 17:45

        @GrassHopper90 said in CMake adds unwanted files while installing:

        When i switch to Debug, i build and i launch deploy, it behaves like it's trying to compile all the sources present in the project even if there's no test target specified..

        Why should nothing gets compiled in Debug mode? And what has this to do with a test target (whatever this is in your case)?

        G Offline
        G Offline
        GrassHopper90
        wrote on 1 May 2022, 17:55 last edited by
        #3

        @Christian-Ehrlicher In Debug mode, it should compile the stuff in src directory. But while installing, instead of simply copying the include directory and the just compiled library into Dist/include and Dist/lib which is what i expect, it compiles also the test content, which is not part of the library and it should not be compiled and linked into it..

        How can i exclude the content of test dir while installing?

        C 1 Reply Last reply 1 May 2022, 18:04
        0
        • G GrassHopper90
          1 May 2022, 17:55

          @Christian-Ehrlicher In Debug mode, it should compile the stuff in src directory. But while installing, instead of simply copying the include directory and the just compiled library into Dist/include and Dist/lib which is what i expect, it compiles also the test content, which is not part of the library and it should not be compiled and linked into it..

          How can i exclude the content of test dir while installing?

          C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 1 May 2022, 18:04 last edited by Christian Ehrlicher 5 Jan 2022, 18:05
          #4

          @GrassHopper90 said in CMake adds unwanted files while installing:

          How can i exclude the content of test dir while installing?

          Since they're targets they will be compiled, no matter with which compiler options you compile them. Since you did not add an install command for it they won't be installed.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          G 1 Reply Last reply 1 May 2022, 18:08
          0
          • C Christian Ehrlicher
            1 May 2022, 18:04

            @GrassHopper90 said in CMake adds unwanted files while installing:

            How can i exclude the content of test dir while installing?

            Since they're targets they will be compiled, no matter with which compiler options you compile them. Since you did not add an install command for it they won't be installed.

            G Offline
            G Offline
            GrassHopper90
            wrote on 1 May 2022, 18:08 last edited by
            #5

            @Christian-Ehrlicher Ok so is there a way to tell CMake "install just this <target> and nothing else" ?

            C 1 Reply Last reply 1 May 2022, 18:29
            0
            • G GrassHopper90
              1 May 2022, 18:08

              @Christian-Ehrlicher Ok so is there a way to tell CMake "install just this <target> and nothing else" ?

              C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 1 May 2022, 18:29 last edited by
              #6

              @GrassHopper90 No because before install the build system must be sure that everything is up-to date

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              G 1 Reply Last reply 1 May 2022, 18:47
              0
              • C Christian Ehrlicher
                1 May 2022, 18:29

                @GrassHopper90 No because before install the build system must be sure that everything is up-to date

                G Offline
                G Offline
                GrassHopper90
                wrote on 1 May 2022, 18:47 last edited by
                #7

                @Christian-Ehrlicher I'm developing a library, and i'd like to add gtest for it. Which is the correct setup for this?

                I expect this workflow:

                • Write code on the library.
                • Build the library (generate .so file)
                • Install the library in a Dist directory (Dist will have include and lib directories, with respectively library headers and library binary into them)
                • Write the test suites in the test directory
                • Switch to test configuration and build test executable
                • Run tests manually from CLI

                Do you suggest to have double project, one for the library and the other for the tests?

                C 1 Reply Last reply 1 May 2022, 18:48
                0
                • G GrassHopper90
                  1 May 2022, 18:47

                  @Christian-Ehrlicher I'm developing a library, and i'd like to add gtest for it. Which is the correct setup for this?

                  I expect this workflow:

                  • Write code on the library.
                  • Build the library (generate .so file)
                  • Install the library in a Dist directory (Dist will have include and lib directories, with respectively library headers and library binary into them)
                  • Write the test suites in the test directory
                  • Switch to test configuration and build test executable
                  • Run tests manually from CLI

                  Do you suggest to have double project, one for the library and the other for the tests?

                  C Offline
                  C Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on 1 May 2022, 18:48 last edited by
                  #8

                  @GrassHopper90 said in CMake adds unwanted files while installing:

                  Switch to test configuration and build test executable

                  I don't see what this should be and why it should be needed.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mchinand
                    wrote on 1 May 2022, 21:19 last edited by
                    #9

                    I would split up your project into two sub-projects; your main library and your gtest-based tests. Then you can conditionally build/run your tests when you want based on a boolean variable in your top-level CMakeLists.txt file.

                    1 Reply Last reply
                    1

                    1/9

                    1 May 2022, 17:43

                    • Login

                    • Login or register to search.
                    1 out of 9
                    • First post
                      1/9
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved