1
0
mirror of https://github.com/wjwwood/serial.git synced 2026-01-22 19:54:57 +08:00

Revamped the build system a bit to make it more friendly to embeding in other projects.

This commit is contained in:
William Woodall 2011-06-22 00:05:11 -05:00
parent cbe669f756
commit 7dbd1d53a6
3 changed files with 95 additions and 40 deletions

View File

@ -1,8 +1,19 @@
## Project Setup
cmake_minimum_required(VERSION 2.4.6) cmake_minimum_required(VERSION 2.4.6)
project(Serial) project(Serial)
# set the default path for built executables to the "bin" directory ## Configurations
option(SERIAL_BUILD_TESTS "Build all of the Serial tests." OFF)
option(SERIAL_BUILD_EXAMPLES "Build all of the Serial examples." OFF)
# Allow for building shared libs override
IF(NOT BUILD_SHARED_LIBS)
set(BUILD_SHARED_LIBS OFF)
ENDIF(NOT BUILD_SHARED_LIBS)
# Set the default path for built executables to the "bin" directory
IF(NOT DEFINED(EXECUTABLE_OUTPUT_PATH)) IF(NOT DEFINED(EXECUTABLE_OUTPUT_PATH))
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
ENDIF(NOT DEFINED(EXECUTABLE_OUTPUT_PATH)) ENDIF(NOT DEFINED(EXECUTABLE_OUTPUT_PATH))
@ -11,29 +22,60 @@ IF(NOT DEFINED(LIBRARY_OUTPUT_PATH))
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib) set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
ENDIF(NOT DEFINED(LIBRARY_OUTPUT_PATH)) ENDIF(NOT DEFINED(LIBRARY_OUTPUT_PATH))
# add the include folder to the include path ## Configure the build system
# Add the include folder to the include path
include_directories(${PROJECT_SOURCE_DIR}/include) include_directories(${PROJECT_SOURCE_DIR}/include)
# Find Boost # Add default source files
set(SERIAL_SRCS src/serial.cpp)
# Add default header files
set(SERIAL_HEADERS include/serial.h)
# Find Boost, if it hasn't already been found
IF(NOT Boost_FOUND OR NOT Boost_SYSTEM_FOUND OR NOT Boost_FILESYSTEM_FOUND OR NOT Boost_THREAD_FOUND)
find_package(Boost COMPONENTS system filesystem thread REQUIRED) find_package(Boost COMPONENTS system filesystem thread REQUIRED)
ENDIF(NOT Boost_FOUND OR NOT Boost_SYSTEM_FOUND OR NOT Boost_FILESYSTEM_FOUND OR NOT Boost_THREAD_FOUND)
link_directories(${Boost_LIBRARY_DIRS}) link_directories(${Boost_LIBRARY_DIRS})
include_directories(${Boost_INCLUDE_DIRS}) include_directories(${Boost_INCLUDE_DIRS})
# Compile the Serial Library set(SERIAL_LINK_LIBS ${Boost_SYSTEM_LIBRARY}
add_library(serial src/serial.cpp include/serial.h) ${Boost_FILESYSTEM_LIBRARY}
target_link_libraries(serial ${Boost_SYSTEM_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ${Boost_THREAD_LIBRARY}) ${Boost_THREAD_LIBRARY})
# Compile the Test program ## Build the Serial Library
add_executable(test_serial src/test_serial.cpp)
# Link the Test program to the Serial library # Compile the Library
target_link_libraries(test_serial serial) add_library(serial ${SERIAL_SRCS} ${SERIAL_HEADERS})
target_link_libraries(serial ${SERIAL_LINK_LIBS})
# Check for OS X and if so disable kqueue support in asio # Check for OS X and if so disable kqueue support in asio
IF(CMAKE_SYSTEM_NAME MATCHES Darwin) IF(CMAKE_SYSTEM_NAME MATCHES Darwin)
add_definitions(-DBOOST_ASIO_DISABLE_KQUEUE) add_definitions(-DBOOST_ASIO_DISABLE_KQUEUE)
ENDIF(CMAKE_SYSTEM_NAME MATCHES Darwin) ENDIF(CMAKE_SYSTEM_NAME MATCHES Darwin)
## Build Examples
# If asked to
IF(SERIAL_BUILD_EXAMPLES)
# Compile the Test program
add_executable(serial_example examples/serial_example.cpp)
# Link the Test program to the Serial library
target_link_libraries(serial_example serial)
ENDIF(SERIAL_BUILD_EXAMPLES)
## Build tests
# If asked to
IF(SERIAL_BUILD_TESTS)
# none yet...
ENDIF(SERIAL_BUILD_TESTS)
## Setup install and uninstall
# Unless asked not to...
IF(NOT SERIAL_DONT_CONFIGURE_INSTALL)
# Configure make install # Configure make install
IF(NOT CMAKE_INSTALL_PREFIX) IF(NOT CMAKE_INSTALL_PREFIX)
SET(CMAKE_INSTALL_PREFIX /usr/local) SET(CMAKE_INSTALL_PREFIX /usr/local)
@ -68,3 +110,4 @@ ELSE(UNIX)
TARGET uninstall TARGET uninstall
) )
ENDIF(UNIX) ENDIF(UNIX)
ENDIF(NOT SERIAL_DONT_CONFIGURE_INSTALL)

View File

@ -19,3 +19,15 @@ endif
clean: clean:
-cd build && make clean -cd build && make clean
rm -rf build bin lib rm -rf build bin lib
.PHONY: test
test:
@mkdir -p build
@mkdir -p bin
cd build && cmake $(CMAKE_FLAGS) -DSERIAL_BUILD_TESTS=1 -DSERIAL_BUILD_EXAMPLES=1 ..
ifneq ($(MAKE),)
cd build && $(MAKE)
else
cd build && make
endif
# cd bin && ./serial_tests