Fix cmake when custom CMAKE_INSTALL_LIBDIR is given

According to cmake documents, we cannot assume CMAKE_INSTALL_LIBDIR is a
relative path. This commit fixes the "no rule to make libjsoncpp.a"
error by passing -DCMAKE_INSTALL_LIBDIR=lib to jsoncpp external project.
This commit is contained in:
mingchuan 2018-06-06 14:03:07 +08:00
parent 4073c02cf3
commit a104e5fb03
No known key found for this signature in database
GPG Key ID: 607CD25FA2D03651

View File

@ -6,15 +6,8 @@ else()
set(JSONCPP_CMAKE_COMMAND ${CMAKE_COMMAND}) set(JSONCPP_CMAKE_COMMAND ${CMAKE_COMMAND})
endif() endif()
include(GNUInstallDirs)
set(libdir ${CMAKE_INSTALL_LIBDIR})
if(CMAKE_LIBRARY_ARCHITECTURE)
# Do not use Debian multiarch library dir.
string(REPLACE "/${CMAKE_LIBRARY_ARCHITECTURE}" "" libdir ${libdir})
endif()
set(prefix "${CMAKE_BINARY_DIR}/deps") set(prefix "${CMAKE_BINARY_DIR}/deps")
set(JSONCPP_LIBRARY "${prefix}/${libdir}/${CMAKE_STATIC_LIBRARY_PREFIX}jsoncpp${CMAKE_STATIC_LIBRARY_SUFFIX}") set(JSONCPP_LIBRARY "${prefix}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}jsoncpp${CMAKE_STATIC_LIBRARY_SUFFIX}")
set(JSONCPP_INCLUDE_DIR "${prefix}/include") set(JSONCPP_INCLUDE_DIR "${prefix}/include")
if(NOT MSVC) if(NOT MSVC)
@ -36,6 +29,7 @@ ExternalProject_Add(jsoncpp-project
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_INSTALL_LIBDIR=lib
# Build static lib but suitable to be included in a shared lib. # Build static lib but suitable to be included in a shared lib.
-DCMAKE_POSITION_INDEPENDENT_CODE=${BUILD_SHARED_LIBS} -DCMAKE_POSITION_INDEPENDENT_CODE=${BUILD_SHARED_LIBS}
-DJSONCPP_WITH_TESTS=OFF -DJSONCPP_WITH_TESTS=OFF