]> Git Repo - serial.git/commitdiff
Revamped the build system a bit to make it more friendly to embeding in other projects.
authorWilliam Woodall <[email protected]>
Wed, 22 Jun 2011 05:05:11 +0000 (00:05 -0500)
committerWilliam Woodall <[email protected]>
Wed, 22 Jun 2011 05:05:11 +0000 (00:05 -0500)
CMakeLists.txt
Makefile
examples/serial_example.cpp [new file with mode: 0644]
src/test_serial.cpp [deleted file]

index 178a154cd4d52a37d7083aaa3438ed6190582013..da9e349bc4c9d0b11d3bd0678f35ba88f61fb3e0 100644 (file)
@@ -1,8 +1,19 @@
+## Project Setup
 cmake_minimum_required(VERSION 2.4.6)
 
 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))
     set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
 ENDIF(NOT DEFINED(EXECUTABLE_OUTPUT_PATH))
@@ -11,60 +22,92 @@ IF(NOT DEFINED(LIBRARY_OUTPUT_PATH))
     set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
 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)
 
-# Find Boost
-find_package(Boost COMPONENTS system filesystem thread REQUIRED)
+# 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)
+ENDIF(NOT Boost_FOUND OR NOT Boost_SYSTEM_FOUND OR NOT Boost_FILESYSTEM_FOUND OR NOT Boost_THREAD_FOUND)
 
 link_directories(${Boost_LIBRARY_DIRS})
 include_directories(${Boost_INCLUDE_DIRS})
 
