rttr-0.9.6/0000755000175000017500000000000013462532423010311 5ustar memerttr-0.9.6/.travis.yml0000755000175000017500000003473013256224263012435 0ustar meme#################################################################################### # # # Copyright (c) 2014 - 2018 Axel Menzel # # # # This file is part of RTTR (Run Time Type Reflection) # # License: MIT License # # # # Permission is hereby granted, free of charge, to any person obtaining # # a copy of this software and associated documentation files (the "Software"), # # to deal in the Software without restriction, including without limitation # # the rights to use, copy, modify, merge, publish, distribute, sublicense, # # and/or sell copies of the Software, and to permit persons to whom the # # Software is furnished to do so, subject to the following conditions: # # # # The above copyright notice and this permission notice shall be included in # # all copies or substantial portions of the Software. # # # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # # SOFTWARE. # # # #################################################################################### language: cpp dist: trusty sudo: false env: global: - ARCH_FLAGS_x86='-m32' - ARCH_FLAGS_x86_64='' - BUILD_DOCU=false - secure: "k1o939GwFc0AJY8cCprAeF9OYUs00Ad+ggrhzxtw4GLdjn0CYGnqrftHtkJ5WySDXj7rnEL4qur1oO19OeVGufhLQTV0+yian8meYppk7rlPIOOl6ygltTxMxNgvmkqCsHC1J1l+7vMEJUm1MunWedCnORWySoK2pZ89nAiMmzY/fjpsOKR8vpXQw5BTZPR775lYZyzbm8/ZY8eATd4EJGH+4YH/sTzYFa9SL2J/ieWR+SvALNLos7x6Civ0Nl6LXx5hXMenpSUpAbu7wBm6KDoL6vGHYa7oKrnJ5BAqOP4poNXF000riy3TENSO1sf+dGQJO8O2IQwe352VKw+paQ4s0SGe5lWAmn2hexU+dZ7rNO0LwA+bdt8XGIXZo2lvdHgsO2Ymj/wPLrqYHGwBgGceBilyD7ZAcKQ/OvHmvkHCytMSVhftcllsOZFwDen/5FliNTRI+Cs68pZUiT2PgT44t/8i5X3F1o8FlV9T+wDsPdH909g/pOFt4U3N8aGxst9bmrQvYAhVmPKtuxjz7ycBfsOTxON9HfTQFEGv3KCREdN8lzi/J9FBCFTtIwHbBKvEeaXrZ3oHSa9UoVG5VQtw14aBdzs7K2MrEYMxg4LCfSHe8ecYbRg1LM9uSdK5dcn/A9wLKEdFmU/pvbl3ryaF4KpL7w0fvNMC/k6o5tc=" - secure: "1ogFHnhUroT3nA1HxyXN5/Hoek6LcTazRPTGpYjKAge8To/x614D6R9j2yu0EDOZalolq0VeOONnHLnss6aPGeMvvHH1rvoKTDQsFjsm1fB6qLRr/qpZXs+G4mxStarxrXr5487hEkPP10fEi/PSOx8Gme6Kny+tXHxDzP04ljcZYVvxWfkb+cQBCnYupbHk4hzfKRmPYcUn6lCPyOGIzwsHQQI/LubmkiU+wQ0zcLLsTZSThk+zt6FlxYWykZGL24yrqmoXRszx8dR14cWPzvkxVeEOe3OY9mNix1Z7ki2eVeEk8m7d70yPmV5p8F2/nPGC7kUXTvPrAL62CcE5moHubijJwKXJM6nBQJYCPGygnvRnWxnoqO/9JpDuds4Cv+tbJMgo2ViLPsYk3BgMnYo4z+p4JViN9P4/jzbhsVtWd4rnXmPt9j4FkED+Eyt8BUzXFdTAPpuzwZSvmYzzR8MdZE/telCAcWUoiS35IQcWJ0UmPpNZfR1Lll0cWQ+dTmjNETJvwognuaTAexL7m0uMhX6KQIZfap2H0w+CIua7+jl6eb9iyvXv9vZZEUCH2kTWnYXqBmDGRHG3tEp97o5+yWQm1qjweLvKAMRirdkSaZEL0lrsJ8mBS6Y+PQwAQxlu+P3pFEJ6uU3fJrKyciuWnVDZKyddIrJEZorXjOA=" matrix: include: # check code formatting - os: linux compiler: gcc env: NAME="check code formatting" CHECK_FORMATTING=true addons: apt: packages: ['vera++'] # valgrind memory check - os: linux compiler: gcc addons: apt: sources: ['ubuntu-toolchain-r-test'] packages: ['g++-4.9', 'valgrind', 'ninja-build'] env: NAME="valgrind" COMPILER=g++-4.9 ARCH=x64 CONF=Debug VALGRIND=true UNIT_TESTS=true # check code coverage x86 => result https://coveralls.io/github/rttrorg/rttr - os: linux compiler: gcc addons: apt: sources: ['ubuntu-toolchain-r-test'] packages: ['g++-4.8-multilib', 'linux-libc-dev:i386'] after_success: - pip install --user urllib3[secure] cpp-coveralls - coveralls -e 3rd_party -e src/benchmarks -e src/unit_tests -i src/rttr --gcov-options '\-lp' --gcov 'gcov-4.8' env: NAME="code coverage x86" COMPILER=g++-4.8 ARCH=x86 CONF=Debug GCOV_FLAGS='--coverage' UNIT_TESTS=true # check code coverage x64 => result https://coveralls.io/github/rttrorg/rttr - os: linux compiler: gcc addons: apt: sources: ['ubuntu-toolchain-r-test'] packages: ['g++-4.8-multilib'] after_success: - pip install --user urllib3[secure] cpp-coveralls - coveralls -e 3rd_party -e src/benchmarks -e src/unit_tests -i src/rttr --gcov-options '\-lp' --gcov 'gcov-4.8' env: NAME="code coverage x64" COMPILER=g++-4.8 ARCH=x86_64 CONF=Debug GCOV_FLAGS='--coverage' UNIT_TESTS=true # build docu and upload to server - os: linux compiler: gcc addons: apt: sources: ['ubuntu-toolchain-r-test'] packages: ['g++-4.8-multilib', 'linux-libc-dev:i386', 'lftp'] after_success: - | echo "current branch: ${TRAVIS_BRANCH}" if [[ "${TRAVIS_BRANCH}" == "master" ]]; then echo "Upload documentation..." lftp -c "set ssl:verify-certificate no; open -u ${FTP_USER},${FTP_PASSWORD} ftp://server3.febas.net:21/; mirror -R ${TRAVIS_BUILD_DIR}/build/doc_website/master doc_tmp" lftp -c "set ssl:verify-certificate no; open -u ${FTP_USER},${FTP_PASSWORD} ftp://server3.febas.net:21/; rm -r doc" lftp -c "set ssl:verify-certificate no; open -u ${FTP_USER},${FTP_PASSWORD} ftp://server3.febas.net:21/; mv doc_tmp doc" fi env: NAME="documentation build" BUILD_DOCU=true COMPILER=g++-4.8 ARCH=x86 CONF=Release UNIT_TESTS=false # Linux / GCC - os: linux compiler: gcc addons: apt: sources: ['ubuntu-toolchain-r-test'] packages: ['g++-4.9-multilib', 'linux-libc-dev:i386', 'ninja-build'] env: NAME="g++-4.9 x86" COMPILER=g++-4.9 ARCH=x86 CONF=Release UNIT_TESTS=true - os: linux compiler: gcc addons: apt: sources: ['ubuntu-toolchain-r-test'] packages: ['g++-4.9', 'ninja-build'] env: NAME="g++-4.9 x64" COMPILER=g++-4.9 ARCH=x86_64 CONF=Release UNIT_TESTS=true - os: linux compiler: gcc addons: apt: sources: ['ubuntu-toolchain-r-test'] packages: ['g++-4.9', 'libboost-all-dev'] env: NAME="g++-4.9 x64 - Build benchmarks & examples" COMPILER=g++-4.9 ARCH=x86_64 CONF=Release UNIT_TESTS=false BUILD_EXAMPLES=true BUILD_BENCHMARKS=true - os: linux compiler: gcc addons: apt: sources: ['ubuntu-toolchain-r-test'] packages: ['g++-5', 'ninja-build'] env: NAME="g++-5" COMPILER=g++-5 ARCH=x86_64 CONF=Release UNIT_TESTS=true - os: linux compiler: gcc addons: apt: sources: ['ubuntu-toolchain-r-test'] packages: ['g++-6', 'ninja-build'] env: NAME="g++-6" COMPILER=g++-6 ARCH=x86_64 CONF=Release UNIT_TESTS=true - os: linux compiler: gcc addons: apt: sources: ['ubuntu-toolchain-r-test'] packages: ['g++-7', 'libboost-all-dev', 'ninja-build'] env: NAME="g++-7" COMPILER=g++-7 ARCH=x86_64 CONF=Release UNIT_TESTS=true BUILD_BENCHMARKS=true # Linux / CLang - os: linux compiler: clang addons: apt: sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.7'] packages: ['libstdc++-5-dev', 'clang-3.7', 'ninja-build'] env: COMPILER=clang++-3.7 ARCH=x86_64 CONF=Release UNIT_TESTS=true - os: linux compiler: clang addons: apt: sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-4.0'] packages: ['libstdc++-6-dev', 'clang-4.0', 'libboost-all-dev', 'ninja-build'] env: NAME="clang++-4.0 - build benchmarks & examples" COMPILER=clang++-4.0 ARCH=x86_64 CONF=Release UNIT_TESTS=false BUILD_EXAMPLES=true BUILD_BENCHMARKS=true - os: linux compiler: clang addons: apt: sources: ['ubuntu-toolchain-r-test'] packages: ['libstdc++-5-dev', 'clang-3.8', 'ninja-build'] env: COMPILER=clang++-3.8 ARCH=x86_64 CONF=Release UNIT_TESTS=true - os: linux compiler: clang addons: apt: sources: ['ubuntu-toolchain-r-test'] packages: ['libstdc++-6-dev', 'clang-3.9', 'ninja-build'] env: COMPILER=clang++-3.9 ARCH=x86_64 CONF=Release UNIT_TESTS=true - os: linux compiler: clang addons: apt: sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-4.0'] packages: ['libstdc++-6-dev', 'clang-4.0', 'ninja-build'] env: COMPILER=clang++-4.0 ARCH=x86_64 CONF=Release UNIT_TESTS=true - os: linux compiler: clang addons: apt: sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-5.0'] packages: ['libstdc++-7-dev', 'clang-5.0',] env: COMPILER=clang++-5.0 ARCH=x86_64 CONF=Release UNIT_TESTS=true # OSX/Clang - os: osx osx_image: xcode9.2 compiler: clang env: COMPILER=clang++ ARCH=x86 CONF=Release UNIT_TESTS=true BUILD_BENCHMARKS=true - os: osx osx_image: xcode9.2 compiler: clang env: COMPILER=clang++ ARCH=x86_64 CONF=Release UNIT_TESTS=true - os: osx osx_image: xcode9 compiler: clang env: COMPILER=clang++ ARCH=x86_64 CONF=Release UNIT_TESTS=true - os: osx osx_image: xcode8.3 compiler: clang env: COMPILER=clang++ ARCH=x86 CONF=Release UNIT_TESTS=true - os: osx osx_image: xcode8.3 compiler: clang env: COMPILER=clang++ ARCH=x86_64 CONF=Release UNIT_TESTS=true allow_failures: - env: NAME="documentation build" BUILD_DOCU=true COMPILER=g++-4.8 ARCH=x86 CONF=Release UNIT_TESTS=false before_install: - export CIT_ROOT=`pwd` - cd $CIT_ROOT install: - DEPS_DIR="${TRAVIS_BUILD_DIR}/3rd_party" - cd ${DEPS_DIR} ####################################################################################### # Setup default versions ####################################################################################### - if [[ "${LLVM_VERSION}" == "default" ]]; then LLVM_VERSION=3.7.0; fi - if [[ "${COMPILER}" != "" ]]; then export CXX=${COMPILER}; fi - if [[ "${COMPILER}" == "g++-4.8" ]]; then export CC=gcc-4.8; fi - if [[ "${ARCH}" == "x86" ]]; then export CMAKE_ARCH_FLAGS=-m32; fi ####################################################################################### # Install a recent CMake (unless already installed on OS X) ####################################################################################### - | if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then CMAKE_URL="http://www.cmake.org/files/v3.10/cmake-3.10.2-Linux-x86_64.tar.gz" mkdir cmake && travis_retry wget --no-check-certificate --quiet -O - ${CMAKE_URL} | tar --strip-components=1 -xz -C cmake export PATH=${DEPS_DIR}/cmake/bin:${PATH} else brew upgrade cmake || brew install cmake ninja || brew link --overwrite cmake fi - cmake --version ####################################################################################### # Install recent Doxygen ####################################################################################### - | if [[ "${BUILD_DOCU}" == "true" ]]; then DOXYGEN_URL="http://ftp.stack.nl/pub/users/dimitri/doxygen-1.8.10.linux.bin.tar.gz" mkdir doxygen && travis_retry wget --quiet -O - ${DOXYGEN_URL} | tar --strip-components=1 -xz -C doxygen export PATH=${DEPS_DIR}/doxygen/bin:${PATH} fi before_script: - cd ${TRAVIS_BUILD_DIR} - mkdir build - > eval "ARCH_FLAGS=\${ARCH_FLAGS_${ARCH}}" ; (cd build && cmake -DCMAKE_CXX_COMPILER=${COMPILER} -DCMAKE_BUILD_TYPE=${CONF} -DCMAKE_CXX_FLAGS="$ARCH_FLAGS $CMAKE_ADDITIONAL_FLAGS $GCOV_FLAGS" -DBUILD_WEBSITE_DOCU=$BUILD_DOCU -DBUILD_EXAMPLES=$BUILD_EXAMPLES -DBUILD_BENCHMARKS=$BUILD_BENCHMARKS ..) script: # show OS/compiler version - uname -a - $CXX --version - | if [[ "${CHECK_FORMATTING}" == "true" ]]; then # F001: Source files should not use the '\r' (CR) character # L001: No trailing whitespace at the end of lines # L002: Don't use tab characters # T001: One-line comments should not have forced continuation # T002: Reserved names should not be used for preprocessor macros # T009: Comma should not be preceded by whitespace, but should be followed by one # T013: Source files should contain the copyright notice find src/rttr src/unit_tests -name \*\.h -print -o -name \*\.cpp -print | vera++ --rule F001 --rule L001 --rule L002 --rule T001 --rule T002 --rule T009 --rule T013 --error fi - | if [[ "${UNIT_TESTS}" == "true" ]]; then # Run unit tests on two cores (cd build && make run_tests -j2) fi - | if [[ "${BUILD_DOCU}" == "true" ]]; then # Run unit tests on two cores (cd build && make doc_website -j2) fi - | if [[ "${BUILD_BENCHMARKS}" == "true" ]]; then # Run unit tests on two cores (cd build && make bench_method -j2 && make bench_rttr_cast -j2 && make bench_variant -j2) fi - | if [[ "${BUILD_EXAMPLES}" == "true" ]]; then # Run unit tests on two cores (cd build && make json_example -j2 && make library_loader_example -j2) fi - | if [[ "${VALGRIND}" == "true" ]]; then # Run unit tests on two cores (valgrind --leak-check=full --error-exitcode=1 ${TRAVIS_BUILD_DIR}/build/bin/unit_tests_d) fi notifications: email: - info@rttr.org rttr-0.9.6/LICENSE.txt0000755000175000017500000000210313256263165012140 0ustar memeMIT License Copyright (c) 2014 - 2018 Axel Menzel Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. rttr-0.9.6/README.md0000755000175000017500000001467213256226415011607 0ustar meme[![Version](https://badge.fury.io/gh/rttrorg%2Frttr.svg)](https://github.com/rttrorg/rttr/releases/latest) [![Travis status](https://travis-ci.org/rttrorg/rttr.svg?branch=master)](https://travis-ci.org/rttrorg/rttr) [![Appveyor status](https://ci.appveyor.com/api/projects/status/github/rttrorg/rttr?svg=true&branch=master)](https://ci.appveyor.com/project/acki-m/rttr) [![Coverage Status](https://coveralls.io/repos/rttrorg/rttr/badge.svg?branch=master&service=github)](https://coveralls.io/github/rttrorg/rttr) [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/783/badge)](https://bestpractices.coreinfrastructure.org/projects/783) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/9821799170644782ac8d7885d393e686)](https://www.codacy.com/app/acki-m/rttr?utm_source=github.com&utm_medium=referral&utm_content=rttrorg/rttr&utm_campaign=Badge_Grade) [![Documentation](https://img.shields.io/badge/docs-latest-blue.svg)](http://www.rttr.org/doc/master/classes.html) [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/rttrorg/rttr/master/LICENSE.txt) [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=JQ65KGGCSUZMS) !New Release - 0.9.6! == RTTR ==== > C++ Reflection Library RTTR stands for Run Time Type Reflection. It describes the ability of a computer program to introspect and modify an object at runtime. It is also the name of the library itself, which is written in C++ and released as open source library. You can find more information on: www.rttr.org ---------- How to Use ---------- ### Manual registration ```cpp #include using namespace rttr; struct MyStruct { MyStruct() {}; void func(double) {}; int data; }; RTTR_REGISTRATION { registration::class_("MyStruct") .constructor<>() .property("data", &MyStruct::data) .method("func", &MyStruct::func); } ``` ### Iterate over members ```cpp type t = type::get(); for (auto& prop : t.get_properties()) std::cout << "name: " << prop.get_name(); for (auto& meth : t.get_methods()) std::cout << "name: " << meth.get_name(); ``` ### Constructing types ```cpp type t = type::get_by_name("MyStruct"); variant var = t.create(); // will invoke the previously registered ctor constructor ctor = t.get_constructor(); // 2nd way with the constructor class var = ctor.invoke(); std::cout << var.get_type().get_name(); // prints 'MyStruct' ``` ### Set/get properties ```cpp MyStruct obj; property prop = type::get(obj).get_property("data"); prop.set_value(obj, 23); variant var_prop = prop.get_value(obj); std::cout << var_prop.to_int(); // prints '23' ``` ### Invoke Methods: ```cpp MyStruct obj; method meth = type::get(obj).get_method("func"); meth.invoke(obj, 42.0); variant var = type::get(obj).create(); meth.invoke(var, 42.0); ``` Features --------- - reflect constructors, methods, data member or enums - classes; with *single*-, *multiple*- and *virtual*-inheritance - constructors (arbitrary argument count) - methods (*virtual*, *abstract*, *overloaded*, arbitrary argument count) - arrays (incl. raw-arrays; arbitrary dimension count) - ability to invoke properties and methods of classes from any arbitrary class level - no header pollution; the reflection information is created in the cpp file to minimize compile time when modifying the data - working with custom types without the need of having the declaration of the type available at compile time (useful for plugins) - possibility to add additional *metadata* to all reflection objects - possibility to add *default arguments* to methods or constructors - adjust registration behaviour through *policies* - minimal macro usage - **no** additional 3rd party dependencies are needed - **no** rtti required; contains a faster and across shared libraries working replacement - **no** exceptions (this feature come with cost and is also regularly disabled on consoles) - **no** external compiler or tool needed, only standard ISO C++11 Portability ----------- Tested and compiled with: - Microsoft Visual Studio 2013, 2015 & 2017 - GCC 4.8.1 - Clang 3.7 - MinGW 4.8.2 License ------- RTTR is released under the terms of the [MIT](LICENSE.txt) license, so it is free to use in your free or commercial projects. Copyright (c) 2014 - 2018 Axel Menzel Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Installation ------------ The installation guide can be found [here][rttr.install]. Get Started: ------------ Take a look at the [documentation][rttr.docs] or start with the [tutorial][rttr.tutorial]. Donation: --------- When you use RTTR and you would like to say thank you for its development, I am happy to receive any donation. [![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=JQ65KGGCSUZMS) [rttr.docs]: http://www.rttr.org/doc/master/classes.html [rttr.install]: http://www.rttr.org/doc/master/building_install_page.html [rttr.tutorial]: http://www.rttr.org/doc/master/tutorial_page.html rttr-0.9.6/CMake/0000755000175000017500000000000013460576672011305 5ustar memerttr-0.9.6/CMake/utility.cmake0000755000175000017500000006610013256263173014010 0ustar meme#################################################################################### # # # Copyright (c) 2014 - 2018 Axel Menzel # # # # This file is part of RTTR (Run Time Type Reflection) # # License: MIT License # # # # Permission is hereby granted, free of charge, to any person obtaining # # a copy of this software and associated documentation files (the "Software"), # # to deal in the Software without restriction, including without limitation # # the rights to use, copy, modify, merge, publish, distribute, sublicense, # # and/or sell copies of the Software, and to permit persons to whom the # # Software is furnished to do so, subject to the following conditions: # # # # The above copyright notice and this permission notice shall be included in # # all copies or substantial portions of the Software. # # # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # # SOFTWARE. # # # #################################################################################### #################################################################################### # Welcome to the CMake build system for RTTR. # This file contains several helper function to make the life easier with cmake. #################################################################################### #################################################################################### # create hierarchical source groups, useful for big VS-Projects # FILE_LIST <= a list of files with absolute path #################################################################################### function (createSrcGroups FILE_LIST ) # we want to get the relative path from the # current source dir string(LENGTH ${CMAKE_CURRENT_SOURCE_DIR} curDirLen) set(TMP_FILE_LIST ${${FILE_LIST}}) foreach ( SOURCE ${TMP_FILE_LIST} ) string(LENGTH ${SOURCE} fullPathLen) math(EXPR RelPathLen ${fullPathLen}-${curDirLen}) string(SUBSTRING ${SOURCE} ${curDirLen} ${RelPathLen} curStr) string ( REGEX REPLACE "[\\/]" "\\\\" normPath ${curStr} ) string ( REGEX MATCH "\\\\(.*)\\\\" ouput ${normPath} ) if(NOT CMAKE_MATCH_1 STREQUAL "") source_group ( ${CMAKE_MATCH_1} FILES ${SOURCE} ) endif() endforeach() endfunction() #################################################################################### # Create a UnityFile. This is a file which inlcudes all other source files. # This is usefull, when you want a fast rebuild. # _UNITY_FILE <= The name of the UnityFile # _SRC_FILES <= The list of source files #################################################################################### function(generateUnityFile _UNITY_FILE _SRC_FILES) set(files ${${_SRC_FILES}}) # Generate a unique filename for the unity build translation unit set(unit_build_file ${CMAKE_CURRENT_BINARY_DIR}/ub_${_UNITY_FILE}.cpp) set_source_files_properties(${files} PROPERTIES HEADER_FILE_ONLY true) # Open the ub file FILE(WRITE ${unit_build_file} "// Unity Build generated by CMake\n") # Add include statement for each translation unit foreach(sourceFile ${files} ) #FILE( APPEND ${unit_build_file} "#include <${CMAKE_CURRENT_SOURCE_DIR}/${sourceFile}>\n") FILE( APPEND ${unit_build_file} "#include \"${sourceFile}\"\n") endforeach() # Complement list of translation units with the name of ub set(${_UNITY_FILE} ${unit_build_file} PARENT_SCOPE) source_group("Generated Files" FILES ${unit_build_file}) endfunction() #################################################################################### # Returns the name of the Directory, where the file in the FILE_PATH is located. #################################################################################### function(getNameOfDir FILE_PATH DIR_NAME) get_filename_component(HAS_FILE_IN_PATH ${${FILE_PATH}} EXT) if (HAS_FILE_IN_PATH) get_filename_component(PATH_WITHOUT_FILENAME ${${FILE_PATH}} PATH) get_filename_component(NAME_OF_DIR ${PATH_WITHOUT_FILENAME} NAME) set(${DIR_NAME} ${NAME_OF_DIR} PARENT_SCOPE) else() get_filename_component(NAME_OF_DIR ${${FILE_PATH}} NAME) set(${DIR_NAME} ${NAME_OF_DIR} PARENT_SCOPE) endif() endfunction() #################################################################################### # Returns relative path from the given file path; starting from CMAKE_CURRENT_SOURCE_DIR #################################################################################### function(getRelativePath FILE_PATH RELATIVE_PATH) string(LENGTH ${CMAKE_CURRENT_SOURCE_DIR} CUR_DIR_LEN) get_filename_component(PATH_WITHOUT_FILE ${${FILE_PATH}} PATH) string(LENGTH ${PATH_WITHOUT_FILE} FULL_PATH_LEN) math(EXPR REL_PATH_LEN ${FULL_PATH_LEN}-${CUR_DIR_LEN}) math(EXPR REL_PATH_START "${CUR_DIR_LEN}") string(SUBSTRING ${PATH_WITHOUT_FILE} ${REL_PATH_START} ${REL_PATH_LEN} REL_PATH) string(REGEX REPLACE "^/" "" out_path "${REL_PATH}") set(${RELATIVE_PATH} ${out_path} PARENT_SCOPE) endfunction() #################################################################################### # Loads a FOLDER, which should contain a FOLDER.cmake. # In this file all source and header files should be declared. # In this cmake files all files have to be declared relative. # They will be read with absolut path. # FOLDER <= The name of the folder # _HEADER_FILES => The list of header files # _SOURCE_FILES => The list of source files # [OPTIONAL] 3rdArg => performs the installation of the header and source files #################################################################################### function(loadFolder FOLDER _HEADER_FILES _SOURCE_FILES) set(FULL_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${FOLDER}.cmake) include(${FULL_PATH}) get_filename_component(ABS_PATH_TO_FILES ${FULL_PATH} PATH) set(shouldInstall ${ARGV3}) set(QT_MOC_HEADERS) set(QT_UI_FILES) set(QT_QRC_FILES) foreach(headerFile ${HEADER_FILES} ) if (${headerFile} MATCHES ".*.h.in$") string ( REGEX REPLACE ".h.in$" ".h" out_path ${headerFile} ) configure_file(${headerFile} ${CMAKE_CURRENT_BINARY_DIR}/${out_path} @ONLY) set(FULL_HEADER_PATH ${ABS_PATH_TO_FILES}/${headerFile}) getRelativePath(FULL_HEADER_PATH REL_PATH) set(FULL_HEADER_PATH ${CMAKE_CURRENT_BINARY_DIR}/${out_path}) if (REL_PATH) string ( REGEX REPLACE "[\\/]" "\\\\" normalized_path ${REL_PATH} ) source_group ( ${normalized_path} FILES ${FULL_HEADER_PATH} ) endif() list(APPEND ALL_HPP_FILES ${FULL_HEADER_PATH}) elseif (${headerFile} MATCHES ".*.rc.in$") string ( REGEX REPLACE ".rc.in$" ".rc" out_path ${headerFile} ) configure_file(${headerFile} ${CMAKE_CURRENT_BINARY_DIR}/${out_path} @ONLY) source_group("Generated Files" FILES ${CMAKE_CURRENT_BINARY_DIR}/${out_path}) list(APPEND ALL_HPP_FILES ${CMAKE_CURRENT_BINARY_DIR}/${out_path}) elseif (${headerFile} MATCHES ".*.ui$") set(FULL_HEADER_PATH ${ABS_PATH_TO_FILES}/${headerFile}) list(APPEND QT_UI_FILES ${FULL_HEADER_PATH}) list(APPEND ALL_HPP_FILES ${FULL_HEADER_PATH}) elseif (${headerFile} MATCHES ".*.qrc$") set(FULL_HEADER_PATH ${ABS_PATH_TO_FILES}/${headerFile}) list(APPEND QT_QRC_FILES ${FULL_HEADER_PATH}) list(APPEND ALL_HPP_FILES ${FULL_HEADER_PATH}) else() set(FULL_HEADER_PATH ${ABS_PATH_TO_FILES}/${headerFile}) file(STRINGS ${FULL_HEADER_PATH} var REGEX "Q_OBJECT") if(var) list(APPEND QT_MOC_HEADERS ${FULL_HEADER_PATH}) endif() # returns the relative path, from the current source dir getRelativePath(FULL_HEADER_PATH REL_PATH) list(APPEND HEADER_LIST_OF_CUR_DIR ${FULL_HEADER_PATH}) endif() # get the name of the current directory getNameOfDir(CMAKE_CURRENT_SOURCE_DIR DIRNAME) if (${shouldInstall}) if (NOT ${FULL_HEADER_PATH} MATCHES ".*_p.h$") # we don't want to install header files which are marked as private install(FILES ${FULL_HEADER_PATH} DESTINATION "include/${DIRNAME}/${REL_PATH}" PERMISSIONS OWNER_READ) endif() endif() endforeach() # and now the source files list(APPEND QML_SOURCES) foreach(srcFile ${SOURCE_FILES} ) # the source_group placement doesn't work at the moment if (${srcFile} MATCHES ".*.qml$") string(REGEX REPLACE "[\\/]" "_" qrc_resource_file ${srcFile} ) string(REGEX REPLACE ".qml$" ".qrc" qrc_resource_file ${qrc_resource_file} ) set(qrc_resource_file ${CMAKE_CURRENT_BINARY_DIR}/${qrc_resource_file}) file(WRITE ${qrc_resource_file} "${ABS_PATH_TO_FILES}/${srcFile}") qt5_add_resources(compiled_resource_file ${qrc_resource_file}) source_group("Generated Files" FILES ${compiled_resource_file}) source_group("Generated Files" FILES ${qrc_resource_file}) list(APPEND QML_SOURCES ${compiled_resource_file}) elseif (${srcFile} MATCHES ".*.ui$") set(FULL_SRC_PATH ${ABS_PATH_TO_FILES}/${srcFile}) list(APPEND QT_UI_FILES ${FULL_SRC_PATH}) list(APPEND SOURCE_LIST_OF_CUR_DIR ${FULL_SRC_PATH}) elseif (${srcFile} MATCHES ".*.qrc$") set(FULL_SRC_PATH ${ABS_PATH_TO_FILES}/${srcFile}) list(APPEND QT_QRC_FILES ${FULL_SRC_PATH}) list(APPEND SOURCE_LIST_OF_CUR_DIR ${FULL_SRC_PATH}) else() list(APPEND SOURCE_LIST_OF_CUR_DIR ${ABS_PATH_TO_FILES}/${srcFile}) endif() list(APPEND SOURCE_LIST_OF_CUR_DIR ${ABS_PATH_TO_FILES}/${srcFile}) endforeach() list(APPEND QT_MOC_SOURCES) if (QT_MOC_HEADERS) qt5_wrap_cpp(QT_MOC_SOURCES ${QT_MOC_HEADERS}) source_group("Generated Files" FILES ${QT_MOC_SOURCES}) endif() list(APPEND QT_UI_SOURCES) if (QT_UI_FILES) qt5_wrap_ui(QT_UI_SOURCES ${QT_UI_FILES}) source_group("Generated Files" FILES ${QT_UI_SOURCES}) endif() list(APPEND QT_QRC_SOURCES) if (QT_QRC_FILES) qt5_add_resources(QT_QRC_SOURCES ${QT_QRC_FILES}) source_group("Generated Files" FILES ${QT_QRC_SOURCES}) endif() list(APPEND ALL_HPP_FILES ${${_HEADER_FILES}} ${HEADER_LIST_OF_CUR_DIR}) list(APPEND ALL_CPP_FILES ${${_SOURCE_FILES}} ${SOURCE_LIST_OF_CUR_DIR} ${QT_MOC_SOURCES} ${QT_UI_SOURCES} ${QT_QRC_SOURCES} ${QML_SOURCES}) set(${_HEADER_FILES} ${ALL_HPP_FILES} PARENT_SCOPE) set(${_SOURCE_FILES} ${ALL_CPP_FILES} PARENT_SCOPE) createSrcGroups(HEADER_LIST_OF_CUR_DIR) createSrcGroups(SOURCE_LIST_OF_CUR_DIR) message( STATUS "${FOLDER} directory included" ) endfunction() #################################################################################### # This function checks if the current generator is used for a Viusal Studio build # _INPUT This variable will be set to TRUE if its a Visual Studio build, otherwise to FALSE. #################################################################################### function (is_vs_based_build _INPUT) if(${CMAKE_GENERATOR} MATCHES "Visual Studio") set(${_INPUT} TRUE PARENT_SCOPE) else() set(${_INPUT} FALSE PARENT_SCOPE) endif() endfunction() #################################################################################### # Copy a release dependency in the correct CMAKE_RUNTIME_OUTPUT_DIRECTORY # _INPUT The full path of the dependency incl. FileName # _OUTPUT The directory where the libraries should be installed. # OPTIONAL: RELATIVE Path - as third argument an optional relative path can be specified #################################################################################### function(copy_dependency_release _INPUT _OUTPUT) is_vs_based_build(VS_BUILD) # when this is a DEBUG build we dont copy the files if(NOT VS_BUILD) if(${CMAKE_BUILD_TYPE} STREQUAL Debug) return() endif() endif() # as third argument an optional relative path can be specified set(REL_PATH ${ARGV2}) set(_PATH ${_INPUT}) # make the path to normal path with / as dir separator string ( REGEX REPLACE "[\\/]" "/" FILE_PATH ${_PATH} ) get_filename_component(FILE_NAME ${FILE_PATH} NAME) if (VS_BUILD) if (IS_DIRECTORY ${_INPUT}) file(COPY ${_INPUT} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Release/${REL_PATH}) else() configure_file(${FILE_PATH} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Release/${REL_PATH}/${FILE_NAME} COPYONLY) configure_file(${FILE_PATH} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/RelWithDebInfo/${REL_PATH}/${FILE_NAME} COPYONLY) configure_file(${FILE_PATH} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/MinSizeRel/${REL_PATH}/${FILE_NAME} COPYONLY) endif() else() if (IS_DIRECTORY ${_INPUT}) file(COPY ${_INPUT} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${REL_PATH}) else() configure_file(${FILE_PATH} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${REL_PATH}/${FILE_NAME} COPYONLY) endif() endif() if (IS_DIRECTORY ${_INPUT}) install(DIRECTORY ${FILE_PATH} DESTINATION ${_OUTPUT}/${REL_PATH} CONFIGURATIONS Release) else() install(FILES ${FILE_PATH} DESTINATION ${_OUTPUT}/${REL_PATH} CONFIGURATIONS Release) endif() endfunction() #################################################################################### # Copy a debug dependency in the correct CMAKE_RUNTIME_OUTPUT_DIRECTORY # _INPUT The full path of the dependency incl. FileName # _OUTPUT The directory where the libraries should be installed. # OPTIONAL: RELATIVE Path - as third argument an optional relative path can be specified #################################################################################### function(copy_dependency_debug _INPUT _OUTPUT) is_vs_based_build(VS_BUILD) # when this is NOT a DEBUG build we dont copy the files if(NOT VS_BUILD) if(NOT ${CMAKE_BUILD_TYPE} STREQUAL Debug) return() endif() endif() # as third argument an optional relative path can be specified set(REL_PATH ${ARGV2}) set(_PATH ${_INPUT}) # make the path to normal path with / as dir separator string ( REGEX REPLACE "[\\/]" "////" FILE_PATH ${_PATH} ) get_filename_component(FILE_NAME ${FILE_PATH} NAME) if (VS_BUILD) if (IS_DIRECTORY ${_INPUT}) file(COPY ${_INPUT} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Debug/${REL_PATH}) else() configure_file(${FILE_PATH} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Debug/${REL_PATH}/${FILE_NAME} COPYONLY) endif() else() if (IS_DIRECTORY ${_INPUT}) file(COPY ${_INPUT} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${REL_PATH}) else() configure_file(${FILE_PATH} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${REL_PATH}/${FILE_NAME} COPYONLY) endif() endif() if (IS_DIRECTORY ${_INPUT}) install(DIRECTORY ${FILE_PATH} DESTINATION ${_OUTPUT}/${REL_PATH} CONFIGURATIONS Debug) else() install(FILES ${FILE_PATH} DESTINATION ${_OUTPUT}/${REL_PATH} CONFIGURATIONS Debug) endif() endfunction() #################################################################################### # Creates a PreCompiled Header # _PRECOMPILED_HEADER The full path of the dependency incl. FileName # _SRC_FILES (Only works with CPP files) #################################################################################### function(activate_precompiled_headers _PRECOMPILED_HEADER _SOURCE_FILES) set(SRC_FILES ${${_SOURCE_FILES}}) get_filename_component(pch_basename ${_PRECOMPILED_HEADER} NAME_WE) set(pch_abs ${CMAKE_CURRENT_SOURCE_DIR}/${_PRECOMPILED_HEADER}) set(pch_unity ${CMAKE_CURRENT_BINARY_DIR}/${pch_basename}.cpp) if(MSVC) # First specify the name of the PCH file # it seems to be that nmake build cant handle the $(IntDir) variable if(NOT MSVC_IDE) set(pch_bin ${CMAKE_CURRENT_BINARY_DIR}/${pch_basename}.pch) else() set(pch_bin "$(IntDir)/${pch_basename}.pch") endif() # Generate precompiled header translation unit if (NOT EXISTS ${pch_unity}) file(WRITE ${pch_unity} "// Precompiled header unity generated by CMake\n") file(APPEND ${pch_unity} "#include <${pch_abs}>\n") endif() # this creates the precompild header set_source_files_properties(${pch_unity} PROPERTIES COMPILE_FLAGS "/Yc\"${pch_abs}\" /Fp\"${pch_bin}\"" OBJECT_OUTPUTS "${pch_bin}") # Update properties of source files to use the precompiled header. # Additionally, force the inclusion of the precompiled header at beginning of each source file. set_source_files_properties(${SRC_FILES} PROPERTIES COMPILE_FLAGS "/Yu\"${pch_abs}\" /FI\"${pch_abs}\" /Fp\"${pch_bin}\"" OBJECT_DEPENDS "${pch_bin}") # Finally, update the source file collection to contain the precompiled header translation unit set(${_SOURCE_FILES} ${pch_unity} ${pch_abs} ${${_SOURCE_FILES}} PARENT_SCOPE) source_group("Generated Files" FILES ${pch_unity}) get_filename_component(PATH_TO_PCH ${_PRECOMPILED_HEADER} DIRECTORY) if (PATH_TO_PCH) string ( REGEX REPLACE "[\\/]" "\\\\" normalized_path ${PATH_TO_PCH} ) source_group(${normalized_path} FILES ${pch_abs}) endif() endif() endfunction() #################################################################################### # Adds warnings compiler options to the target depending on the category # target Target name #################################################################################### function( set_compiler_warnings target) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") set(WARNINGS "-Werror" "-Wall") elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(WARNINGS "-Werror" "-Wall") elseif(MSVC) set(WARNINGS "/WX" "/W4") endif() target_compile_options(${target} PRIVATE ${WARNINGS}) endfunction() #################################################################################### # Adds or replace a compiler option # _OLD_OPTION The option which should be replaced # _NEW_OPTION The new option which should be added #################################################################################### function( replace_compiler_option _OLD_OPTION _NEW_OPTION) foreach(flag_var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) if(${flag_var} MATCHES ${_OLD_OPTION}) # the whitespace after_OLD_OPTION is necessary to really match only the flag and not some sub flag (/MD should match by /MDd) string(REGEX REPLACE "${_OLD_OPTION} " "${_NEW_OPTION}" ${flag_var} "${${flag_var}}") else() set(${flag_var} "${${flag_var}} ${_NEW_OPTION}") endif() set(${flag_var} ${${flag_var}} PARENT_SCOPE) endforeach() endfunction() #################################################################################### # enables or disables the user of RTTI for all following source files. # _ENABLE If true, will enable RTTI, otherwise will disable RTTI. #################################################################################### macro(enable_rtti _ENABLE) set(enable_rtti_opt "") set(disable_rtti_opt "") if (MSVC) set(enable_rtti_opt "/GR") set(disable_rtti_opt "/GR-") elseif(CMAKE_COMPILER_IS_GNUCXX ) set(enable_rtti_opt "-frtti") set(disable_rtti_opt "-fno-rtti") elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(enable_rtti_opt "-frtti") set(disable_rtti_opt "-fno-rtti") else() message(FATAL_ERROR "Don't know how to enable/disable RTTI for this compiler.") endif() if (${_ENABLE}) message(STATUS "Enabled: use of RTTI") replace_compiler_option("${disable_rtti_opt}" "${enable_rtti_opt}") else() message(STATUS "Disabled: use of RTTI") replace_compiler_option(${enable_rtti_opt} ${disable_rtti_opt}) endif() endmacro() #################################################################################### # Returns the name of the used compiler. # _COMPILER_NAME #################################################################################### function(getCompilerName _COMPILER_NAME) if(MSVC_VERSION EQUAL 1400) set(COMPILER_NAME "vs2005") elseif(MSVC_VERSION EQUAL 1500) set(COMPILER_NAME "vs2008") elseif(MSVC_VERSION EQUAL 1600) set(COMPILER_NAME "vs2010") elseif(MSVC_VERSION EQUAL 1700) set(COMPILER_NAME "vs2012") elseif(MSVC_VERSION EQUAL 1800) set(COMPILER_NAME "vs2013") elseif(MSVC_VERSION EQUAL 1900) set(COMPILER_NAME "vs2015") elseif((MSVC_VERSION EQUAL 1910 OR MSVC_VERSION GREATER 1910) AND (MSVC_VERSION EQUAL 1919 OR MSVC_VERSION LESS 1919)) set(COMPILER_NAME "vs2017") elseif(CMAKE_COMPILER_IS_GNUCXX) set(COMPILER_NAME "gcc") if(WIN32) execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "-dumpversion" OUTPUT_VARIABLE GCC_VERSION_OUTPUT) string(REGEX REPLACE "([0-9]+\\.[0-9]+).*" "\\1" GCC_VERSION "${GCC_VERSION_OUTPUT}") set(COMPILER_NAME ${COMPILER_NAME}${GCC_VERSION}) endif() elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(COMPILER_NAME "clang") else() message(WARNING "Can not retrieve compiler name!") return() endif() set(${_COMPILER_NAME} ${COMPILER_NAME} PARENT_SCOPE) endfunction() #################################################################################### # This will install the PDB files also into the "bin" folder of the installation directory # _TARGET_NAME The name of the target #################################################################################### function(install_pdb_files _TARGET_NAME) if (MSVC) install(FILES $ DESTINATION "bin" CONFIGURATIONS Debug RelWithDebInfo) endif() endfunction() #################################################################################### # Get environment variable, define it as ENV_$var and make sure backslashes are converted to forward slashes # _COMPILER_NAME #################################################################################### macro(getenv_path VAR) set(ENV_${VAR} $ENV{${VAR}}) # replace won't work if var is blank if (ENV_${VAR}) string( REGEX REPLACE "\\\\" "/" ENV_${VAR} ${ENV_${VAR}} ) endif () endmacro() macro(generateLibraryVersionVariables MAJOR MINOR PATCH PRODUCT_NAME PRODUCT_CPY_RIGHT PRODUCT_LICENSE) set(LIBRARY_VERSION_MAJOR ${MAJOR}) set(LIBRARY_VERSION_MINOR ${MINOR}) set(LIBRARY_VERSION_PATCH ${PATCH}) set(LIBRARY_VERSION ${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}.${LIBRARY_VERSION_PATCH}) set(LIBRARY_VERSION_STR "${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}.${LIBRARY_VERSION_PATCH}") math(EXPR LIBRARY_VERSION_CALC "${LIBRARY_VERSION_MAJOR}*1000 + ${LIBRARY_VERSION_MINOR}*100 + ${LIBRARY_VERSION_PATCH}") set(LIBRARY_PRODUCT_NAME ${PRODUCT_NAME}) set(LIBRARY_COPYRIGHT ${PRODUCT_CPY_RIGHT}) set(LIBRARY_LICENSE ${PRODUCT_LICENSE}) endmacro() function(get_latest_supported_cxx CXX_STANDARD) if (POLICY CMP0067) cmake_policy(SET CMP0067 NEW) endif() # we need to set CMAKE_CXX_STANDARD in order to use the flags for 'check_cxx_source_compiles' if(${CMAKE_VERSION} VERSION_LESS "3.8.0") set(CMAKE_CXX_STANDARD 14) else() set(CMAKE_CXX_STANDARD 17) endif() include(CheckCXXSourceCompiles) check_cxx_source_compiles(" #include typedef void F(); typedef void G() noexcept; std::enable_if< !std::is_same::value, int >::type i = 42; int main() { return 0; } " HAS_NO_EXCEPT_TYPE_SIGNATURE_SUPPORT) check_cxx_source_compiles(" #include struct foo { void func() const noexcept {} }; template void test_func(T) { static_assert(std::is_member_function_pointer::value, \"Failed\"); } int main() { test_func(&foo::func); return 0; } " HAS_STL_NO_EXCEPT_TYPE_SIGNATURE_SUPPORT) check_cxx_source_compiles(" constexpr int abs(int x) { if(x < 0) x = -x; return x; } int main() { } " HAS_CXX_CONSTEXPR) check_cxx_source_compiles( " #include template struct template_type_trait : std::false_type {}; template