cmake: simplifications

* All options reside in the top-level CMakeLists.txt file
* No need to find gmio library, just add "gmio" as a target dependency
* In tests, link to gmio library instead of recompiling needed source code
This commit is contained in:
Hugues Delorme 2015-09-01 18:20:31 +02:00
parent 9fa87e8b20
commit 56bb6d8e65
4 changed files with 29 additions and 46 deletions

View File

@ -27,17 +27,20 @@ set(GMIO_VERSION_PATCH 0)
set(GMIO_VERSION set(GMIO_VERSION
${GMIO_VERSION_MAJOR}.${GMIO_VERSION_MINOR}.${GMIO_VERSION_PATCH}) ${GMIO_VERSION_MAJOR}.${GMIO_VERSION_MINOR}.${GMIO_VERSION_PATCH})
#set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) # Options
option(GMIO_BUILD_STRICT_C90 "Build gmio library(and tests) with strict conformance to C90 standard" OFF)
option(GMIO_BUILD_SHARED_LIBS "Build gmio as a shared library (DLL)" OFF)
option(GMIO_BUILD_BENCHMARKS "Build performance benchmarks for the gmio library" OFF)
if(GMIO_BUILD_BENCHMARKS)
option(GMIO_BUILD_BENCHMARK_ASSIMP "Build benchmark for Assimp" ON)
option(GMIO_BUILD_BENCHMARK_OPENCASCADE "Build benchmark for OpenCascade" ON)
endif()
# Detect Clang # Detect Clang
if (CMAKE_C_COMPILER MATCHES ".*clang") if (CMAKE_C_COMPILER MATCHES ".*clang")
set(CMAKE_COMPILER_IS_CLANG 1) set(CMAKE_COMPILER_IS_CLANG 1)
endif () endif ()
# Options
option(GMIO_BUILD_STRICT_C90 "Build gmio library(and tests) with strict conformance to C90 standard" OFF)
option(GMIO_BUILD_BENCHMARKS "Build performance benchmarks for the gmio library" OFF)
# Find bit size of the target architecture # Find bit size of the target architecture
math(EXPR GMIO_TARGET_ARCH_BIT_SIZE "8 * ${CMAKE_SIZEOF_VOID_P}") math(EXPR GMIO_TARGET_ARCH_BIT_SIZE "8 * ${CMAKE_SIZEOF_VOID_P}")
@ -182,6 +185,8 @@ if(MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Oi") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Oi")
endif() endif()
#set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# Sub-directories # Sub-directories
add_subdirectory(src) add_subdirectory(src)
add_subdirectory(tests) add_subdirectory(tests)

View File

@ -13,10 +13,6 @@
## "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html". ## "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
############################################################################# #############################################################################
# Options
option(GMIO_BUILD_BENCHMARK_ASSIMP "Build benchmark for Assimp" ON)
option(GMIO_BUILD_BENCHMARK_OPENCASCADE "Build benchmark for OpenCascade" ON)
set(ASSIMP_DIR ${CMAKE_SOURCE_DIR} CACHE PATH "Directory where the Assimp library resides") set(ASSIMP_DIR ${CMAKE_SOURCE_DIR} CACHE PATH "Directory where the Assimp library resides")
set(OPENCASCADE_DIR ${CMAKE_SOURCE_DIR} CACHE PATH "Directory where the OpenCascade library resides") set(OPENCASCADE_DIR ${CMAKE_SOURCE_DIR} CACHE PATH "Directory where the OpenCascade library resides")
@ -26,14 +22,8 @@ set(COMMONS_FILES ${COMMONS_FILES})
include_directories(${CMAKE_SOURCE_DIR}/src) include_directories(${CMAKE_SOURCE_DIR}/src)
include_directories(${CMAKE_BINARY_DIR}/src/gmio_core) # For cmake generated headers include_directories(${CMAKE_BINARY_DIR}/src/gmio_core) # For cmake generated headers
link_directories(${CMAKE_BINARY_DIR}/src) link_libraries(gmio)
find_library(GMIO_LIBPATH gmio HINTS ${CMAKE_BINARY_DIR}/src) if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
get_filename_component(GMIO_LIB_BASENAME ${GMIO_LIBPATH} NAME_WE)
if ("${GMIO_LIB_BASENAME}" STREQUAL "")
set(GMIO_LIB_BASENAME "gmio")
endif()
link_libraries(${GMIO_LIB_BASENAME})
if(CMAKE_COMPILER_IS_GNUCC)
link_libraries(m) # -lm link_libraries(m) # -lm
endif() endif()

