Browse Source

build: enhance cmake build options

legacy
Dnomd343 2 years ago
parent
commit
a37f49f415
  1. 13
      CMakeLists.txt
  2. 8
      src/klotski_core/CMakeLists.txt
  3. 33
      test/CMakeLists.txt
  4. 0
      test/basic/all_cases.cc
  5. 0
      test/basic/utils.cc
  6. 0
      test/codec/common_code.cc
  7. 0
      test/codec/raw_code.cc
  8. 0
      test/codec/short_code.cc

13
CMakeLists.txt

@ -1,7 +1,6 @@
cmake_minimum_required(VERSION 3.0) cmake_minimum_required(VERSION 3.0)
project(klotski) project(klotski)
#set(CMAKE_CXX_STANDARD 14)
if(NOT CMAKE_BUILD_TYPE) if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release) set(CMAKE_BUILD_TYPE Release)
@ -9,6 +8,8 @@ endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
################################################################################
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
@ -18,15 +19,15 @@ file(
FOLLOW_SYMLINK_CHAIN FOLLOW_SYMLINK_CHAIN
) )
# TODO: only in libklotski.so
add_compile_options(-fPIC)
add_subdirectory(src) add_subdirectory(src)
################################################ ################################################################################
option(CORE_TEST "build test for klotski core" ON)
#if (CORE_TEST)
include_directories(third_party/googletest/googletest/include) include_directories(third_party/googletest/googletest/include)
add_subdirectory(third_party/googletest EXCLUDE_FROM_ALL) add_subdirectory(third_party/googletest EXCLUDE_FROM_ALL)
add_subdirectory(test) add_subdirectory(test)
#endif()
################################################ ################################################################################

8
src/klotski_core/CMakeLists.txt

@ -6,6 +6,13 @@ project(klotski-core VERSION 0.1.2 LANGUAGES CXX)
################################################################################ ################################################################################
option(BUILD_DYN "build shared klotski core library" OFF)
if (BUILD_DYN)
add_compile_options(-fPIC)
endif()
################################################################################
macro(git_tag _tag) macro(git_tag _tag)
find_package(Git QUIET) find_package(Git QUIET)
if (GIT_FOUND) if (GIT_FOUND)
@ -122,7 +129,6 @@ list(APPEND OBJS $<TARGET_OBJECTS:benchmark>)
################################################################################ ################################################################################
option(BUILD_DYN "build shared klotski core library" OFF)
if (BUILD_DYN) if (BUILD_DYN)
add_library(klotski SHARED ${OBJS}) add_library(klotski SHARED ${OBJS})
else() else()

33
test/CMakeLists.txt

@ -1,32 +1,47 @@
cmake_minimum_required(VERSION 3.0) cmake_minimum_required(VERSION 3.0)
################################################################ ################################################################################
enable_testing() enable_testing()
set(TEST_DEPS gtest gtest_main klotski) set(TEST_DEPS gtest gtest_main klotski)
################################################################ ################################################################################
unset(CMAKE_ARCHIVE_OUTPUT_DIRECTORY) unset(CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
include_directories(../third_party/md5) include_directories(../third_party/md5)
add_library(md5 STATIC ../third_party/md5/md5.cpp) add_library(md5 STATIC ../third_party/md5/md5.cpp)
################################################################ ################################################################################
include_directories(../src/klotski_core/utils) include_directories(../src/klotski_core/utils)
include_directories(../src/klotski_core/all_cases) include_directories(../src/klotski_core/all_cases)
set(TEST_BASIC_SRC utils.cc all_cases.cc)
list(TRANSFORM TEST_BASIC_SRC PREPEND "basic/")
add_executable(test_basic ${TEST_BASIC_SRC})
#add_executable(test_basic
# basic/utils.cc
# basic/all_cases.cc
#)
target_link_libraries(test_basic PUBLIC ${TEST_DEPS} md5)
add_test(NAME basic COMMAND test_basic)
################################################################################
include_directories(../src/klotski_core/raw_code) include_directories(../src/klotski_core/raw_code)
include_directories(../src/klotski_core/short_code) include_directories(../src/klotski_core/short_code)
include_directories(../src/klotski_core/common_code) include_directories(../src/klotski_core/common_code)
add_executable(test_basic utils.cc all_cases.cc) set(TEST_CODEC_SRC short_code.cc raw_code.cc common_code.cc)
target_link_libraries(test_basic PUBLIC ${TEST_DEPS} md5) list(TRANSFORM TEST_CODEC_SRC PREPEND "codec/")
add_test(NAME basic COMMAND test_basic) add_executable(test_codec ${TEST_CODEC_SRC})
#add_executable(test_codec
add_executable(test_codec short_code.cc raw_code.cc common_code.cc) # codec/short_code.cc
# codec/common_code.cc
# codec/raw_code.cc
#)
target_link_libraries(test_codec ${TEST_DEPS}) target_link_libraries(test_codec ${TEST_DEPS})
add_test(NAME codec COMMAND test_codec) add_test(NAME codec COMMAND test_codec)
################################################################ ################################################################################

0
test/all_cases.cc → test/basic/all_cases.cc

0
test/utils.cc → test/basic/utils.cc

0
test/common_code.cc → test/codec/common_code.cc

0
test/raw_code.cc → test/codec/raw_code.cc

0
test/short_code.cc → test/codec/short_code.cc

Loading…
Cancel
Save