[CMake] Running find_package after dependencies are built
Игорь Пашев
pashev.igor at gmail.com
Fri Oct 18 09:17:54 EDT 2013
I use this:
SET (ZLIB_DIR "${CMAKE_CURRENT_LIST_DIR}/bin/${TARGET_ARCH}")
SET (ZLIB "${ZLIB_DIR}/libz.so")
IF (NOT EXISTS "${ZLIB}" OR ALWAYS_BUILD_EXTERNAL)
ADD_LIBRARY (z SHARED
${CMAKE_CURRENT_LIST_DIR}/src/adler32.c
${CMAKE_CURRENT_LIST_DIR}/src/compress.c
${CMAKE_CURRENT_LIST_DIR}/src/crc32.c
${CMAKE_CURRENT_LIST_DIR}/src/crc32.h
${CMAKE_CURRENT_LIST_DIR}/src/deflate.c
${CMAKE_CURRENT_LIST_DIR}/src/deflate.h
${CMAKE_CURRENT_LIST_DIR}/src/gzclose.c
${CMAKE_CURRENT_LIST_DIR}/src/gzguts.h
${CMAKE_CURRENT_LIST_DIR}/src/gzlib.c
${CMAKE_CURRENT_LIST_DIR}/src/gzread.c
${CMAKE_CURRENT_LIST_DIR}/src/gzwrite.c
${CMAKE_CURRENT_LIST_DIR}/src/infback.c
${CMAKE_CURRENT_LIST_DIR}/src/inffast.c
${CMAKE_CURRENT_LIST_DIR}/src/inffast.h
${CMAKE_CURRENT_LIST_DIR}/src/inffixed.h
${CMAKE_CURRENT_LIST_DIR}/src/inflate.c
${CMAKE_CURRENT_LIST_DIR}/src/inflate.h
${CMAKE_CURRENT_LIST_DIR}/src/inftrees.c
${CMAKE_CURRENT_LIST_DIR}/src/inftrees.h
${CMAKE_CURRENT_LIST_DIR}/src/trees.c
${CMAKE_CURRENT_LIST_DIR}/src/trees.h
${CMAKE_CURRENT_LIST_DIR}/src/uncompr.c
${CMAKE_CURRENT_LIST_DIR}/src/zconf.h
${CMAKE_CURRENT_LIST_DIR}/src/zlib.h
${CMAKE_CURRENT_LIST_DIR}/src/zutil.c
${CMAKE_CURRENT_LIST_DIR}/src/zutil.h
)
ADD_CUSTOM_COMMAND (TARGET z POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"libz.so" "${ZLIB}"
)
MESSAGE (STATUS "Will build `${LIBZLIB}' from source")
ELSE()
ADD_LIBRARY (z SHARED IMPORTED GLOBAL)
SET_PROPERTY (TARGET z PROPERTY IMPORTED_LOCATION "${ZLIB}")
ENDIF()
# *** Important part: ***
SET_PROPERTY (TARGET z PROPERTY INCLUDE_PATH "${CMAKE_CURRENT_LIST_DIR}/src")
SET_PROPERTY (TARGET z PROPERTY LIBRARY_PATH "${ZLIB_DIR}")
I use those properties (INCLUDE_PATH and LIBRARY_PATH) to construct
LDFLAGS and CPPFLAGS for other targets and external projects
More information about the CMake
mailing list