cmake: split main CMakeLists.txt into sub-directory files

This commit is contained in:
Hugues Delorme 2015-08-11 23:57:57 +02:00
parent ef7538a4c8
commit a06fdc331d
6 changed files with 203 additions and 147 deletions

View File

@ -35,13 +35,7 @@ if (CMAKE_C_COMPILER MATCHES ".*clang")
endif ()
# Options
option(BUILD_SHARED_LIBS "Build shared libraries (DLL)" OFF)
option(BUILD_STRICT_C90 "Build with strict conformance to C90 standard" OFF)
option(BUILD_WITH_LIBSTL "Build the libSTL module" ON)
# Add core source files
file(GLOB ALL_SRC_FILES src/gmio_core/* src/gmio_core/internal/*)
set(ALL_SRC_FILES ${ALL_SRC_FILES})
option(GMIO_BUILD_STRICT_C90 "Build with strict conformance to C90 standard" OFF)
# Find bit size of the target architecture
math(EXPR GMIO_TARGET_ARCH_BIT_SIZE "8 * ${CMAKE_SIZEOF_VOID_P}")
@ -50,9 +44,9 @@ math(EXPR GMIO_TARGET_ARCH_BIT_SIZE "8 * ${CMAKE_SIZEOF_VOID_P}")
include(TestBigEndian)
test_big_endian(GMIO_HOST_IS_BIG_ENDIAN)
# Adapt C compiler flags to satisfy the BUILD_STRICT_C90 option
# Adapt C compiler flags to satisfy the GMIO_BUILD_STRICT_C90 option
# It must be done before checking of C99 and POSIX features
if(BUILD_STRICT_C90)
if(GMIO_BUILD_STRICT_C90)
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ansi -pedantic-errors")
elseif(MSVC)
@ -66,7 +60,7 @@ set(CMAKE_REQUIRED_FLAGS "${CMAKE_C_FLAGS}")
check_include_files(stdint.h GMIO_HAVE_STDINT_H)
# Check non-ANSI available features
if(NOT BUILD_STRICT_C90)
if(NOT GMIO_BUILD_STRICT_C90)
# Check C99 features
check_function_exists(strtof GMIO_HAVE_STRTOF_FUNC)
@ -141,11 +135,7 @@ if(NOT BUILD_STRICT_C90)
int main() { return (int)_byteswap_ulong(0x11223344); }"
GMIO_HAVE_MSVC_BUILTIN_BSWAP_FUNC)
endif()
endif() # !BUILD_STRICT_C90
configure_file(src/gmio_core/version.h.cmake version.h @ONLY)
configure_file(src/gmio_core/config.h.cmake config.h @ONLY)
include_directories(${CMAKE_BINARY_DIR}) # For generated header files
endif() # !GMIO_BUILD_STRICT_C90
# Specific flags for GCC and Clang
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
@ -191,122 +181,13 @@ if(MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Oi")
endif()
# Enable DLL generation (export symbols)
if(BUILD_SHARED_LIBS)
add_definitions(-DGMIO_LIB_DLL
-DGMIO_LIB_MAKE_DLL)
if(MSVC)
configure_file(src/gmio_core/gmio.rc.cmake gmio.rc @ONLY)
set(ALL_SRC_FILES ${ALL_SRC_FILES} ${CMAKE_BINARY_DIR}/gmio.rc)
endif()
endif()
# Declare installs
install(FILES ${CMAKE_BINARY_DIR}/version.h DESTINATION include/gmio_core)
install(FILES ${CMAKE_BINARY_DIR}/config.h DESTINATION include/gmio_core)
file(GLOB C_CORE_HEADERS src/gmio_core/*.h)
install(FILES ${C_CORE_HEADERS} DESTINATION include/gmio_core)
# Module libSTL
if(BUILD_WITH_LIBSTL)
if(BUILD_SHARED_LIBS)
add_definitions(-DGMIO_LIBSTL_DLL
-DGMIO_LIBSTL_MAKE_DLL)
endif()
file(GLOB ALL_LIBSTL_SRC_FILES src/gmio_stl/* src/gmio_stl/internal/*)
set(ALL_SRC_FILES ${ALL_SRC_FILES} ${ALL_LIBSTL_SRC_FILES})
endif()
file(GLOB C_LIBSTL_HEADERS src/gmio_stl/*.h)
install(FILES ${C_LIBSTL_HEADERS} DESTINATION include/gmio_stl)
# Common for support modules
install(FILES src/gmio_support/support_global.h DESTINATION include/gmio_support)
# Qt support
install(FILES src/gmio_support/stream_qt.h DESTINATION include/gmio_support)
install(FILES src/gmio_support/stream_qt.cpp DESTINATION src/gmio_support)
# OpenCASCADE support
install(FILES src/gmio_support/stl_occ.h DESTINATION include/gmio_support)
install(FILES src/gmio_support/stl_occ.cpp DESTINATION src/gmio_support)
# Installs for target
add_library(gmio ${ALL_SRC_FILES})
install(TARGETS gmio
RUNTIME DESTINATION lib
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
# Add a target to generate API documentation with Doxygen
find_package(Doxygen)
if(DOXYGEN_FOUND)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile.cmake
${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile @ONLY)
add_custom_target(
doc
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc
COMMENT "Generating API documentation with Doxygen" VERBATIM)
endif(DOXYGEN_FOUND)
# Sub-directories
add_subdirectory(src)
add_subdirectory(tests)
add_subdirectory(doc)
# 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
# Tests
enable_testing()
set(CMAKE_CTEST_COMMAND ctest -V)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
add_executable(
test_internal
EXCLUDE_FROM_ALL
tests/stream_buffer.c
tests/utils.c
tests/test_internal.c
src/gmio_core/stream.c
src/gmio_core/internal/string_parse.c)
add_executable(
test_platform EXCLUDE_FROM_ALL tests/test_platform.c)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/tests/models
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/tests)
add_executable(
test_stl
EXCLUDE_FROM_ALL
tests/test_stl_io.c
src/gmio_core/buffer.c
src/gmio_core/stream.c
src/gmio_core/internal/string_parse.c
src/gmio_stl/stl_format.c
src/gmio_stl/stl_io.c
src/gmio_stl/stla_read.c
src/gmio_stl/stlb_read.c
src/gmio_stl/internal/stl_rw_common.c
src/gmio_stl/internal/stla_write.c
src/gmio_stl/internal/stlb_byte_swap.c
src/gmio_stl/internal/stlb_write.c)
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
target_link_libraries(test_internal m) # -lm
target_link_libraries(test_stl m) # -lm
endif()
add_test(test_internal test_internal)
add_test(test_platform test_platform)
add_test(test_stl test_stl)
add_dependencies(
check
test_internal
test_platform
test_stl)

28
doc/CMakeLists.txt Normal file
View File

@ -0,0 +1,28 @@
#############################################################################
## gmio
## Copyright Fougue (2 Mar. 2015)
## contact@fougue.pro
##
## This software is a reusable library whose purpose is to provide complete
## I/O support for various CAD file formats (eg. STL)
##
## This software is governed by the CeCILL-B license under French law and
## abiding by the rules of distribution of free software. You can use,
## modify and/ or redistribute the software under the terms of the CeCILL-B
## license as circulated by CEA, CNRS and INRIA at the following URL
## "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
#############################################################################
# Add a target to generate API documentation with Doxygen
find_package(Doxygen)
if(DOXYGEN_FOUND)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.cmake
${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
add_custom_target(
doc
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen" VERBATIM)
endif(DOXYGEN_FOUND)

View File

@ -38,7 +38,7 @@ PROJECT_NUMBER = @GMIO_VERSION@
# for a project that appears at the top of each page and should give viewer
# a quick idea about the purpose of the project. Keep the description short.
PROJECT_BRIEF = "Fast, portable geometry input/output C library"
PROJECT_BRIEF = "Fast, portable C library for geometry input/output"
# With the PROJECT_LOGO tag one can specify an logo or icon that is
# included in the documentation. The maximum height of the logo should not
@ -128,7 +128,7 @@ FULL_PATH_NAMES = YES
# If left blank the directory from which doxygen is run is used as the
# path to strip.
STRIP_FROM_PATH = @CMAKE_CURRENT_SOURCE_DIR@/src
STRIP_FROM_PATH = @CMAKE_CURRENT_SOURCE_DIR@/../src
# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of
# the path mentioned in the documentation of a class, which tells
@ -249,7 +249,7 @@ EXTENSION_MAPPING =
MARKDOWN_SUPPORT = YES
USE_MDFILE_AS_MAINPAGE = @CMAKE_CURRENT_SOURCE_DIR@/README.md
USE_MDFILE_AS_MAINPAGE = @CMAKE_CURRENT_SOURCE_DIR@/../README.md
# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want
# to include (a tag file for) the STL sources as input, then you should
@ -641,8 +641,8 @@ WARN_LOGFILE =
# directories like "/usr/src/myproject". Separate the files or directories
# with spaces.
INPUT = @CMAKE_CURRENT_SOURCE_DIR@/README.md \
@CMAKE_CURRENT_SOURCE_DIR@/src
INPUT = @CMAKE_CURRENT_SOURCE_DIR@/../README.md \
@CMAKE_CURRENT_SOURCE_DIR@/../src
# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
@ -675,7 +675,7 @@ RECURSIVE = YES
# run.
EXCLUDE = \
@CMAKE_CURRENT_SOURCE_DIR@/src/gmio_support/support_global.h \
@CMAKE_CURRENT_SOURCE_DIR@/../src/gmio_support/support_global.h \
# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
# directories that are symbolic links (a Unix file system feature) are excluded

82
src/CMakeLists.txt Normal file
View File

@ -0,0 +1,82 @@
#############################################################################
## gmio
## Copyright Fougue (2 Mar. 2015)
## contact@fougue.pro
##
## This software is a reusable library whose purpose is to provide complete
## I/O support for various CAD file formats (eg. STL)
##
## This software is governed by the CeCILL-B license under French law and
## abiding by the rules of distribution of free software. You can use,
## modify and/ or redistribute the software under the terms of the CeCILL-B
## license as circulated by CEA, CNRS and INRIA at the following URL
## "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
#############################################################################
# Options
option(GMIO_BUILD_SHARED_LIBS "Build gmio as a shared library (DLL)" OFF)
option(GMIO_BUILD_WITH_LIBSTL "Build the libSTL module" ON)
# Add core source files
file(GLOB GMIO_SRC_FILES gmio_core/* gmio_core/internal/*)
set(GMIO_SRC_FILES ${GMIO_SRC_FILES})
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 generated header files
# Enable DLL generation (export symbols)
if(GMIO_BUILD_SHARED_LIBS)
add_definitions(-DGMIO_LIB_DLL
-DGMIO_LIB_MAKE_DLL)
if(MSVC)
configure_file(gmio_core/gmio.rc.cmake gmio.rc @ONLY)
set(GMIO_SRC_FILES ${GMIO_SRC_FILES} ${CMAKE_BINARY_DIR}/gmio.rc)
endif()
endif()
# Declare installs
install(FILES ${CMAKE_BINARY_DIR}/src/version.h DESTINATION include/gmio_core)
install(FILES ${CMAKE_BINARY_DIR}/src/config.h DESTINATION include/gmio_core)
file(GLOB GMIO_CORE_HEADERS gmio_core/*.h)
install(FILES ${GMIO_CORE_HEADERS} DESTINATION include/gmio_core)
# Module libSTL
if(GMIO_BUILD_WITH_LIBSTL)
if(GMIO_BUILD_SHARED_LIBS)
add_definitions(-DGMIO_LIBSTL_DLL
-DGMIO_LIBSTL_MAKE_DLL)
endif()
file(GLOB GMIO_LIBSTL_SRC_FILES gmio_stl/* gmio_stl/internal/*)
set(GMIO_SRC_FILES ${GMIO_SRC_FILES} ${GMIO_LIBSTL_SRC_FILES})
endif()
file(GLOB GMIO_LIBSTL_HEADERS gmio_stl/*.h)
install(FILES ${GMIO_LIBSTL_HEADERS} DESTINATION include/gmio_stl)
# Common for support modules
install(FILES gmio_support/support_global.h DESTINATION include/gmio_support)
# Qt support
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.h DESTINATION include/gmio_support)
install(FILES gmio_support/stl_occ.cpp DESTINATION src/gmio_support)
# Installs for target
if(GMIO_BUILD_SHARED_LIBS)
add_library(gmio SHARED ${GMIO_SRC_FILES})
else()
add_library(gmio STATIC ${GMIO_SRC_FILES})
endif()
install(TARGETS gmio
RUNTIME DESTINATION lib
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)

65
tests/CMakeLists.txt Normal file
View File

@ -0,0 +1,65 @@
#############################################################################
## gmio
## Copyright Fougue (2 Mar. 2015)
## contact@fougue.pro
##
## This software is a reusable library whose purpose is to provide complete
## I/O support for various CAD file formats (eg. STL)
##
## This software is governed by the CeCILL-B license under French law and
## abiding by the rules of distribution of free software. You can use,
## modify and/ or redistribute the software under the terms of the CeCILL-B
## license as circulated by CEA, CNRS and INRIA at the following URL
## "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
#############################################################################
enable_testing()
set(CMAKE_CTEST_COMMAND ctest -V)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
include_directories(${CMAKE_BINARY_DIR}/src/gmio_core) # For generated header files
add_executable(
test_internal
EXCLUDE_FROM_ALL
stream_buffer.c
utils.c
test_internal.c
../src/gmio_core/stream.c
../src/gmio_core/internal/string_parse.c)
add_executable(
test_platform EXCLUDE_FROM_ALL test_platform.c)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/models
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
add_executable(
test_stl
EXCLUDE_FROM_ALL
test_stl_io.c
../src/gmio_core/buffer.c
../src/gmio_core/stream.c
../src/gmio_core/internal/string_parse.c
../src/gmio_stl/stl_format.c
../src/gmio_stl/stl_io.c
../src/gmio_stl/stla_read.c
../src/gmio_stl/stlb_read.c
../src/gmio_stl/internal/stl_rw_common.c
../src/gmio_stl/internal/stla_write.c
../src/gmio_stl/internal/stlb_byte_swap.c
../src/gmio_stl/internal/stlb_write.c)
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
target_link_libraries(test_internal m) # -lm
target_link_libraries(test_stl m) # -lm
endif()
add_test(test_internal test_internal)
add_test(test_platform test_platform)
add_test(test_stl test_stl)
add_dependencies(
check
test_internal
test_platform
test_stl)

View File

@ -60,57 +60,57 @@ typedef struct stl_testcase stl_testcase;
const char* test_stl_read()
{
const stl_testcase expected[] = {
{ "tests/models/file_empty",
{ "models/file_empty",
GMIO_STL_ERROR_UNKNOWN_FORMAT,
GMIO_STL_FORMAT_UNKNOWN,
NULL
},
{ "tests/models/solid_4vertex.stla",
{ "models/solid_4vertex.stla",
GMIO_STL_ERROR_PARSING,
GMIO_STL_FORMAT_ASCII,
NULL
},
{ "tests/models/solid_anonymous_empty.stla",
{ "models/solid_anonymous_empty.stla",
GMIO_ERROR_OK,
GMIO_STL_FORMAT_ASCII,
NULL
},
{ "tests/models/solid_empty.stla",
{ "models/solid_empty.stla",
GMIO_ERROR_OK,
GMIO_STL_FORMAT_ASCII,
"emptysolid"
},
{ "tests/models/solid_empty.stlb",
{ "models/solid_empty.stlb",
GMIO_ERROR_OK,
GMIO_STL_FORMAT_BINARY_LE,
NULL
},
{ "tests/models/solid_empty_name_many_words.stla",
{ "models/solid_empty_name_many_words.stla",
GMIO_ERROR_OK,
GMIO_STL_FORMAT_ASCII,
"name with multiple words"
},
{ "tests/models/solid_empty_name_many_words_single_letters.stla",
{ "models/solid_empty_name_many_words_single_letters.stla",
GMIO_ERROR_OK,
GMIO_STL_FORMAT_ASCII,
"a b c d e f\t\tg h"
},
{ "tests/models/solid_lack_z.stla",
{ "models/solid_lack_z.stla",
GMIO_STL_ERROR_PARSING,
GMIO_STL_FORMAT_ASCII,
NULL
},
{ "tests/models/solid_one_facet.stla",
{ "models/solid_one_facet.stla",
GMIO_ERROR_OK,
GMIO_STL_FORMAT_ASCII,
NULL
},
{ "tests/models/solid_one_facet.le_stlb",
{ "models/solid_one_facet.le_stlb",
GMIO_ERROR_OK,
GMIO_STL_FORMAT_BINARY_LE,
NULL
},
{ "tests/models/solid_one_facet_uppercase.stla",
{ "models/solid_one_facet_uppercase.stla",
GMIO_ERROR_OK,
GMIO_STL_FORMAT_ASCII,
NULL
@ -190,7 +190,7 @@ void stl_triangle_array_get_triangle(
void generate_stlb_tests_models()
{
{
FILE* outfile = fopen("tests/models/solid_empty.stlb", "wb");
FILE* outfile = fopen("models/solid_empty.stlb", "wb");
gmio_stream_t stream = gmio_stream_stdio(outfile);
gmio_stlb_write_header(&stream, GMIO_ENDIANNESS_LITTLE, NULL, 0);
fclose(outfile);
@ -216,7 +216,7 @@ void generate_stlb_tests_models()
gmio_stl_write_file(
GMIO_STL_FORMAT_BINARY_LE,
"tests/models/solid_one_facet.le_stlb",
"models/solid_one_facet.le_stlb",
&mesh,
NULL,
NULL);