问题
cmake_minimum_required(VERSION 3.2.1 FATAL_ERROR)
project("soxy")
add_definitions(-std=c99)
include_directories(soxy)
# Includes
include(ExternalProject)
ExternalProject_Add(
LibUV
GIT_REPOSITORY "https://github.com/libuv/libuv.git"
GIT_TAG "v1.4.2"
CONFIGURE_COMMAND sh <SOURCE_DIR>/autogen.sh && ./configure --prefix=${CMAKE_CURRENT_SOURCE_DIR}
PATCH_COMMAND ""
BUILD_COMMAND "make"
BUILD_IN_SOURCE 1
PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/build
)
set( SOXY_SRC src/file_utils.c
src/http_parser.c
src/http_request.c
src/path_utils.c
src/string_utils.c
)
set( SOXY_HDR src/debug.h
src/file_utils.h
src/http_client.h
src/http_parser.h
src/http_request.h
src/logger.h
src/path_utils.h
src/soxy_constantsh
src/soxy.h
src/string_utils.h
)
set( SOXY_BIN src/soxy.c )
add_executable(soxy ${SOXY_BIN})
add_dependencies(soxy LibUV)
Project structure:
/soxy
/soxy/CMakeLists.txt
/soxy/build/
When I build the makefile and run make, the lib and include for the external project end up in /soxy, I'd like them to show up in /soxy/build/ and when it builds my project it doesn't setup the include right such that #include <uv.h>
doesn't work and is an unresolved header file inclusion.
回答1:
You are using --prefix=${CMAKE_CURRENT_SOURCE_DIR}
. Try using CMAKE_CURRENT_BINARY_DIR
instead.
回答2:
Hmmm, you are getting several things wrong.
- You usually don't need to define a list of header files.
- You are not telling anywhere to compile the files contained in the
SOXY_SRC
variable. You would compile them for example if you didadd_executable(soxy ${SOXY_BIN} ${SOXY_SRC})
. - After
add_dependencies
you'll also needtarget_link_libraries
. - You should target "out of source" build. That is, you shouldn't have stuff like
${CMAKE_CURRENT_SOURCE_DIR}/build
So, try the following (I don't know the ExternalProject_Add
command so I can only guess the behaviour). Modify two lines of ExternalProject_Add
like this:
BUILD_IN_SOURCE 0
PREFIX ${CMAKE_BINARY_DIR}/LibUV
And add:
include_directories(${CMAKE_BINARY_DIR}/LibUV)
You'll probably need also
link_directories(${CMAKE_BINARY_DIR}/LibUV)
Ideally the include directory of LibUV is different from the library directory, take a look to what your
ExternalProject_Add
effictively does.
As said before, you'll probably need a target_link_libraries(soxy uv)
or something similar, depending on the generated library name
来源:https://stackoverflow.com/questions/29619032/cmake-change-where-the-lib-and-include-directories-are-for-an-externalproject