CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(network)
#message(CMAKE_SOURCE_DIR=${CMAKE_SOURCE_DIR})
#message(PROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR})
#message(CMAKE_BINARY_DIR =${CMAKE_BINARY_DIR})
#message(PROJECT_BINARY_DIR=${PROJECT_BINARY_DIR})
set(top_dir ${CMAKE_SOURCE_DIR})
message(top_dir = ${top_dir})
set(src_dir ${top_dir} ${top_dir}/conv ${top_dir}/ftp ${top_dir}/json ${top_dir}/msg_queue ${top_dir}/network ${top_dir}/rss ${top_dir}/stock ${top_dir}/uart)
message(src_dir=${src_dir})
set(inc_dir ${top_dir} ${top_dir}/conv ${top_dir}/ftp ${top_dir}/json ${top_dir}/msg_queue ${top_dir}/network ${top_dir}/rss ${top_dir}/stock ${top_dir}/uart)
message(inc_dir=${inc_dir})
FOREACH(dir ${inc_dir})
INCLUDE_DIRECTORIES(${dir})
ENDFOREACH(dir)
FOREACH(dir ${src_dir})
AUX_SOURCE_DIRECTORY(${dir} SRC_LIST)
ENDFOREACH(dir)
#FIND_PACKAGE(CURL)
#IF(CURL_FOUND)
# INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIR})
# LINK_LIBRARIES(${CURL_LIBRARY})
#ENDIF(CURL_FOUND)
#LINK_LIBRARIES(thread)
#find_package(Threads)
#LINK_LIBRARIES(${CMAKE_THREAD_LIBS_INIT})
#message(CMAKE_THREAD_LIBS_INIT=${CMAKE_THREAD_LIBS_INIT})
LINK_LIBRARIES(-lpthread -lm -lcrypto -lssl -lcurl -lxml2)
#LINK_LIBRARIES(crypto)
#LINK_LIBRARIES(ssl)
#LINK_LIBRARIES(m)
#LINK_LIBRARIES(xml2)
#LINK_LIBRARIES(curl)
add_executable(${PROJECT_NAME} ${SRC_LIST})
也可以配合使用简单的makefile:
AT=@
all:build/Makefile
$(AT)$(MAKE) -C build $@
clean:
$(AT)rm -rf build
build/Makefile:CMakeLists.txt
$(AT)mkdir -p build
$(AT)cd build && cmake ..
比如代码结构如下
./
├── CMakeLists.txt
├── makefile
└── test.c
改下CMakeLists.txt里面的
set(src_dir ${top_dir})
set(inc_dir ${top_dir})
然后make clean;make即可