Skip to content

Commit

Permalink
Merge pull request #17 from QuTech-Delft/add_languages_to_cmake_project
Browse files Browse the repository at this point in the history
Fix CMake warnings locally and when fetching tree-gen from another project
  • Loading branch information
rturrado authored Sep 27, 2023
2 parents 6481988 + 6a1339e commit 9f54878
Showing 1 changed file with 11 additions and 9 deletions.
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

0 comments on commit 9f54878

Please sign in to comment.