cmake_minimum_required(VERSION 3.16...3.21) # set a default CXX standard used by the external tools like clang-tidy, cppcheck, etc. # You can later set fine-grained standards for each target using `target_compile_features` set(CMAKE_CXX_STANDARD 20) ### Add project_options # include(FetchContent) # FetchContent_Declare(_project_options URL https://github.com/cpp-best-practices/project_options/archive/refs/heads/main.zip) # FetchContent_MakeAvailable(_project_options) # include(${_project_options_SOURCE_DIR}/Index.cmake) include(../src/Index.cmake) run_vcpkg() project( myproj VERSION 0.2.0 LANGUAGES CXX C) # Initialize project_options # uncomment the options to enable them project_options( ENABLE_CACHE # ENABLE_CONAN # WARNINGS_AS_ERRORS ENABLE_CPPCHECK ENABLE_CLANG_TIDY # ENABLE_INCLUDE_WHAT_YOU_USE # ENABLE_COVERAGE # ENABLE_PCH # PCH_HEADERS ENABLE_DOXYGEN # ENABLE_INTERPROCEDURAL_OPTIMIZATION # ENABLE_USER_LINKER # ENABLE_BUILD_WITH_TIME_TRACE # ENABLE_UNITY # ENABLE_SANITIZER_ADDRESS # ENABLE_SANITIZER_LEAK # ENABLE_SANITIZER_UNDEFINED_BEHAVIOR # ENABLE_SANITIZER_THREAD # ENABLE_SANITIZER_MEMORY # CLANG_WARNINGS "-Weverything" ) # NOTE: project_options and project_warnings are defined inside project_options # Executable add_executable(main ./src/main/main.cpp) target_link_libraries(main PRIVATE project_options project_warnings) ## dependencies set(DEPENDENCIES_CONFIGURED fmt Eigen3) foreach(DEPENDENCY ${DEPENDENCIES_CONFIGURED}) find_package(${DEPENDENCY} CONFIG REQUIRED) endforeach() target_link_system_libraries( main PRIVATE fmt::fmt Eigen3::Eigen) ## tests enable_testing() add_test(NAME main COMMAND main) # Header-only library add_library(lib INTERFACE) set(INCLUDE_DIR "include") target_include_directories(lib INTERFACE "$" "$") # TODO(refactor) target_link_libraries(lib INTERFACE project_options project_warnings) target_link_system_libraries( lib INTERFACE fmt::fmt Eigen3::Eigen) # Library add_library(lib2 "./src/mylib2/lib.cpp") set(INCLUDE_DIR2 "include") target_include_directories(lib2 INTERFACE "$" "$") # TODO(refactor) target_link_libraries(lib2 INTERFACE project_options project_warnings) target_link_system_libraries( lib2 PRIVATE fmt::fmt Eigen3::Eigen) # package everything automatically package_project( # NAME # myproj # TARGETS # main # lib # project_warnings # project_options INTERFACE_DEPENDENCIES_CONFIGURED ${DEPENDENCIES_CONFIGURED} INTERFACE_INCLUDES ${INCLUDE_DIR}) # package separately (for testing) package_project( NAME myproj_header_only_lib TARGETS lib INTERFACE_DEPENDENCIES_CONFIGURED ${DEPENDENCIES_CONFIGURED} INTERFACE_INCLUDES ${INCLUDE_DIR}) package_project( NAME myproj_lib TARGETS lib2 INTERFACE_INCLUDES ${INCLUDE_DIR2}) package_project( NAME myproj_main TARGETS main)