Skip to content

Commit

Permalink
make install with packaging (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
agladilin authored Jan 3, 2025
1 parent b0a154d commit e40c5c0
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 13 deletions.
23 changes: 22 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
63 changes: 61 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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\"")
Expand Down Expand Up @@ -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 <export_config_name>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 '<export_config_name>Targets.cmake' for a build tree
export(
EXPORT ${PROJECT_NAME}Targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/${export_config_name}Targets.cmake"
)

# Configure '<export_config_name>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 '<export_config_name>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}"
)
7 changes: 5 additions & 2 deletions cppast/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ add_library(cppast STATIC
src/cppast.cpp
)
target_include_directories(cppast
PUBLIC
include
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CPPPARSER_INSTALL_INCLUDE_DIR}>
)
set_target_properties(cppast PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}")

add_subdirectory(test)

install(DIRECTORY "include/cppast" DESTINATION "include")
18 changes: 13 additions & 5 deletions cppparser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ 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
cppast
)
target_include_directories(cppparser_lex_and_yacc
PUBLIC
include
src
../../common/third_party/boost_tp
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
../../common/third_party/boost_tp
src/win_hack
)
target_compile_definitions(cppparser_lex_and_yacc
Expand All @@ -86,4 +86,12 @@ target_link_libraries(cppparser
cppparser_lex_and_yacc
)

target_include_directories(cppparser
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

set_target_properties(cppparser PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}")

install(DIRECTORY "include/cppparser" DESTINATION "include" COMPONENT Development)
2 changes: 1 addition & 1 deletion cppparser/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions cppparserConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -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})
7 changes: 5 additions & 2 deletions cppwriter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ set(CPP_WRITER_SOURCES
add_library(cppwriter STATIC ${CPP_WRITER_SOURCES})

target_include_directories(cppwriter
PUBLIC
include
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(cppwriter
PUBLIC
cppast
)
set_target_properties(cppwriter PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}")

install(DIRECTORY "include/cppwriter" DESTINATION "include")

0 comments on commit e40c5c0

Please sign in to comment.