View File

@ -13,10 +13,6 @@
## "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html". ## "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
############################################################################# #############################################################################
# Options
option(GMIO_BUILD_SHARED_LIBS "Build gmio as a shared library (DLL)" OFF)
option(GMIO_BUILD_LIBSTL "Build also the libSTL module" ON)
# Add core source files # Add core source files
file(GLOB GMIO_SRC_FILES gmio_core/* gmio_core/internal/*) file(GLOB GMIO_SRC_FILES gmio_core/* gmio_core/internal/*)
set(GMIO_SRC_FILES ${GMIO_SRC_FILES}) set(GMIO_SRC_FILES ${GMIO_SRC_FILES})
@ -43,7 +39,6 @@ file(GLOB GMIO_CORE_HEADERS gmio_core/*.h)
install(FILES ${GMIO_CORE_HEADERS} DESTINATION include/gmio_core) install(FILES ${GMIO_CORE_HEADERS} DESTINATION include/gmio_core)
# Module libSTL # Module libSTL
if(GMIO_BUILD_LIBSTL)
if(GMIO_BUILD_SHARED_LIBS) if(GMIO_BUILD_SHARED_LIBS)
add_definitions(-DGMIO_LIBSTL_DLL add_definitions(-DGMIO_LIBSTL_DLL
-DGMIO_LIBSTL_MAKE_DLL) -DGMIO_LIBSTL_MAKE_DLL)
@ -52,7 +47,6 @@ if(GMIO_BUILD_LIBSTL)
file(GLOB GMIO_LIBSTL_SRC_FILES gmio_stl/* gmio_stl/internal/*) file(GLOB GMIO_LIBSTL_SRC_FILES gmio_stl/* gmio_stl/internal/*)
set(GMIO_SRC_FILES ${GMIO_SRC_FILES} ${GMIO_LIBSTL_SRC_FILES}) set(GMIO_SRC_FILES ${GMIO_SRC_FILES} ${GMIO_LIBSTL_SRC_FILES})
endif()
file(GLOB GMIO_LIBSTL_HEADERS gmio_stl/*.h) file(GLOB GMIO_LIBSTL_HEADERS gmio_stl/*.h)
install(FILES ${GMIO_LIBSTL_HEADERS} DESTINATION include/gmio_stl) install(FILES ${GMIO_LIBSTL_HEADERS} DESTINATION include/gmio_stl)

View File

@ -17,43 +17,37 @@ enable_testing()
set(CMAKE_CTEST_COMMAND ctest -V) set(CMAKE_CTEST_COMMAND ctest -V)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}) add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
include_directories(${CMAKE_BINARY_DIR}/src/gmio_core) # For generated header files include_directories(${CMAKE_BINARY_DIR}/src/gmio_core) # For generated cmake headers
# test_internal
add_executable( add_executable(
test_internal test_internal
EXCLUDE_FROM_ALL EXCLUDE_FROM_ALL
stream_buffer.c stream_buffer.c
utils.c utils.c
test_internal.c test_internal.c)
../src/gmio_core/stream.c target_link_libraries(test_internal gmio)
../src/gmio_core/internal/string_parse.c)
# test_platform
add_executable( add_executable(
test_platform EXCLUDE_FROM_ALL test_platform.c) test_platform EXCLUDE_FROM_ALL test_platform.c)
# test_stl
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/models file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/models
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
add_executable( add_executable(
test_stl test_stl
EXCLUDE_FROM_ALL EXCLUDE_FROM_ALL
test_stl_io.c test_stl_io.c)
../src/gmio_core/buffer.c target_link_libraries(test_stl gmio)
../src/gmio_core/stream.c
../src/gmio_core/internal/string_parse.c
../src/gmio_stl/stl_format.c
../src/gmio_stl/stl_io.c
../src/gmio_stl/stla_read.c
../src/gmio_stl/stlb_read.c
../src/gmio_stl/internal/stl_rw_common.c
../src/gmio_stl/internal/stla_write.c
../src/gmio_stl/internal/stlb_byte_swap.c
../src/gmio_stl/internal/stlb_write.c)
# GCC and Clang requires lm
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG) if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
target_link_libraries(test_internal m) # -lm target_link_libraries(test_internal m) # -lm
target_link_libraries(test_stl m) # -lm target_link_libraries(test_stl m) # -lm
endif() endif()
# Declare tests
add_test(test_internal test_internal) add_test(test_internal test_internal)
add_test(test_platform test_platform) add_test(test_platform test_platform)
add_test(test_stl test_stl) add_test(test_stl test_stl)