CMake include and source paths do not match Windows Directory paths

I want to create a library with Visual Studio 2010 / VC10 and CMake.

The Windows tree does not match the CMake project tree. The problem is that CMake does not create foolib with the header and source files in Visual Studio.

I cannot change the library tree because it is an old extended code with a lot of libraries that have several included files.

root
|-'includes
|  '-foo.h
|-'src  
|  '-libprojects
|  | '-foolib
|  | | '-bin
|  | | '-project
|  | | | '-mak100
|  | | | '-CMakeLists01.txt
|  | | '-src
|  | | | '-CMakeLists02.txt
|  | | | '-foo.cxx

CMakeLists.txt only has an explanation number.

CMakeLists01.txt

cmake_minimum_required (VERSION 2.8)
cmake_policy (SET CMP0015 NEW)
project (foolib)

set (CMAKE_BUILD_TYPE Debug)

include_directories ("${PROJECT_SOURCE_DIR}/../../../../include")

# This dosen't works and CMake can't find the CMakeLists02.txt ??? 
add_subdirectory("${PROJECT_SOURCE_DIR}/../src")

CMakeLists02.txt

# CMakeLists02.txt
set (QueryHeader
    "./../../../../include/foo.h")

set (QuerySources
    "foo.cxx")

Question: How to enable CMakeLists02.txt in CMakeLists01.txt with add_subdirectory ()

This is a batch file if someone tests it

#doCMake.cmd
@echo off
call "c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tool\vsvars32.bat"
mkdir mak100
cd mak100
cmake -G "Visual Studio 10" ..
cd ..
pause
+4
source share
1 answer

,

CMake Error at CMakeLists.txt:10 (add_subdirectory):
  add_subdirectory not given a binary directory but the given source
  directory ".../src/libprojects/foolib/src"
  is not a subdirectory of
  ".../src/libprojects/foolib/project".  When
  specifying an out-of-tree source a binary directory must be explicitly
  specified.

@LPs , . CMAKE , . add_subdirectory() - :

add_subdirectory("../src" "src")

1- ${PROJECT_SOURCE_DIR}, - ${CMAKE_CURRENT_BINARY_DIR} ( , . add_subdirectory()).

, / CMakeLists01.txt foolib. CMakeLists02.txt.

/libprojects/foolib/CMakeLists.txt

cmake_minimum_required (VERSION 2.8)

project (foolib CXX)

include_directories("../../../include")

add_library(foo "src/foo.cxx")

, () , - add_library(foo src/foo.cxx) / .

+2

Source: https://habr.com/ru/post/1609927/


All Articles