cmake: remove LIB_SOURCES and LMP_SOURCES

This commit is contained in:
Christoph Junghans 2020-03-22 14:42:29 -06:00
parent b533fdb31b
commit 62cb760ee2
9 changed files with 25 additions and 23 deletions

View File

@ -21,11 +21,6 @@ if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "$ENV{HOME}/.local" CACHE PATH "default install path" FORCE )
endif()
# To avoid conflicts with the conventional Makefile build system, we build everything here
file(GLOB LIB_SOURCES ${LAMMPS_SOURCE_DIR}/[^.]*.cpp)
file(GLOB LMP_SOURCES ${LAMMPS_SOURCE_DIR}/main.cpp)
list(REMOVE_ITEM LIB_SOURCES ${LMP_SOURCES})
# Cmake modules/macros are in a subdirectory to keep this file cleaner
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/Modules)
@ -110,8 +105,19 @@ endif()
option(BUILD_TOOLS "Build and install LAMMPS tools (msi2lmp, binary2txt, chain)" OFF)
if(NOT BUILD_EXE AND NOT BUILD_LIB)
message(FATAL_ERROR "You need to at least enable one of two following options: BUILD_LIB or BUILD_EXE")
if(BUILD_LIB)
file(GLOB MAIN_SOURCES ${LAMMPS_SOURCE_DIR}/main.cpp)
list(REMOVE_ITEM ALL_SOURCES ${MAIN_SOURCES})
add_library(lammps ${ALL_SOURCES})
if(BUILD_EXE)
add_executable(lmp ${MAIN_SOURCES})
target_link_libraries(lmp PRIVATE lammps)
endif()
else()
if(NOT BUILD_EXE)
message(FATAL_ERROR "You need to at least enable one of two following options: BUILD_LIB or BUILD_EXE")
endif()
add_executable(lammps ${ALL_SOURCES})
endif()
option(CMAKE_VERBOSE_MAKEFILE "Generate verbose Makefiles" OFF)
@ -391,7 +397,7 @@ foreach(PKG ${DEFAULT_PACKAGES})
# detects styles in package and adds them to global list
RegisterStyles(${${PKG}_SOURCES_DIR})
list(APPEND LIB_SOURCES ${${PKG}_SOURCES})
target_sources(lammps PRIVATE ${${PKG}_SOURCES})
include_directories(${${PKG}_SOURCES_DIR})
endif()
@ -533,7 +539,6 @@ if (${_index} GREATER -1)
endif()
list(REMOVE_DUPLICATES LAMMPS_LINK_LIBS)
if(BUILD_LIB)
add_library(lammps ${LIB_SOURCES})
target_link_libraries(lammps ${LAMMPS_LINK_LIBS})
if(LAMMPS_DEPS)
add_dependencies(lammps ${LAMMPS_DEPS})
@ -579,15 +584,10 @@ if(BUILD_LIB)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/liblammps${LAMMPS_LIB_SUFFIX}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
configure_file(FindLAMMPS.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/FindLAMMPS${LAMMPS_LIB_SUFFIX}.cmake @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/FindLAMMPS${LAMMPS_LIB_SUFFIX}.cmake DESTINATION ${CMAKE_INSTALL_DATADIR}/cmake/Modules)
else()
list(APPEND LMP_SOURCES ${LIB_SOURCES})
endif()
if(BUILD_EXE)
add_executable(lmp ${LMP_SOURCES})
if(BUILD_LIB)
target_link_libraries(lmp lammps)
else()
if(NOT BUILD_LIB)
target_link_libraries(lmp ${LAMMPS_LINK_LIBS})
if(LAMMPS_DEPS)
add_dependencies(lmp ${LAMMPS_DEPS})

View File

@ -8,6 +8,6 @@ if(PKG_CORESHELL)
get_property(CORESHELL_SOURCES GLOBAL PROPERTY CORESHELL_SOURCES)
list(APPEND LIB_SOURCES ${CORESHELL_SOURCES})
target_sources(lammps PRIVATE ${CORESHELL_SOURCES})
include_directories(${CORESHELL_SOURCES_DIR})
endif()

View File

@ -192,6 +192,6 @@ if(PKG_GPU)
get_property(GPU_SOURCES GLOBAL PROPERTY GPU_SOURCES)
list(APPEND LIB_SOURCES ${GPU_SOURCES})
target_sources(lammps PRIVATE ${GPU_SOURCES})
include_directories(${GPU_SOURCES_DIR})
endif()

View File

@ -69,6 +69,6 @@ if(PKG_KOKKOS)
get_property(KOKKOS_PKG_SOURCES GLOBAL PROPERTY KOKKOS_PKG_SOURCES)
list(APPEND LIB_SOURCES ${KOKKOS_PKG_SOURCES})
target_sources(lammps PRIVATE ${KOKKOS_PKG_SOURCES})
include_directories(${KOKKOS_PKG_SOURCES_DIR})
endif()

View File

@ -8,6 +8,6 @@ if(PKG_OPT)
get_property(OPT_SOURCES GLOBAL PROPERTY OPT_SOURCES)
list(APPEND LIB_SOURCES ${OPT_SOURCES})
target_sources(lammps PRIVATE ${OPT_SOURCES})
include_directories(${OPT_SOURCES_DIR})
endif()

View File

@ -15,6 +15,6 @@ if(PKG_QEQ)
endforeach()
get_property(QEQ_SOURCES GLOBAL PROPERTY QEQ_SOURCES)
list(APPEND LIB_SOURCES ${QEQ_SOURCES})
target_sources(lammps PRIVATE ${QEQ_SOURCES})
include_directories(${QEQ_SOURCES_DIR})
endif()

View File

@ -108,6 +108,6 @@ if(PKG_USER-INTEL)
RegisterIntegrateStyle(${USER-INTEL_SOURCES_DIR}/verlet_lrt_intel.h)
endif()
list(APPEND LIB_SOURCES ${USER-INTEL_SOURCES})
target_sources(lammps PRIVATE ${USER-INTEL_SOURCES})
include_directories(${USER-INTEL_SOURCES_DIR})
endif()

View File

@ -37,6 +37,6 @@ if(PKG_USER-OMP)
${USER-OMP_SOURCES_DIR}/reaxc_valence_angles_omp.cpp)
endif()
list(APPEND LIB_SOURCES ${USER-OMP_SOURCES})
target_sources(lammps PRIVATE ${USER-OMP_SOURCES})
include_directories(${USER-OMP_SOURCES_DIR})
endif()

View File

@ -5,7 +5,9 @@ if(PKG_USER-SDPD)
get_property(hlist GLOBAL PROPERTY FIX)
if(NOT PKG_RIGID)
list(REMOVE_ITEM hlist ${USER-SDPD_SOURCES_DIR}/fix_rigid_meso.h)
list(REMOVE_ITEM LIB_SOURCES ${USER-SDPD_SOURCES_DIR}/fix_rigid_meso.cpp)
get_target_property(LAMMPS_SOURCES lammps SOURCES)
list(REMOVE_ITEM LAMMPS_SOURCES ${USER-SDPD_SOURCES_DIR}/fix_rigid_meso.cpp)
set_property(TARGET lammps PROPERTY SOURCES ${LAMMPS_SOURCES})
endif()
set_property(GLOBAL PROPERTY FIX "${hlist}")