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

CMake: prevent leaking of CXX_STANDARD and allow linking as regular library from add_subdirectory #241

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
30 changes: 22 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@ if (DEFINED ENV{OMPI_CXX} OR DEFINED ENV{MPICH_CXX})
endif()
endif()

# set CXX standard
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_STANDARD 11)
if (${COMPILER_IS_NVCC})
# GNU CXX extensions are not supported by nvcc
set(CMAKE_CXX_EXTENSIONS OFF)
endif()

###############################################################################
# COMPILER FLAGS
###############################################################################
Expand All @@ -71,6 +63,16 @@ endif()
add_library(backward_object OBJECT backward.cpp)
target_compile_definitions(backward_object PRIVATE ${BACKWARD_DEFINITIONS})
target_include_directories(backward_object PRIVATE ${BACKWARD_INCLUDE_DIRS})
if(BACKWARD_HAS_EXTERNAL_LIBRARIES)
target_link_libraries(backward_object PUBLIC ${BACKWARD_LIBRARIES})
endif()
# set CXX standard
set_property(TARGET backward_object PROPERTY CXX_STANDARD_REQUIRED True)
set_property(TARGET backward_object PROPERTY CXX_STANDARD 11)
if (${COMPILER_IS_NVCC})
# GNU CXX extensions are not supported by nvcc
set_property(TARGET backward_object PROPERTY CXX_EXTENSIONS OFF)
endif()
set(BACKWARD_ENABLE $<TARGET_OBJECTS:backward_object> CACHE STRING
"Link with this object to setup backward automatically")

Expand All @@ -86,6 +88,18 @@ endif()
add_library(backward ${libtype} backward.cpp)
target_compile_definitions(backward PUBLIC ${BACKWARD_DEFINITIONS})
target_include_directories(backward PUBLIC ${BACKWARD_INCLUDE_DIRS})
if(BACKWARD_HAS_EXTERNAL_LIBRARIES)
target_link_libraries(backward PUBLIC ${BACKWARD_LIBRARIES})
endif()
# set CXX standard
set_property(TARGET backward PROPERTY CXX_STANDARD_REQUIRED True)
set_property(TARGET backward PROPERTY CXX_STANDARD 11)
if (${COMPILER_IS_NVCC})
# GNU CXX extensions are not supported by nvcc
set_property(TARGET backward PROPERTY CXX_EXTENSIONS OFF)
endif()

add_library(Backward::Backward ALIAS backward)

###############################################################################
# TESTS
Expand Down
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,9 @@ In this case you have a subdirectory containing the whole repository of Backward
```
add_subdirectory(/path/to/backward-cpp)

# This will add backward.cpp to your target
add_executable(mytarget mysource.cpp ${BACKWARD_ENABLE})

# This will add libraries, definitions and include directories needed by backward
# by setting each property on the target.
add_backward(mytarget)
# through an ALIAS target.
target_link_libraries(mytarget PUBLIC Backward::Backward)
```

#### Modifying CMAKE_MODULE_PATH
Expand Down