I try to add GTest project to my solution. I have a project structure: my project structure I created Cryptograph and CryptographTests directories, after that created binTests and lib into CryptographTests. I have a few CMakeLists.txt files:
- Cryptograph/CMakeLists.txt:
cmake_minimum_required(VERSION 3.17)
project(Cryptograph)
set(CMAKE_CXX_STANDARD 17)
find_package(OpenSSL REQUIRED)
add_executable(Cryptograph main.cpp modulArithmetics.cpp modulArithmetics.h Speakers.cpp Speakers.h Crypt.cpp Crypt.h LongArithmetic.cpp LongArithmetic.h Signs.cpp Signs.h)
target_link_libraries(Cryptograph OpenSSL::SSL)
- CryptographTests/CMakeLists.txt:
project(CryptographTest)
add_subdirectory(lib/googletest)
add_subdirectory(binTests)
- CryptographTests/lib/CMakeLists.txt:
project(CryptographGTest)
add_subdirectory(lib)
- CryptographTests/binTests/CMakeLists.txt:
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
add_executable(runCommonTests FirstTest.cpp)
target_link_libraries(runCommonTests gtest gtest_main)
target_link_libraries(runCommonTests Cryptograph)
- And CMakeLists.txt:
cmake_minimum_required(VERSION 3.17)
project(CryptographGlobal)
set(CMAKE_CXX_STANDARD 17)
set (SOURCE_FILES main.cpp)
add_executable(cryptograph_samples ${SOURCE_FILES})
include_directories(Cryptograph)
add_subdirectory(Cryptograph)
add_subdirectory(CryptographTests)
target_link_libraries(cryptograph_samples Cryptograph)
After that i got errors:
CMake Error at CryptographTests/binTests/CMakeLists.txt:6 (target_link_libraries):
Target "Cryptograph" of type EXECUTABLE may not be linked into another
target. One may link only to INTERFACE, OBJECT, STATIC or SHARED
libraries, or to executables with the ENABLE_EXPORTS property set.
CMake Error at CMakeLists.txt:14 (target_link_libraries):
Target "Cryptograph" of type EXECUTABLE may not be linked into another
target. One may link only to INTERFACE, OBJECT, STATIC or SHARED
libraries, or to executables with the ENABLE_EXPORTS property set.
Before this error I got error lool like can't connect to Cryptograph.lib
, but after my changes errors also changed.
I try to add GTest project to my solution, but got the error.