Issue
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 test stuff 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
Solution
As @Tsyvarev said, adding the "EXCLUDE_FROM_ALL" setting to the add_executable() cmake-command for the test target fixed the issue.
More info on: CMake
Answered By - HeapOverflow Answer Checked By - Pedro (WPSolving Volunteer)