Skip to content

Commit

Permalink
Merge pull request #717 from bam241/build_exe
Browse files Browse the repository at this point in the history
  • Loading branch information
gonuke authored Feb 15, 2021
2 parents 0fa764a + 39d28d1 commit 80c2a0e
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 65 deletions.
144 changes: 79 additions & 65 deletions cmake/DAGMC_macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,20 @@ macro (dagmc_setup_options)

option(BUILD_FLUKA "Build FluDAG" OFF)

option(BUILD_UWUW "Build UWUW library and uwuw_preproc" ON)
option(BUILD_UWUW "Build UWUW library and uwuw_preproc" ON)
option(BUILD_TALLY "Build dagtally library" ON)

option(BUILD_BUILD_OBB "Build build_obb tool" ON)
option(BUILD_MAKE_WATERTIGHT "Build make_watertight tool" ON)
option(BUILD_OVERLAP_CHECK "Build overlap_check tool" ON)
option(BUILD_OVERLAP_CHECK "Build overlap_check tool" ON)

option(BUILD_TESTS "Build unit tests" ON)
option(BUILD_CI_TESTS "Build everything needed to run the CI tests" OFF)

option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(BUILD_STATIC_LIBS "Build static libraries" ON)

option(BUILD_EXE "Build DAGMC executables" ON)
option(BUILD_STATIC_EXE "Build static executables" OFF)
option(BUILD_PIC "Build with PIC" OFF)

Expand Down Expand Up @@ -96,12 +97,14 @@ endif()
if (NOT BUILD_STATIC_LIBS AND BUILD_STATIC_EXE)
message(FATAL_ERROR "BUILD_STATIC_EXE cannot be ON while BUILD_STATIC_LIBS is OFF")
endif ()
if (NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_EXE)
message(FATAL_ERROR "BUILD_STATIC_EXE cannot be OFF while BUILD_SHARED_LIBS is OFF")
endif ()
if (NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS)
message(FATAL_ERROR "BUILD_SHARED_LIBS and BUILD_STATIC_LIBS cannot both be OFF")
endif ()
if (NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_EXE AND BUILD_EXE)
SET(BUILD_EXE OFF)
message("Turning BUILD_EXE OFF: SHARED_BUILD_LIBS and BUILD_STATIC_EXE are OFF")
endif ()

endmacro ()

macro (dagmc_setup_flags)
Expand All @@ -128,21 +131,23 @@ macro (dagmc_setup_flags)
set(CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES "")
set(CMAKE_Fortran_IMPLICIT_LINK_DIRECTORIES "")

if (BUILD_STATIC_EXE)
message(STATUS "Building static executables")
set(BUILD_SHARED_EXE OFF)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX})
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS)
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS)
set(CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS)
set(CMAKE_EXE_LINK_DYNAMIC_C_FLAGS)
set(CMAKE_EXE_LINK_DYNAMIC_CXX_FLAGS)
set(CMAKE_EXE_LINK_DYNAMIC_Fortran_FLAGS)
else ()
message(STATUS "Building shared executables")
set(BUILD_SHARED_EXE ON)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_SHARED_LIBRARY_SUFFIX})
if (BUILD_EXE)
if (BUILD_STATIC_EXE)
message(STATUS "Building static executables")
set(BUILD_SHARED_EXE OFF)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX})
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS)
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS)
set(CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS)
set(CMAKE_EXE_LINK_DYNAMIC_C_FLAGS)
set(CMAKE_EXE_LINK_DYNAMIC_CXX_FLAGS)
set(CMAKE_EXE_LINK_DYNAMIC_Fortran_FLAGS)
else ()
message(STATUS "Building shared executables")
set(BUILD_SHARED_EXE ON)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_SHARED_LIBRARY_SUFFIX})
endif ()
endif ()

if (BUILD_RPATH)
Expand Down Expand Up @@ -240,7 +245,8 @@ macro (dagmc_install_library lib_name)
if (BUILD_STATIC_LIBS)
add_library(${lib_name}-static STATIC ${SRC_FILES})
set_target_properties(${lib_name}-static
PROPERTIES OUTPUT_NAME ${lib_name})
PROPERTIES OUTPUT_NAME ${lib_name}
PUBLIC_HEADER "${PUB_HEADERS}")
if (BUILD_RPATH)
set_target_properties(${lib_name}-static
PROPERTIES INSTALL_RPATH "" INSTALL_RPATH_USE_LINK_PATH FALSE)
Expand All @@ -261,64 +267,72 @@ endmacro ()

# Install an executable
macro (dagmc_install_exe exe_name)
message(STATUS "Building executable: ${exe_name}")
if (NOT BUILD_EXE)
message(STATUS "Skipping executable ${exe_name} build")
else ()
message(STATUS "Building executable: ${exe_name}")

dagmc_get_link_libs()
dagmc_get_link_libs()

