Skip to content

Add MANGROVE_ROOT_DIR & MANGROVE_ROOT_BINARY_DIR variable in CMake #47

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

Open
wants to merge 1 commit 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
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ set(CMAKE_CXX_EXTENSIONS OFF)
include(GenerateExportHeader)
include(InstallRequiredSystemLibraries)

set(MANGROVE_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
file(RELATIVE_PATH MANGROVE_ROOT_BINARY_DIR ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
set(MANGROVE_ROOT_BINARY_DIR ${CMAKE_BINARY_DIR}/${MANGROVE_ROOT_BINARY_DIR})

# If the user did not customize the install prefix,
# set it to live under build so we don't inadverently pollute /usr/local
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set (CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "default install path" FORCE)
set (CMAKE_INSTALL_PREFIX "${MANGROVE_ROOT_BINARY_DIR}/install" CACHE PATH "default install path" FORCE)
endif()

if(NOT CMAKE_BUILD_TYPE)
Expand All @@ -71,12 +75,12 @@ endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

add_custom_target(format
python ${CMAKE_SOURCE_DIR}/etc/clang_format.py format
python ${MANGROVE_ROOT_DIR}/etc/clang_format.py format
VERBATIM
)

add_custom_target(format-lint
python ${CMAKE_SOURCE_DIR}/etc/clang_format.py lint
python ${MANGROVE_ROOT_DIR}/etc/clang_format.py lint
VERBATIM
)

Expand Down
4 changes: 2 additions & 2 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ add_custom_target(run-examples DEPENDS examples)

# Run all boson examples on `make run-examples`.
foreach(EXAMPLE ${BOSON_EXAMPLE_EXECUTABLES})
get_filename_component(EXAMPLE_EXECUTABLE "${CMAKE_BINARY_DIR}/examples/boson/${EXAMPLE}" ABSOLUTE)
get_filename_component(EXAMPLE_EXECUTABLE "${MANGROVE_ROOT_BINARY_DIR}/examples/boson/${EXAMPLE}" ABSOLUTE)
add_custom_command(TARGET run-examples POST_BUILD COMMAND ${EXAMPLE_EXECUTABLE})
endforeach(EXAMPLE)

# Run all mangrove examples on `make run-examples`.
foreach(EXAMPLE ${MANGROVE_EXAMPLE_EXECUTABLES})
get_filename_component(EXAMPLE_EXECUTABLE "${CMAKE_BINARY_DIR}/examples/mangrove/${EXAMPLE}" ABSOLUTE)
get_filename_component(EXAMPLE_EXECUTABLE "${MANGROVE_ROOT_BINARY_DIR}/examples/mangrove/${EXAMPLE}" ABSOLUTE)
add_custom_command(TARGET run-examples POST_BUILD COMMAND ${EXAMPLE_EXECUTABLE})
endforeach(EXAMPLE)
2 changes: 1 addition & 1 deletion src/boson/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

include_directories(
${CMAKE_SOURCE_DIR}/src/third_party/catch/include
${MANGROVE_ROOT_DIR}/src/third_party/catch/include
)

add_executable(test_boson
Expand Down
8 changes: 4 additions & 4 deletions src/mangrove/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ add_subdirectory(config)

# auto-generate MANGROVE_CHILD macros for accessing nested fields in the query builder.
message(STATUS "Generating MANGROVE_CHILD preprocessor macros...")
execute_process(COMMAND ${CMAKE_SOURCE_DIR}/buildscripts/generate_macros.py ${CMAKE_SOURCE_DIR}/src/mangrove/mangrove_child_autogen.hpp)
execute_process(COMMAND ${MANGROVE_ROOT_DIR}/buildscripts/generate_macros.py ${MANGROVE_ROOT_DIR}/src/mangrove/mangrove_child_autogen.hpp)

set(mangrove_sources
"model.cpp"
Expand All @@ -58,9 +58,9 @@ include_directories(
${LIBMONGOCXX_INCLUDE_DIRS}
${LIBBSON_INCLUDE_DIRS}
${LIBMONGOC_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/src
${CMAKE_BINARY_DIR}/src
${CMAKE_SOURCE_DIR}/src/third_party/cereal/include
${MANGROVE_ROOT_DIR}/src
${MANGROVE_ROOT_BINARY_DIR}/src
${MANGROVE_ROOT_DIR}/src/third_party/cereal/include
)

link_directories(
Expand Down
2 changes: 1 addition & 1 deletion src/mangrove/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

include_directories(
${CMAKE_SOURCE_DIR}/src/third_party/catch/include
${MANGROVE_ROOT_DIR}/src/third_party/catch/include
)

add_executable(test_mangrove
Expand Down