Skip to content

Commit

Permalink
refactor: config options target
Browse files Browse the repository at this point in the history
  • Loading branch information
alandefreitas committed Aug 15, 2024
1 parent c3c65f6 commit 4c52089
Show file tree
Hide file tree
Showing 20 changed files with 2,115 additions and 1,194 deletions.
101 changes: 74 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ if (NOT DUKTAPE_FOUND)
find_package(duktape REQUIRED CONFIG)
endif()

# python
find_program(PYTHON_EXECUTABLE python3 python)
if (NOT PYTHON_EXECUTABLE)
message(FATAL_ERROR "Python is needed to configure mrdocs")
endif()

unset(CMAKE_FOLDER)

#-------------------------------------------------
Expand All @@ -136,14 +142,46 @@ configure_file(
@ONLY
)

# Config files for mrdocs-core
add_custom_target(
mrdocs-config-files
COMMAND
${PYTHON_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/util/generate-config-info.py
src/lib/Lib/ConfigOptions.json
${CMAKE_CURRENT_BINARY_DIR}
VERBATIM
DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/util/generate-config-info.py
src/lib/Lib/ConfigOptions.json
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating Config Source Files"
)


# Main library
file(
GLOB_RECURSE LIB_SOURCES CONFIGURE_DEPENDS
src/lib/*.cpp src/lib/*.hpp src/lib/*.ipp
# Public
include/*.hpp
include/*.inc
include/*.ipp
# Private
src/lib/*.cpp
src/lib/*.hpp
src/lib/*.ipp
src/lib/*.natvis
include/*.hpp include/*.inc include/*.ipp
${CMAKE_CURRENT_BINARY_DIR}/src/lib/*.hpp
# Natvis
include/*.natvis
SourceFileNames.cpp)
SourceFileNames.cpp
# Config
${CMAKE_CURRENT_BINARY_DIR}/src/lib/*.hpp
${CMAKE_CURRENT_BINARY_DIR}/src/lib/*.cpp
)
list(APPEND LIB_SOURCES
${CMAKE_CURRENT_BINARY_DIR}/include/mrdocs/Version.hpp
${MRDOCS_CONFIG_OUTPUT_FILES}
)
add_library(mrdocs-core ${LIB_SOURCES})
target_compile_features(mrdocs-core PUBLIC cxx_std_20)
target_include_directories(mrdocs-core
Expand All @@ -153,7 +191,7 @@ target_include_directories(mrdocs-core
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
PRIVATE
"${PROJECT_SOURCE_DIR}/src"
"${PROJECT_SOURCE_DIR}/include")
"${PROJECT_BINARY_DIR}/src")
target_compile_definitions(
mrdocs-core
PUBLIC
Expand All @@ -162,19 +200,20 @@ target_compile_definitions(
-DMRDOCS_TOOL
)

# Deps
# Dependencies
target_include_directories(mrdocs-core SYSTEM PUBLIC ${LLVM_INCLUDE_DIRS})
target_include_directories(mrdocs-core SYSTEM PUBLIC ${CLANG_INCLUDE_DIRS})
target_link_libraries(mrdocs-core PUBLIC fmt::fmt)
target_include_directories(mrdocs-core SYSTEM PRIVATE ${DUKTAPE_INCLUDE_DIRS})
target_link_libraries(mrdocs-core PRIVATE ${DUKTAPE_LIBRARY})
add_dependencies(mrdocs-core mrdocs-config-files)

# Clang
if (CLANG_SIMPLE_LIBS)
target_link_libraries(mrdocs-core PUBLIC LLVM clang clang-cpp)
else()
target_link_libraries(mrdocs-core
PUBLIC
PUBLIC
clangAST
clangBasic
clangFrontend
Expand Down Expand Up @@ -232,7 +271,11 @@ endif ()
#
#-------------------------------------------------

file(GLOB_RECURSE TOOL_SOURCES CONFIGURE_DEPENDS src/tool/*.cpp src/tool/*.hpp)
file(GLOB_RECURSE TOOL_SOURCES CONFIGURE_DEPENDS
src/tool/*.cpp
src/tool/*.hpp
${PROJECT_BINARY_DIR}/src/tool/*.hpp
${PROJECT_BINARY_DIR}/src/tool/*.cpp)
add_executable(mrdocs ${TOOL_SOURCES})
target_compile_definitions(mrdocs PRIVATE -DMRDOCS_TOOL)

Expand All @@ -243,6 +286,7 @@ target_include_directories(mrdocs
PRIVATE
"${PROJECT_SOURCE_DIR}/include"
"${PROJECT_SOURCE_DIR}/src"
"${PROJECT_BINARY_DIR}/src"
)

target_compile_definitions(mrdocs PRIVATE -DMRDOCS_TOOL)
Expand Down Expand Up @@ -284,11 +328,22 @@ if (MRDOCS_BUILD_TESTS)
endif ()
target_compile_definitions(mrdocs-test PRIVATE -DMRDOCS_TEST_FILES_DIR="${CMAKE_CURRENT_SOURCE_DIR}/test-files")
add_test(NAME mrdocs-unit-tests COMMAND mrdocs-test --unit=true)
add_test(NAME mrdocs-golden-tests COMMAND mrdocs-test --unit=false --action=test "${PROJECT_SOURCE_DIR}/test-files/golden-tests" --addons="${CMAKE_SOURCE_DIR}/share/mrdocs/addons")
add_test(NAME mrdocs-golden-tests
COMMAND
mrdocs-test
--unit=false
--action=test
"${PROJECT_SOURCE_DIR}/test-files/golden-tests"
--addons="${CMAKE_SOURCE_DIR}/share/mrdocs/addons")
foreach (action IN ITEMS create update)
add_custom_target(
mrdocs-${action}-test-fixtures
COMMAND mrdocs-test --unit=false --action=${action} "${PROJECT_SOURCE_DIR}/test-files/golden-tests" --addons="${CMAKE_SOURCE_DIR}/share/mrdocs/addons"
COMMAND
mrdocs-test
--unit=false
--action=${action}
"${PROJECT_SOURCE_DIR}/test-files/golden-tests"
--addons="${CMAKE_SOURCE_DIR}/share/mrdocs/addons"
DEPENDS mrdocs-test
)
endforeach ()
Expand Down Expand Up @@ -421,23 +476,15 @@ if (MRDOCS_INSTALL)
#-------------------------------------------------
# include
#-------------------------------------------------
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/mrdocs
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT development
FILES_MATCHING
PATTERN "*.[hi]pp")

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/mrdocs
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT development
FILES_MATCHING
PATTERN "*.inc")

install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/mrdocs
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT development
FILES_MATCHING
PATTERN "*.[hi]pp")
foreach(MRDOCS_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include/mrdocs ${CMAKE_CURRENT_BINARY_DIR}/include/mrdocs)
foreach(MRDOCS_FILE_PATTERN "*.hpp" "*.ipp" "*.inc")
install(DIRECTORY ${MRDOCS_INCLUDE_DIR}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT development
FILES_MATCHING
PATTERN ${MRDOCS_FILE_PATTERN})
endforeach()
endforeach()

#-------------------------------------------------
# share
Expand Down
Loading

0 comments on commit 4c52089

Please sign in to comment.