I have a problem with a locally installed library. There is xmlrpC ++ 0.7 library in my project:
myproject/
+
+
I want CMake to return using the local xmlrpC ++ 0.7 directory, unless otherwise found. Two problems, the first, find_path () or find_library () do not work with the local dir. I used a workaround if the variables handled by find_xxx () are empty or not. If empty, I install them manually. Now cmake generates a Makefile without errors. But if I want to compile the project using make, the C ++ compiler returns "error: XmlRpc.h: file not found". The XmlRpc.h file is located in myproject / xmlrpC ++ 0.7 / src, and if I compile all of them manually, it works fine.
Here is my CMakeLists.txt. I am very happy if anyone could point out the right decision to use cmake in the conditions described above.
--- CMakeLists.txt ---
project (webservice_tesseract)
cmake_minimum_required (VERSION 2.6)
set (CMAKE_INCLUDE_CURRENT_DIR ON)
# find tesseract
find_path (TESSERACT_INCLUDE_DIR tesseract / tesseractmain.h
/ opt / local / include
/ usr / local / include
/ usr / include
)
find_library (TESSERACT_LIBRARY_DIR
NAMES tesseract_main
PATHS
/ opt / local / lib /
/ usr / local / lib /
/ usr / lib
)
message (STATUS "looked for tesseract library.")
message (STATUS "Include file detected: [$ {TESSERACT_INCLUDE_DIR}].")
message (STATUS "Lib file detected: [$ {TESSERACT_LIBRARY_DIR}].")
add_library (tesseract STATIC IMPORTED)
set_property (TARGET tesseract PROPERTY IMPORTED_LOCATION
$ {TESSERACT_LIBRARY_DIR} /libtesseractmain.a
)
#find xmlrpc ++
message (STATUS "cmake home dir: [$ {CMAKE_HOME_DIRECTORY}].")
set (LOCAL_XMLRPCPLUSPLUS $ {CMAKE_HOME_DIRECTORY} /xmlrpc0.7 ++ /)
message (STATUS "xmlrpc ++ local dir: [$ {LOCAL_XMLRPCPLUSPLUS}].")
find_path (XMLRPCPLUSPLUS_INCLUDE_DIR XmlRpcServer.h
$ {LOCAL_XMLRPCPLUSPLUS} src
/ opt / local / include
/ usr / local / include
/ usr / include
)
find_library (XMLRPCPLUSPLUS_LIBRARY_DIR
NAMES XmlRpc
PATHS
$ {LOCAL_XMLRPCPLUSPLUS}
/ opt / local / lib /
/ usr / local / lib /
/ usr / lib /
)
# next lines are an ugly workaround because cmake find_xxx () does not find local stuff
if (XMLRPCPLUSPLUS_INCLUDE_DIR)
else (XMLRPCPLUSPLUS_INCLUDE_DIR)
set (XMLRPCPLUSPLUS_INCLUDE_DIR $ {LOCAL_XMLRPCPLUSPLUS} src)
endif (XMLRPCPLUSPLUS_INCLUDE_DIR)
if (XMLRPCPLUSPLUS_LIBRARY_DIR)
else (XMLRPCPLUSPLUS_LIBRARY_DIR)
set (XMLRPCPLUSPLUS_LIBRARY_DIR $ {LOCAL_XMLRPCPLUSPLUS})
endif (XMLRPCPLUSPLUS_LIBRARY_DIR)
message (STATUS "looked for xmlrpc ++ library.")
message (STATUS "Include file detected: [$ {XMLRPCPLUSPLUS_INCLUDE_DIR}].")
message (STATUS "Lib file detected: [$ {XMLRPCPLUSPLUS_LIBRARY_DIR}].")
add_library (xmlrpc STATIC IMPORTED)
set_property (TARGET xmlrpc PROPERTY IMPORTED_LOCATION
$ {XMLRPCPLUSPLUS_LIBRARY_DIR} /libXmlRpc.a
)
#### link together
include_directories ($ {XMLRPCPLUSPLUS_INCLUDE_DIR} $ {TESSERACT_INCLUDE_DIR})
link_directories ($ {XMLRPCPLUSPLUS_LIBRARY_DIR} $ {TESSERACT_LIBRARY_DIR})
add_library (simpleocr STATIC simple_ocr.cpp)
add_executable (webservice_tesseract webservice.cpp)
target_link_libraries (webservice_tesseract xmlrpc tesseract simpleocr)
source
share