add_executable(${exe_name} ${SRC_FILES})
if (BUILD_RPATH)
if (BUILD_STATIC_EXE)
set_target_properties(${exe_name}
PROPERTIES INSTALL_RPATH ""
INSTALL_RPATH_USE_LINK_PATH FALSE)
target_link_libraries(${exe_name} ${LINK_LIBS_STATIC})
else ()
set_target_properties(${exe_name}
PROPERTIES INSTALL_RPATH "${INSTALL_RPATH_DIRS}"
INSTALL_RPATH_USE_LINK_PATH TRUE)
target_link_libraries(${exe_name} PUBLIC ${LINK_LIBS_SHARED})
endif ()
else ()
if (BUILD_STATIC_EXE)
target_link_libraries(${exe_name} ${LINK_LIBS_STATIC})
add_executable(${exe_name} ${SRC_FILES})
if (BUILD_RPATH)
if (BUILD_STATIC_EXE)
set_target_properties(${exe_name}
PROPERTIES INSTALL_RPATH ""
INSTALL_RPATH_USE_LINK_PATH FALSE)
target_link_libraries(${exe_name} ${LINK_LIBS_STATIC})
else ()
set_target_properties(${exe_name}
PROPERTIES INSTALL_RPATH "${INSTALL_RPATH_DIRS}"
INSTALL_RPATH_USE_LINK_PATH TRUE)
target_link_libraries(${exe_name} PUBLIC ${LINK_LIBS_SHARED})
endif ()
else ()
target_link_libraries(${exe_name} PUBLIC ${LINK_LIBS_SHARED})
if (BUILD_STATIC_EXE)
target_link_libraries(${exe_name} ${LINK_LIBS_STATIC})
else ()
target_link_libraries(${exe_name} PUBLIC ${LINK_LIBS_SHARED})
endif ()
endif ()
install(TARGETS ${exe_name} DESTINATION ${INSTALL_BIN_DIR})
endif ()
install(TARGETS ${exe_name} DESTINATION ${INSTALL_BIN_DIR})
endmacro ()

# Install a unit test
macro (dagmc_install_test test_name ext)
message(STATUS "Building unit tests: ${test_name}")
if (NOT BUILD_EXE)
message(STATUS "Skipping unit tests ${test_name} build.")
else ()
message(STATUS "Building unit tests: ${test_name}")

list(APPEND LINK_LIBS gtest)
list(APPEND LINK_LIBS gtest)

dagmc_get_link_libs()
dagmc_get_link_libs()

add_executable(${test_name} ${test_name}.${ext} ${DRIVERS})
if (BUILD_RPATH)
if (BUILD_STATIC_EXE)
set_target_properties(${test_name}
PROPERTIES INSTALL_RPATH ""
INSTALL_RPATH_USE_LINK_PATH FALSE)
target_link_libraries(${test_name} ${LINK_LIBS_STATIC})
else ()
set_target_properties(${test_name}
PROPERTIES INSTALL_RPATH "${INSTALL_RPATH_DIRS}"
INSTALL_RPATH_USE_LINK_PATH TRUE)
target_link_libraries(${test_name} ${LINK_LIBS_SHARED})
endif ()
else ()
if (BUILD_STATIC_EXE)
target_link_libraries(${test_name} ${LINK_LIBS_STATIC})
add_executable(${test_name} ${test_name}.${ext} ${DRIVERS})
if (BUILD_RPATH)
if (BUILD_STATIC_EXE)
set_target_properties(${test_name}
PROPERTIES INSTALL_RPATH ""
INSTALL_RPATH_USE_LINK_PATH FALSE)
target_link_libraries(${test_name} ${LINK_LIBS_STATIC})
else ()
set_target_properties(${test_name}
PROPERTIES INSTALL_RPATH "${INSTALL_RPATH_DIRS}"
INSTALL_RPATH_USE_LINK_PATH TRUE)
target_link_libraries(${test_name} ${LINK_LIBS_SHARED})
endif ()
else ()
target_link_libraries(${test_name} ${LINK_LIBS_SHARED})
if (BUILD_STATIC_EXE)
target_link_libraries(${test_name} ${LINK_LIBS_STATIC})
else ()
target_link_libraries(${test_name} ${LINK_LIBS_SHARED})
endif ()
endif ()
endif ()
install(TARGETS ${test_name} DESTINATION ${INSTALL_TESTS_DIR})
add_test(NAME ${test_name} COMMAND ${test_name})
set_property(TEST ${test_name} PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=''")
install(TARGETS ${test_name} DESTINATION ${INSTALL_TESTS_DIR})
add_test(NAME ${test_name} COMMAND ${test_name})
set_property(TEST ${test_name} PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=''")
endif ()
endmacro ()

# Install a file needed for unit testing
Expand Down
16 changes: 16 additions & 0 deletions news/PR-0717.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
**Added:**

- adding BUILD_EXE option (default ON) alowing to build only the dagmc libs
without the executable (for static and/or shared libs)

**Changed:** None

- now install dagmc header when building and instaling static libs

**Deprecated:** None

**Removed:** None

**Fixed:** None

**Security:** None

0 comments on commit 80c2a0e

Please sign in to comment.