4 cmake_minimum_required(VERSION 2.4.6)
6 if(COMMAND cmake_policy)
7 cmake_policy(SET CMP0003 NEW)
8 endif(COMMAND cmake_policy)
14 # Assuming unix means a gcc style compiler, eg. g++ or clang++.
16 #set(CMAKE_CXX_FLAGS "-Wall -Weffc++ -pedantic -pedantic-errors -Wextra -Wall -Waggregate-return -Wcast-align -Wcast-qual -Wchar-subscripts -Wcomment -Wconversion -Wdisabled-optimization -Wfloat-equal -Wformat -Wformat=2 -Wformat-nonliteral -Wformat-security -Wformat-y2k -Wimplicit -Wimport -Winit-self -Winline -Winvalid-pch -Wlong-long -Wmissing-braces -Wmissing-field-initializers -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn -Wpacked -Wparentheses -Wpointer-arith -Wredundant-decls -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wstack-protector -Wstrict-aliasing -Wstrict-aliasing=2 -Wswitch -Wswitch-default -Wswitch-enum -Wtrigraphs -Wuninitialized -Wunknown-pragmas -Wunreachable-code -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value -Wunused-variable -Wvariadic-macros -Wvolatile-register-var -Wwrite-strings")
18 # Force to always compile with W4
19 if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
20 string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
22 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
26 IF(NOT DEFINED BUILD_NO_CLANG)
27 option(BUILD_NO_CLANG "Do not use the Clang compiler." OFF)
28 ENDIF(NOT DEFINED BUILD_NO_CLANG)
30 # Use clang if available
31 IF(EXISTS /usr/bin/clang AND NOT BUILD_NO_CLANG)
32 set(CMAKE_CXX_COMPILER /usr/bin/clang++)
33 set(CMAKE_OSX_DEPLOYMENT_TARGET "")
34 set(SERIAL_BUILD_WARNINGS TRUE)
35 set(CMAKE_BUILD_TYPE Debug)
36 ENDIF(EXISTS /usr/bin/clang AND NOT BUILD_NO_CLANG)
38 option(SERIAL_BUILD_TESTS "Build all of the Serial tests." OFF)
39 option(SERIAL_BUILD_EXAMPLES "Build all of the Serial examples." OFF)
41 # Allow for building shared libs override
42 IF(NOT BUILD_SHARED_LIBS)
43 set(BUILD_SHARED_LIBS OFF)
44 ENDIF(NOT BUILD_SHARED_LIBS)
46 # Threading libraries added for mutexs
47 FIND_PACKAGE (Threads)
49 # Set the default path for built executables to the "bin" directory
50 IF(NOT DEFINED(EXECUTABLE_OUTPUT_PATH))
51 set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
52 ENDIF(NOT DEFINED(EXECUTABLE_OUTPUT_PATH))
53 # set the default path for built libraries to the "lib" directory
54 IF(NOT DEFINED(LIBRARY_OUTPUT_PATH))
55 set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
56 ENDIF(NOT DEFINED(LIBRARY_OUTPUT_PATH))
58 ## Configure the build system
60 # Add the include folder to the include path
61 include_directories(${PROJECT_SOURCE_DIR}/include)
63 # Add default source files
64 set(SERIAL_SRCS src/serial.cc)
66 list(APPEND SERIAL_SRCS src/impl/win.cc)
68 list(APPEND SERIAL_SRCS src/impl/unix.cc)
70 # Add default header files
71 set(SERIAL_HEADERS include/serial/serial.h)
79 if(UNIX AND NOT APPLE)
80 list(APPEND OTHER_LIBS rt pthread)
81 endif(UNIX AND NOT APPLE)
83 ## Build the Serial Library
86 add_library(serial ${SERIAL_SRCS})
87 target_link_libraries(serial ${CMAKE_THREAD_LIBS_INIT} ${OTHER_LIBS})
92 IF(SERIAL_BUILD_EXAMPLES)
93 # Compile the Serial Test program
94 add_executable(serial_example examples/serial_example.cc)
95 # Link the Test program to the Serial library
96 target_link_libraries(serial_example serial)
97 ENDIF(SERIAL_BUILD_EXAMPLES)
102 IF(SERIAL_BUILD_TESTS)
105 find_package(GTest REQUIRED)
106 include_directories(${GTEST_INCLUDE_DIRS})
108 # Compile the Serial Test program
109 add_executable(serial_tests tests/serial_tests.cc)
110 # Link the Test program to the serial library
111 target_link_libraries(serial_tests ${GTEST_BOTH_LIBRARIES}
114 add_test(AllTestsIntest_serial serial_tests)
115 ENDIF(SERIAL_BUILD_TESTS)
117 ## Setup install and uninstall
119 # Unless asked not to...
120 IF(NOT SERIAL_DONT_CONFIGURE_INSTALL)
121 # Configure make install
122 IF(NOT CMAKE_INSTALL_PREFIX)
123 SET(CMAKE_INSTALL_PREFIX /usr/local)
124 ENDIF(NOT CMAKE_INSTALL_PREFIX)
126 INSTALL(TARGETS serial
127 RUNTIME DESTINATION bin
128 LIBRARY DESTINATION lib
129 ARCHIVE DESTINATION lib
132 INSTALL(FILES include/serial/serial.h
133 include/serial/v8stdint.h
134 DESTINATION include/serial)
136 IF(NOT CMAKE_FIND_INSTALL_PATH)
137 set(CMAKE_FIND_INSTALL_PATH ${CMAKE_ROOT})
138 ENDIF(NOT CMAKE_FIND_INSTALL_PATH)
140 INSTALL(FILES Findserial.cmake
141 DESTINATION ${CMAKE_FIND_INSTALL_PATH}/Modules/)
143 ADD_CUSTOM_TARGET(uninstall @echo uninstall package)
147 COMMENT "uninstall package"
148 COMMAND xargs ARGS rm < install_manifest.txt
154 COMMENT "uninstall only implemented in unix"
158 ENDIF(NOT SERIAL_DONT_CONFIGURE_INSTALL)
159 endmacro(build_serial)