Skip to content

Commit 370f9dc

Browse files
committed
Better CMakeLists.txt
1 parent 60f1e87 commit 370f9dc

File tree

3 files changed

+83
-47
lines changed

3 files changed

+83
-47
lines changed

CMakeLists.txt

Lines changed: 21 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,18 @@ project(grive)
22

33
cmake_minimum_required(VERSION 2.8)
44

5-
include(FindOpenSSL)
5+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
66

7-
###############################################################################
8-
# finding cppunit
9-
###############################################################################
10-
find_path( CPPUNIT_INCLUDE_DIR cppunit/TestFixture.h /usr/include
11-
/usr/local/include
12-
${CPPUNIT_PREFIX}/include )
13-
find_library( CPPUNIT_LIBRARY_DEBUG NAMES cppunit cppunit_dll
14-
PATHS /usr/lib
15-
/usr/lib64
16-
/usr/local/lib
17-
/usr/local/lib64
18-
${CPPUNIT_PREFIX}/lib
19-
PATH_SUFFIXES debug )
7+
find_package(OpenSSL REQUIRED)
8+
find_package(CppUnit REQUIRED)
9+
find_package(JSONC REQUIRED)
10+
find_package(CURL REQUIRED)
2011

21-
find_library( CPPUNIT_LIBRARY_RELEASE NAMES cppunit cppunit_dll
22-
PATHS /usr/lib
23-
/usr/lib64
24-
/usr/local/lib
25-
/usr/local/lib64
26-
${CPPUNIT_PREFIX}/lib
27-
PATH_SUFFIXES release )
28-
29-
set( CPPUNIT_LIBRARY debug ${CPPUNIT_LIBRARY_DEBUG}
30-
optimized ${CPPUNIT_LIBRARY_RELEASE} )
31-
32-
if ( CPPUNIT_INCLUDE_DIR AND CPPUNIT_LIBRARY )
33-
message( STATUS "found cppunit" )
34-
set( CPPUNIT_FOUND TRUE )
35-
set( OPT_INCS ${CPPUNIT_INCLUDE_DIR} )
36-
endif ( CPPUNIT_INCLUDE_DIR AND CPPUNIT_LIBRARY )
37-
38-
###############################################################################
12+
set( OPT_INCS ${CPPUNIT_INCLUDE_DIR} )
3913

4014
include_directories(
4115
${grive_SOURCE_DIR}/src
42-
${OPT_INCS}
16+
${OPT_INCS}
4317
)
4418

4519
add_executable( grive
@@ -56,24 +30,24 @@ add_executable( grive
5630
)
5731

5832
target_link_libraries( grive
59-
curl
60-
json
33+
${CURL_LIBRARIES}
34+
${JSONC_LIBRARY}
6135
${OPENSSL_LIBRARIES}
6236
)
6337

64-
if ( CPPUNIT_FOUND )
38+
IF ( CPPUNIT_FOUND )
6539

66-
add_executable( unittest
67-
test/UnitTest.cc
68-
src/util/DateTime.cc
69-
test/util/DateTimeTest.cc
70-
test/util/FunctionTest.cc
71-
)
40+
add_executable( unittest
41+
test/UnitTest.cc
42+
src/util/DateTime.cc
43+
test/util/DateTimeTest.cc
44+
test/util/FunctionTest.cc
45+
)
7246

73-
target_link_libraries( unittest
74-
${CPPUNIT_LIBRARY}
75-
)
47+
target_link_libraries( unittest
48+
${CPPUNIT_LIBRARY}
49+
)
7650

77-
else ( CPPUNIT_FOUND )
51+
ELSE ( CPPUNIT_FOUND )
7852
message( STATUS "skip building unittest" )
79-
endif ( CPPUNIT_FOUND )
53+
ENDIF ( CPPUNIT_FOUND )

cmake/Modules/FindCppUnit.cmake

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# - Find CppUnit
2+
# http://root.cern.ch/viewvc/trunk/cint/reflex/cmake/modules/FindCppUnit.cmake
3+
#
4+
# This module finds an installed CppUnit package.
5+
#
6+
# It sets the following variables:
7+
# CPPUNIT_FOUND - Set to false, or undefined, if CppUnit isn't found.
8+
# CPPUNIT_INCLUDE_DIR - The CppUnit include directory.
9+
# CPPUNIT_LIBRARY - The CppUnit library to link against.
10+
11+
FIND_PATH(CPPUNIT_INCLUDE_DIR cppunit/Test.h)
12+
FIND_LIBRARY(CPPUNIT_LIBRARY NAMES cppunit)
13+
14+
IF (CPPUNIT_INCLUDE_DIR AND CPPUNIT_LIBRARY)
15+
SET(CPPUNIT_FOUND TRUE)
16+
ENDIF (CPPUNIT_INCLUDE_DIR AND CPPUNIT_LIBRARY)
17+
18+
IF (CPPUNIT_FOUND)
19+
20+
# show which CppUnit was found only if not quiet
21+
IF (NOT CppUnit_FIND_QUIETLY)
22+
MESSAGE(STATUS "Found CppUnit: ${CPPUNIT_LIBRARY}")
23+
ENDIF (NOT CppUnit_FIND_QUIETLY)
24+
25+
ELSE (CPPUNIT_FOUND)
26+
27+
# fatal error if CppUnit is required but not found
28+
IF (CppUnit_FIND_REQUIRED)
29+
MESSAGE(FATAL_ERROR "Could not find CppUnit")
30+
ENDIF (CppUnit_FIND_REQUIRED)
31+
32+
ENDIF (CPPUNIT_FOUND)

cmake/Modules/FindJSONC.cmake

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# - Find JSON-C
2+
# This module finds an installed JSON-C package.
3+
#
4+
# It sets the following variables:
5+
# JSONC_FOUND - Set to false, or undefined, if JSON-C isn't found.
6+
# JSONC_INCLUDE_DIR - The JSON-C include directory.
7+
# JSONC_LIBRARY - The JSON-C library to link against.
8+
9+
FIND_PATH(JSONC_INCLUDE_DIR json/json.h)
10+
FIND_LIBRARY(JSONC_LIBRARY NAMES json)
11+
12+
IF (JSONC_INCLUDE_DIR AND JSONC_LIBRARY)
13+
SET(JSONC_FOUND TRUE)
14+
ENDIF (JSONC_INCLUDE_DIR AND JSONC_LIBRARY)
15+
16+
IF (JSONC_FOUND)
17+
18+
# show which JSON-C was found only if not quiet
19+
IF (NOT JSONC_FIND_QUIETLY)
20+
MESSAGE(STATUS "Found JSON-C: ${JSONC_LIBRARY}")
21+
ENDIF (NOT JSONC_FIND_QUIETLY)
22+
23+
ELSE (JSONC_FOUND)
24+
25+
# fatal error if JSON-C is required but not found
26+
IF (JSONC_FIND_REQUIRED)
27+
MESSAGE(FATAL_ERROR "Could not find JSON-C")
28+
ENDIF (JSONC_FIND_REQUIRED)
29+
30+
ENDIF (JSONC_FOUND)

0 commit comments

Comments
 (0)