Skip to content

Commit

Permalink
add default build type release (OpenAtomFoundation#1337)
Browse files Browse the repository at this point in the history
  • Loading branch information
lqxhub authored Mar 12, 2023
1 parent c250203 commit abc94cf
Showing 1 changed file with 52 additions and 6 deletions.
58 changes: 52 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@ set(CMAKE_CXX_FLAGS "-pthread -Wl,--no-as-needed -ldl")
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RElEASE)
endif ()

string(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE)

if (${BUILD_TYPE} STREQUAL DEBUG)
set(LIB_BUILD_TYPE DEBUG)
elseif (${BUILD_TYPE} STREQUAL MINSIZEREL)
set(LIB_BUILD_TYPE MINSIZEREL)
elseif (${BUILD_TYPE} STREQUAL RELWITHDEBINFO)
set(LIB_BUILD_TYPE RELWITHDEBINFO)
else ()
set(LIB_BUILD_TYPE RElEASE)
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
endif ()

set(EP_BASE_SUFFIX "buildtrees")
set_property(DIRECTORY PROPERTY EP_BASE ${CMAKE_CURRENT_SOURCE_DIR}/${EP_BASE_SUFFIX})
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/modules/")
Expand Down Expand Up @@ -49,6 +66,7 @@ ExternalProject_Add(gtest
1
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${STAGED_INSTALL_PREFIX}
-DCMAKE_BUILD_TYPE=${LIB_BUILD_TYPE}
BUILD_ALWAYS
1
BUILD_COMMAND
Expand Down Expand Up @@ -80,14 +98,21 @@ ExternalProject_Add(gflags
1
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${STAGED_INSTALL_PREFIX}
-DCMAKE_BUILD_TYPE=${LIB_BUILD_TYPE}
-DGFLAGS_NAMESPACE=gflags
-DBUILD_STATIC_LIBS=ON
-DBUILD_SHARED_LIBS=OFF
BUILD_COMMAND
make -j${CPU_CORE}
)

set(GFLAGS_LIBRARY ${INSTALL_LIBDIR}/libgflags.a)
if (${LIB_BUILD_TYPE} STREQUAL DEBUG)
set(LIB_GFLAGS libgflags_debug.a)
else ()
set(LIB_GFLAGS libgflags.a)
endif ()

set(GFLAGS_LIBRARY ${INSTALL_LIBDIR}/LIB_GFLAGS)
set(GFLAGS_INCLUDE_DIR ${INSTALL_INCLUDEDIR})

ExternalProject_Add(unwind
Expand Down Expand Up @@ -141,6 +166,7 @@ ExternalProject_Add(glog
1
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${STAGED_INSTALL_PREFIX}
-DCMAKE_BUILD_TYPE=${LIB_BUILD_TYPE}
-DWITH_GFLAGS=ON
-DBUILD_TESTING=OFF
-DBUILD_SHARED_LIBS=OFF
Expand All @@ -149,7 +175,14 @@ ExternalProject_Add(glog
BUILD_COMMAND
make -j${CPU_CORE}
)
set(GLOG_LIBRARY ${INSTALL_LIBDIR}/libglog.a)

if (${LIB_BUILD_TYPE} STREQUAL DEBUG)
set(LIB_GLOG libglogd.a)
else ()
set(LIB_GLOG libglog.a)
endif ()

set(GLOG_LIBRARY ${INSTALL_LIBDIR}/${LIB_GLOG})
set(GLOG_INCLUDE_DIR ${INSTALL_INCLUDEDIR})

ExternalProject_Add(snappy
Expand All @@ -170,6 +203,7 @@ ExternalProject_Add(snappy
1
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${STAGED_INSTALL_PREFIX}
-DCMAKE_BUILD_TYPE=${LIB_BUILD_TYPE}
-DSNAPPY_BUILD_TESTS=OFF
-DBUILD_STATIC_LIBS=ON
-DBUILD_SHARED_LIBS=OFF
Expand Down Expand Up @@ -206,6 +240,7 @@ ExternalProject_Add(zstd
build/cmake
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${STAGED_INSTALL_PREFIX}
-DCMAKE_BUILD_TYPE=${LIB_BUILD_TYPE}
-DBUILD_TESTING=OFF
-DZSTD_BUILD_STATIC=ON
-DZSTD_BUILD_SHARED=OFF
Expand Down Expand Up @@ -242,6 +277,7 @@ ExternalProject_Add(lz4
build/cmake
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${STAGED_INSTALL_PREFIX}
-DCMAKE_BUILD_TYPE=${LIB_BUILD_TYPE}
-DBUILD_TESTING=OFF
-DBUILD_STATIC_LIBS=ON
-DBUILD_SHARED_LIBS=OFF
Expand Down Expand Up @@ -276,6 +312,7 @@ ExternalProject_Add(zlib
1
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${STAGED_INSTALL_PREFIX}
-DCMAKE_BUILD_TYPE=${LIB_BUILD_TYPE}
BUILD_ALWAYS
1
BUILD_COMMAND
Expand Down Expand Up @@ -304,6 +341,7 @@ ExternalProject_Add(gperftools
1
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${STAGED_INSTALL_PREFIX}
-DCMAKE_BUILD_TYPE=${LIB_BUILD_TYPE}
-DGPERFTOOLS_BUILD_STATIC=ON
-DEFAULT_BUILD_MINIMAL=ON
BUILD_COMMAND
Expand Down Expand Up @@ -369,6 +407,7 @@ ExternalProject_Add(protobuf
cmake
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${STAGED_INSTALL_PREFIX}
-DCMAKE_BUILD_TYPE=${LIB_BUILD_TYPE}
-DBUILD_SHARED_LIBS=FALSE
-Dprotobuf_BUILD_TESTS=FALSE
BUILD_IN_SOURCE
Expand All @@ -379,8 +418,13 @@ ExternalProject_Add(protobuf
make -j${CPU_CORE}
)

if (${LIB_BUILD_TYPE} STREQUAL DEBUG)
set(LIB_PROTOBUF libprotobufd.a)
else ()
set(LIB_PROTOBUF libprotobuf.a)
endif ()
set(PROTOBUF_INCLUDE_DIR ${INSTALL_INCLUDEDIR})
set(PROTOBUF_LIBRARY ${INSTALL_LIBDIR}/libprotobuf.a)
set(PROTOBUF_LIBRARY ${INSTALL_LIBDIR}/LIB_PROTOBUF)
set(PROTOBUF_PROTOC ${STAGED_INSTALL_PREFIX}/bin/protoc)

ExternalProject_Add(rocksdb
Expand Down Expand Up @@ -412,6 +456,8 @@ ExternalProject_Add(rocksdb
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${STAGED_INSTALL_PREFIX}
-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
-DCMAKE_BUILD_TYPE=${LIB_BUILD_TYPE}
-DUSE_RTTI=1
-DWITH_BENCHMARK=OFF
-DWITH_BENCHMARK_TOOLS=OFF
-DWITH_TOOLS=OFF
Expand Down Expand Up @@ -518,10 +564,10 @@ target_link_libraries(${PROJECT_NAME}
blackwidow
pink
slash
libglog.a
${LIB_GLOG}
librocksdb.a
libprotobuf.a
libgflags.a
${LIB_PROTOBUF}
${LIB_GFLAGS}
libsnappy.a
libzstd.a
liblz4.a
Expand Down

0 comments on commit abc94cf

Please sign in to comment.