cmake: build static and DLL targets

This commit is contained in:
Hugues Delorme 2016-12-05 17:51:27 +01:00
parent fbf56aaa78
commit 091f665a6d
10 changed files with 45 additions and 73 deletions

View File

@ -13,32 +13,32 @@ _anchors:
matrix:
include:
# Linux GCC-4.6 debug static coveralls
# Linux GCC-4.6 debug coveralls
- compiler: gcc
env: TRAVIS_BUILD_TYPE=Debug TRAVIS_COVERALLS=ON
# Linux GCC-4.6 debug static google_double-conversion
# Linux GCC-4.6 debug google_double-conversion
- compiler: gcc
env: TRAVIS_BUILD_TYPE=Debug TRAVIS_FLOAT2STR_LIB=google_doubleconversion
# Linux GCC-4.6 debug dll c90
# Linux GCC-4.6 debug no-dll c90
- compiler: gcc
env: TRAVIS_BUILD_TYPE=Debug TRAVIS_SHARED_LIBS=ON TRAVIS_STRICT_C90=ON
# Linux GCC-4.9 release static
env: TRAVIS_BUILD_TYPE=Debug TRAVIS_BUILD_DLL=OFF TRAVIS_STRICT_C90=ON
# Linux GCC-4.9 release
- compiler: gcc-4.9
addons: *gcc49-packages
env: TRAVIS_BUILD_TYPE=Release TRAVIS_GCC_VERSION=4.9
# OSX Clang debug static
# OSX Clang debug
- os: osx
compiler: clang
env: TRAVIS_BUILD_TYPE=Debug
# OSX Clang debug static google_double-conversion
# OSX Clang debug google_double-conversion
- os: osx
compiler: clang
env: TRAVIS_BUILD_TYPE=Debug TRAVIS_FLOAT2STR_LIB=google_doubleconversion
# OSX Clang debug dll c90
# OSX Clang debug no-dll c90
- os: osx
compiler: clang
env: TRAVIS_BUILD_TYPE=Debug TRAVIS_SHARED_LIBS=ON TRAVIS_STRICT_C90=ON
# OSX Clang release static
env: TRAVIS_BUILD_TYPE=Debug TRAVIS_BUILD_DLL=OFF TRAVIS_STRICT_C90=ON
# OSX Clang release
- os: osx
compiler: clang
env: TRAVIS_BUILD_TYPE=Release

View File

@ -67,8 +67,8 @@ else()
endif()
# Options
option(GMIO_BUILD_DLL "Build gmio also as a shared library(DLL)" ON)
option(GMIO_BUILD_STRICT_C90 "Build gmio library(and tests) with strict conformance to C90 standard" OFF)
option(GMIO_BUILD_SHARED_LIBS "Build gmio as a shared library (DLL)" OFF)
option(GMIO_BUILD_BENCHMARKS "Build performance benchmarks for the gmio library" OFF)
option(GMIO_BUILD_EXAMPLES "Build gmio examples" OFF)
option(GMIO_BUILD_TESTS_FAKE_SUPPORT "Build tests/fake_support target" OFF)

View File

@ -14,11 +14,11 @@ clone_folder: c:\projects\gmio.git
environment:
matrix:
- APPVEYOR_SHARED_LIBS: OFF
- APPVEYOR_BUILD_DLL: ON
APPVEYOR_CMAKE_GENERATOR: "Visual Studio 12 2013"
APPVEYOR_FLOAT2STR_LIB: std
- APPVEYOR_SHARED_LIBS: ON
- APPVEYOR_BUILD_DLL: ON
APPVEYOR_CMAKE_GENERATOR: "Visual Studio 12 2013"
APPVEYOR_FLOAT2STR_LIB: google_doubleconversion
@ -32,7 +32,7 @@ build_script:
-G "%APPVEYOR_CMAKE_GENERATOR%" ^
-DCMAKE_BUILD_TYPE=%CONFIGURATION% ^
-DCMAKE_DEBUG_POSTFIX=_d ^
-DGMIO_BUILD_SHARED_LIBS=%APPVEYOR_SHARED_LIBS% ^
-DGMIO_BUILD_DLL=%APPVEYOR_BUILD_DLL% ^
-DGMIO_FLOAT2STR_LIB=%APPVEYOR_FLOAT2STR_LIB% ^
-DGMIO_BUILD_EXAMPLES=ON ^
-DGMIO_BUILD_BENCHMARKS=ON ^

View File

@ -45,7 +45,7 @@ set(COMMONS_FILES ${COMMONS_FILES})
include_directories(${CMAKE_SOURCE_DIR}/src)
include_directories(${CMAKE_BINARY_DIR}/src) # For cmake generated headers
include_directories(${CMAKE_BINARY_DIR}/src/gmio_core)
link_libraries(gmio)
link_libraries(gmio_static)
if(CMAKE_C_COMPILER_IS_GCC_COMPATIBLE)
link_libraries(m) # -lm
endif()

