From c6ea63ba95dcae116c872cedea29bfafd93f4cd9 Mon Sep 17 00:00:00 2001 From: Random <35673979+RandomErrorMessage@users.noreply.github.com> Date: Wed, 10 May 2023 18:45:51 -0700 Subject: [PATCH] made CMake relative for use as a sub-project within other CMake projects (#356) --- CMakeLists.txt | 7 ++-- common/CMakeLists.txt | 94 +++++++++++++++++++++---------------------- light/CMakeLists.txt | 32 +++++++-------- qbsp/CMakeLists.txt | 58 +++++++++++++------------- testmaps.hh.in | 2 +- tests/CMakeLists.txt | 2 +- vis/CMakeLists.txt | 4 +- 7 files changed, 99 insertions(+), 100 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 33ef9d43..aae3ba2b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/3rdparty/Catch2/extras") # Thanks to http://xit0.org/2013/04/cmake-use-git-branch-and-commit-details-in-project/ execute_process( COMMAND git describe --dirty - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE GIT_DESCRIBE OUTPUT_STRIP_TRAILING_WHITESPACE ) @@ -20,8 +20,7 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_SIMULATE_ID STREQUAL "M message(STATUS "working around exceptions not being enabled by default on clang-cl") endif() -include_directories( - "${CMAKE_SOURCE_DIR}/include") +include_directories(include) find_package (Threads) @@ -101,7 +100,7 @@ set(TEST_QUAKE2_MAP_EXPORT_DIR "" CACHE PATH "When running unit tests, export Qu # just creates testmaps.hh with absolute path to the testmaps source directory. # include it as #include configure_file(testmaps.hh.in testmaps.hh @ONLY) -include_directories(${CMAKE_BINARY_DIR}) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) add_subdirectory(3rdparty) add_subdirectory(common) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index d0857b74..7e66d13a 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -1,50 +1,50 @@ -add_library(common STATIC - ${CMAKE_SOURCE_DIR}/common/bspinfo.cc - ${CMAKE_SOURCE_DIR}/common/bspfile.cc - ${CMAKE_SOURCE_DIR}/common/bspfile_generic.cc - ${CMAKE_SOURCE_DIR}/common/bspfile_q1.cc - ${CMAKE_SOURCE_DIR}/common/bspfile_q2.cc - ${CMAKE_SOURCE_DIR}/common/bsputils.cc - ${CMAKE_SOURCE_DIR}/common/bspxfile.cc - ${CMAKE_SOURCE_DIR}/common/cmdlib.cc - ${CMAKE_SOURCE_DIR}/common/decompile.cc - ${CMAKE_SOURCE_DIR}/common/entdata.cc - ${CMAKE_SOURCE_DIR}/common/log.cc - ${CMAKE_SOURCE_DIR}/common/mathlib.cc - ${CMAKE_SOURCE_DIR}/common/parser.cc - ${CMAKE_SOURCE_DIR}/common/qvec.cc - ${CMAKE_SOURCE_DIR}/common/threads.cc - ${CMAKE_SOURCE_DIR}/common/fs.cc - ${CMAKE_SOURCE_DIR}/common/imglib.cc - ${CMAKE_SOURCE_DIR}/common/settings.cc - ${CMAKE_SOURCE_DIR}/common/prtfile.cc - ${CMAKE_SOURCE_DIR}/common/debugger.natvis - ${CMAKE_SOURCE_DIR}/include/common/aabb.hh - ${CMAKE_SOURCE_DIR}/include/common/bitflags.hh - ${CMAKE_SOURCE_DIR}/include/common/bspinfo.hh - ${CMAKE_SOURCE_DIR}/include/common/bspfile.hh - ${CMAKE_SOURCE_DIR}/include/common/bspfile_generic.hh - ${CMAKE_SOURCE_DIR}/include/common/bspfile_q1.hh - ${CMAKE_SOURCE_DIR}/include/common/bspfile_q2.hh - ${CMAKE_SOURCE_DIR}/include/common/bsputils.hh - ${CMAKE_SOURCE_DIR}/include/common/bspxfile.hh - ${CMAKE_SOURCE_DIR}/include/common/cmdlib.hh - ${CMAKE_SOURCE_DIR}/include/common/decompile.hh - ${CMAKE_SOURCE_DIR}/include/common/entdata.h - ${CMAKE_SOURCE_DIR}/include/common/iterators.hh - ${CMAKE_SOURCE_DIR}/include/common/log.hh - ${CMAKE_SOURCE_DIR}/include/common/mathlib.hh - ${CMAKE_SOURCE_DIR}/include/common/parser.hh - ${CMAKE_SOURCE_DIR}/include/common/polylib.hh - ${CMAKE_SOURCE_DIR}/include/common/qvec.hh - ${CMAKE_SOURCE_DIR}/include/common/json.hh - ${CMAKE_SOURCE_DIR}/include/common/parallel.hh - ${CMAKE_SOURCE_DIR}/include/common/threads.hh - ${CMAKE_SOURCE_DIR}/include/common/fs.hh - ${CMAKE_SOURCE_DIR}/include/common/imglib.hh - ${CMAKE_SOURCE_DIR}/include/common/settings.hh - ${CMAKE_SOURCE_DIR}/include/common/prtfile.hh - ${CMAKE_SOURCE_DIR}/include/common/vectorutils.hh +add_library(common STATIC + bspinfo.cc + bspfile.cc + bspfile_generic.cc + bspfile_q1.cc + bspfile_q2.cc + bsputils.cc + bspxfile.cc + cmdlib.cc + decompile.cc + entdata.cc + log.cc + mathlib.cc + parser.cc + qvec.cc + threads.cc + fs.cc + imglib.cc + settings.cc + prtfile.cc + debugger.natvis + ../include/common/aabb.hh + ../include/common/bitflags.hh + ../include/common/bspinfo.hh + ../include/common/bspfile.hh + ../include/common/bspfile_generic.hh + ../include/common/bspfile_q1.hh + ../include/common/bspfile_q2.hh + ../include/common/bsputils.hh + ../include/common/bspxfile.hh + ../include/common/cmdlib.hh + ../include/common/decompile.hh + ../include/common/entdata.h + ../include/common/iterators.hh + ../include/common/log.hh + ../include/common/mathlib.hh + ../include/common/parser.hh + ../include/common/polylib.hh + ../include/common/qvec.hh + ../include/common/json.hh + ../include/common/parallel.hh + ../include/common/threads.hh + ../include/common/fs.hh + ../include/common/imglib.hh + ../include/common/settings.hh + ../include/common/prtfile.hh + ../include/common/vectorutils.hh ) target_link_libraries(common ${CMAKE_THREAD_LIBS_INIT} TBB::tbb TBB::tbbmalloc fmt::fmt nlohmann_json::nlohmann_json) diff --git a/light/CMakeLists.txt b/light/CMakeLists.txt index f37fc81c..ca8209fa 100644 --- a/light/CMakeLists.txt +++ b/light/CMakeLists.txt @@ -1,13 +1,13 @@ set(LIGHT_INCLUDES - ${CMAKE_SOURCE_DIR}/include/light/entities.hh - ${CMAKE_SOURCE_DIR}/include/light/light.hh - ${CMAKE_SOURCE_DIR}/include/light/lightgrid.hh - ${CMAKE_SOURCE_DIR}/include/light/phong.hh - ${CMAKE_SOURCE_DIR}/include/light/bounce.hh - ${CMAKE_SOURCE_DIR}/include/light/surflight.hh - ${CMAKE_SOURCE_DIR}/include/light/ltface.hh - ${CMAKE_SOURCE_DIR}/include/light/trace.hh - ${CMAKE_SOURCE_DIR}/include/light/litfile.hh) + ../include/light/entities.hh + ../include/light/light.hh + ../include/light/lightgrid.hh + ../include/light/phong.hh + ../include/light/bounce.hh + ../include/light/surflight.hh + ../include/light/ltface.hh + ../include/light/trace.hh + ../include/light/litfile.hh) set(LIGHT_SOURCES entities.cc @@ -27,11 +27,11 @@ if (embree_FOUND) MESSAGE(STATUS "Embree library found: ${EMBREE_LIBRARY}") INCLUDE_DIRECTORIES(${EMBREE_INCLUDE_DIRS}) set(LIGHT_INCLUDES - ${CMAKE_SOURCE_DIR}/include/light/trace_embree.hh + ../include/light/trace_embree.hh ${LIGHT_INCLUDES}) set(LIGHT_SOURCES trace_embree.cc - ${CMAKE_SOURCE_DIR}/include/light/trace_embree.hh + ../include/light/trace_embree.hh ${LIGHT_SOURCES}) # This needs to be before the add_executable @@ -54,7 +54,7 @@ if (embree_FOUND) # causing it not to find the LICENSE.txt get_filename_component(embree_DIR_ABS "${embree_DIR}" REALPATH CACHE) - find_file(EMBREE_LICENSE LICENSE.txt + find_file(EMBREE_LICENSE LICENSE.txt "${embree_DIR_ABS}/doc" "${embree_DIR_ABS}/../../../doc" "${embree_DIR_ABS}/../embree3/embree3" # vcpkg puts it here @@ -90,12 +90,12 @@ if (embree_FOUND) COMMAND ${CMAKE_COMMAND} -E copy_if_different "${EMBREE_TBB_DLL}" "$") endif() - # so the executable will search for dylib's in the same directory as the executable + # so the executable will search for dylib's in the same directory as the executable if(APPLE) - add_custom_command(TARGET light POST_BUILD + add_custom_command(TARGET light POST_BUILD COMMAND bash ARGS -c \"install_name_tool -add_rpath @loader_path $ || true\") endif() - + install(FILES $ DESTINATION bin) # install TBB @@ -127,4 +127,4 @@ if (embree_FOUND) endif(embree_FOUND) install(TARGETS light RUNTIME DESTINATION bin) -install(FILES ${CMAKE_SOURCE_DIR}/gpl_v3.txt DESTINATION bin) +install(FILES ../gpl_v3.txt DESTINATION bin) diff --git a/qbsp/CMakeLists.txt b/qbsp/CMakeLists.txt index 34f750d5..78d52de7 100644 --- a/qbsp/CMakeLists.txt +++ b/qbsp/CMakeLists.txt @@ -1,35 +1,35 @@ set(QBSP_INCLUDES - ${CMAKE_SOURCE_DIR}/include/qbsp/qbsp.hh - ${CMAKE_SOURCE_DIR}/include/qbsp/brush.hh - ${CMAKE_SOURCE_DIR}/include/qbsp/csg.hh - ${CMAKE_SOURCE_DIR}/include/qbsp/exportobj.hh - ${CMAKE_SOURCE_DIR}/include/qbsp/map.hh - ${CMAKE_SOURCE_DIR}/include/qbsp/winding.hh - ${CMAKE_SOURCE_DIR}/include/qbsp/merge.hh - ${CMAKE_SOURCE_DIR}/include/qbsp/outside.hh - ${CMAKE_SOURCE_DIR}/include/qbsp/portals.hh - ${CMAKE_SOURCE_DIR}/include/qbsp/prtfile.hh - ${CMAKE_SOURCE_DIR}/include/qbsp/brushbsp.hh - ${CMAKE_SOURCE_DIR}/include/qbsp/faces.hh - ${CMAKE_SOURCE_DIR}/include/qbsp/tjunc.hh - ${CMAKE_SOURCE_DIR}/include/qbsp/tree.hh - ${CMAKE_SOURCE_DIR}/include/qbsp/writebsp.hh) + ../include/qbsp/qbsp.hh + ../include/qbsp/brush.hh + ../include/qbsp/csg.hh + ../include/qbsp/exportobj.hh + ../include/qbsp/map.hh + ../include/qbsp/winding.hh + ../include/qbsp/merge.hh + ../include/qbsp/outside.hh + ../include/qbsp/portals.hh + ../include/qbsp/prtfile.hh + ../include/qbsp/brushbsp.hh + ../include/qbsp/faces.hh + ../include/qbsp/tjunc.hh + ../include/qbsp/tree.hh + ../include/qbsp/writebsp.hh) set(QBSP_SOURCES - ${CMAKE_SOURCE_DIR}/qbsp/brush.cc - ${CMAKE_SOURCE_DIR}/qbsp/csg.cc - ${CMAKE_SOURCE_DIR}/qbsp/map.cc - ${CMAKE_SOURCE_DIR}/qbsp/merge.cc - ${CMAKE_SOURCE_DIR}/qbsp/outside.cc - ${CMAKE_SOURCE_DIR}/qbsp/portals.cc - ${CMAKE_SOURCE_DIR}/qbsp/prtfile.cc - ${CMAKE_SOURCE_DIR}/qbsp/qbsp.cc - ${CMAKE_SOURCE_DIR}/qbsp/brushbsp.cc - ${CMAKE_SOURCE_DIR}/qbsp/faces.cc - ${CMAKE_SOURCE_DIR}/qbsp/tjunc.cc - ${CMAKE_SOURCE_DIR}/qbsp/tree.cc - ${CMAKE_SOURCE_DIR}/qbsp/writebsp.cc - ${CMAKE_SOURCE_DIR}/qbsp/exportobj.cc + brush.cc + csg.cc + map.cc + merge.cc + outside.cc + portals.cc + prtfile.cc + qbsp.cc + brushbsp.cc + faces.cc + tjunc.cc + tree.cc + writebsp.cc + exportobj.cc ${QBSP_INCLUDES}) add_library(libqbsp STATIC ${QBSP_SOURCES}) diff --git a/testmaps.hh.in b/testmaps.hh.in index b98a9e11..e5e7486a 100644 --- a/testmaps.hh.in +++ b/testmaps.hh.in @@ -1,3 +1,3 @@ -inline const char *testmaps_dir = "@CMAKE_SOURCE_DIR@/testmaps"; +inline const char *testmaps_dir = "@CMAKE_CURRENT_SOURCE_DIR@/testmaps"; inline const char *test_quake_maps_dir = "@TEST_QUAKE_MAP_EXPORT_DIR@"; inline const char *test_quake2_maps_dir = "@TEST_QUAKE2_MAP_EXPORT_DIR@"; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 14abe48b..b85d4546 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -12,7 +12,7 @@ add_executable(tests test_qbsp_q2.cc test_vis.cc testutils.hh - ${CMAKE_BINARY_DIR}/testmaps.hh + ${CMAKE_CURRENT_BINARY_DIR}/../testmaps.hh testutils.hh benchmark.cc test_bsputil.cc) diff --git a/vis/CMakeLists.txt b/vis/CMakeLists.txt index 20525f5a..987542a0 100644 --- a/vis/CMakeLists.txt +++ b/vis/CMakeLists.txt @@ -1,6 +1,6 @@ set(VIS_INCLUDES - ${CMAKE_SOURCE_DIR}/include/vis/leafbits.hh - ${CMAKE_SOURCE_DIR}/include/vis/vis.hh) + ../include/vis/leafbits.hh + ../include/vis/vis.hh) set(VIS_SOURCES flow.cc