Przeglądaj źródła

Fix linking errors

Eric Ramat 7 lat temu
rodzic
commit
f34cf250ed

+ 22 - 0
CMakeLists.txt

@@ -142,6 +142,28 @@ ELSE(UNIX)
   INSTALL(FILES "COPYING" DESTINATION "${ARTIS_SHARE_DIRS}" RENAME "CopyRight.txt")
 ENDIF(UNIX)
 
+#
+# Add sources for a target
+# add_sources(<target> <source1> [<source2> ...])
+#
+function(add_sources target)
+  get_property(prop_defined GLOBAL PROPERTY ${target}_SRCS DEFINED)
+  if(NOT prop_defined)
+    define_property(GLOBAL PROPERTY ${target}_SRCS
+      BRIEF_DOCS "Sources for the ${target} target"
+      FULL_DOCS "List of source files for the ${target} target")
+  endif()
+
+  set(SRCS)
+  foreach(src ${ARGN})
+    if(NOT IS_ABSOLUTE "${src}")
+      get_filename_component(src "${src}" ABSOLUTE)
+    endif()
+    list(APPEND SRCS "${src}")
+  endforeach()
+  set_property(GLOBAL APPEND PROPERTY "${target}_SRCS" "${SRCS}")
+endfunction()
+
 #
  # Browse the src subdirectory
 #

+ 8 - 3
src/artis/CMakeLists.txt

@@ -1,16 +1,21 @@
+INCLUDE_DIRECTORIES(
+  ${CMAKE_SOURCE_DIR}/src)
+
 ADD_SUBDIRECTORY(kernel)
 ADD_SUBDIRECTORY(observer)
 ADD_SUBDIRECTORY(utils)
 
-add_library(artis-lib SHARED lib.hpp lib.cpp)
+add_sources(artis-lib lib.hpp lib.cpp)
+get_property(artis-lib_SRCS GLOBAL PROPERTY artis-lib_SRCS)
+
+add_library(artis-lib SHARED ${artis-lib_SRCS})
 
 set_target_properties(artis-lib PROPERTIES
   VERSION 0
   OUTPUT_NAME "artis-${ARTIS_VERSION_SHORT}"
   CLEAN_DIRECT_OUTPUT 1)
 
-target_link_libraries(artis-lib artis-kernel artis-observer artis-utils
-  ${Boost_LIBRARIES})
+target_link_libraries(artis-lib ${Boost_LIBRARIES})
 
 install(TARGETS artis-lib RUNTIME DESTINATION bin LIBRARY DESTINATION
   lib ARCHIVE DESTINATION lib)

+ 2 - 8
src/artis/kernel/CMakeLists.txt

@@ -10,12 +10,6 @@ SET(ARTIS_KERNEL_HPP AbstractAtomicModel.hpp
 
 SET(ARTIS_KERNEL_CPP Simulator.cpp Builder.cpp)
 
-ADD_LIBRARY(artis-kernel SHARED ${ARTIS_KERNEL_HPP}
-  ${ARTIS_KERNEL_CPP})
-TARGET_LINK_LIBRARIES(artis-kernel artis-observer artis-utils)
+ADD_SOURCES(artis-lib ${ARTIS_KERNEL_HPP} ${ARTIS_KERNEL_CPP})
 
-INSTALL(FILES ${ARTIS_KERNEL_HPP} DESTINATION
-  ${ARTIS_INCLUDE_DIRS}/kernel)
-
-INSTALL(TARGETS artis-kernel RUNTIME DESTINATION bin LIBRARY DESTINATION
-  lib ARCHIVE DESTINATION lib)
+INSTALL(FILES ${ARTIS_KERNEL_HPP} DESTINATION ${ARTIS_INCLUDE_DIRS}/kernel)

+ 1 - 7
src/artis/observer/CMakeLists.txt

@@ -7,13 +7,7 @@ SET(ARTIS_OBSERVER_HPP Observer.hpp Output.hpp View.hpp)
 
 SET(ARTIS_OBSERVER_CPP Observer.cpp Output.cpp View.cpp)
 
-ADD_LIBRARY(artis-observer SHARED
-  ${ARTIS_OBSERVER_HPP}
-  ${ARTIS_OBSERVER_CPP})
-TARGET_LINK_LIBRARIES(artis-observer )
+ADD_SOURCES(artis-lib ${ARTIS_OBSERVER_HPP} ${ARTIS_OBSERVER_CPP})
 
 INSTALL(FILES ${ARTIS_OBSERVER_HPP} DESTINATION
   ${ARTIS_INCLUDE_DIRS}/observer)
-
-INSTALL(TARGETS artis-observer RUNTIME DESTINATION bin LIBRARY DESTINATION
-  lib ARCHIVE DESTINATION lib)

+ 1 - 6
src/artis/utils/CMakeLists.txt

@@ -10,11 +10,6 @@ SET(ARTIS_UTILS_CPP DateTime.cpp ParametersReader.cpp)
 SET(ARTIS_UTILS_HPP DateTime.hpp DoubleTime.hpp Exception.hpp
   ParametersReader.hpp Time.hpp Trace.hpp)
 
-ADD_LIBRARY(artis-utils SHARED ${ARTIS_UTILS_CPP} ${ARTIS_UTILS_HPP})
-
-TARGET_LINK_LIBRARIES(artis-utils ${Boost_LIBRARIES})
+ADD_SOURCES(artis-lib ${ARTIS_UTILS_CPP} ${ARTIS_UTILS_HPP})
 
 INSTALL(FILES ${ARTIS_UTILS_HPP} DESTINATION ${ARTIS_INCLUDE_DIRS}/utils)
-
-INSTALL(TARGETS artis-utils RUNTIME DESTINATION bin LIBRARY DESTINATION
-  lib ARCHIVE DESTINATION lib)

+ 9 - 0
src/artis/utils/DateTime.hpp

@@ -310,6 +310,15 @@ public:
     static void currentDate(long& year,
                             long& month,
                             long& day);
+
+    static void format_date(const std::string& str, std::string& date)
+    {
+        std::vector < std::string > list;
+
+        boost::split(list, str, boost::is_any_of("-/"));
+        date = (boost::format("%1%/%2%/%3%") % list[2] % list[1] %
+                list[0]).str();
+    }
 };
 
 } }

+ 2 - 4
src/test/CMakeLists.txt

@@ -6,14 +6,12 @@ LINK_DIRECTORIES()
 
 ADD_EXECUTABLE(artis-tests test.cpp)
 
-TARGET_LINK_LIBRARIES(artis-tests artis-kernel artis-observer artis-utils
-  ${Boost_LIBRARIES})
+TARGET_LINK_LIBRARIES(artis-tests artis-lib ${Boost_LIBRARIES})
 
 INSTALL(TARGETS artis-tests DESTINATION bin)
 
 ADD_EXECUTABLE(artis-meta test2.cpp)
 
-TARGET_LINK_LIBRARIES(artis-meta artis-kernel artis-observer artis-utils
-  ${Boost_LIBRARIES})
+TARGET_LINK_LIBRARIES(artis-meta artis-lib ${Boost_LIBRARIES})
 
 INSTALL(TARGETS artis-meta DESTINATION bin)