View File

@ -30,7 +30,7 @@
include_directories(${CMAKE_SOURCE_DIR}/src)
include_directories(${CMAKE_BINARY_DIR}/src/gmio_core) # For cmake generated headers
include_directories(${CMAKE_SOURCE_DIR}/tests/fake_support/opencascade)
link_libraries(gmio)
link_libraries(gmio_static)
if(CMAKE_C_COMPILER_IS_GCC_COMPATIBLE)
link_libraries(m) # -lm
endif()

View File

@ -45,16 +45,6 @@ configure_file(gmio_core/version.h.cmake gmio_core/version.h @ONLY)
configure_file(gmio_core/config.h.cmake gmio_core/config.h @ONLY)
include_directories(${CMAKE_BINARY_DIR}/src/gmio_core) # For cmake generated headers
# Enable DLL generation (export symbols)
if(GMIO_BUILD_SHARED_LIBS)
add_definitions(-DGMIO_DLL
-DGMIO_MAKING_DLL)
if(MSVC)
configure_file(gmio_core/gmio.rc.cmake gmio_core/gmio.rc @ONLY)
set(GMIO_SRC_FILES ${GMIO_SRC_FILES} ${CMAKE_BINARY_DIR}/src/gmio_core/gmio.rc)
endif()
endif()
# Declare installs
install(FILES ${CMAKE_BINARY_DIR}/src/gmio_core/version.h DESTINATION include/gmio_core)
install(FILES ${CMAKE_BINARY_DIR}/src/gmio_core/config.h DESTINATION include/gmio_core)
@ -63,11 +53,6 @@ file(GLOB GMIO_CORE_HEADERS gmio_core/*.h)
install(FILES ${GMIO_CORE_HEADERS} DESTINATION include/gmio_core)
# Module libSTL
#if(GMIO_BUILD_SHARED_LIBS)
# add_definitions(-DGMIO_STL_DLL
# -DGMIO_STL_MAKING_DLL)
#endif()
file(GLOB GMIO_LIBSTL_SRC_FILES gmio_stl/* gmio_stl/internal/*)
set(GMIO_SRC_FILES ${GMIO_SRC_FILES} ${GMIO_LIBSTL_SRC_FILES})
@ -83,30 +68,39 @@ install(FILES gmio_support/stream_qt.h DESTINATION include/gmio_support)
install(FILES gmio_support/stream_qt.cpp DESTINATION src/gmio_support)
# OpenCASCADE support
install(FILES gmio_support/stl_occ_brep.h DESTINATION include/gmio_support)
install(FILES gmio_support/stl_occ_mesh.h DESTINATION include/gmio_support)
install(FILES gmio_support/stl_occ_meshvs.h DESTINATION include/gmio_support)
install(FILES gmio_support/stl_occ_brep.h DESTINATION include/gmio_support)
install(FILES gmio_support/stl_occ_mesh.h DESTINATION include/gmio_support)
install(FILES gmio_support/stl_occ_meshvs.h DESTINATION include/gmio_support)
install(FILES gmio_support/stl_occ_brep.cpp DESTINATION src/gmio_support)
install(FILES gmio_support/stl_occ_mesh.cpp DESTINATION src/gmio_support)
install(FILES gmio_support/stl_occ_meshvs.cpp DESTINATION src/gmio_support)
install(FILES gmio_support/stl_occ_utils.h DESTINATION src/gmio_support)
# target
if(GMIO_BUILD_SHARED_LIBS)
add_library(gmio SHARED ${GMIO_SRC_FILES})
else()
add_library(gmio STATIC ${GMIO_SRC_FILES})
endif()
# zlib
if(GMIO_USE_BUNDLED_ZLIB)
add_subdirectory(3rdparty/zlib)
endif()
include_directories(${ZLIB_INCLUDE_DIRS})
target_link_libraries(gmio ${ZLIB_LIBRARIES})
# target
add_library(gmio_static STATIC ${GMIO_SRC_FILES})
target_link_libraries(gmio_static ${ZLIB_LIBRARIES})
if(GMIO_BUILD_DLL)
if(MSVC)
configure_file(gmio_core/gmio.rc.cmake gmio_core/gmio.rc @ONLY)
set(GMIO_SRC_FILES
${GMIO_SRC_FILES}
${CMAKE_BINARY_DIR}/src/gmio_core/gmio.rc)
endif()
add_library(gmio SHARED ${GMIO_SRC_FILES})
set_target_properties(
gmio PROPERTIES COMPILE_DEFINITIONS "GMIO_DLL;GMIO_MAKING_DLL")
target_link_libraries(gmio ${ZLIB_LIBRARIES})
set(GMIO_DLL_NAME gmio)
endif()
# Installs for target
install(TARGETS gmio
RUNTIME DESTINATION lib
install(TARGETS ${GMIO_DLL_NAME} gmio_static
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)

View File

@ -29,10 +29,6 @@
enable_testing()
set(CMAKE_CTEST_COMMAND ctest -V --timeout 120)
if(WIN32 AND GMIO_BUILD_SHARED_LIBS)
configure_file(win_ctest_cmd.bat.cmake win_ctest_cmd.bat @ONLY)
set(CMAKE_CTEST_COMMAND win_ctest_cmd.bat)
endif()
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
include_directories(${CMAKE_BINARY_DIR}/src/gmio_core) # For generated cmake headers
@ -45,19 +41,9 @@ set(GMIO_TEST_CORE_SRC
core_utils.c
stream_buffer.c
../benchmarks/commons/benchmark_tools.c)
if(GMIO_BUILD_SHARED_LIBS)
# Note_1: MSVC wants it because internal symbols are not exported (GCC
# exports all symbols)
set(GMIO_TEST_CORE_SRC
${GMIO_TEST_CORE_SRC}
../src/gmio_core/internal/error_check.c
../src/gmio_core/internal/locale_utils.c
../src/gmio_core/internal/numeric_utils.c
../src/gmio_core/internal/stringstream.c)
endif()
add_executable(test_core EXCLUDE_FROM_ALL ${GMIO_TEST_CORE_SRC})
target_link_libraries(test_core gmio)
target_link_libraries(test_core gmio_static)
# test_stl
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/models
@ -67,17 +53,9 @@ set(GMIO_TEST_STL_SRC
stl_testcases.c
core_utils.c
stl_utils.c)
if(GMIO_BUILD_SHARED_LIBS)
# See Note_1
set(GMIO_TEST_STL_SRC
${GMIO_TEST_STL_SRC}
../src/gmio_core/internal/locale_utils.c
../src/gmio_core/internal/numeric_utils.c
../src/gmio_stl/internal/stl_error_check.c)
endif()
add_executable(test_stl EXCLUDE_FROM_ALL ${GMIO_TEST_STL_SRC})
target_link_libraries(test_stl gmio)
target_link_libraries(test_stl gmio_static)
# fake_support
if(GMIO_BUILD_TESTS_FAKE_SUPPORT)

View File

@ -43,7 +43,7 @@ add_executable(
../../src/gmio_support/stl_occ_meshvs.cpp
../../src/gmio_support/stl_occ_brep.cpp
../../src/gmio_support/stream_qt.cpp)
target_link_libraries(fake_support gmio)
target_link_libraries(fake_support gmio_static)
include_directories(
${CMAKE_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/opencascade

View File

@ -54,7 +54,7 @@ static const char* test_core__buffer()
UTEST_ASSERT(buff.ptr != NULL);
UTEST_ASSERT(buff.size == buff_size);
UTEST_ASSERT(memcmp(buff.ptr, &zero_buff[0], buff_size) == 0);
/* TODO: make assert succeed with mingw and GMIO_BUILD_SHARED_LIBS=ON
/* TODO: make assert succeed with mingw and gmio as a DLL
* In this case free() has not the same address in libgmio.dll and
* test_core.exe */
UTEST_ASSERT(buff.func_deallocate == &free);

View File

@ -21,8 +21,8 @@ if [ -n "${TRAVIS_GCC_VERSION}" ]; then
export CXX=g++-$TRAVIS_GCC_VERSION;
fi
if [ -z "${TRAVIS_SHARED_LIBS}" ]; then
export TRAVIS_SHARED_LIBS=OFF;
if [ -z "${TRAVIS_BUILD_DLL}" ]; then
export TRAVIS_BUILD_DLL=OFF;
fi
if [ -z "${TRAVIS_STRICT_C90}" ]; then
@ -41,7 +41,7 @@ cmake .. -G "Unix Makefiles" \
-DCMAKE_DEBUG_POSTFIX=_d \
-DCMAKE_BUILD_TYPE=$TRAVIS_BUILD_TYPE \
-DCMAKE_INSTALL_PREFIX=../install \
-DGMIO_BUILD_SHARED_LIBS=$TRAVIS_SHARED_LIBS \
-DGMIO_BUILD_DLL=$TRAVIS_BUILD_DLL \
-DGMIO_BUILD_STRICT_C90=$TRAVIS_STRICT_C90 \
-DGMIO_BUILD_EXAMPLES=ON \
-DGMIO_BUILD_BENCHMARKS=ON \