首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我如何告诉IDE以特定的方式编译我的CMake项目?

我如何告诉IDE以特定的方式编译我的CMake项目?
EN

Stack Overflow用户
提问于 2017-10-15 15:52:09
回答 1查看 232关注 0票数 1

我有一个CMake (主要是C,带有一些C++)项目,其安装说明如下:

代码语言:javascript
复制
mkdir build
cd build
cmake /*some options*/ ../
make

如果我是从命令行编译的话,这是非常有效的。

我想使用IDE来编译这个程序,这样我就可以用图形调试器来调试它。但是,当我试图使用IDE编译时,我会得到链接器错误。

我不熟悉CMake的内部工作,因此不知道如何实现所期望的行为。事实上,我不确定这是否是一个CMake问题;也许这只是一个关于IDE配置的问题。如果有帮助的话,我使用的IDE是JetBrains‘CLion。

IDE中给出的错误是

CMake文件是

代码语言:javascript
复制
set(CMAKE_CXX_COMPILER "/Library/Developer/CommandLineTools/usr/bin/c++")
set(CMAKE_C_COMPILER "/Library/Developer/CommandLineTools/usr/bin/cc")
project(mpmc)
cmake_minimum_required(VERSION 3.8)
option(MPI "Use MPI to parallelize the calculations (requires MPI)" OFF)
option(CUDA "Use CUDA to offload polarization calculations to a GPU (requires CUDA)" OFF)
option(OPENCL "Use OpenCL to offload polarization calculations to a GPU (requires OpenCL)" OFF)
option(QM_ROTATION "Enable Quantum Mechanics Rigid Rotator calculations (requires LAPACK)" OFF)
option(VDW "Enable Coupled-Dipole Van der Waals (requires LAPACK)" OFF)


configure_file (
"${PROJECT_SOURCE_DIR}/src/include/cmake_config.h.in"
"${PROJECT_BINARY_DIR}/src/include/cmake_config.h"
)

set(CMAKE_BUILD_TYPE Release)

if(CMAKE_COMPILER_IS_GNUCC)
    set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall")
    set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wall")
endif()

set(LIB m)

set(INCLUDE src/include/ src/mersenne/ ${PROJECT_BINARY_DIR}/src/include)

set(SRC
src/mc/mc_moves.c
src/mc/surface_fit_arbitrary.c
src/mc/qshift.c
src/mc/single_point.c
src/mc/mc.c
src/mc/replay.c
src/mc/pimc.c
src/mc/surface.c
src/mc/surf_fit.c
src/mc/fugacity.c
src/mc/cavity.c
src/mc/checkpoint.c
src/histogram/histogram.c
src/energy/lj_buffered_14_7.c
src/energy/bessel.c
src/energy/dreiding.c
src/energy/energy.c
src/energy/polar.c
src/energy/pbc.c
src/energy/disp_expansion.c
src/energy/vdw.c
src/energy/pairs.c
src/energy/bond.c
src/energy/coulombic_gwp.c
src/energy/exp_repulsion.c
src/energy/coulombic.c
src/energy/sg.c
src/energy/lj.c
src/energy/axilrod_teller.cpp
src/mersenne/mt.c
src/mersenne/dSFMT.h
src/mersenne/dSFMT.c
src/mersenne/dSFMT-common.h
src/mersenne/dSFMT-params.h
src/main/quaternion.c
src/main/CArng.c
src/main/memnullcheck.c
src/main/main.c
src/main/cleanup.c
src/main/usefulmath.c
src/io/dxwrite.c
src/io/simulation_box.c
src/io/average.c
src/io/output.c
src/io/check_input.c
src/io/input.c
src/io/mpi.c
src/io/read_pqr.c
src/io/setup_ocl.c
src/polarization/thole_field.c
src/polarization/polar_wolf_lookup.c
src/polarization/thole_polarizability.c
src/polarization/thole_matrix.c
src/polarization/polar_ewald.c
src/polarization/thole_iterative.c
)

if(MPI)
    message("-- MPI Enabled")
    find_package(MPI REQUIRED)
    if(NOT MPI_C_FOUND)
        message(FATAL_ERROR "-- MPI not found! Exiting ...")
    endif()
    set(INCLUDE ${INCLUDE} ${MPI_C_INCLUDE_PATH})
    set(LIB ${LIB} ${MPI_C_LIBRARIES})
else()
    message("-- MPI Disabled")
endif()

if(CUDA)
    message("-- CUDA Enabled")
    find_package(CUDA REQUIRED)
    set(SRC ${SRC} src/polarization_gpu/polar_cuda.cu)
else()
    message("-- CUDA Disabled")
endif()

if(OPENCL)
    message("-- OpenCl Enabled")
    set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
    find_package(OpenCL REQUIRED)
    if(NOT OPENCL_FOUND)
        message(FATAL_ERROR "--OpenCl not found! Exiting ...")
    endif()
    set(SRC ${SRC}
        src/polarization_gpu/polar_ocl.c
        src/io/setup_ocl.c)
    set(INCLUDE ${INCLUDE} ${OpenCL_INCLUDE_DIRS})
    set(LIB ${LIB} ${OpenCL_LIBRARIES})
else()
    message("-- OpenCl Disabled")
endif()

if(QM_ROTATION)
    message("-- QM Rotation Enabled")
    set(SRC ${SRC}
        src/quantum_rotation/rotational_basis.c
        src/quantum_rotation/rotational_eigenspectrum.c
        src/quantum_rotation/rotational_integrate.c
        src/quantum_rotation/rotational_potential.c)
    set(LIB ${LIB} lapack)
else()
    message("-- QM Rotation Disabled")
endif()

if(VDW)
    message("-- CDVDW Enabled")
    if(NOT QM_ROTATION)
        set(LIB ${LIB} lapack)
    endif()
else()
    message("-- CDVDW Disabled")
endif()

include_directories(${INCLUDE})
if(CUDA)
    cuda_add_executable(${PROJECT_NAME} ${SRC})
else()
    add_executable(${PROJECT_NAME} ${SRC})
endif()
target_link_libraries(${PROJECT_NAME} ${LIB})

if(MPI)
    if(MPI_C_COMPILE_FLAGS)
      set_target_properties(${PROJECT_NAME} PROPERTIES
        COMPILE_FLAGS "${MPI_C_COMPILE_FLAGS}")
    endif()

    if(MPI_C_LINK_FLAGS)
      set_target_properties(${PROJECT_NAME} PROPERTIES
        LINK_FLAGS "${MPI_C_LINK_FLAGS}")
    endif()
endif()

目录结构是

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-10-16 09:58:30

您可以通过命令行编译将CLion指向构建目录。转到"File -> Settings -> Build,Execution,. -> Cmake“,并将”生成路径“指向您的”原始“生成目录。否则,CLion会在“”中生成自己的dir。即使将CLion指向另一个dir,它也可能会根据"Debug/Release“配置等其他参数在相同的设置选项卡上更改cmake变量。因为从您的cmake安装程序中,我们可以看到"Release“是默认的,只是切换可能会产生不同,甚至不需要切换build。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46756948

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档