# The atom_types.h file is written to the build directory
INCLUDE_DIRECTORIES (
	${CMAKE_BINARY_DIR}
)

# Generate the .pb.h and .pb.cc files dynamically.
ADD_CUSTOM_COMMAND(
	OUTPUT ZMQMessages.pb.h ZMQMessages.pb.cc
	COMMAND protoc
	ARGS --cpp_out=. -I ${CMAKE_CURRENT_SOURCE_DIR}
		${CMAKE_CURRENT_SOURCE_DIR}/ZMQMessages.proto
	DEPENDS ZMQMessages.proto
	COMMENT "Serializing with protobuf"
)

ADD_LIBRARY (zmqatoms
	ZMQMessages.pb.cc ZMQMessages.pb.h
	ProtocolBufferSerializer
	ZMQClient
	ZMQPersistSCM
)

TARGET_LINK_LIBRARIES(zmqatoms
	zmq
	atombase
	truthvalue
	${COGUTIL_LIBRARY}
	${PROTOBUF_LIBRARY}
)

IF(HAVE_GUILE)
	TARGET_LINK_LIBRARIES(zmqatoms smob)
ENDIF(HAVE_GUILE)

INSTALL (TARGETS zmqatoms
	DESTINATION "lib${LIB_DIR_SUFFIX}/opencog"
)

INSTALL (FILES
	${CMAKE_CURRENT_BINARY_DIR}/ZMQMessages.pb.h
	ProtocolBufferSerializer.h
	ZMQClient.h
	ZMQPersistSCM.h
	DESTINATION "include/opencog/persist/zmq/atomspace"
)

# The atom_types.h file is written to the build directory
INCLUDE_DIRECTORIES (
	${CMAKE_BINARY_DIR}
	${PROTOBUF_INCLUDE_DIR}
)

# Generate the .pb.h and .pb.cc files dynamically.
ADD_CUSTOM_COMMAND(
	OUTPUT ZMQMessages.pb.h ZMQMessages.pb.cc
	COMMAND ${PROTOBUF_PROTOC_EXECUTABLE}
	ARGS --cpp_out=. -I ${CMAKE_CURRENT_SOURCE_DIR}
		${CMAKE_CURRENT_SOURCE_DIR}/ZMQMessages.proto
	DEPENDS ZMQMessages.proto
	COMMENT "Serializing with protobuf"
)

ADD_LIBRARY (zmqatoms
	ZMQMessages.pb.cc ZMQMessages.pb.h
	ProtocolBufferSerializer
	ZMQClient
	ZMQPersistSCM
)

TARGET_LINK_LIBRARIES(zmqatoms
	zmq
	atombase
	truthvalue
	${COGUTIL_LIBRARY}
	${PROTOBUF_LIBRARY}
)

IF(HAVE_GUILE)
	TARGET_LINK_LIBRARIES(zmqatoms smob)
ENDIF(HAVE_GUILE)

INSTALL (TARGETS zmqatoms
	DESTINATION "lib${LIB_DIR_SUFFIX}/opencog"
)

INSTALL (FILES
	${CMAKE_CURRENT_BINARY_DIR}/ZMQMessages.pb.h
	ProtocolBufferSerializer.h
	ZMQClient.h
	ZMQPersistSCM.h
	DESTINATION "include/opencog/persist/zmq/atomspace"
)

Fix build for unusual protobuf environments
Fix build for unusual protobuf environments

Use ```protoc``` executable and Protobuf include path found by Protobuf
cmake module instead of relying that they are located in standard places.
