Commit 19563ed6 authored by Patrick Chen's avatar Patrick Chen

use CMake to build targets

parent 8d530c1b
cmake_minimum_required(VERSION 3.5)
set(CMAKE_FIND_LIBRARY_PREFIXES "lib")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".so")
set(PROJECT_ROOT_DIR
"${CMAKE_CURRENT_SOURCE_DIR}"
)
set(PROJECT_INCLUDE_DIR
"${PROJECT_ROOT_DIR}/include"
)
set(PROJECT_SOURCE_DIR
"${PROJECT_ROOT_DIR}/src"
)
# setup language
enable_language(CXX)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS "-std=c++14 -pedantic")
# find packages/library files
find_package(Boost COMPONENTS filesystem system)
if(NOT Boost_FOUND)
message(SEND_ERROR "cannot find at least one Boost components")
endif()
# setup exchange-server libraries
set(ES_LIBS
-l:libexchange_server.a
-l:libomniDynamic4.a
-l:libCOSNotify4.a
-l:libCOS4.a
-l:libomniZIOP4.a
-l:libomniCodeSets4.a
-l:libomniORB4.a
-l:libomnithread.a
z
pthread
)
# setup xs-test project
set(XS_TEST_SRCS
${PROJECT_SOURCE_DIR}/xs-test.cc
${PROJECT_SOURCE_DIR}/test/Config.cc
${PROJECT_SOURCE_DIR}/test/Expectation.cc
${PROJECT_SOURCE_DIR}/test/Service.cc
${PROJECT_SOURCE_DIR}/test/Tester.cc
)
set(XS_TEST_LIBS
${Boost_LIBRARIES}
${ES_LIBS}
)
project(xs-test)
add_executable(xs-test ${XS_TEST_SRCS})
target_include_directories(xs-test PRIVATE
"/usr/local/include"
${PROJECT_INCLUDE_DIR}
)
target_link_libraries(xs-test
${XS_TEST_LIBS}
)
# setup greeting project
set(GREETING_SRCS
${PROJECT_ROOT_DIR}/example/greeting.cc
)
set(GREETING_LIBS
${ES_LIBS}
)
project(greeting)
add_executable(greeting ${GREETING_SRCS})
target_include_directories(greeting PRIVATE
"/usr/local/include"
)
target_link_libraries(greeting
${GREETING_LIBS}
)
REPO_DIR=$(shell pwd)
INCLUDE_DIR=$(REPO_DIR)/include
SRC_DIR=$(REPO_DIR)/src
BUILD_DIR=$(REPO_DIR)/build
CXX=clang++
CXX_FLAGS=-g -std=c++14 \
-I/usr/local/include \
-I$(INCLUDE_DIR)
LD_FLAGS=-L/usr/local/lib \
-lboost_system \
-lboost_filesystem \
-l:libexchange_server.a \
-l:libomniDynamic4.a \
-l:libCOSNotify4.a \
-l:libCOS4.a \
-l:libomniZIOP4.a \
-l:libomniCodeSets4.a \
-l:libomniORB4.a \
-l:libomnithread.a \
-lz \
-lpthread
XSTEST_HDRS=$(INCLUDE_DIR)/test/Config.h $(INCLUDE_DIR)/test/Service.h $(INCLUDE_DIR)/test/Tester.h $(INCLUDE_DIR)/test/Expectation.h
XSTEST_SRCS=$(SRC_DIR)/xs-test.cc $(SRC_DIR)/test/Config.cc $(SRC_DIR)/test/Service.cc $(SRC_DIR)/test/Tester.cc $(SRC_DIR)/test/Expectation.cc
XSTEST_OBJS=$(subst $(REPO_DIR),$(BUILD_DIR),$(XSTEST_SRCS:.cc=.o))
GREETING_SRCS=$(REPO_DIR)/example/greeting.cc
GREETING_OBJS=$(subst $(REPO_DIR),$(BUILD_DIR),$(GREETING_SRCS:.cc=.o))
all: $(BUILD_DIR)/xs-test example
$(BUILD_DIR)/xs-test: $(XSTEST_OBJS)
$(CXX) -o $@ $(XSTEST_OBJS) $(LD_FLAGS)
$(BUILD_DIR)/%.o: $(REPO_DIR)/%.cc $(XSTEST_HDRS)
mkdir -p $(dir $@)
$(CXX) -o $@ -c $(CXX_FLAGS) $<
example: $(BUILD_DIR)/greeting
$(BUILD_DIR)/greeting: $(GREETING_OBJS)
$(CXX) -o $@ $(GREETING_OBJS) $(LD_FLAGS)
clean:
rm -rf $(BUILD_DIR)/xs-test
rm -rf $(BUILD_DIR)/greeting
rm -rf $(XSTEST_OBJS)
rm -rf $(GREETING_OBJS)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment