cmake_minimum_required(VERSION 3.15)#setthe project name and versionproject(Tutorial VERSION 1.0)#specifythe C++ standardadd_library(tutorial_compiler_flags INTERFACE)target_compile_features(tutorial_compiler_flags INTERFACE cxx_std_11)#addcompiler warning flags just when building this project via#theBUILD_INTERFACE genexset(gcc_like_cxx "$<COMPILE_LANG_AND_ID:CXX,ARMClang,AppleClang,Clang,GNU,LCC>")set(msvc_cxx "$<COMPILE_LANG_AND_ID:CXX,MSVC>")target_compile_options(tutorial_compiler_flags INTERFACE"$<${gcc_like_cxx}:$<BUILD_INTERFACE:-Wall;-Wextra;-Wshadow;-Wformat=2;-Wunused>>""$<${msvc_cxx}:$<BUILD_INTERFACE:-W3>>")#configurea header file to pass some of the CMake settings#tothe source codeconfigure_file(TutorialConfig.h.in TutorialConfig.h)#addthe MathFunctions libraryadd_subdirectory(MathFunctions)#addthe executableadd_executable(Tutorial tutorial.cxx)target_link_libraries(Tutorial PUBLIC MathFunctions tutorial_compiler_flags)#addthe binary tree to the search path for include files#sothat we will find TutorialConfig.htarget_include_directories(Tutorial PUBLIC"${PROJECT_BINARY_DIR}")#addthe install targetsinstall(TARGETS Tutorial DESTINATION bin)install(FILES "${PROJECT_BINARY_DIR}/TutorialConfig.h"DESTINATION include)#enabletestinginclude(CTest)#doesthe application runadd_test(NAME Runs COMMAND Tutorial 25)#doesthe usage message work?add_test(NAME Usage COMMAND Tutorial)set_tests_properties(UsagePROPERTIES PASS_REGULAR_EXPRESSION "Usage:.*number")#defineafunction to simplify adding testsfunction(do_test target arg result)add_test(NAME Comp${arg} COMMAND ${target} ${arg})set_tests_properties(Comp${arg}PROPERTIES PASS_REGULAR_EXPRESSION ${result})endfunction()target_include_directories(Tutorial PUBLIC"${PROJECT_BINARY_DIR}")#addthe install targetsinstall(TARGETS Tutorial DESTINATION bin)install(FILES "${PROJECT_BINARY_DIR}/TutorialConfig.h"DESTINATION include)#enabletestinginclude(CTest)#doesthe application runadd_test(NAME Runs COMMAND Tutorial 25)#doesthe usage message work?add_test(NAME Usage COMMAND Tutorial)set_tests_properties(UsagePROPERTIES PASS_REGULAR_EXPRESSION "Usage:.*number")#defineafunction to simplify adding testsfunction(do_test target arg result)add_test(NAME Comp${arg} COMMAND ${target} ${arg})set_tests_properties(Comp${arg}PROPERTIES PASS_REGULAR_EXPRESSION ${result})endfunction()
MathFunctions/CMakeLists.txt
add_library(MathFunctions MathFunctions.cxx)#statethat anybody linking to us needs to include the current source dir#tofind MathFunctions.h,while we don't.target_include_directories(MathFunctionsINTERFACE ${CMAKE_CURRENT_SOURCE_DIR})#shouldwe use our own math functionsoption(USE_MYMATH "Use tutorial provided math implementation" ON)if(USE_MYMATH)target_compile_definitions(MathFunctions PRIVATE "USE_MYMATH")#librarythat just does sqrtadd_library(SqrtLibrary STATICmysqrt.cxx)#linkSqrtLibrary to tutorial_compiler_flagstarget_link_libraries(SqrtLibrary PUBLIC tutorial_compiler_flags)#TODO 1: Include CheckCXXSourceCompilesinclude(CheckCXXSourceCompiles)#TODO 2: Use check_cxx_source_compiles with simple C++ code to verify#availabilityof:# * std::log# * std::exp#Store the results in HAVE_LOG and HAVE_EXP respectively.#Hint: Sample C++ code which uses log:# #include <cmath>#intmain(){#std::log(1.0);#return0;# }check_cxx_source_compiles("#include<cmath>intmain(){std::log(1.0);return0;}" HAVE_LOG)check_cxx_source_compiles("#include<cmath>intmain(){std::exp(1.0);return0;}" HAVE_EXP)#TODO 3: Conditionally on HAVE_LOG and HAVE_EXP, add private compile#definitions"HAVE_LOG"and "HAVE_EXP"to the SqrtLibrary target.#Hint: Use target_compile_definitions()if( HAVE_LOG AND HAVE_EXP )target_compile_definitions(SqrtLibrary PRIVATE "HAVE_LOG""HAVE_EXP")else()if( NOT HAVE_LOG )message( WARNING "DONT HAVE LOG FUNC")endif()if( NOT HAVE_EXP )message( WARNING "DONT HAVE EXP FUNC")endif()endif()target_link_libraries(MathFunctions PRIVATE SqrtLibrary)endif()#linkMathFunctions to tutorial_compiler_flagstarget_link_libraries(MathFunctions PUBLIC tutorial_compiler_flags)#installlibsset(installable_libs MathFunctions tutorial_compiler_flags)if(TARGET SqrtLibrary)list(APPEND installable_libs SqrtLibrary)endif()install(TARGETS ${installable_libs} DESTINATION lib)#installinclude headersinstall(FILES MathFunctions.h DESTINATION include)
Alex教程每一P的教程原代码加上我自己的理解初步理解写的注释,可供学习Alex教程的人参考 此代码仅为较上一P有所改变的代码
【Unity教程】从0编程制作类银河恶魔城游戏_哔哩哔哩_bilibili
PlayerStat
using System.Collections;
using System.Collections.Generi…