CMake adds unwanted files while installing
-
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
-
@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)?
-
@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?
-
Christian Ehrlicher Lifetime Qt Championreplied to GrassHopper90 on last edited by Christian Ehrlicher
@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.
-
@Christian-Ehrlicher Ok so is there a way to tell CMake "install just this <target> and nothing else" ?
-
@GrassHopper90 No because before install the build system must be sure that everything is up-to date
-
@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?
-
@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.