I'm building a project whose final output is a static library, and my CMake-based build system consists of two subdirectories - the Src and the Tests - where the build for the tests produces an executable and links the to the library which is built from src.
My problem is that the test build requires the library to already exist if it is to proceed without any errors. Is there a way to get CMake to understand that the library will exists when it comes to build the tests, or do I have to do these in separate steps?
My CMakeLists.txt files as as follows:
Root file:
cmake_minimum_required( VERSION 2.8 )
project( mylib )
add_subdirectory( Src )
add_subdirectory( Tests )
Src file:
file( GLOB MYLIB_SOURCES *.cpp )
add_library( mylib ${MYLIB_SOURCES} )
Test file:
file( GLOB MYLIB_TESTS *.cpp )
add_executable( tests ${MYLIB_TESTS} )
find_package( GTest REQUIRED )
find_library( LIB_MYLIB NAMES mylib PATHS "${CMAKE_SOURCE_DIR}/Build/Src" )
include_directories( ../Src )
include_directories( ${GTEST_INCLUDE_DIRECTORIES} )
target_link_libraries( tests ${LIB_MYLIB} ${GTEST_LIBRARIES} pthread )