0

Environment

they're all newest version.

CMakeLists.txt

the CMakeLists.txt are:

project(xeditd LANGUAGES CXX VERSION 0.1)

find_package(PkgConfig REQUIRED)
pkg_search_module(ICU_UC icu-uc)
pkg_search_module(SPDLOG spdlog)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ICU_UC_CXXFLAGS_OTHER}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SPDLOG_CXXFLAGS_OTHER}")

set(SRC_FILE
    xeditd.cpp
    )

set(LIB_DIR
    ${ICU_UC_LIBRARY_DIRS}
    ${SPDLOG_LIBRARY_DIRS}
    )

set(LIB
    ${ICU_UC_LIBRARIES}
    ${SPDLOG_LIBRARIES}
    )

set(INC_DIR
    ${ICU_UC_INCLUDE_DIRS}
    ${SPDLOG_INCLUDE_DIRS}
    )

message(ICU_UC_CXXFLAGS_OTHER: ${ICU_UC_CXXFLAGS_OTHER})
message(SPDLOG_CXXFLAGS_OTHER: ${SPDLOG_CXXFLAGS_OTHER})
message(ICU_UC_LIBRARY_DIRS: ${ICU_UC_LIBRARY_DIRS})
message(SPDLOG_LIBRARY_DIRS: ${SPDLOG_LIBRARY_DIRS})
message(ICU_UC_LIBRARIES: ${ICU_UC_LIBRARIES})
message(SPDLOG_LIBRARIES: ${SPDLOG_LIBRARIES})
message(ICU_UC_INCLUDE_DIRS: ${ICU_UC_INCLUDE_DIRS})
message(SPDLOG_INCLUDE_DIRS: ${SPDLOG_INCLUDE_DIRS})

link_directories(${LIB_DIR})
add_executable(xeditd ${SRC_FILE})
target_include_directories(xeditd PUBLIC ${INC_DIR})
target_link_libraries(xeditd ${LIB})

Error

the message shows:

ICU_UC_CXXFLAGS_OTHER:
SPDLOG_CXXFLAGS_OTHER:
ICU_UC_LIBRARY_DIRS:/usr/local/Cellar/icu4c/64.2/lib
SPDLOG_LIBRARY_DIRS:
ICU_UC_LIBRARIES:icuucicudata
SPDLOG_LIBRARIES:
ICU_UC_INCLUDE_DIRS:/usr/local/Cellar/icu4c/64.2/include
SPDLOG_INCLUDE_DIRS:

header file <spdlog/spdlog.h> not found. Obviously the spdlog header directory is not include in cmake.

Question

Why pkg_search_module works for icu4c, bug not for spdlog ? And not for pthread ?

linrongbin
  • 2,967
  • 6
  • 31
  • 59
  • spdlog links successfully via `find_package(spdlog REQUIRED)` and `target_link_libraries(xeditd spdlog::spdlog)`. But I don't know why it works, and is there a way to use `find_package` for `icu4c` on macos ? – linrongbin Jun 12 '19 at 05:47
  • "Why pkg_search_module works for icu4c, but not for spdlog?" - Probably, because there is no `spdlog.pc` file, which is needed for `pkg-config` to find `spdlog` package. Most likely, `pkg_search_module(SPDLOG spdlog)` is simply failed. You haven't detect this, because neither use *REQUIRED* keyword nor check `SPDLOG_FOUND` variable. – Tsyvarev Jun 12 '19 at 08:07
  • Commands `find_package` and `pkg_search_module` are **different** ways for locate the package. And these commands use **different** tools for their purpose. `pkg_search_module` is a wrapper around `pkg-config` utility, which need `XXX.pc` for locate the package. `find_package` is a pure CMake thing. It either uses `FindXXX.cmake` module, either [shipped with CMake](https://cmake.org/cmake/help/v3.9/manual/cmake-modules.7.html) itself or provided by **your project**, or uses `XXXConfig.cmake` or `xxx-config.cmake` scripts, provided by the searched package. – Tsyvarev Jun 12 '19 at 08:13

1 Answers1

0
IF(APPLE)
    FIND_PACKAGE(spdlog REQUIRED)
ENDIF(APPLE)
...
# Translation is your traget
IF(APPLE)
    target_link_libraries(Translation PUBLIC spdlog::spdlog)
ENDIF(APPLE)
David Buck
  • 3,752
  • 35
  • 31
  • 35