2013-02-21 21:37:42 +08:00
|
|
|
cmake_minimum_required(VERSION 2.6)
|
2014-01-24 00:24:50 +08:00
|
|
|
|
2013-02-21 21:37:42 +08:00
|
|
|
include(CheckIncludeFiles)
|
2014-01-24 00:24:50 +08:00
|
|
|
include(CheckFunctionExists)
|
|
|
|
include(CheckCSourceCompiles)
|
2013-02-21 21:37:42 +08:00
|
|
|
|
2014-03-28 23:33:35 +08:00
|
|
|
project(gmio C)
|
2013-02-21 21:37:42 +08:00
|
|
|
|
2014-03-14 00:49:39 +08:00
|
|
|
#set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
2014-02-19 19:13:28 +08:00
|
|
|
|
2014-01-22 01:28:29 +08:00
|
|
|
# Options
|
2014-11-19 16:38:24 +08:00
|
|
|
option(BUILD_SHARED_LIBS "Build shared libraries (DLL)" ON)
|
|
|
|
option(BUILD_STRICT_C90 "Build with strict conformance to C90 standard. If disabled, C99 features can be used (eg. strtof(), <stdint.h>, ...)" ON)
|
|
|
|
option(BUILD_WITH_LIBSTL "Build the libSTL module" ON)
|
2013-02-21 21:37:42 +08:00
|
|
|
|
2013-03-06 17:31:21 +08:00
|
|
|
# Add core source files
|
2014-03-28 23:33:35 +08:00
|
|
|
file(GLOB ALL_SRC_FILES src/gmio_core/* src/gmio_core/internal/*)
|
2014-01-29 02:00:36 +08:00
|
|
|
set(ALL_SRC_FILES ${ALL_SRC_FILES})
|
2013-02-21 21:37:42 +08:00
|
|
|
|
2014-11-19 16:38:24 +08:00
|
|
|
if(NOT BUILD_STRICT_C90)
|
|
|
|
# Have <stdint.h> ?
|
|
|
|
check_include_files(stdint.h GMIO_HAVE_STDINT_H)
|
2014-01-24 00:24:50 +08:00
|
|
|
|
2014-11-19 16:38:24 +08:00
|
|
|
# Have strtof() ?
|
|
|
|
check_function_exists(strtof GMIO_HAVE_STRTOF_FUNC)
|
2014-11-11 01:31:44 +08:00
|
|
|
|
2014-11-19 16:38:24 +08:00
|
|
|
# Have <stdbool.h> ?
|
|
|
|
check_include_files(stdbool.h GMIO_HAVE_STDBOOL_H)
|
2014-01-24 00:24:50 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Have builtin byte swap functions ?
|
|
|
|
if(CMAKE_COMPILER_IS_GNUCC)
|
2014-11-19 16:38:24 +08:00
|
|
|
# __builtin_bswap16() is missing in x86 GCC version prior to v4.7
|
|
|
|
# See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52624
|
|
|
|
check_c_source_compiles("int main() { return (int)__builtin_bswap16(0x1122); }"
|
|
|
|
GMIO_HAVE_GCC_BUILTIN_BSWAP16_FUNC)
|
|
|
|
check_c_source_compiles("int main() { return (int)__builtin_bswap32(0x11223344); }"
|
|
|
|
GMIO_HAVE_GCC_BUILTIN_BSWAP32_FUNC)
|
2014-01-24 00:24:50 +08:00
|
|
|
elseif(MSVC)
|
2014-11-19 16:38:24 +08:00
|
|
|
check_c_source_compiles("#include <stdlib.h>
|
|
|
|
int main() { return (int)_byteswap_ulong(0x11223344); }"
|
|
|
|
GMIO_HAVE_MSVC_BUILTIN_BSWAP_FUNC)
|
2014-01-24 00:24:50 +08:00
|
|
|
endif()
|
|
|
|
|
2014-03-28 23:33:35 +08:00
|
|
|
configure_file(src/gmio_core/config.h.cmake config.h @ONLY)
|
2013-02-21 21:37:42 +08:00
|
|
|
include_directories(${CMAKE_BINARY_DIR}) # For generated "config.h"
|
|
|
|
|
2014-02-19 19:13:28 +08:00
|
|
|
# Specific flags for GCC
|
2013-02-21 21:37:42 +08:00
|
|
|
if(CMAKE_COMPILER_IS_GNUCC)
|
2014-11-19 16:38:24 +08:00
|
|
|
if(BUILD_STRICT_C90)
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ansi")
|
|
|
|
endif()
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic-errors -fstrict-aliasing")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Winline -Wextra -Wstrict-aliasing -Wcast-align -Wlogical-op -Wfloat-equal")
|
|
|
|
# Force PIC for GCC, see : https://www.gentoo.org/proj/en/base/amd64/howtos/index.xml?part=1&chap=3
|
|
|
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
2013-02-21 21:37:42 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Specific flags for Visual C++
|
|
|
|
if(MSVC)
|
2014-11-19 16:38:24 +08:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -TC")
|
|
|
|
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
2013-02-21 21:37:42 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(BUILD_SHARED_LIBS)
|
2014-11-19 16:38:24 +08:00
|
|
|
add_definitions(-DGMIO_LIB_DLL
|
|
|
|
-DGMIO_LIB_MAKE_DLL)
|
2013-02-21 21:37:42 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Declare installs
|
2014-03-28 23:33:35 +08:00
|
|
|
install(FILES ${CMAKE_BINARY_DIR}/config.h DESTINATION include/gmio_core)
|
2013-02-21 21:37:42 +08:00
|
|
|
|
2014-03-28 23:33:35 +08:00
|
|
|
file(GLOB C_CORE_HEADERS src/gmio_core/*.h)
|
|
|
|
install(FILES ${C_CORE_HEADERS} DESTINATION include/gmio_core)
|
2013-02-21 21:37:42 +08:00
|
|
|
|
2013-03-06 17:31:21 +08:00
|
|
|
# Module libSTL
|
2014-01-24 00:24:50 +08:00
|
|
|
if(BUILD_WITH_LIBSTL)
|
2014-11-19 16:38:24 +08:00
|
|
|
if(BUILD_SHARED_LIBS)
|
|
|
|
add_definitions(-DGMIO_LIBSTL_DLL
|
|
|
|
-DGMIO_LIBSTL_MAKE_DLL)
|
|
|
|
endif()
|
2013-03-06 17:31:21 +08:00
|
|
|
|
2014-11-19 16:38:24 +08:00
|
|
|
file(GLOB ALL_LIBSTL_SRC_FILES src/gmio_stl/* src/gmio_stl/internal/*)
|
|
|
|
set(ALL_SRC_FILES ${ALL_SRC_FILES} ${ALL_LIBSTL_SRC_FILES})
|
2013-02-21 21:37:42 +08:00
|
|
|
|
2014-01-22 01:28:29 +08:00
|
|
|
endif()
|
2014-03-28 23:33:35 +08:00
|
|
|
file(GLOB C_LIBSTL_HEADERS src/gmio_stl/*.h)
|
|
|
|
install(FILES ${C_LIBSTL_HEADERS} DESTINATION include/gmio_stl)
|
2014-01-22 01:28:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
# Common for support modules
|
2014-03-28 23:33:35 +08:00
|
|
|
install(FILES src/gmio_support/support_global.h DESTINATION include/gmio_support)
|
2014-01-22 01:28:29 +08:00
|
|
|
|
|
|
|
# Qt support
|
2014-03-28 23:33:35 +08:00
|
|
|
install(FILES src/gmio_support/qt_stream.h DESTINATION include/gmio_support)
|
|
|
|
install(FILES src/gmio_support/qt_stream.cpp DESTINATION src/gmio_support)
|
2014-01-22 01:28:29 +08:00
|
|
|
|
|
|
|
# OpenCASCADE support
|
2014-03-28 23:33:35 +08:00
|
|
|
install(FILES src/gmio_support/occ_libstl.h DESTINATION include/gmio_support)
|
|
|
|
install(FILES src/gmio_support/occ_libstl.cpp DESTINATION src/gmio_support)
|
2013-03-06 17:31:21 +08:00
|
|
|
|
2014-02-19 19:13:28 +08:00
|
|
|
# Installs for target
|
2014-03-28 23:33:35 +08:00
|
|
|
add_library(gmio ${ALL_SRC_FILES})
|
|
|
|
install(TARGETS gmio
|
2013-02-21 21:37:42 +08:00
|
|
|
RUNTIME DESTINATION lib
|
|
|
|
LIBRARY DESTINATION lib
|
2013-03-06 17:31:21 +08:00
|
|
|
ARCHIVE DESTINATION lib)
|
2013-02-21 21:37:42 +08:00
|
|
|
|
2014-01-22 01:28:29 +08:00
|
|
|
|
2013-02-21 21:37:42 +08:00
|
|
|
# Examples:
|
|
|
|
# cmake ../.. -DCMAKE_INSTALL_PREFIX=../../gcc-linux64 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_DEBUG_POSTFIX=.debug
|
|
|
|
# cmake ../.. -DCMAKE_INSTALL_PREFIX=../../gcc-linux64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_RELEASE_POSTFIX=.release
|
|
|
|
# make VERBOSE=1 or cmake -DCMAKE_VERBOSE_MAKEFILE=TRUE
|
2014-01-30 07:26:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
# Tests
|
|
|
|
|
|
|
|
enable_testing()
|
|
|
|
set(CMAKE_CTEST_COMMAND ctest -V)
|
|
|
|
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
|
|
|
|
|
2014-02-11 18:13:15 +08:00
|
|
|
add_executable(test_internal EXCLUDE_FROM_ALL tests/stream_buffer.c
|
|
|
|
tests/test_internal.c
|
2014-03-28 23:33:35 +08:00
|
|
|
src/gmio_core/stream.c
|
|
|
|
src/gmio_core/internal/ascii_parse.c)
|
2014-02-11 18:13:15 +08:00
|
|
|
add_executable(test_platform EXCLUDE_FROM_ALL tests/test_platform.c)
|
2014-11-19 16:38:24 +08:00
|
|
|
|
2014-01-30 07:26:30 +08:00
|
|
|
add_test(test_internal test_internal)
|
2014-02-11 18:13:15 +08:00
|
|
|
add_test(test_platform test_platform)
|
2014-11-19 16:38:24 +08:00
|
|
|
|
|
|
|
add_dependencies(check test_internal
|
|
|
|
test_platform)
|