Cmake 编译设置
来源:互联网 发布:mac qq 讨论组 改昵称 编辑:程序博客网 时间:2024/06/08 05:31
问题描述
利用编写的CmakeLists文件编译链接fortran编写函数库与C++编写的geant4程序;需要解决的问题有:
1.如何设置环境变量;
2.如何利用CmakeLists编译fortran代码;
3.如何在C++中调用fortran编写的函数;
代码实现
1.环境变量设置
export PATH=$PATH::$PWD/bin #设置执行文件安装路径export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(pwd)/lib #设置库文件路径
2.如何利用CmakeLists编译fortran代码;
#----------------------------------------------------------------------------# Setup the projectcmake_minimum_required(VERSION 2.6 FATAL_ERROR)set(PROJ_NAME FortranEarthAtmosphere)project($PROJ_NAME)enable_language(Fortran)set(CMAKE_BUILD_TYPE Release)#----------------------------------------------------------------------------# Locate sources and headers for this project# NB: headers are included so they will show up in IDEs#file(GLOB_RECURSE sources ${PROJECT_SOURCE_DIR}/*.f*)add_library(${PROJ_NAME} SHARED ${sources})install(TARGETS ${PROJ_NAME} DESTINATION lib)
3.如何在C++中调用fortran编写的函数;
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)set(PROJ_NAME PLANETOCOSMICS)project(${PROJ_NAME})#----------------------------------------------------------------------------# Find Geant4 package, activating all available UI and Vis drivers by default# You can set WITH_GEANT4_UIVIS to OFF via the command line or ccmake/cmake-gui# to build a batch mode only executable#option(WITH_GEANT4_UIVIS "Build example with Geant4 UI and Vis drivers" ON)if(WITH_GEANT4_UIVIS)find_package(Geant4 REQUIRED ui_all vis_all)else()find_package(Geant4 REQUIRED)endif()#----------------------------------------------------------------------------# Setup Geant4 include directories and compile definitions# Setup include directory for this project#include(${Geant4_USE_FILE})include_directories(${PROJECT_SOURCE_DIR}/include ${Geant4_INCLUDE_DIR} ${ROOT_INCLUDE_DIR}/opt/Root/root60902/include/root/ #/opt/Root/include/ #/opt/Root/include/root/ ${PROJECT_SOURCE_DIR}/atmosphere/)#----------------------------------------------------------------------------# Find ROOT (required package)#find_package(ROOT REQUIRED)#----------------------------------------------------------------------------# Locate sources and headers for this project# NB: headers are included so they will show up in IDEs#file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cc )file(GLOB headers ${PROJECT_SOURCE_DIR}/include/*.hh)file(GLOB macs ${PROJECT_SOURCE_DIR}/root/* )#----------------------------------------------------------------------------# Add the executable, and link it to the Geant4 libraries##add_subdirectory(magfieldmodels)#add_custom_target(FortranEarthMagFieldlib DEPENDS fortran)add_subdirectory(atmosphere)add_custom_target(FortranEarthAtmospherelib DEPENDS fortran)#add_subdirectory(lib)#add_custom_target(spice DEPENDS fortran)add_executable(${PROJ_NAME} ${PROJ_NAME}.cc ${sources} ${headers})target_link_libraries(${PROJ_NAME} ${Geant4_LIBRARIES} ${ROOT_LIBRARIES} -L${PROJECT_SOURCE_DIR}/lib FortranEarthAtmosphere)#----------------------------------------------------------------------------# Copy all scripts to the build directory, i.e. the directory in which we# build B1. This is so that we can run the executable directly because it# relies on these scripts being in the current working directory.#set(_SCRIPTS)foreach(_script ${_SCRIPTS})configure_file(${PROJECT_SOURCE_DIR}/${_script}${PROJECT_BINARY_DIR}/../bin/${_script}COPYONLY)endforeach()#----------------------------------------------------------------------------# Install the executable to 'bin' directory under CMAKE_INSTALL_PREFIX#install(TARGETS ${PROJ_NAME} DESTINATION bin)install(FILES ${macs} DESTINATION bin)
阅读全文
0 0
- CMAKE交叉编译设置
- Cmake 编译设置
- Cmake 设置交叉编译环境
- cmake设置mfc编译项目
- Cmake 设置交叉编译环境
- 有关QGIS编译,cmake中设置问题
- CMake编译
- Cmake编译
- [cmake]如何设置Debug和Release编译模式
- CMake编译Qt
- CMake编译ogre、mygui
- mysql编译工具 cmake
- ogre cmake编译
- CMake的交叉编译
- cmake编译opencv程序
- CMake 编译 ITK出错
- CMake编译linux C++
- cmake交叉编译
- 说说cache那些最基本的事
- HTC Vive Unity 教程
- 操作系统基础训练十个问题及解答
- 启动nova-compute不成功报错AMQP server controller:5672
- 作业
- Cmake 编译设置
- I'm going to be a coder !
- PAT:1124. Raffle for Weibo Followers (20)
- 20171207 自省
- C#使用聚合组织相关数据
- 分区人脸二值化
- 哈希算法 C语言 (数组实现)
- Js New一个函数和直接调用的区别
- 使用javah 命令 报找不到 类文件