diff --git a/CMakeLists.txt b/CMakeLists.txt index 9bc6f933..be621261 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,17 +2,35 @@ # CMakeLists.txt # top-level CMake input file # ---------------------------------------------------------------------------- +cmake_minimum_required(VERSION 3.15) +project(camera C CXX) + # ---------------------------------------------------------------------------- # user must define the interface type here # valid types are: "AstroCam" | "Archon" # ---------------------------------------------------------------------------- +set(INTERFACE_TYPE "Archon" CACHE STRING "Type of instrument interface to build for") +set_property(CACHE INTERFACE_TYPE PROPERTY STRINGS Archon AstroCam) + +#for some reason all libraries are built static by default +#I'm not sure if this is for technical reasons or just preferred +#Anyway, give the option but set it to static by default +option(BUILD_SHARED_LIBS "build shared libraries instead of static" OFF) + + +#the build system of camerad previously outputted binaries to the source folder +# leave this by default for compatibility but allow an option to put the binaries in the usual place +# (the build folder) +option(OUTPUT_TO_SRC_DIR "output binaries and libraries to source folder rather than build folder" ON) -# Interface type can be set via command line ( Archon | AstroCam ) -IF (NOT DEFINED INTERFACE_TYPE) - set(INTERFACE_TYPE "Archon") -endif () + + +if(NOT CMAKE_BUILD_TYPE) + message(STATUS "no build type specified defaulting to RelWithDebInfo") + set(CMAKE_BUILD_TYPE RelWithDebInfo) +endif() # Instrument can be set via command line generic is the default value IF (NOT DEFINED INSTR) @@ -28,39 +46,54 @@ endif () # un-comment the following to log verbose debug messages #add_definitions(-DLOGLEVEL_DEBUG) -cmake_minimum_required(VERSION 3.12) +#setting these standard variables will (since CMake 3.1) +#setup the proper -std=c++17 etc flags, no need to do it manually +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) -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.") +if(OUTPUT_TO_SRC_DIR) + #this is the "legacy" behaviour + #if this option is not set, binaries will output in their default place in the CMake build output folder + set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin) + set(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/lib) +endif() + +if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + include_directories(/usr/local/include) endif() -project(camera) +find_package(Threads) -set(CMAKE_GXX_STANDARD 17) -set(CMAKE_GXX_STANDARD_REQUIRED ON) -set(CMAKE_GXX_EXTENSIONS OFF) -# Run "cmake .." from the project's build/ directory! -# -set(PROJECT_BASE_DIR $ENV{PWD}/../) +#both emulator and camerad actually depend on cfitsio and CCfits (one only by header) +#so we need to do those finds here, not in camerad/CMakeLists. -set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BASE_DIR}/bin) -set(LIBRARY_OUTPUT_PATH ${PROJECT_BASE_DIR}/lib) +#NOTE (by danw): strictly, the archon interface requires linking to cfitsio because +#CCfits is included by archon.h. I'm not sure this is intentional. +#Anyway, to reflect that I moved the public linkage of these packages down to the interface +#target rather than camerad. +#cfitsio has provided a cmake config file for quite a long time +#on some systems where include files are not in the default place, this will still find them +#if it fails, we fall back to camerad previous behaviour, manually finding the library file ONLY +#(and not bothering about includes if they're not in the right place) + + +#for cfitsio and CCfits we now provide our own find module +#this allows for systems with non-standard paths to +#replace that find module without hacking our build system (e.g. fedora, suse, etc) + +list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") +find_package(cfitsio REQUIRED) +find_package(CCfits REQUIRED) -if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - include_directories(/usr/local/include) -endif() -find_package(Threads) -add_subdirectory(${PROJECT_BASE_DIR}/utils) -add_subdirectory(${PROJECT_BASE_DIR}/common) -add_subdirectory(${PROJECT_BASE_DIR}/camerad) -add_subdirectory(${PROJECT_BASE_DIR}/emulator) -add_subdirectory(${PROJECT_BASE_DIR}/tests EXCLUDE_FROM_ALL) +#no need for absolute paths here, they are by default relative to ${CMAKE_CURRENT_LIST_DIR} +add_subdirectory(utils) +add_subdirectory(common) +add_subdirectory(camerad) +add_subdirectory(emulator) +add_subdirectory(tests EXCLUDE_FROM_ALL) diff --git a/camerad/CMakeLists.txt b/camerad/CMakeLists.txt index cbd40e25..80824f62 100644 --- a/camerad/CMakeLists.txt +++ b/camerad/CMakeLists.txt @@ -4,11 +4,9 @@ cmake_minimum_required(VERSION 3.12) -set(CAMERA_DIR ${PROJECT_BASE_DIR}/camerad) +include_directories(${CMAKE_SOURCE_DIR}/utils) +include_directories(${CMAKE_SOURCE_DIR}/common) -include_directories(${PROJECT_BASE_DIR}/utils) -include_directories(${PROJECT_BASE_DIR}/common) -link_directories(${PROJECT_BASE_DIR}/lib) # ---------------------------------------------------------------------------- # Setup for appropriate hardware interface... @@ -20,6 +18,8 @@ link_directories(${PROJECT_BASE_DIR}/lib) # interface target for interfacing to appropriate hardware # ---------------------------------------------------------------------------- + + # ---------------------------------------------------------------------------- # AstroCam ARC-64/66 PCI/e interfaces # ---------------------------------------------------------------------------- @@ -58,21 +58,18 @@ if (${INTERFACE_TYPE} STREQUAL "AstroCam") find_library(CARC_DEVICE "CArcDevice3.6" NAMES "libCArcDevice3.6.so" PATHS ${ARCAPI_DIR}/Release) find_library(CARC_FITS "CArcFitsFile3.6" NAMES "libCArcFitsFile3.6.so" PATHS ${ARCAPI_DIR}/Release) + add_library(interface STATIC ${INTERFACE_SOURCE}) + + # ---------------------------------------------------------------------------- # STA Archon interfaces # ---------------------------------------------------------------------------- elseif (${INTERFACE_TYPE} STREQUAL "Archon") message(STATUS "compiling for STA Archon") - set(INTERFACE_TARGET archon) add_definitions(-Wall -ansi -O1 -Wno-variadic-macros -std=c++17 -ggdb) add_definitions(-DSTA_ARCHON) - list(APPEND INTERFACE_SOURCE - "${CAMERA_DIR}/archon.cpp" - ) - list(APPEND INTERFACE_INCLUDES - "${ARCHON_INCLUDE}" - ) + list(APPEND INTERFACE_SOURCE "archon.cpp") add_library(interface STATIC "${INTERFACE_SOURCE}") if (${DETECTOR_TYPE} STREQUAL "Hxrg") message(STATUS "compiling for HXRG detector") @@ -95,17 +92,17 @@ if (NOT DEFINED INSTR) else () if (${INSTR} STREQUAL "nirc2") message(STATUS "building for nirc2 instrument") - list(APPEND INTERFACE_SOURCE "${CAMERA_DIR}/nirc2.cpp") + list(APPEND INTERFACE_SOURCE "nirc2.cpp") elseif (${INSTR} STREQUAL "generic") message(STATUS "building for generic instrument") - list(APPEND INTERFACE_SOURCE "${CAMERA_DIR}/generic.cpp") + list(APPEND INTERFACE_SOURCE "generic.cpp") elseif (${INSTR} STREQUAL "undefined") message(STATUS "no INSTR defined. using generic but other options are:") message(STATUS "cmake -DINSTR=nirc2,generic ..") - list(APPEND INTERFACE_SOURCE "${CAMERA_DIR}/generic.cpp") + list(APPEND INTERFACE_SOURCE "generic.cpp") else () message(STATUS "unknown instrument " ${INSTR} ": using generic") - list(APPEND INTERFACE_SOURCE "${CAMERA_DIR}/generic.cpp") + list(APPEND INTERFACE_SOURCE "generic.cpp") endif () endif () @@ -115,27 +112,18 @@ endif () # Now add the defined interface target: # -add_library(${INTERFACE_TARGET} ${INTERFACE_SOURCE}) -target_include_directories(${INTERFACE_TARGET} PUBLIC ${INTERFACE_INCLUDES}) +target_link_libraries(interface PUBLIC cfitsio CCfits) -add_library(camera STATIC - ${CAMERA_DIR}/camera.cpp -) -# ---------------------------------------------------------------------------- -# External libraries, such as FITS, etc. -# ---------------------------------------------------------------------------- +#Note from danw: I'm afraid camera.h technically includes CCfits, and so a public +#dependency on those is needed +add_library(camera camera.cpp) +target_link_libraries(camera PUBLIC cfitsio CCfits) -find_library(CCFITS_LIB CCfits NAMES libCCfits PATHS /usr/local/lib) -find_library(CFITS_LIB cfitsio NAMES libcfitsio PATHS /usr/local/lib) find_package(Threads) - -add_executable(camerad - ${CAMERA_DIR}/camerad.cpp - ${INTERFACE_INCLUDES} -) +add_executable(camerad camerad.cpp ${INTERFACE_INCLUDES}) # ---------------------------------------------------------------------------- # Everyone gets this: @@ -147,15 +135,14 @@ target_link_libraries(camerad logentry common utilities - ${INTERFACE_TARGET} + interface ${CMAKE_THREAD_LIBS_INIT} - ${CCFITS_LIB} - ${CFITS_LIB} + cfitsio + CCfits ) -target_link_libraries(camerad ${CARC_BASE}) -target_link_libraries(camerad ${CARC_DEVICE}) -target_link_libraries(camerad ${CARC_FITS}) +target_link_libraries(camerad ${CARC_BASE} ${CARC_DEVICE} ${CARC_FITS}) + # ---------------------------------------------------------------------------- # cURL is not used here, so it's not strictly required, but cfitsio can @@ -163,7 +150,7 @@ target_link_libraries(camerad ${CARC_FITS}) # If it's installed on the system then link it, but don't make it mandatory. # ---------------------------------------------------------------------------- # -include(FindCURL) +find_package(CURL) if (CURL_FOUND STREQUAL "FALSE") message(STATUS "cURL was not found but may be needed by some systems if built into cfitsio.\n If you experience undefined curl references during linking \n then please your cURL installation.") diff --git a/camerad/archon.cpp b/camerad/archon.cpp index 2637e0f5..ba6e8ae0 100644 --- a/camerad/archon.cpp +++ b/camerad/archon.cpp @@ -104,6 +104,17 @@ namespace Archon { } /**************** Archon::Interface::interface ******************************/ + + /***Note from danw: I couldn't get this to link without adding a dummy method here no idea why + **/ + + long Interface::power(std::string state_in, std::string& retstring) + { + return do_power(state_in, retstring); + } + + + /***** Archon::Interface::do_power ******************************************/ /** * @brief set/get the power state @@ -876,7 +887,7 @@ namespace Archon { * */ long Interface::archon_cmd(std::string cmd) { // use this form when the calling - std::string reply; // function doesn't need to look at the reply + std::string reply; // function doesn't need to look at the reply return( archon_cmd(cmd, reply) ); } long Interface::archon_cmd(std::string cmd, std::string &reply) { diff --git a/cmake/FindCCfits.cmake b/cmake/FindCCfits.cmake new file mode 100644 index 00000000..3a2fdcc1 --- /dev/null +++ b/cmake/FindCCfits.cmake @@ -0,0 +1,37 @@ +#CCfits does by default provide a pkg-config recipe. Try this first, it's likely the best +#however may not work on mac or windows + + +#note that using the IMPORTED_TARGET argument below requires at least cmake 3.7 + +find_package(PkgConfig QUIET) +if(PKG_CONFIG_FOUND) + message(VERBOSE "found pkg-config, trying to locate CCfits using it") + pkg_check_modules(CCFITS CCfits REQUIRED IMPORTED_TARGET) + + #for compatibility with camera-interface build system, alias the target to CCFITS_LIB as well + add_library(CCfits ALIAS PkgConfig::CCFITS) + set(CCfits_FOUND TRUE) + +else() + message(VERBOSE "no pkg-config, trying to locate CCfits manually") + find_library(CCFITS_LIB CCfits NAMES libCCfits PATHS /usr/local/lib) + message(VERBOSE "CCFITS library: ${CCFITS_LIB}") + + find_path(CCFITS_INCLUDE CCfits.h PATHS /usr/local/lib) + message(VERBOSE "CCFITS include: ${CCFITS_INCLUDE}") + + get_filename_component(CCFITS_INCLUDE_DIR ${CCFITS_INCLUDE} DIRECTORY) + + #note that we don't even bother to find non-standard include paths. + #neither did the previous camera-interface build system. + #If you have a non-standard include path, your CCfits installation should + #have included a pkg-config file and mentioned it, or you should have dropped in your + #own find module here. Good luck. + add_library(CCfits UNKNOWNN IMPORTED) + set_target_properties(CCfits PROPERTIES IMPORTED_LOCATION ${CCFITS_LIB}) + set_target_properties(CCfits PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CCFITS_INCLUDE_DIR}) + + set(CCfits_FOUND TRUE) + +endif() diff --git a/cmake/FindCCfits.cmake~ b/cmake/FindCCfits.cmake~ new file mode 100644 index 00000000..7d96f07e --- /dev/null +++ b/cmake/FindCCfits.cmake~ @@ -0,0 +1,4 @@ +#CCfits does by default provide a pkg-config recipe. Try this first, it's likely the best +#however may not work on mac or windows + +find_package(PkgConfig QUIET) diff --git a/cmake/Findcfitsio.cmake b/cmake/Findcfitsio.cmake new file mode 100644 index 00000000..6851405b --- /dev/null +++ b/cmake/Findcfitsio.cmake @@ -0,0 +1,37 @@ +#cfitsio *sometimes* includes a CMake config file. This is the worst of all possible worlds. +#On systems where it doesn't, it will fall back to this find module + +find_package(PkgConfig QUIET) +if(PKG_CONFIG_FOUND) + message(VERBOSE "found pkg-config, trying to locate cfitsio using it") + pkg_check_modules(cfitsio cfitsio REQUIRED IMPORTED_TARGET) + + add_library(cfitsio ALIAS PkgConfig::cfitsio) + + get_target_property(PROP cfitsio INTERFACE_INCLUDE_DIRECTORIES) + message(VERBOSE "iid: ${PROP}") + message(VERBOSE "id: ${cfitsio_INCLUDE_DIRS}") + + + +else() + message(VERBOSE "no pkg-config, trying to locate cfitsio manually") + find_library(CFITS_LIB cfitsio NAMES libcfitsio PATHS /usr/local/lib) + add_library(cfitsio UNKNOWN IMPORTED) + set_target_properties(cfitsio PROPERTIES IMPORTED_LOCATION ${CFITS_LIB}) + + find_path(FITSIO_INCLUDE fitsio.h) + + message(VERBOSE "fitsio.h include location: ${FITSIO_INCLUDE}") + + if(NOT FITSIO_INCLUDE) + message(FATAL_ERROR "could not find fitsio.h file, build cannot continue!") + endif() + + get_filename_component(CFITSIO_INCLUDE_DIR ${FITSIO_INCLUDE} DIRECTORY) + + set_target_properties(cfitsio PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CFITSIO_INCLUDE_DIR}) + + set(cfitsio_FOUND TRUE) + +endif() diff --git a/cmake/Findcfitsio.cmake~ b/cmake/Findcfitsio.cmake~ new file mode 100644 index 00000000..5fd8de54 --- /dev/null +++ b/cmake/Findcfitsio.cmake~ @@ -0,0 +1,2 @@ +#cfitsio *sometimes* includes a CMake config file. This is the worst of all possible worlds. +#On systems where it doesn't, it will fall back to this find module diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 99328c5a..a67bc653 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -6,13 +6,12 @@ cmake_minimum_required(VERSION 3.12) -set(PROJECT_UTILS_DIR ${PROJECT_BASE_DIR}/common) +add_definitions(-Wall -Wno-variadic-macros) -add_definitions(-Wall -ansi -O2 -Wno-variadic-macros -std=c++17 -ggdb) +#for now have hard coded path here, better in future +#to add include directory as a link interface property +#of a preceeding target. But that may not be available in +#cmake 3.12 +include_directories(${CMAKE_SOURCE_DIR}/utils) # needed for logentry -include_directories(${PROJECT_BASE_DIR}/common) -include_directories(${PROJECT_BASE_DIR}/utils) # needed for logentry - -add_library(common STATIC - ${PROJECT_UTILS_DIR}/common.cpp -) +add_library(common common.cpp) diff --git a/emulator/CMakeLists.txt b/emulator/CMakeLists.txt index b4a79cc5..e88e9b21 100644 --- a/emulator/CMakeLists.txt +++ b/emulator/CMakeLists.txt @@ -3,31 +3,28 @@ # ---------------------------------------------------------------------------- cmake_minimum_required( VERSION 3.12 ) +add_definitions( -Wall -Wno-variadic-macros) -set( EMULATOR_DIR ${PROJECT_BASE_DIR}/emulator ) -add_definitions( -Wall -ansi -O1 -Wno-variadic-macros -std=c++17 -ggdb ) - -include_directories( ${PROJECT_BASE_DIR}/utils - ${PROJECT_BASE_DIR}/camerad - ${PROJECT_BASE_DIR}/common ) +include_directories( ${CMAKE_SOURCE_DIR}/utils + ${CMAKE_SOURCE_DIR}/camerad + ${CMAKE_SOURCE_DIR}/common ) if( ${INTERFACE_TYPE} STREQUAL "Archon" ) add_definitions(-DSTA_ARCHON) set( EMULATOR_TARGET emulatorArchon ) list(APPEND EMULATOR_SOURCE - "${EMULATOR_DIR}/emulator-archon.cpp" + "emulator-archon.cpp" ) add_library(emulatorInterface STATIC - ${EMULATOR_DIR}/emulator-archon.cpp + emulator-archon.cpp ) add_library(${EMULATOR_TARGET} ${EMULATOR_SOURCE}) +target_link_libraries(${EMULATOR_TARGET} PUBLIC cfitsio CCfits) +target_link_libraries(emulatorInterface PUBLIC cfitsio CCfits) -target_include_directories(${EMULATOR_TARGET} PUBLIC ${PROJECT_INCL_DIR}) - -add_executable(emulator - ${EMULATOR_DIR}/emulator-server.cpp +add_executable(emulator emulator-server.cpp ) target_link_libraries(emulator diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index e50e267b..612a0e37 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -1,34 +1,20 @@ # ---------------------------------------------------------------------------- # utils/CMakeLists.txt # ---------------------------------------------------------------------------- -cmake_minimum_required(VERSION 3.12) +#cmake_minimum_required(VERSION 3.12) -set(PROJECT_UTILS_DIR ${PROJECT_BASE_DIR}/utils) +add_definitions(-Wall -Wno-variadic-macros) -add_definitions(-Wall -ansi -O1 -Wno-variadic-macros -std=c++17 -ggdb) +add_library(utilities utilities.cpp md5) -add_library(utilities STATIC - ${PROJECT_UTILS_DIR}/utilities.cpp - md5 -) +add_library(logentry logentry.cpp) -add_library(logentry STATIC - ${PROJECT_UTILS_DIR}/logentry.cpp -) target_link_libraries(logentry $,,stdc++fs>) -add_library(network STATIC - ${PROJECT_UTILS_DIR}/network.cpp -) +add_library(network STATIC network.cpp) -add_library(md5 STATIC - ${PROJECT_UTILS_DIR}/md5.cpp -) +add_library(md5 STATIC md5.cpp) -add_executable(listener - ${PROJECT_UTILS_DIR}/listener.cpp -) +add_executable(listener listener.cpp) -add_executable(socksend - ${PROJECT_UTILS_DIR}/sendcmd.cpp -) +add_executable(socksend sendcmd.cpp)