diff --git a/CMakeLists.txt b/CMakeLists.txt index 967b48454..3fa43e8ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,19 @@ project (lib3MF) # Define Version set(LIB3MF_VERSION_MAJOR 1) # increase on every backward-compatibility breaking change of the API set(LIB3MF_VERSION_MINOR 3) # increase on every backward compatible change of the API -set(LIB3MF_VERSION_MICRO 1) # increase on on every change that does not alter the API +set(LIB3MF_VERSION_MICRO 2) # increase on on every change that does not alter the API + + +# Add targets +# By default the shared libray is being built +# To build the static library, add the cmake option -DBUILD_SHARED_LIBS:BOOL=OFF +option(BUILD_SHARED_LIBS "build as shared library" ON) +message("BUILD_SHARED_LIBS ... " ${BUILD_SHARED_LIBS}) + +# By default the tests of the library are being built +# To not build the tests, use cmake . -DBUILD_TESTING:BOOL=OFF +option(BUILD_TESTING "build the tests of the library" ON) +message("BUILD_TESTING ... " ${BUILD_TESTING}) set(CMAKE_INSTALL_BINDIR bin CACHE PATH "directory for installing binary files") set(CMAKE_INSTALL_LIBDIR lib CACHE PATH "directory for installing library files") @@ -32,6 +44,8 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") add_definitions(-DBUILD_DLL -DLIB3MF_EXPORTS /W3) SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} xmllite.lib") add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS) + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") if(NMR_COM_NATIVE) add_definitions(-DNMR_COM_NATIVE) endif() @@ -91,44 +105,28 @@ endif() ######################################################### -# Static library (as base for other targets) -add_library(${PROJECT_NAME}_s STATIC ${SRCS_MAIN_PLATFORM} ${SRCS_COMMON}) -target_include_directories(${PROJECT_NAME}_s PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/Include) -target_include_directories(${PROJECT_NAME}_s PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/Include) -SET_TARGET_PROPERTIES(${PROJECT_NAME}_s PROPERTIES PREFIX "" IMPORT_PREFIX "") -if (UNIX OR MINGW) - target_compile_options(${PROJECT_NAME}_s PUBLIC "-fPIC") - # Uncomment the following to but the version info into the .so-file. - SET_TARGET_PROPERTIES(${PROJECT_NAME}_s PROPERTIES VERSION "${LIB3MF_VERSION_MAJOR}.${LIB3MF_VERSION_MINOR}.${LIB3MF_VERSION_MICRO}.${BUILD_NUMBER}") - SET_TARGET_PROPERTIES(${PROJECT_NAME}_s PROPERTIES SOVERSION "${LIB3MF_VERSION_MAJOR}") - if (NOT APPLE) - SET_TARGET_PROPERTIES(${PROJECT_NAME}_s PROPERTIES LINK_FLAGS -s) - endif() - find_library(LIBUUID_PATH uuid) - if(NOT LIBUUID_PATH) - message(FATAL_ERROR "libuuid not found") - endif() - target_link_libraries(${PROJECT_NAME}_s ${LIBUUID_PATH}) -else() - # wd4996 masks the deprecated-warning - target_compile_options(${PROJECT_NAME}_s PUBLIC "$<$:/Od;/Ob0;/Gm;/sdl;/W3;/WX;/FC;/wd4996>") - target_compile_options(${PROJECT_NAME}_s PUBLIC "$<$:/O2;/sdl;/WX;/Oi;/Gy;/FC;/wd4996>") -endif() - - -######################################################### -# Shared library -add_library(${PROJECT_NAME} SHARED ${SRCS_MAIN_PLATFORM} - "./Source/Model/COM/NMR_DLLInterfaces.cpp" +# The main lib3MF library +add_library(${PROJECT_NAME} + ${SRCS_MAIN_PLATFORM} ${SRCS_COMMON} ${VERSION_FILES_OUTPUTLOCATION} ) +target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/Include) +target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/Include) set(STARTUPPROJECT ${PROJECT_NAME}) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "" IMPORT_PREFIX "") -target_link_libraries(${PROJECT_NAME} ${PROJECT_NAME}_s) if (UNIX OR MINGW) # Uncomment the following to but the version info into the .so-file. SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION "${LIB3MF_VERSION_MAJOR}.${LIB3MF_VERSION_MINOR}.${LIB3MF_VERSION_MICRO}.${BUILD_NUMBER}") SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION "${LIB3MF_VERSION_MAJOR}") + + find_library(LIBUUID_PATH uuid) + if(NOT LIBUUID_PATH) + message(FATAL_ERROR "libuuid not found") + endif() + target_link_libraries(${PROJECT_NAME} ${LIBUUID_PATH}) + if (NOT APPLE) + SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES LINK_FLAGS -s) + endif() endif() install(TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" @@ -138,20 +136,18 @@ install(DIRECTORY Include/Model DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") install(DIRECTORY Include/Common DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Include/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") + ######################################################### -if(NOT DEFINED LIB3MF_TESTS) - set(LIB3MF_TESTS TRUE) -endif() -message("LIB3MF_TESTS ... " ${LIB3MF_TESTS}) -if(LIB3MF_TESTS) +if(${BUILD_TESTING}) include(CTest) # platform independent tests on the C-interface of the library add_subdirectory(UnitTests) - # windows specific tests + # windows specific tests for the C++ classes of the library if (WIN32) SET(UNITTEST_NAME "${PROJECT_NAME}unittests") - add_library(${UNITTEST_NAME} SHARED "${SRCS_WIN_MANAGEDTEST}") + add_library(${UNITTEST_NAME} SHARED ${SRCS_MAIN_PLATFORM} ${SRCS_COMMON} ${SRCS_WIN_MANAGEDTEST}) + target_include_directories(${UNITTEST_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/Include) target_include_directories(${UNITTEST_NAME} PUBLIC "${VCINSTALLDIR}/../../../UnitTest/include") target_include_directories(${UNITTEST_NAME} PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/Include) @@ -159,9 +155,6 @@ if(LIB3MF_TESTS) target_compile_options(${UNITTEST_NAME} PUBLIC "$<$:/Od;/Ob0;/Gm;/sdl;/W3;/WX;/FC;-DNMR_USEASSERTIONS;-DNMR_UNITTESTS;/wd4996>") target_compile_options(${UNITTEST_NAME} PUBLIC "$<$:/O2;/sdl;/WX;/Oi;/Gy;/FC;/wd4996>") - add_dependencies(${UNITTEST_NAME} ${PROJECT_NAME}_s) - target_link_libraries(${UNITTEST_NAME} ${PROJECT_NAME}_s) - file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/TestOutput") endif() endif() diff --git a/UnitTests/CMakeLists.txt b/UnitTests/CMakeLists.txt index 7c8d4b0b8..df3a9843e 100644 --- a/UnitTests/CMakeLists.txt +++ b/UnitTests/CMakeLists.txt @@ -1,6 +1,7 @@ ######################################################### # platform independent tests on the C-interface of the library +set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) ADD_SUBDIRECTORY (googletest EXCLUDE_FROM_ALL) enable_testing() SET(TEST_CINTERFACE "Test_CInterface") @@ -30,7 +31,9 @@ if (WIN32) target_compile_options(${TEST_CINTERFACE} PUBLIC "$<$:/O2;/sdl;/WX;/Oi;/Gy;/FC;/MT;/wd4996>") endif() +message(CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}) target_include_directories(${TEST_CINTERFACE} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Include ${gtest_SOURCE_DIR}/include) + target_link_libraries(${TEST_CINTERFACE} ${PROJECT_NAME} gtest gtest_main) add_dependencies(${TEST_CINTERFACE} ${PROJECT_NAME}) set_target_properties(${TEST_CINTERFACE} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/") diff --git a/Include/UnitTests/UnitTest_Utilities.h b/UnitTests/Include/UnitTest_Utilities.h similarity index 100% rename from Include/UnitTests/UnitTest_Utilities.h rename to UnitTests/Include/UnitTest_Utilities.h diff --git a/UnitTests/Source/UnitTest_Attachments.cpp b/UnitTests/Source/UnitTest_Attachments.cpp index 6c809b912..00f6c9356 100644 --- a/UnitTests/Source/UnitTest_Attachments.cpp +++ b/UnitTests/Source/UnitTest_Attachments.cpp @@ -30,7 +30,7 @@ in 3MF files. --*/ -#include "UnitTests/UnitTest_Utilities.h" +#include "UnitTest_Utilities.h" #include "Model/COM/NMR_DLLInterfaces.h" #include diff --git a/UnitTests/Source/UnitTest_BeamLattice.cpp b/UnitTests/Source/UnitTest_BeamLattice.cpp index 805dc7e9d..22e41ca85 100644 --- a/UnitTests/Source/UnitTest_BeamLattice.cpp +++ b/UnitTests/Source/UnitTest_BeamLattice.cpp @@ -29,7 +29,7 @@ UnitTest_ReadWrite.cpp: Defines Unittests for reading and writing of 3MFs --*/ -#include "UnitTests/UnitTest_Utilities.h" +#include "UnitTest_Utilities.h" #include "Model/COM/NMR_DLLInterfaces.h" #include diff --git a/UnitTests/Source/UnitTest_Extensions.cpp b/UnitTests/Source/UnitTest_Extensions.cpp index 0100eaed0..1501f4156 100644 --- a/UnitTests/Source/UnitTest_Extensions.cpp +++ b/UnitTests/Source/UnitTest_Extensions.cpp @@ -29,7 +29,7 @@ UnitTest_Extensions.cpp: Defines Unittests for general extension handling --*/ -#include "UnitTests/UnitTest_Utilities.h" +#include "UnitTest_Utilities.h" #include "Model/COM/NMR_DLLInterfaces.h" #include #include diff --git a/UnitTests/Source/UnitTest_OPC_Issues.cpp b/UnitTests/Source/UnitTest_OPC_Issues.cpp index 248a9d348..b602e2f25 100644 --- a/UnitTests/Source/UnitTest_OPC_Issues.cpp +++ b/UnitTests/Source/UnitTest_OPC_Issues.cpp @@ -29,7 +29,7 @@ UnitTest_OPC_Issues.cpp: Defines Unittests for OPC related requirements of a 3MF-reader/writer. --*/ -#include "UnitTests/UnitTest_Utilities.h" +#include "UnitTest_Utilities.h" #include "Model/COM/NMR_DLLInterfaces.h" #include diff --git a/UnitTests/Source/UnitTest_Production.cpp b/UnitTests/Source/UnitTest_Production.cpp index 2265aae67..77bf8b065 100644 --- a/UnitTests/Source/UnitTest_Production.cpp +++ b/UnitTests/Source/UnitTest_Production.cpp @@ -30,7 +30,7 @@ Defines Unittests for reading and writing the production extenstion to 3MF. --*/ -#include "UnitTests/UnitTest_Utilities.h" +#include "UnitTest_Utilities.h" #include "Model/COM/NMR_DLLInterfaces.h" #include diff --git a/UnitTests/Source/UnitTest_ProgressCallback.cpp b/UnitTests/Source/UnitTest_ProgressCallback.cpp index 6dd049f8f..cbd6d3dab 100644 --- a/UnitTests/Source/UnitTest_ProgressCallback.cpp +++ b/UnitTests/Source/UnitTest_ProgressCallback.cpp @@ -29,7 +29,7 @@ UnitTest_ProgressCallback.cpp: Defines Unittests for the progress callback funct --*/ -#include "UnitTests/UnitTest_Utilities.h" +#include "UnitTest_Utilities.h" #include "Model/COM/NMR_DLLInterfaces.h" #include diff --git a/UnitTests/Source/UnitTest_ReadWrite.cpp b/UnitTests/Source/UnitTest_ReadWrite.cpp index e016b9cfe..94a0bbbe0 100644 --- a/UnitTests/Source/UnitTest_ReadWrite.cpp +++ b/UnitTests/Source/UnitTest_ReadWrite.cpp @@ -29,7 +29,7 @@ UnitTest_ReadWrite.cpp: Defines Unittests for reading and writing of 3MFs --*/ -#include "UnitTests/UnitTest_Utilities.h" +#include "UnitTest_Utilities.h" #include "Model/COM/NMR_DLLInterfaces.h" #include diff --git a/UnitTests/Source/UnitTest_ReaderStrictMode.cpp b/UnitTests/Source/UnitTest_ReaderStrictMode.cpp index cf594259f..8806ff8d1 100644 --- a/UnitTests/Source/UnitTest_ReaderStrictMode.cpp +++ b/UnitTests/Source/UnitTest_ReaderStrictMode.cpp @@ -29,10 +29,9 @@ UnitTest_UnitTest_ReaderStrictMode.cpp: Defines Unittests for the StrictMode of --*/ -#include "UnitTests/UnitTest_Utilities.h" +#include "UnitTest_Utilities.h" #include "Model/COM/NMR_DLLInterfaces.h" - #include #include "gtest/gtest.h" diff --git a/UnitTests/Source/UnitTest_Slice.cpp b/UnitTests/Source/UnitTest_Slice.cpp index ea9a2eb77..47a36373b 100644 --- a/UnitTests/Source/UnitTest_Slice.cpp +++ b/UnitTests/Source/UnitTest_Slice.cpp @@ -29,7 +29,7 @@ UnitTest_Slice.cpp: Defines Unittests for the slice extension to 3MF --*/ -#include "UnitTests/UnitTest_Utilities.h" +#include "UnitTest_Utilities.h" #include "Model/COM/NMR_DLLInterfaces.h" #include diff --git a/UnitTests/Source/UnitTest_Textures.cpp b/UnitTests/Source/UnitTest_Textures.cpp index a2f36a4b9..909ecaf03 100644 --- a/UnitTests/Source/UnitTest_Textures.cpp +++ b/UnitTests/Source/UnitTest_Textures.cpp @@ -30,7 +30,7 @@ UnitTest_Textures.cpp: Defines Unittests for reading and writing textures from/t --*/ -#include "UnitTests/UnitTest_Utilities.h" +#include "UnitTest_Utilities.h" #include "Model/COM/NMR_DLLInterfaces.h" #include diff --git a/UnitTests/Source/UnitTest_Thumbnails.cpp b/UnitTests/Source/UnitTest_Thumbnails.cpp index be871984e..6b85fd69f 100644 --- a/UnitTests/Source/UnitTest_Thumbnails.cpp +++ b/UnitTests/Source/UnitTest_Thumbnails.cpp @@ -30,7 +30,7 @@ a 3MF package or individual objects within a model. --*/ -#include "UnitTests/UnitTest_Utilities.h" +#include "UnitTest_Utilities.h" #include "Model/COM/NMR_DLLInterfaces.h" #include diff --git a/cmake/README.md b/cmake/README.md index cc2b189be..21c79123f 100644 --- a/cmake/README.md +++ b/cmake/README.md @@ -12,3 +12,8 @@ A new folder “build” is created and contains projects for the IDE/build targ 1. navigate to the “build”-folder 2. Call “make” to build the projects 3. Run/debug a project + +By default, lib3MF is built as a shared (dynamic) library, and tests are enabled. +- The shared library only offers the C-like interface +- The static library offers both the C-like interface as well as the underlying C++ classes. To enable static library building, add the cmake option `-DBUILD_SHARED_LIBS:BOOL=OFF` either in the scripts in this folder or in the parent project that includes the lib3MF-project. +- To disable the tests, add the cmake option `-DBUILD_TESTING:BOOL=OFF` either in the scripts in this folder or in the parent project that includes the lib3MF-project.