How to fix this cmake file? - a problem with binding to an imported library

I am just starting with cmake and trying to create a fairly simple project. Although the project itself is simple, it links to several static libraries that cmake did not create. They may be, I suppose, these are my libraries, but I still need to figure out how to connect third-party libraries.

Here is what I still have ...

cmake_minimum_required(VERSION 2.8.1)
cmake_policy(VERSION 2.8.1)

project( test01 )

include_directories("../../cpplib/sh_core" "../../cpplib/sh_core2" "../../cpplib/sh_genlib")

link_directories("../../cpplib/_vc_debug")

add_library( sh_core   STATIC IMPORTED )
add_library( sh_core2  STATIC IMPORTED )
add_library( sh_genlib STATIC IMPORTED )

add_executable( test01 test01 test01_ast test01_parse test01_scan test01_main )
target_link_libraries(test01 sh_core sh_core2 sh_genlib)

The problem is that the three libraries with which I am trying to establish the link are incorrectly referenced in the generated project file. They are listed as sh_core-NOTFOUND, sh_core2-NOTFOUNDand sh_genlib-NOTFOUND.

, link_directories , find_library. ​​... WTF!!! , , , ATM. , -, , , .

... cmake, ?

- , , ? . , "../../cpplib/_vc_release".

+2
2

, include_directories add_library.

include_directories , add_library ( ):

add_library(core UNKNOWN IMPORTED)
set_target_properties(core PROPERTIES IMPORTED_LOCATION "../../cpplib/_vs_release/core.lib")

, , , - :

set(CPPLIB_DIR "${CMAKE_SOURCE_DIR}/../../cpplib")

set(CPPLIB_DEBUG_DIR "${CPPLIB_DIR}/_vc_debug")
set(CPPLIB_RELEASE_DIR "$(CPPLIB_DIR}/_vc_release")

if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
    set(CPPLIB_LIB_HINT ${CPPLIB_RELEASE_DIR})
else ()
    set(CPPLIB_LIB_HINT ${CPPLIB_DEBUG_DIR})
endif ()

find_library(CPPLIB_CORE_LIBRARY NAMES "core"
                                 PATHS ${CPPLIB_LIB_HINT})

find_library(CPPLIB_CORE2_LIBRARY NAMES "core2"
                                  PATHS ${CPPLIB_LIB_HINT})

find_library(CPPLIB_GENLIB_LIBRARY NAMES "genlib"
                                   PATHS ${CPPLIB_LIB_HINT})

if (("${CPPLIB_CORE_LIBRARY}" STREQUAL "CPPLIB_CORE_LIBRARY-NOTFOUND") OR
    ("${CPPLIB_CORE2_LIBRARY}" STREQUAL "CPPLIB_CORE2_LIBRARY-NOTFOUND") OR
    ("${CPPLIB_GENLIB_LIBRARY}" STREQUAL "CPPLIB_GENLIB_LIBRARY-NOTFOUND"))
    message(FATAL_ERROR "One of the libs wasn't found!")
endif ()

set(CPPLIB_LIBRARIES ${CPPLIB_CORE_LIBRARY} ${CPPLIB_CORE2_LIBRARY} ${CPPLIB_GENLIB_LIBRARY})

target_link_libraries(my_exe ${CPPLIB_LIBRARIES})

EDIT: , :

find_path(CPPLIB_INCLUDE_DIR "my_header.h"
    PATHS ${CPPLIB_HINT_INCLUDE_DIR})

...

include_directories(${CPPLIB_INCLUDE_DIR})
+6

the_void:

if, :

if (("${CPPLIB_CORE_LIBRARY}" STREQUAL "CPPLIB_CORE_LIBRARY-NOTFOUND") OR
    ("${CPPLIB_CORE2_LIBRARY}" STREQUAL "CPPLIB_CORE2_LIBRARY-NOTFOUND") OR
    ("${CPPLIB_GENLIB_LIBRARY}" STREQUAL "CPPLIB_GENLIB_LIBRARY-NOTFOUND"))
    message(FATAL_ERROR "One of the libs wasn't found!")
endif ()

:

if (CPPLIB_CORE_LIBRARY OR
    CPPLIB_CORE2_LIBRARY OR
    CPPLIB_GENLIB_LIBRARY)
    message(FATAL_ERROR "One of the libs wasn't found!")
endif ()

CMake if.

+1

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


All Articles