Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CMake warnings locally and when fetching tree-gen from another project #17

Merged
merged 2 commits into from
Sep 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ if(POLICY CMP0048)
cmake_policy(SET CMP0048 NEW)
endif()

project(tree-gen CXX)
project(tree-gen LANGUAGES CXX)

# If tree-gen was already included elsewhere in the project, don't include it
# again. There should be only one place for it and one version per project.
Expand Down Expand Up @@ -109,26 +109,19 @@ endif()
#=============================================================================#

# Create the library.
set(
TREE_LIB_SRCS
"${CMAKE_CURRENT_SOURCE_DIR}/src/tree-all.cpp"
)
set(TREE_LIB_SRCS ${TREE_LIB_SRCS} PARENT_SCOPE)
set(TREE_LIB_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/src/tree-all.cpp")
add_library(tree-lib-obj OBJECT ${TREE_LIB_SRCS})
set_property(TARGET tree-lib-obj PROPERTY POSITION_INDEPENDENT_CODE ON)

# tree-lib has a global, which (thanks to MSVC declspec nonsense) requires a
# header file to be different when the library is compiled compared to when it
# is used.
set(TREE_LIB_PRIVATE_DEFS BUILDING_TREE_LIB)
set(TREE_LIB_PRIVATE_DEFS ${TREE_LIB_PRIVATE_DEFS} PARENT_SCOPE)
target_compile_definitions(tree-lib-obj PRIVATE ${TREE_LIB_PRIVATE_DEFS})

# Add the appropriate include paths.
set(TREE_LIB_PRIVATE_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/src/")
set(TREE_LIB_PRIVATE_INCLUDE ${TREE_LIB_PRIVATE_INCLUDE} PARENT_SCOPE)
set(TREE_LIB_PUBLIC_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/include/")
set(TREE_LIB_PUBLIC_INCLUDE ${TREE_LIB_PUBLIC_INCLUDE} PARENT_SCOPE)
target_include_directories(
tree-lib-obj
PRIVATE ${TREE_LIB_PRIVATE_INCLUDE}
Expand All @@ -138,6 +131,15 @@ target_link_libraries(tree-lib-obj
PRIVATE fmt::fmt
)

# Set variables at possible parent projects.
get_directory_property(hasParent PARENT_DIRECTORY)
if(hasParent)
set(TREE_LIB_SRCS ${TREE_LIB_SRCS} PARENT_SCOPE)
set(TREE_LIB_PRIVATE_DEFS ${TREE_LIB_PRIVATE_DEFS} PARENT_SCOPE)
set(TREE_LIB_PRIVATE_INCLUDE ${TREE_LIB_PRIVATE_INCLUDE} PARENT_SCOPE)
set(TREE_LIB_PUBLIC_INCLUDE ${TREE_LIB_PUBLIC_INCLUDE} PARENT_SCOPE)
endif()

# Main tree-gen library in shared or static form as managed by cmake's
# internal BUILD_SHARED_LIBS variable.
add_library(tree-lib $<TARGET_OBJECTS:tree-lib-obj>)
Expand Down