diff --git a/.vscode/settings.json b/.vscode/settings.json index 5b5a5307..a3ef096d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -85,7 +85,28 @@ "__verbose_abort": "cpp", "__threading_support": "cpp", "ios": "cpp", - "locale": "cpp" + "locale": "cpp", + "charconv": "cpp", + "format": "cpp", + "queue": "cpp", + "stack": "cpp", + "stop_token": "cpp", + "xfacet": "cpp", + "xhash": "cpp", + "xiosbase": "cpp", + "xlocale": "cpp", + "xlocbuf": "cpp", + "xlocinfo": "cpp", + "xlocmes": "cpp", + "xlocmon": "cpp", + "xlocnum": "cpp", + "xloctime": "cpp", + "xmemory": "cpp", + "xstddef": "cpp", + "xstring": "cpp", + "xtr1common": "cpp", + "xtree": "cpp", + "xutility": "cpp" }, "git.ignoreLimitWarning": true, "sonarlint.pathToCompileCommands": "${workspaceFolder}/build/compile_commands.json" diff --git a/CMakeLists.txt b/CMakeLists.txt index c2d2ebb7..0275ab61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,13 @@ -cmake_minimum_required(VERSION 3.4) +cmake_minimum_required(VERSION 3.4...3.28) enable_testing() -project(cppparser) +project(cppparser VERSION 1.0.0) set(CMAKE_CXX_STANDARD 17) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}) set(CLANG_TIDY_COMMAND "clang-tidy" "--config-file=${CMAKE_CURRENT_SOURCE_DIR}/.clang-tidy") +set(export_config_name ${PROJECT_NAME}) if(MSVC) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd\"4996\"") @@ -36,3 +37,61 @@ if(NOT ${MARKDOWN_PP} MATCHES "MARKDOWN_PP-NOTFOUND") else() message("Markdown-pp NOT FOUND: README cannot be updated.") endif() + +install( + TARGETS cppast cppparser_lex_and_yacc cppparser cppwriter + EXPORT ${export_config_name}Targets + ARCHIVE DESTINATION "lib" COMPONENT Development + LIBRARY DESTINATION "lib" COMPONENT RuntimeLibraries + LIBRARY DESTINATION "bin" COMPONENT RuntimeLibraries +) + +if(NOT DEFINED CPPPARSER_INSTALL_CONFIG_DIR) + set(CPPPARSER_INSTALL_CONFIG_DIR lib/cmake/${export_config_name}) +endif() + +#------------------------------------------------------------------------------ +# Configure ConfigVersion.cmake common to build and install tree +include(CMakePackageConfigHelpers) +set(config_version_file ${PROJECT_BINARY_DIR}/${export_config_name}ConfigVersion.cmake) +write_basic_package_version_file( + ${config_version_file} + VERSION "${CPPPARSER_VERSION}" + COMPATIBILITY ExactVersion +) + +#------------------------------------------------------------------------------ +# Export 'Targets.cmake' for a build tree +export( + EXPORT ${PROJECT_NAME}Targets + FILE "${CMAKE_CURRENT_BINARY_DIR}/${export_config_name}Targets.cmake" +) + +# Configure 'Config.cmake' for a build tree +set(build_config ${CMAKE_BINARY_DIR}/${export_config_name}Config.cmake) +configure_package_config_file( + ${export_config_name}Config.cmake.in + ${build_config} + INSTALL_DESTINATION "${PROJECT_BINARY_DIR}" +) + +#------------------------------------------------------------------------------ +# Export 'Targets.cmake' for an install tree +install( + EXPORT ${export_config_name}Targets + FILE ${export_config_name}Targets.cmake + DESTINATION ${CPPPARSER_INSTALL_CONFIG_DIR} +) + +set(install_config ${PROJECT_BINARY_DIR}/CMakeFiles/${export_config_name}Config.cmake) +configure_package_config_file( + ${export_config_name}Config.cmake.in + ${install_config} + INSTALL_DESTINATION ${CPPPARSER_INSTALL_CONFIG_DIR} +) + +# Install config files +install( + FILES ${config_version_file} ${install_config} + DESTINATION "${CPPPARSER_INSTALL_CONFIG_DIR}" +) diff --git a/cppast/CMakeLists.txt b/cppast/CMakeLists.txt index 8fcc1d90..d631d246 100644 --- a/cppast/CMakeLists.txt +++ b/cppast/CMakeLists.txt @@ -14,9 +14,12 @@ add_library(cppast STATIC src/cppast.cpp ) target_include_directories(cppast - PUBLIC - include + PUBLIC + $ + $ ) set_target_properties(cppast PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}") add_subdirectory(test) + +install(DIRECTORY "include/cppast" DESTINATION "include") diff --git a/cppparser/CMakeLists.txt b/cppparser/CMakeLists.txt index d544bf89..052860d2 100644 --- a/cppparser/CMakeLists.txt +++ b/cppparser/CMakeLists.txt @@ -51,8 +51,8 @@ add_custom_command( add_library(cppparser_lex_and_yacc OBJECT src/parser.l src/parser.y - src/parser.lex.cpp - src/parser.tab.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/parser.lex.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/parser.tab.cpp ) target_link_libraries(cppparser_lex_and_yacc PUBLIC @@ -60,10 +60,10 @@ target_link_libraries(cppparser_lex_and_yacc ) target_include_directories(cppparser_lex_and_yacc PUBLIC - include - src - ../../common/third_party/boost_tp + $ + $ PRIVATE + ../../common/third_party/boost_tp src/win_hack ) target_compile_definitions(cppparser_lex_and_yacc @@ -86,4 +86,12 @@ target_link_libraries(cppparser cppparser_lex_and_yacc ) +target_include_directories(cppparser + PUBLIC + $ + $ +) + set_target_properties(cppparser PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}") + +install(DIRECTORY "include/cppparser" DESTINATION "include" COMPONENT Development) diff --git a/cppparser/test/CMakeLists.txt b/cppparser/test/CMakeLists.txt index 301daf84..c90076b6 100644 --- a/cppparser/test/CMakeLists.txt +++ b/cppparser/test/CMakeLists.txt @@ -5,7 +5,7 @@ endif() add_definitions(-DBOOST_AUTO_LINK_NOMANGLE) -include_directories(../../../common/third_party) +include_directories(../../../common/third_party ../src) add_executable(cppparsertest app/cppparsertest.cpp diff --git a/cppparserConfig.cmake.in b/cppparserConfig.cmake.in new file mode 100644 index 00000000..fd867b29 --- /dev/null +++ b/cppparserConfig.cmake.in @@ -0,0 +1,7 @@ +@PACKAGE_INIT@ + +set(export_config_name "@export_config_name@") + +set_and_check(${export_config_name}_TARGETS "${CMAKE_CURRENT_LIST_DIR}/${export_config_name}Targets.cmake") + +include(${${export_config_name}_TARGETS}) \ No newline at end of file diff --git a/cppwriter/CMakeLists.txt b/cppwriter/CMakeLists.txt index 61ea393f..88a817bf 100644 --- a/cppwriter/CMakeLists.txt +++ b/cppwriter/CMakeLists.txt @@ -5,11 +5,14 @@ set(CPP_WRITER_SOURCES add_library(cppwriter STATIC ${CPP_WRITER_SOURCES}) target_include_directories(cppwriter - PUBLIC - include + PUBLIC + $ + $ ) target_link_libraries(cppwriter PUBLIC cppast ) set_target_properties(cppwriter PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}") + +install(DIRECTORY "include/cppwriter" DESTINATION "include")