Created
February 17, 2022 19:30
-
-
Save gnowzil/1a136ccc7844019fab591238bb461dd4 to your computer and use it in GitHub Desktop.
EMTG CMakeList.txt modification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.8) | |
#pull in the user-defined configurations | |
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}) | |
include(EMTG-Config.cmake) | |
if (${EMTG_MPI}) | |
add_definitions(-DEMTG_MPI) | |
message(STATUS "Activating MPI with compiler: ${CMAKE_CXX_COMPILER}") | |
endif() | |
#identify the project | |
project(EMTG) | |
# If the NavLab system Boost is compiled with is gcc 4.6.x or older, we need this | |
#add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0) | |
link_directories(${PROJECT_SOURCE_DIR}/Release) | |
link_directories(${PROJECT_SOURCE_DIR}/Debug) | |
# enable multicore build on Windows | |
if (MSVC) | |
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} " /MP") | |
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} " /MP") | |
endif() | |
# Boost spews auto_ptr deprecation warnings | |
add_definitions(-D_HAS_AUTO_PTR_ETC) | |
if (NOT MSVC) | |
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} " -Wno-deprecated-declarations") | |
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} " -Wno-deprecated-declarations") | |
endif() | |
# Boost doesn't recognize newer compilers | |
add_definitions(-DBOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE) | |
# Boost doesn't like std::iterator either | |
add_definitions(-D_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING) | |
# specify where the executable will be installed | |
if(MSVC) | |
STRING(REGEX REPLACE "/" "\\\\" OUTPUTDESTINATION "${PROJECT_SOURCE_DIR}\\bin") | |
else(MSVC) | |
set(OUTPUTDESTINATION ${PROJECT_SOURCE_DIR}/bin) | |
endif(MSVC) | |
if(NOT IS_DIRECTORY ${PROJECT_SOURCE_DIR}/bin) | |
file(MAKE_DIRECTORY ${OUTPUTDESTINATION}) | |
endif(NOT IS_DIRECTORY ${PROJECT_SOURCE_DIR}/bin) | |
#compiler-time Define-level options for EMTG | |
option(QUIET_SNOPT "If you have a special build of SNOPT, this will silence it completely." OFF) | |
option(SAFE_SNOPT "Trap things that could blow up SNOPT" ON) | |
option(SNOPT72 "Set SNOPT 7.2" OFF) | |
option(SNOPT75 "Use SNOPT 7.5" OFF) | |
option(SNOPT76 "Use SNOPT 7.6" ON) | |
option(SNOPT_MINGW_DLL "Use SNOPT built with MINGW in Windows" OFF) | |
option(DEBUG_CHECK_VARIABLES_AND_CONSTRAINTS_IN_USER_FUNCTION "Check decision and objective/constraint vectors for NaN and inf" OFF) | |
option(FAST_EMTG_MATRIX "Enable fast EMTG matrix class (dangerous!)" ON) | |
option(PROPRIETARY_POWER_MODEL "Enable proprietary power model" OFF) | |
option(SPLINE_EPHEM "Enable SplineEphem" ON) | |
option(BUILD_EMTG_TESTBED "Build the EMTG testing framework" OFF) | |
option(BUILD_PROPULATOR "Build the Propulator" OFF) | |
option(BUILD_PYHARDWARE "Build PyHardware" OFF) | |
# We want Background mode to default to ON for NavLab runs | |
if (MSVC) | |
option(BACKGROUND_MODE "This suppresses 'press any key to continue' at the end of an EMTG run" OFF) | |
else() | |
option(BACKGROUND_MODE "This suppresses 'press any key to continue' at the end of an EMTG run" ON) | |
endif() | |
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build in Debug or Release mode") | |
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release) | |
message(STATUS "Creating build files for " ${CMAKE_BUILD_TYPE} " mode... \n") | |
if(CMAKE_BUILD_TYPE MATCHES Release) | |
if (${CMAKE_CXX_COMPILER_ID} MATCHES "MSVC") | |
set(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE} " /Ot /Ox /GL") | |
elseif (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") | |
set(CMAKE_CXX_FLAGS_RELEASE " -g -O2") | |
endif() | |
message(STATUS "The following compiler optimization flags have been set: " ${CMAKE_CXX_FLAGS_RELEASE} "\n") | |
elseif(CMAKE_BUILD_TYPE MATCHES Debug) | |
message(STATUS "The following compiler optimization flags have been set: " ${CMAKE_CXX_FLAGS_DEBUG} "\n") | |
endif() | |
if(QUIET_SNOPT) | |
add_definitions(-DQUIET_SNOPT) | |
endif(QUIET_SNOPT) | |
if(BACKGROUND_MODE) | |
message(STATUS "Background mode activated") | |
add_definitions(-DBACKGROUND_MODE) | |
endif(BACKGROUND_MODE) | |
if(SAFE_SNOPT) | |
add_definitions(-DSAFE_SNOPT) | |
endif(SAFE_SNOPT) | |
if(DEBUG_CHECK_VARIABLES_AND_CONSTRAINTS_IN_USER_FUNCTION) | |
add_definitions(-DDEBUG_CHECK_VARIABLES_AND_CONSTRAINTS_IN_USER_FUNCTION) | |
endif(DEBUG_CHECK_VARIABLES_AND_CONSTRAINTS_IN_USER_FUNCTION) | |
if(SNOPT75) | |
add_definitions(-DSNOPT75) | |
endif(SNOPT75) | |
if(SNOPT76) | |
add_definitions(-DSNOPT76) | |
endif(SNOPT76) | |
if(FAST_EMTG_MATRIX) | |
add_definitions(-DFAST_EMTG_MATRIX) | |
endif(FAST_EMTG_MATRIX) | |
if(PROPRIETARY_POWER_MODEL) | |
add_definitions(-DPROPRIETARY_POWER_MODEL) | |
set(EMTG_LIBRARIES ${EMTG_LIBRARIES} PROPRIETARY_POWER_MODEL) | |
include_directories("${PROPRIETARY_POWER_MODEL_PATH}") | |
link_directories("${PROPRIETARY_POWER_MODEL_PATH}") | |
endif(PROPRIETARY_POWER_MODEL) | |
if(SPLINE_EPHEM) | |
add_definitions(-DSPLINE_EPHEM) | |
# GNU Scientific Library | |
set(GSL_INCLUDE_DIRS ${GSL_PATH}) | |
include_directories(${GSL_INCLUDE_DIRS}) | |
add_library(gsl STATIC IMPORTED) | |
add_library(gslcblas STATIC IMPORTED) | |
if(MSVC) | |
set_property(TARGET gsl PROPERTY IMPORTED_LOCATION ${GSL_PATH}/${CMAKE_CFG_INTDIR}/gsl.lib) | |
set_property(TARGET gslcblas PROPERTY IMPORTED_LOCATION ${GSL_PATH}/${CMAKE_CFG_INTDIR}/gslcblas.lib) | |
else() | |
set_property(TARGET gsl PROPERTY IMPORTED_LOCATION ${GSL_PATH}/${CMAKE_CFG_INTDIR}/libgsl.a) | |
set_property(TARGET gslcblas PROPERTY IMPORTED_LOCATION ${GSL_PATH}/${CMAKE_CFG_INTDIR}/libgslcblas.a) | |
endif() | |
set(GSL_LIBRARIES gsl gslcblas) | |
set(EMTG_LIBRARIES ${EMTG_LIBRARIES} ${GSL_LIBRARIES}) | |
endif(SPLINE_EPHEM) | |
#----------------CSpice Work------------------------------------------------------ | |
message(STATUS "Now checking for CSpice...") | |
if (MSVC) # aka 'windows' | |
set(CSPICE_FILE_TO_BE_CORRECTED "${CSPICE_DIR}/src/cspice/mkprodct.bat") | |
set(CSPICE_MAKEFILE "makeall.bat") | |
else (MSVC) #aka Linux or Mac, as both of those use the mkprodct.csh system | |
set(CSPICE_FILE_TO_BE_CORRECTED "${CSPICE_DIR}/src/cspice/mkprodct.csh") | |
set(CSPICE_MAKEFILE "makeall.csh") | |
endif(MSVC) | |
if (EXISTS "${CSPICE_DIR}/${CSPICE_MAKEFILE}") | |
message(STATUS "Cspice located and unzipped correctly.") | |
else() | |
message(FATAL_ERROR "CSPICE is not unzipped into the emtg/cspice folder correctly.") | |
endif() | |
if (NOT MSVC) #cspice doesn't label the file correctly when it is done; easier to just rename it | |
if (NOT EXISTS "${CSPICE_DIR}/lib/libcspice.a") | |
message(STATUS "Renaming cspice.a to libcspice.a") | |
file(RENAME "${CSPICE_DIR}/lib/cspice.a" "${CSPICE_DIR}/lib/libcspice.a") | |
if (NOT EXISTS "${CSPICE_DIR}/lib/libcspice.a") | |
message(FATAL_ERROR "CSpice not built properly for a Unix System.") | |
endif() | |
endif() | |
else() | |
if(NOT EXISTS "${CSPICE_DIR}/lib/cspice.lib") | |
message(FATAL_ERROR "CSpice not built properly for a Windows System. Please run the cspice/makeall.bat from within the Visual Studio Command Line tools and then reconfigure cmake.") | |
endif() | |
endif() | |
set(CSPICE_LIBRARY cspice) | |
set(EMTG_LIBRARIES ${EMTG_LIBRARIES} ${CSPICE_LIBRARY}) | |
include_directories("${CSPICE_DIR}/include") | |
link_directories("${CSPICE_DIR}/lib") | |
#----------------------------SNOPT Stuff------------------------------------- | |
message(STATUS "Now checking on SNOPT...") | |
#assume newest version of SNOPT | |
if (IS_DIRECTORY ${SNOPT_ROOT_DIR}/interfaces) | |
include_directories("${SNOPT_ROOT_DIR}/interfaces/include") | |
set(SNOPT_INTERFACE_HEADERS ${SNOPT_ROOT_DIR}/interfaces/include/snoptProblem.hpp ${SNOPT_ROOT_DIR}/interfaces/include/snopt.h) | |
set(SNOPT_INTERFACE_SOURCE ${SNOPT_ROOT_DIR}/interfaces/src/snoptProblem.cpp) | |
if (MSVC AND SNOPT_MINGW_DLL) | |
set(SNOPT_LIBRARIES ${SNOPT_ROOT_DIR}/build/${CMAKE_CFG_INTDIR}/libsnopt.lib) | |
add_library(snopt_interface STATIC IMPORTED) | |
set_property(TARGET snopt_interface PROPERTY IMPORTED_LOCATION "${SNOPT_ROOT_DIR}/build/${CMAKE_CFG_INTDIR}/snopt_interface.lib") | |
link_directories(${SNOPT_ROOT_DIR}/build/${CMAKE_CFG_INTDIR}) | |
set(SNOPT_LIBRARIES ${SNOPT_LIBRARIES} snopt_interface) | |
else() | |
#PULL IN SNOPT. THIS ASSUMES SNOPT HAS ALREADY BEEN COMPILED AND IS IN A VERY SPECIFIC SPOT. | |
if (NOT MSVC) | |
add_library(snopt SHARED IMPORTED) | |
add_library(snopt_cpp SHARED IMPORTED) | |
set_property(TARGET snopt PROPERTY IMPORTED_LOCATION "${SNOPT_ROOT_DIR}/lib/.libs/libsnopt7.so") | |
set_property(TARGET snopt_cpp PROPERTY IMPORTED_LOCATION "${SNOPT_ROOT_DIR}/lib/.libs/libsnopt7_cpp.so") | |
else(NOT MSVC) | |
add_library(snopt STATIC IMPORTED) | |
set_property(TARGET snopt PROPERTY IMPORTED_LOCATION "${SNOPT_ROOT_DIR}/lib/snopt.lib") | |
set(EMTG_LIBRARIES ${EMTG_LIBRARIES} ifmodintr.lib) | |
link_directories("${INTEL_FORTRAN_DIR}") | |
endif(NOT MSVC) | |
if (MSVC) | |
link_directories("${PROJECT_SOURCE_DIR}/lib") | |
link_directories(${SNOPT_ROOT_DIR}/lib) | |
else() | |
link_directories("${PROJECT_SOURCE_DIR}/lib") | |
link_directories(${SNOPT_ROOT_DIR}/lib/.libs) | |
endif() | |
add_library(snopt_interface ${SNOPT_INTERFACE_HEADERS} ${SNOPT_INTERFACE_SOURCE}) | |
if (MSVC) | |
set(SNOPT_LIBRARIES snopt_interface snopt) | |
else() | |
target_link_libraries(snopt_interface gfortran) | |
set(SNOPT_LIBRARIES snopt_interface snopt_cpp snopt) | |
endif() | |
set_property(TARGET snopt_interface PROPERTY POSITION_INDEPENDENT_CODE ON) | |
endif() | |
#okay, do we have an older version of SNOPT? | |
elseif(IS_DIRECTORY ${SNOPT_ROOT_DIR}/cppsrc) | |
include_directories("${SNOPT_ROOT_DIR}/cppsrc") | |
include_directories("${SNOPT_ROOT_DIR}/win32") | |
set(SNOPT_INTERFACE_HEADERS ${SNOPT_ROOT_DIR}/win32/f2c.h ${SNOPT_ROOT_DIR}/cppsrc/snoptProblem.hh ${SNOPT_ROOT_DIR}/cppsrc/snopt.hh ${SNOPT_ROOT_DIR}/cppsrc/snfilewrapper.hh) | |
set(SNOPT_INTERFACE_SOURCE ${SNOPT_ROOT_DIR}/cppsrc/snfilewrapper.c ${SNOPT_ROOT_DIR}/cppsrc/snoptProblem.cc) | |
#PULL IN SNOPT. THIS ASSUMES SNOPT HAS ALREADY BEEN COMPILED AND IS IN A VERY SPECIFIC SPOT. | |
add_library(f2c STATIC IMPORTED) | |
add_library(snopt_cpp STATIC IMPORTED) | |
add_library(snopt_c STATIC IMPORTED) | |
add_library(snoptsnprint STATIC IMPORTED) | |
if (NOT MSVC) | |
set_property(TARGET f2c PROPERTY IMPORTED_LOCATION "${SNOPT_ROOT_DIR}/lib/libf2c.a") | |
set_property(TARGET snopt_cpp PROPERTY IMPORTED_LOCATION "${SNOPT_ROOT_DIR}/lib/libsnopt_cpp.a") | |
set_property(TARGET snoptsnprint PROPERTY IMPORTED_LOCATION "${SNOPT_ROOT_DIR}/lib/libsnprint_c.a") | |
set_property(TARGET snopt_c PROPERTY IMPORTED_LOCATION "${SNOPT_ROOT_DIR}/lib/libsnopt_c.a") | |
set(SNOPT_LIBRARIES snopt_c snoptsnprint snopt_cpp f2c) | |
else(NOT MSVC) | |
set_property(TARGET f2c PROPERTY IMPORTED_LOCATION "${SNOPT_ROOT_DIR}/win32/snopt_csrc/Release/vcf2c.lib") | |
set_property(TARGET snopt_c PROPERTY IMPORTED_LOCATION "${SNOPT_ROOT_DIR}/win32/snopt_csrc/Release/snopt.lib") | |
set(SNOPT_LIBRARIES snopt_c f2c) | |
endif(NOT MSVC) | |
link_directories("${PROJECT_SOURCE_DIR}/lib") | |
add_definitions(-DSNOPT72 "Use SNOPT 7.2-12 or older" ON) | |
elseif(IS_DIRECTORY ${SNOPT_ROOT_DIR}/include) | |
include_directories("${SNOPT_ROOT_DIR}/include") | |
add_library(snopt_cpp STATIC IMPORTED) | |
set_property(TARGET snopt_cpp PROPERTY IMPORTED_LOCATION "${SNOPT_ROOT_DIR}/lib/libsnopt7_cpp.a") | |
link_directories("${PROJECT_SOURCE_DIR}/lib") | |
link_directories(${SNOPT_ROOT_DIR}/lib) | |
set(SNOPT_LIBRARIES snopt_cpp) | |
else(IS_DIRECTORY ${SNOPT_ROOT_DIR}/interfaces) | |
message(FATAL_ERROR "Could not find snopt") | |
endif(IS_DIRECTORY ${SNOPT_ROOT_DIR}/interfaces) | |
include_directories(${SNOPT_INCLUDE_DIR}) | |
set(EMTG_LIBRARIES ${EMTG_LIBRARIES} ${SNOPT_LIBRARIES}) | |
#-------------------------Boost related work------------------------------ | |
message(STATUS "Now looking for BOOST..") | |
include(FindBoost) | |
if(MSVC) | |
Set(Boost_NAMESPACE libboost) | |
endif(MSVC) | |
# if we are on Windows, do not require that MPI be present | |
if (${EMTG_MPI}) | |
find_package(Boost 1.41 COMPONENTS mpi filesystem system serialization REQUIRED) | |
else() | |
find_package(Boost 1.41 COMPONENTS filesystem system serialization REQUIRED) | |
endif() | |
include_directories(${Boost_INCLUDE_DIRS}) | |
link_directories(${Boost_LIBRARY_DIRS}) | |
set(EMTG_LIBRARIES ${EMTG_LIBRARIES} ${Boost_LIBRARIES}) | |
#pull in EMTG itself | |
add_subdirectory(src) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Modified version CMakeList.txt for EMTGv9 (https://github.com/JacobEnglander/EMTG/).
I'm hoping this will allow for use of precompiled SNOPT libraries downloaded from http://ccom.ucsd.edu/~optimizers.
The relevant lines are L268-L276.
I got EMTG to compile most of the way, but had some other issues that appeared to be unrelated to SNOPT so there are no guarantees this will work.
You should have in your download
Create a directory structure where the library is in directory
lib
and the header files are ininclude
. For example,In this case, I would set
SNOPT_ROOT_DIR
to/home/me/snopt7
.Also, in
EMTG-config.cmake
add the following somewhere: