Use correct flags for openddl for static libs
parent
565539bb68
commit
e7cea5a283
|
@ -393,6 +393,7 @@ if(${BUILD_SHARED_LIBS})
|
||||||
set(BUILD_LIB_TYPE SHARED)
|
set(BUILD_LIB_TYPE SHARED)
|
||||||
else()
|
else()
|
||||||
set(BUILD_LIB_TYPE STATIC)
|
set(BUILD_LIB_TYPE STATIC)
|
||||||
|
add_definitions(-DDDL_STATIC_LIBRARY=OFF)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
IF( UNIX )
|
IF( UNIX )
|
||||||
|
|
|
@ -1,57 +1,50 @@
|
||||||
CMAKE_MINIMUM_REQUIRED( VERSION 3.10 )
|
CMAKE_MINIMUM_REQUIRED( VERSION 3.8 )
|
||||||
PROJECT( OpenDDL-Parser )
|
PROJECT( OpenDDL-Parser )
|
||||||
SET ( OPENDDL_PARSER_VERSION_MAJOR 0 )
|
# read version number from cpp file of the form: static const char *Version = "0.4.0";
|
||||||
SET ( OPENDDL_PARSER_VERSION_MINOR 1 )
|
file ( READ code/OpenDDLParser.cpp _ver )
|
||||||
SET ( OPENDDL_PARSER_VERSION_PATCH 0 )
|
string( REGEX MATCH "static const char [*]Version[ ]*=[ ]*\"[^\"]*\"" _ver_line "${_ver}" )
|
||||||
SET ( OPENDDL_PARSER_VERSION ${OPENDDL_PARSER_VERSION_MAJOR}.${OPENDDL_PARSER_VERSION_MINOR}.${OPENDDL_PARSER_VERSION_PATCH} )
|
string( REGEX MATCH "[0-9]+\.[0-9]+\.[0-9]+" openddlparser_VERSION "${_ver_line}" )
|
||||||
SET ( PROJECT_VERSION "${OPENDDL_PARSER_VERSION}" )
|
SET ( PROJECT_VERSION "${openddlparser_VERSION}" )
|
||||||
|
if ( "${PROJECT_VERSION}" STREQUAL "" )
|
||||||
|
message( FATAL_ERROR "Cannot find 'static const char *Version' in 'code/OpenDDLParser.cpp'" )
|
||||||
|
endif()
|
||||||
|
message(STATUS "openddlparser_VERSION: ${openddlparser_VERSION}")
|
||||||
|
|
||||||
option( DDL_DEBUG_OUTPUT "Set to ON to use output debug texts" OFF )
|
option( DDL_DEBUG_OUTPUT "Set to ON to use output debug texts" OFF )
|
||||||
option( DDL_STATIC_LIBRARY "Set to ON to build static libary of OpenDDL Parser." ON )
|
option( DDL_STATIC_LIBRARY "Deprecated, use BUILD_SHARED_LIBS instead." ON )
|
||||||
option( COVERALLS "Generate coveralls data" OFF )
|
# for backwards compatibility use DDL_STATIC_LIBRARY as initial value for cmake variable BUILD_SHARED_LIBS
|
||||||
|
# https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
||||||
|
|
||||||
if( CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX )
|
|
||||||
find_package(Threads)
|
|
||||||
else()
|
|
||||||
add_definitions( -D_CRT_SECURE_NO_WARNINGS )
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if ( DDL_STATIC_LIBRARY )
|
if ( DDL_STATIC_LIBRARY )
|
||||||
add_definitions( -DOPENDDL_STATIC_LIBARY )
|
set ( build_shared_libs_default OFF )
|
||||||
|
else()
|
||||||
|
set ( build_shared_libs_default ON )
|
||||||
endif()
|
endif()
|
||||||
|
option( DDL_BUILD_SHARED_LIBS "Set to ON to build shared libary of OpenDDL Parser." ${build_shared_libs_default} )
|
||||||
|
option( COVERALLS "Generate coveralls data" OFF )
|
||||||
|
option( DDL_DOCUMENTATION "Set to ON to opt in generating API documentation with Doxygen" OFF )
|
||||||
|
option( DDL_BUILD_TESTS "Set to OFF to not build tests by default" ON )
|
||||||
|
option( DDL_BUILD_PARSER_DEMO "Set to OFF to opt out building parser demo" ON )
|
||||||
|
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING")
|
add_definitions(
|
||||||
add_definitions(-DGTEST_HAS_TR1_TUPLE=0)
|
-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING
|
||||||
|
-DGTEST_HAS_TR1_TUPLE=0
|
||||||
|
-D_CRT_SECURE_NO_WARNINGS
|
||||||
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_definitions( -DOPENDDLPARSER_BUILD )
|
|
||||||
add_definitions( -D_VARIADIC_MAX=10 )
|
add_definitions( -D_VARIADIC_MAX=10 )
|
||||||
add_definitions( -DGTEST_HAS_PTHREAD=0 )
|
add_definitions( -DGTEST_HAS_PTHREAD=0 )
|
||||||
if ( DDL_DEBUG_OUTPUT )
|
if ( DDL_DEBUG_OUTPUT )
|
||||||
add_definitions( -DDDL_DEBUG_HEADER_NAME)
|
add_definitions( -DDDL_DEBUG_HEADER_NAME)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
INCLUDE_DIRECTORIES(
|
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
|
||||||
./
|
SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib )
|
||||||
include/
|
SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib )
|
||||||
contrib/gtest-1.7.0/include
|
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin )
|
||||||
contrib/gtest-1.7.0/
|
|
||||||
)
|
|
||||||
|
|
||||||
link_directories(
|
if (MSVC)
|
||||||
${CMAKE_HOME_DIRECTORY}/lib
|
|
||||||
)
|
|
||||||
|
|
||||||
SET( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake )
|
|
||||||
SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/lib )
|
|
||||||
SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/lib )
|
|
||||||
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/bin )
|
|
||||||
|
|
||||||
if( WIN32 AND NOT CYGWIN )
|
|
||||||
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc" ) # Force to always compile with W4
|
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc" ) # Force to always compile with W4
|
||||||
if( CMAKE_CXX_FLAGS MATCHES "/W[0-4]" )
|
if( CMAKE_CXX_FLAGS MATCHES "/W[0-4]" )
|
||||||
string( REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" )
|
string( REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" )
|
||||||
|
@ -72,21 +65,16 @@ if (COVERALLS)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Include the doc component.
|
# Include the doc component.
|
||||||
FIND_PACKAGE( doxygen )
|
if(DDL_DOCUMENTATION)
|
||||||
IF ( DOXYGEN_FOUND )
|
find_package(Doxygen REQUIRED)
|
||||||
CONFIGURE_FILE( doc/openddlparser_doc.in doc/doxygenfile @ONLY )
|
CONFIGURE_FILE( doc/openddlparser_doc.in doc/doxygenfile @ONLY )
|
||||||
ADD_CUSTOM_TARGET( doc ALL ${DOXYGEN_EXECUTABLE} doc/doxygenfile
|
add_custom_target(doc ALL
|
||||||
|
${DOXYGEN_EXECUTABLE} doc/doxygenfile
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
COMMENT "Generating API documentation with Doxygen" VERBATIM )
|
COMMENT "Generating API documentation with Doxygen" VERBATIM )
|
||||||
ENDIF ( DOXYGEN_FOUND )
|
endif()
|
||||||
|
|
||||||
SET ( openddl_parser_src
|
SET ( openddlparser_headers
|
||||||
code/OpenDDLCommon.cpp
|
|
||||||
code/OpenDDLExport.cpp
|
|
||||||
code/OpenDDLParser.cpp
|
|
||||||
code/OpenDDLStream.cpp
|
|
||||||
code/DDLNode.cpp
|
|
||||||
code/Value.cpp
|
|
||||||
include/openddlparser/OpenDDLCommon.h
|
include/openddlparser/OpenDDLCommon.h
|
||||||
include/openddlparser/OpenDDLExport.h
|
include/openddlparser/OpenDDLExport.h
|
||||||
include/openddlparser/OpenDDLParser.h
|
include/openddlparser/OpenDDLParser.h
|
||||||
|
@ -95,76 +83,129 @@ SET ( openddl_parser_src
|
||||||
include/openddlparser/DDLNode.h
|
include/openddlparser/DDLNode.h
|
||||||
include/openddlparser/Value.h
|
include/openddlparser/Value.h
|
||||||
include/openddlparser/TPoolAllocator.h
|
include/openddlparser/TPoolAllocator.h
|
||||||
README.md
|
|
||||||
)
|
)
|
||||||
|
SET ( openddlparser_src
|
||||||
SOURCE_GROUP( code FILES ${openddl_parser_src} )
|
code/OpenDDLCommon.cpp
|
||||||
|
code/OpenDDLExport.cpp
|
||||||
|
code/OpenDDLParser.cpp
|
||||||
|
code/OpenDDLStream.cpp
|
||||||
|
code/DDLNode.cpp
|
||||||
|
code/Value.cpp
|
||||||
|
)
|
||||||
|
|
||||||
if ( DDL_STATIC_LIBRARY )
|
SOURCE_GROUP( code FILES ${openddlparser_src} )
|
||||||
ADD_LIBRARY( openddl_parser STATIC
|
|
||||||
${openddl_parser_src}
|
ADD_LIBRARY( openddlparser ${openddlparser_src})
|
||||||
)
|
|
||||||
|
target_include_directories(openddlparser PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>)
|
||||||
|
|
||||||
|
target_compile_features(openddlparser PUBLIC cxx_std_11)
|
||||||
|
|
||||||
|
if(DDL_BUILD_SHARED_LIBS)
|
||||||
|
set_target_properties(openddlparser PROPERTIES
|
||||||
|
CXX_VISIBILITY_PRESET hidden
|
||||||
|
VISIBILITY_INLINES_HIDDEN TRUE
|
||||||
|
)
|
||||||
else()
|
else()
|
||||||
ADD_LIBRARY( openddl_parser SHARED
|
target_compile_definitions(openddlparser PUBLIC OPENDDL_STATIC_LIBARY)
|
||||||
${openddl_parser_src}
|
|
||||||
)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
SET ( GTEST_PATH contrib/gtest-1.7.0 )
|
set_target_properties( openddlparser PROPERTIES PUBLIC_HEADER "${openddlparser_headers}")
|
||||||
|
|
||||||
SET ( gtest_src
|
if (DDL_BUILD_TESTS)
|
||||||
${GTEST_PATH}/src/gtest-death-test.cc
|
find_package(Threads REQUIRED)
|
||||||
${GTEST_PATH}/src/gtest-filepath.cc
|
|
||||||
${GTEST_PATH}/src/gtest-internal-inl.h
|
|
||||||
${GTEST_PATH}/src/gtest-port.cc
|
|
||||||
${GTEST_PATH}/src/gtest-printers.cc
|
|
||||||
${GTEST_PATH}/src/gtest-test-part.cc
|
|
||||||
${GTEST_PATH}/src/gtest-typed-test.cc
|
|
||||||
${GTEST_PATH}/src/gtest.cc
|
|
||||||
)
|
|
||||||
|
|
||||||
SET( openddl_parser_unittest_src
|
SET ( GTEST_PATH contrib/gtest-1.7.0 )
|
||||||
test/UnitTestCommon.h
|
|
||||||
test/DDLNodeTest.cpp
|
|
||||||
test/OpenDDLCommonTest.cpp
|
|
||||||
test/OpenDDLExportTest.cpp
|
|
||||||
test/OpenDDLParserTest.cpp
|
|
||||||
test/OpenDDLParserUtilsTest.cpp
|
|
||||||
test/OpenDDLStreamTest.cpp
|
|
||||||
test/OpenDDLIntegrationTest.cpp
|
|
||||||
test/ValueTest.cpp
|
|
||||||
test/OpenDDLDefectsTest.cpp
|
|
||||||
test/OssFuzzTest.cpp
|
|
||||||
test/main.cpp
|
|
||||||
)
|
|
||||||
add_definitions(-DOPENDDL_TEST_DATA="${CMAKE_CURRENT_LIST_DIR}/test/TestData")
|
|
||||||
|
|
||||||
SOURCE_GROUP( code FILES ${openddl_parser_unittest_src} )
|
SET ( gtest_src
|
||||||
SOURCE_GROUP( gtest FILES ${gtest_src} )
|
${GTEST_PATH}/src/gtest-death-test.cc
|
||||||
|
${GTEST_PATH}/src/gtest-filepath.cc
|
||||||
|
${GTEST_PATH}/src/gtest-port.cc
|
||||||
|
${GTEST_PATH}/src/gtest-printers.cc
|
||||||
|
${GTEST_PATH}/src/gtest-test-part.cc
|
||||||
|
${GTEST_PATH}/src/gtest-typed-test.cc
|
||||||
|
${GTEST_PATH}/src/gtest.cc
|
||||||
|
)
|
||||||
|
|
||||||
ADD_EXECUTABLE( openddl_parser_unittest
|
SET( openddlparser_unittest_src
|
||||||
${gtest_src}
|
test/DDLNodeTest.cpp
|
||||||
${openddl_parser_unittest_src}
|
test/OpenDDLCommonTest.cpp
|
||||||
)
|
test/OpenDDLExportTest.cpp
|
||||||
|
test/OpenDDLParserTest.cpp
|
||||||
|
test/OpenDDLParserUtilsTest.cpp
|
||||||
|
test/OpenDDLStreamTest.cpp
|
||||||
|
test/OpenDDLIntegrationTest.cpp
|
||||||
|
test/ValueTest.cpp
|
||||||
|
test/OpenDDLDefectsTest.cpp
|
||||||
|
test/OssFuzzTest.cpp
|
||||||
|
test/main.cpp
|
||||||
|
)
|
||||||
|
|
||||||
target_link_libraries( openddl_parser_unittest openddl_parser ${CMAKE_THREAD_LIBS_INIT} )
|
SOURCE_GROUP( code FILES ${openddlparser_unittest_src} )
|
||||||
|
SOURCE_GROUP( gtest FILES ${gtest_src} )
|
||||||
|
|
||||||
SET( openddl_parser_demo_src
|
ADD_EXECUTABLE( openddlparser_unittest
|
||||||
demo/main.cpp
|
${gtest_src}
|
||||||
)
|
${openddlparser_unittest_src}
|
||||||
|
)
|
||||||
|
|
||||||
if (COVERALLS)
|
target_include_directories(openddlparser_unittest
|
||||||
set(COVERAGE_SRCS ${gtest_src} ${openddl_parser_unittest_src} )
|
PRIVATE
|
||||||
|
${GTEST_PATH}
|
||||||
|
${GTEST_PATH}/include
|
||||||
|
)
|
||||||
|
target_link_libraries(openddlparser_unittest openddlparser Threads::Threads)
|
||||||
|
target_compile_features(openddlparser_unittest PRIVATE cxx_std_11)
|
||||||
|
target_compile_definitions(openddlparser_unittest PRIVATE OPENDDL_TEST_DATA="${PROJECT_SOURCE_DIR}/test/TestData")
|
||||||
|
endif ()
|
||||||
|
|
||||||
# Create the coveralls target.
|
if (DDL_BUILD_PARSER_DEMO)
|
||||||
coveralls_setup(
|
SET( openddlparser_demo_src
|
||||||
"${COVERAGE_SRCS}" # The source files.
|
demo/main.cpp
|
||||||
ON # If we should upload.
|
)
|
||||||
"${PROJECT_SOURCE_DIR}/cmake/") # (Optional) Alternate project cmake module path.
|
|
||||||
endif()
|
|
||||||
|
|
||||||
ADD_EXECUTABLE( openddl_parser_demo
|
if (COVERALLS)
|
||||||
${openddl_parser_demo_src}
|
set(COVERAGE_SRCS ${gtest_src} ${openddlparser_unittest_src} )
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries( openddl_parser_demo openddl_parser )
|
# Create the coveralls target.
|
||||||
|
coveralls_setup(
|
||||||
|
"${COVERAGE_SRCS}" # The source files.
|
||||||
|
ON # If we should upload.
|
||||||
|
"${PROJECT_SOURCE_DIR}/cmake/") # (Optional) Alternate project cmake module path.
|
||||||
|
endif()
|
||||||
|
|
||||||
|
ADD_EXECUTABLE( openddlparser_demo
|
||||||
|
${openddlparser_demo_src}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries( openddlparser_demo openddlparser )
|
||||||
|
target_compile_features(openddlparser_demo PRIVATE cxx_std_11)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
include(CMakePackageConfigHelpers)
|
||||||
|
|
||||||
|
install(TARGETS openddlparser
|
||||||
|
EXPORT openddlparser-targets
|
||||||
|
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
|
||||||
|
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||||
|
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||||
|
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
|
||||||
|
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/openddlparser")
|
||||||
|
|
||||||
|
export(EXPORT openddlparser-targets
|
||||||
|
FILE openddlparser-config.cmake
|
||||||
|
NAMESPACE openddlparser::)
|
||||||
|
|
||||||
|
install(EXPORT openddlparser-targets
|
||||||
|
FILE openddlparser-config.cmake
|
||||||
|
NAMESPACE openddlparser::
|
||||||
|
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/openddlparser")
|
||||||
|
|
||||||
|
write_basic_package_version_file(
|
||||||
|
"${CMAKE_BINARY_DIR}/openddlparser-config-version.cmake"
|
||||||
|
COMPATIBILITY SameMajorVersion)
|
||||||
|
|
||||||
|
install(
|
||||||
|
FILES "${CMAKE_BINARY_DIR}/openddlparser-config-version.cmake"
|
||||||
|
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/openddlparser")
|
||||||
|
|
Loading…
Reference in New Issue