diff --git a/CMakeLists.txt b/CMakeLists.txt index 310bbda..9f9e212 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,16 +36,22 @@ option(ENABLE_SHM_OUTPUT "Build shared-memory output support (requires ImageStre cmake_minimum_required(VERSION 3.12) -find_program(GXX_COMPILER NAMES g++) - -if(GXX_COMPILER) - message(STATUS "Found g++: ${GXX_COMPILER}") - set(CMAKE_CXX_COMPILER ${GXX_COMPILER}) -else() - message(FATAL_ERROR "g++ compiler not found. Please install g++ and try again.") +# Choosing the compiler belongs to whoever owns the build. A parent project has +# already detected a compiler by the time it descends into this file, and +# overriding that here would cause CMake to discard its cache and reconfigure, +# losing the command line, -DCONTROLLER included +if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + find_program(GXX_COMPILER NAMES g++) + + if(GXX_COMPILER) + message(STATUS "Found g++: ${GXX_COMPILER}") + set(CMAKE_CXX_COMPILER ${GXX_COMPILER}) + else() + message(FATAL_ERROR "g++ compiler not found. Please install g++ and try again.") + endif() endif() -project(camera) +project(camerad) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -54,8 +60,9 @@ set(CMAKE_CXX_EXTENSIONS OFF) set(PROJECT_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) # A wheel build has nowhere to put a source-tree bin/, so let CMake keep its -# outputs in the build directory -if (NOT SKBUILD) +# outputs in the build directory. A project that add_subdirectory()s this one +# has nowhere to put them either, and its source tree is not ours to write into +if (NOT SKBUILD AND CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BASE_DIR}/bin) set(LIBRARY_OUTPUT_PATH ${PROJECT_BASE_DIR}/lib) endif() diff --git a/camerad/CMakeLists.txt b/camerad/CMakeLists.txt index 681f56f..903c041 100644 --- a/camerad/CMakeLists.txt +++ b/camerad/CMakeLists.txt @@ -127,16 +127,32 @@ list (FILTER INSTRUMENT_SOURCES EXCLUDE REGEX "_interface_factory\\.cpp$") # ---------------------------------------------------------------------------- # Camera Interface Base +# +# Controller-agnostic. Carries its own include directories and link interface +# rather than relying on the directory-scoped include_directories above, which +# a project consuming this one does not inherit # ---------------------------------------------------------------------------- -list (APPEND INTERFACE_SOURCES +add_library(camerad_base ${CAMERAD_DIR}/camera_interface.cpp ${CAMERAD_DIR}/image_process.cpp ) -add_library(${INTERFACE_TARGET} ${INTERFACE_SOURCES}) -target_link_libraries(${INTERFACE_TARGET} +target_include_directories(camerad_base PUBLIC + ${CAMERAD_DIR} + ${PROJECT_BASE_DIR}/common + ${PROJECT_BASE_DIR}/utils + ) +target_link_libraries(camerad_base PUBLIC common + logentry frame_output_factory ) + +# ---------------------------------------------------------------------------- +# controller implementation, linking the base PUBLIC so that anything +# depending on the controller gets the base transitively +# ---------------------------------------------------------------------------- +add_library(${INTERFACE_TARGET} ${INTERFACE_SOURCES}) +target_link_libraries(${INTERFACE_TARGET} PUBLIC camerad_base) target_include_directories(${INTERFACE_TARGET} PUBLIC ${INTERFACE_INCLUDES}) # ---------------------------------------------------------------------------- diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 0cd69a2..51c75a0 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -16,4 +16,4 @@ include_directories(${PROJECT_BASE_DIR}/utils) # needed for logentry add_library(common STATIC ${PROJECT_UTILS_DIR}/common.cpp ) -target_link_libraries(common nlohmann_json::nlohmann_json) +target_link_libraries(common nlohmann_json::nlohmann_json logentry) diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index 9c92167..21b544d 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -46,6 +46,7 @@ find_library(FITSWRITER_CCFITS_LIB CCfits NAMES libCCfits PATHS /usr/local/lib / find_library(FITSWRITER_CFITS_LIB cfitsio NAMES libcfitsio PATHS /usr/local/lib /opt/homebrew/lib) target_link_libraries(fits_writer nlohmann_json::nlohmann_json + utilities ${FITSWRITER_CCFITS_LIB} ${FITSWRITER_CFITS_LIB} )