-# Compile the Serial Library
-add_library(serial src/serial.cpp include/serial.h)
-target_link_libraries(serial ${Boost_SYSTEM_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ${Boost_THREAD_LIBRARY})
+set(SERIAL_LINK_LIBS ${Boost_SYSTEM_LIBRARY}
+                     ${Boost_FILESYSTEM_LIBRARY}
+                     ${Boost_THREAD_LIBRARY})
+
+## Build the Serial Library
 
-# Compile the Test program
-add_executable(test_serial src/test_serial.cpp)
-# Link the Test program to the Serial library
-target_link_libraries(test_serial serial)
+# Compile the Library
+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
 IF(CMAKE_SYSTEM_NAME MATCHES Darwin)
     add_definitions(-DBOOST_ASIO_DISABLE_KQUEUE)
 ENDIF(CMAKE_SYSTEM_NAME MATCHES Darwin)
 
-# Configure make install
-IF(NOT CMAKE_INSTALL_PREFIX)
-    SET(CMAKE_INSTALL_PREFIX /usr/local)
-ENDIF(NOT CMAKE_INSTALL_PREFIX)
-
-INSTALL(TARGETS serial
-  RUNTIME DESTINATION bin
-  LIBRARY DESTINATION lib
-  ARCHIVE DESTINATION lib
-)
-
-INSTALL(FILES include/serial.h DESTINATION include)
-
-IF(NOT CMAKE_FIND_INSTALL_PATH)
-    set(CMAKE_FIND_INSTALL_PATH ${CMAKE_ROOT})
-ENDIF(NOT CMAKE_FIND_INSTALL_PATH)
-
-INSTALL(FILES Findserial.cmake DESTINATION ${CMAKE_FIND_INSTALL_PATH}/Modules/)
-
-ADD_CUSTOM_TARGET (uninstall @echo uninstall package)
-
-IF (UNIX)
-  ADD_CUSTOM_COMMAND(
-    COMMENT "uninstall package"
-    COMMAND xargs ARGS rm < install_manifest.txt
-
-    TARGET  uninstall
-  )
-ELSE(UNIX)
-  ADD_CUSTOM_COMMAND(
-    COMMENT "uninstall only implemented in unix"
-    TARGET  uninstall
-  )
-ENDIF(UNIX)
\ No newline at end of file
+## 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
+    IF(NOT CMAKE_INSTALL_PREFIX)
+        SET(CMAKE_INSTALL_PREFIX /usr/local)
+    ENDIF(NOT CMAKE_INSTALL_PREFIX)
+    
+    INSTALL(TARGETS serial
+      RUNTIME DESTINATION bin
+      LIBRARY DESTINATION lib
+      ARCHIVE DESTINATION lib
+    )
+    
+    INSTALL(FILES include/serial.h DESTINATION include)
+    
+    IF(NOT CMAKE_FIND_INSTALL_PATH)
+        set(CMAKE_FIND_INSTALL_PATH ${CMAKE_ROOT})
+    ENDIF(NOT CMAKE_FIND_INSTALL_PATH)
+    
+    INSTALL(FILES Findserial.cmake DESTINATION ${CMAKE_FIND_INSTALL_PATH}/Modules/)
+    
+    ADD_CUSTOM_TARGET(uninstall @echo uninstall package)
+    
+    IF (UNIX)
+      ADD_CUSTOM_COMMAND(
+        COMMENT "uninstall package"
+        COMMAND xargs ARGS rm < install_manifest.txt
+        
+        TARGET  uninstall
+      )
+    ELSE(UNIX)
+      ADD_CUSTOM_COMMAND(
+        COMMENT "uninstall only implemented in unix"
+        TARGET  uninstall
+      )
+    ENDIF(UNIX)
+ENDIF(NOT SERIAL_DONT_CONFIGURE_INSTALL)
\ No newline at end of file
index 4f5cb5864fe0d18ed4b990506c0833ea698f1dcf..1cd189d2c33123a0b304a8797e79e275912e99e4 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -19,3 +19,15 @@ endif
 clean:
        -cd build && make clean
        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
\ No newline at end of file
diff --git a/examples/serial_example.cpp b/examples/serial_example.cpp
new file mode 100644 (file)
index 0000000..9048b0d
--- /dev/null
@@ -0,0 +1,33 @@
+#include <string>
+#include <iostream>
+
+#include "serial.h"
+
+int main(int argc, char **argv)
+{
+    if(argc < 2) {
+        std::cerr << "Usage: test_serial <serial port address>" << std::endl;
+        return 0;
+    }
+    std::string port(argv[1]);
+    
+    serial::Serial serial(port, 115200, 250);
+    
+    std::cout << "Is the serial port open?";
+    if(serial.isOpen())
+        std::cout << " Yes." << std::endl;
+    else
+        std::cout << " No." << std::endl;
+    
+    int count = 0;
+    while (count >= 0) {
+        int bytes_wrote = serial.write("Testing.");
+        std::string result = serial.read(8);
+        if(count % 10 == 0)
+            std::cout << ">" << count << ">" << bytes_wrote << ">" << result << std::endl;
+        
+        count += 1;
+    }
+    
+    return 0;
+}
diff --git a/src/test_serial.cpp b/src/test_serial.cpp
deleted file mode 100644 (file)
index 9048b0d..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-#include <string>
-#include <iostream>
-
-#include "serial.h"
-
-int main(int argc, char **argv)
-{
-    if(argc < 2) {
-        std::cerr << "Usage: test_serial <serial port address>" << std::endl;
-        return 0;
-    }
-    std::string port(argv[1]);
-    
-    serial::Serial serial(port, 115200, 250);
-    
-    std::cout << "Is the serial port open?";
-    if(serial.isOpen())
-        std::cout << " Yes." << std::endl;
-    else
-        std::cout << " No." << std::endl;
-    
-    int count = 0;
-    while (count >= 0) {
-        int bytes_wrote = serial.write("Testing.");
-        std::string result = serial.read(8);
-        if(count % 10 == 0)
-            std::cout << ">" << count << ">" << bytes_wrote << ">" << result << std::endl;
-        
-        count += 1;
-    }
-    
-    return 0;
-}
This page took 0.031888 seconds and 4 git commands to generate.